Skip to content

Commit

Permalink
add struct republish backward incompatible test (#3833)
Browse files Browse the repository at this point in the history
* add struct republish backward incompatible test

* new unit test

* fix check

---------

Co-authored-by: WGB5445 <919603023@qq.com>
  • Loading branch information
nkysg and WGB5445 authored Jan 31, 2023
1 parent f9ba8b6 commit b5788d6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ stest = { workspace = true }
tempfile = { workspace = true }
test-helper = { workspace = true }
move-transactional-test-runner = { workspace = true }
move-binary-format = { workspace = true }

[features]
default = []
Expand Down
59 changes: 58 additions & 1 deletion executor/tests/script_function_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use starcoin_types::account_config::association_address;
use starcoin_types::transaction::Transaction;
use starcoin_vm_types::identifier::Identifier;
use starcoin_vm_types::language_storage::ModuleId;
use starcoin_vm_types::transaction::{Package, Script, ScriptFunction, TransactionPayload};
use starcoin_vm_types::transaction::{
Package, Script, ScriptFunction, TransactionPayload, TransactionStatus,
};
use starcoin_vm_types::vm_status::KeptVMStatus;
use test_helper::executor::{
compile_ir_script, compile_modules_with_address, compile_script, execute_and_apply,
Expand Down Expand Up @@ -256,3 +258,58 @@ fn test_execute_script_verify() -> Result<()> {
);
Ok(())
}

#[stest::test]
fn test_struct_republish_backward_incompatible() -> Result<()> {
let (chain_state, net) = prepare_genesis();
let module_source = r#"
module 0xA550C18::A {
struct R { f: bool}
struct R2 { f: R}
}
"#;
let compiled_module = compile_modules_with_address(association_address(), module_source)
.pop()
.unwrap();

let txn = create_signed_txn_with_association_account(
TransactionPayload::Package(Package::new_with_module(compiled_module).unwrap()),
0,
DEFAULT_MAX_GAS_AMOUNT,
1,
1,
&net,
);

//publish the module
let output = execute_and_apply(&chain_state, Transaction::UserTransaction(txn));
assert_eq!(KeptVMStatus::Executed, output.status().status().unwrap());

let module_source2 = r#"
module 0xA550C18::A {
native struct R;
struct R2 { f: R}
}
"#;
let compiled_module2 = compile_modules_with_address(association_address(), module_source2)
.pop()
.unwrap();

let txn2 = create_signed_txn_with_association_account(
TransactionPayload::Package(Package::new_with_module(compiled_module2).unwrap()),
1,
DEFAULT_MAX_GAS_AMOUNT,
1,
1,
&net,
);

//publish the module
let output2 = execute_and_apply(&chain_state, Transaction::UserTransaction(txn2));
assert_eq!(
TransactionStatus::Keep(KeptVMStatus::MiscellaneousError),
output2.status().clone()
);

Ok(())
}

0 comments on commit b5788d6

Please sign in to comment.