Skip to content

Commit

Permalink
more test debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
snissn committed Dec 4, 2024
1 parent 3dfe377 commit ab808a2
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 23 deletions.
61 changes: 54 additions & 7 deletions actors/evm/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,22 +205,70 @@ fn test_push_last_byte() {

#[test]
fn transient_storage() {
let bytecode = hex::decode(include_str!("contracts/TransientStorageTest.bin")).unwrap();
transient_storage_test(bytecode);
let transient_storage_bytecode =
hex::decode(include_str!("contracts/TransientStorageTest.bin")).unwrap();
let nested_storage_bytecode =
hex::decode(include_str!("contracts/NestedContract.bin")).unwrap();
let reentrant_storage_bytecode =
hex::decode(include_str!("contracts/ReentrantContract.bin")).unwrap();
transient_storage_test(
transient_storage_bytecode,
nested_storage_bytecode,
reentrant_storage_bytecode,
);
}

fn transient_storage_test(bytecode: Vec<u8>) {
let contract = Address::new_id(100);
fn transient_storage_test(
mut transient_storage_bytecode: Vec<u8>,
nested_contract_bytecode: Vec<u8>,
reentrant_contract_bytecode: Vec<u8>,
) {
let nested_contract = Address::new_id(100);
let _rt_nested_contract = util::init_construct_and_verify(nested_contract_bytecode, |rt| {
rt.actor_code_cids.borrow_mut().insert(nested_contract, *EVM_ACTOR_CODE_ID);
rt.set_origin(nested_contract);
});

let rt = util::init_construct_and_verify(bytecode, |rt| {
let reentrant_contract = Address::new_id(101);
let _rt_reentrant_contract =
util::init_construct_and_verify(reentrant_contract_bytecode, |rt| {
rt.actor_code_cids.borrow_mut().insert(reentrant_contract, *EVM_ACTOR_CODE_ID);
rt.set_origin(reentrant_contract);
});

let mut arg_nested_address = vec![0u8; 32];
arg_nested_address[12] = 0xff; // it's an ID address, so we enable the flag
arg_nested_address[31] = 100; // the owner address
transient_storage_bytecode.append(&mut arg_nested_address);

let mut arg_reentrant_address = vec![0u8; 32];
arg_reentrant_address[12] = 0xff; // it's an ID address, so we enable the flag
arg_reentrant_address[31] = 101; // the owner address
transient_storage_bytecode.append(&mut arg_reentrant_address);

let contract = Address::new_id(102);
let rt = util::init_construct_and_verify(transient_storage_bytecode, |rt| {
rt.actor_code_cids.borrow_mut().insert(contract, *EVM_ACTOR_CODE_ID);
rt.set_origin(contract);
});

let mut solidity_params = vec![];

solidity_params.extend_from_slice(&hex::decode("23d74628").unwrap()); // function selector, "runTests()"
let _result = util::invoke_contract(&rt, &solidity_params);

// Setup for testing that the transient storage data clears when a new transaction occurs
let mut solidity_params_test_cleared = vec![];
solidity_params_test_cleared.extend_from_slice(&hex::decode("54e84d1b").unwrap()); // function selector, "testLifecycleValidationSubsequentTransaction()"
//
// We expect this to fail because no changes are made
util::invoke_contract_expect_fail(&rt, &solidity_params_test_cleared);

//use a new address for our calling context
//This will cause the transient storage data to reset because the transient storage lifecycle value has changed
let new_context = Address::new_id(200);
rt.set_origin(new_context);

util::invoke_contract(&rt, &solidity_params_test_cleared);
}

#[test]
Expand Down Expand Up @@ -249,4 +297,3 @@ fn mcopy_test(bytecode: Vec<u8>) {
let result = util::invoke_contract(&rt, &solidity_params);
assert_eq!(&*result, &*encoded_testdata);
}

2 changes: 1 addition & 1 deletion actors/evm/tests/contracts/ReentrantContract.bin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6080604052348015600e575f5ffd5b5061023e8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b6100476004803603810190610042919061011f565b61005d565b6040516100549190610177565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101ea565b60405180910390fd5b7fdf046168b5f7ac3c45f3a96da829a21850b98827faca4a9853a9d244e461692a60016040516100d59190610177565b60405180910390a1600191505092915050565b5f5ffd5b5f819050919050565b6100fe816100ec565b8114610108575f5ffd5b50565b5f81359050610119816100f5565b92915050565b5f5f60408385031215610135576101346100e8565b5b5f6101428582860161010b565b92505060206101538582860161010b565b9150509250929050565b5f8115159050919050565b6101718161015d565b82525050565b5f60208201905061018a5f830184610168565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f6101d4601883610190565b91506101df826101a0565b602082019050919050565b5f6020820190508181035f830152610201816101c8565b905091905056fea26469706673582212201f962b4b81dfea667fc231f5535eb3b661a369a8f5de4c2a277869f134de9dfa64736f6c634300081c0033
6080604052348015600e575f5ffd5b506102068061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b610047600480360381019061004291906100e7565b61005d565b604051610054919061013f565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101b2565b60405180910390fd5b600191505092915050565b5f5ffd5b5f819050919050565b6100c6816100b4565b81146100d0575f5ffd5b50565b5f813590506100e1816100bd565b92915050565b5f5f604083850312156100fd576100fc6100b0565b5b5f61010a858286016100d3565b925050602061011b858286016100d3565b9150509250929050565b5f8115159050919050565b61013981610125565b82525050565b5f6020820190506101525f830184610130565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f61019c601883610158565b91506101a782610168565b602082019050919050565b5f6020820190508181035f8301526101c981610190565b905091905056fea2646970667358221220446704e7e7001b2a2045094ee4fcdd0f73ab5fbba3c39686bd80ee3099c2e46c64736f6c634300081c0033
2 changes: 1 addition & 1 deletion actors/evm/tests/contracts/ReentrantContract.hex
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6080604052348015600e575f5ffd5b5061023e8061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b6100476004803603810190610042919061011f565b61005d565b6040516100549190610177565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101ea565b60405180910390fd5b7fdf046168b5f7ac3c45f3a96da829a21850b98827faca4a9853a9d244e461692a60016040516100d59190610177565b60405180910390a1600191505092915050565b5f5ffd5b5f819050919050565b6100fe816100ec565b8114610108575f5ffd5b50565b5f81359050610119816100f5565b92915050565b5f5f60408385031215610135576101346100e8565b5b5f6101428582860161010b565b92505060206101538582860161010b565b9150509250929050565b5f8115159050919050565b6101718161015d565b82525050565b5f60208201905061018a5f830184610168565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f6101d4601883610190565b91506101df826101a0565b602082019050919050565b5f6020820190508181035f830152610201816101c8565b905091905056fea26469706673582212201f962b4b81dfea667fc231f5535eb3b661a369a8f5de4c2a277869f134de9dfa64736f6c634300081c0033
6080604052348015600e575f5ffd5b506102068061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063d52aa4471461002d575b5f5ffd5b610047600480360381019061004291906100e7565b61005d565b604051610054919061013f565b60405180910390f35b5f5f835c90508281146100a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161009c906101b2565b60405180910390fd5b600191505092915050565b5f5ffd5b5f819050919050565b6100c6816100b4565b81146100d0575f5ffd5b50565b5f813590506100e1816100bd565b92915050565b5f5f604083850312156100fd576100fc6100b0565b5b5f61010a858286016100d3565b925050602061011b858286016100d3565b9150509250929050565b5f8115159050919050565b61013981610125565b82525050565b5f6020820190506101525f830184610130565b92915050565b5f82825260208201905092915050565b7f5265656e7472616e742076616c7565206d69736d6174636800000000000000005f82015250565b5f61019c601883610158565b91506101a782610168565b602082019050919050565b5f6020820190508181035f8301526101c981610190565b905091905056fea2646970667358221220446704e7e7001b2a2045094ee4fcdd0f73ab5fbba3c39686bd80ee3099c2e46c64736f6c634300081c0033
2 changes: 1 addition & 1 deletion actors/evm/tests/contracts/ReentrantContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract ReentrantContract {
}
require(storedValue == expectedValue, "Reentrant value mismatch");

emit ReentrySuccess(true);
//emit ReentrySuccess(true);
return true;
}
}
2 changes: 1 addition & 1 deletion actors/evm/tests/contracts/TransientStorageTest.abi
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"success","type":"bool"},{"indexed":false,"internalType":"string","name":"message","type":"string"}],"name":"TestResult","type":"event"},{"inputs":[{"internalType":"uint256","name":"slot","type":"uint256"}],"name":"isStorageCleared","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"runTests","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testBasicFunctionality","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testLifecycleValidation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testNestedContracts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testReentry","outputs":[],"stateMutability":"nonpayable","type":"function"}]
[{"inputs":[{"internalType":"address","name":"nestedAddress","type":"address"},{"internalType":"address","name":"reentrantAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"success","type":"bool"},{"indexed":false,"internalType":"string","name":"message","type":"string"}],"name":"TestResult","type":"event"},{"inputs":[{"internalType":"uint256","name":"slot","type":"uint256"}],"name":"isStorageCleared","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"runTests","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testBasicFunctionality","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testLifecycleValidation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testLifecycleValidationSubsequentTransaction","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testNestedContracts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"testReentry","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Loading

0 comments on commit ab808a2

Please sign in to comment.