Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add struct republish backward incompatible test #3833

Merged
merged 3 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(())
}