Skip to content

Commit

Permalink
[functional tests] allow modules published to be used in later transa…
Browse files Browse the repository at this point in the history
…ctions

As stated, this allows modules published in one transaction to be used in all later transactions.

The real problem is that the compiler takes a slice of `CompiledModule` as dependencies, but doesn't have a way to fetch one from the storage. This patch workarounds this limitation by adding modules published to an ever-growing list of dependencies for a given sequence of transactions. It should be pointed out this is a bit hacky and should be replaced by a proper implementation of fetching in the future.

Known glitch caused by this: the compiler does not differentiate two modules with same name under different addresses.
  • Loading branch information
vgao1996 authored and calibra-opensource committed Jun 26, 2019
1 parent 23ec306 commit 20abaaa
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
13 changes: 10 additions & 3 deletions language/functional_tests/src/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub fn eval(config: &GlobalConfig, transactions: &[Transaction]) -> Result<Evalu

// set up standard library
// needed to compile transaction programs
let stdlib = build_stdlib(&AccountAddress::default());
let mut deps = build_stdlib(&AccountAddress::default());

for transaction in transactions {
// get the account data of the sender
Expand All @@ -219,17 +219,24 @@ pub fn eval(config: &GlobalConfig, transactions: &[Transaction]) -> Result<Evalu

// stage 2: compile the program
res.outputs.push(EvaluationOutput::Stage(Stage::Compiler));
let compiled_program = unwrap_or_log!(compile_program(addr, &parsed_program, &stdlib), res);
let compiled_program = unwrap_or_log!(compile_program(addr, &parsed_program, &deps), res);
res.outputs
.push(EvaluationOutput::Output(format!("{:?}", compiled_program)));

// stage 3: verify the program
if !transaction.config.no_verify {
res.outputs.push(EvaluationOutput::Stage(Stage::Verifier));
unwrap_or_log!(do_verify_program(&compiled_program, &stdlib), res);
unwrap_or_log!(do_verify_program(&compiled_program, &deps), res);
res.outputs.push(EvaluationOutput::Output("".to_string()));
}

// add all modules to be published to the vec of dependencies
// TODO: currently the compiler only checks the module name when looking up a module
// it should check that both the name and address match
for m in &compiled_program.modules {
deps.push(m.clone());
}

// stage 4: execute the program
if !transaction.config.no_execute {
res.outputs.push(EvaluationOutput::Stage(Stage::Runtime));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//! account: alice
//! account: bob

//! sender: alice
modules:
module M {
public foo(x: u64): u64 {
return move(x)*2;
}

public bar(x: u64, y: u64): u64 {
return move(x) + move(y);
}
}
script:
main() {
return;
}



//! new-transaction
//! sender: alice

import {{alice}}.M;

main() {
let x: u64;
x = M.foo(3);
assert(move(x) == 6, 42);
return;
}



//! new-transaction
//! sender: bob

import {{alice}}.M;

main() {
let x: u64;
x = M.bar(1, 2);
assert(move(x) == 3, 42);
return;
}

0 comments on commit 20abaaa

Please sign in to comment.