Skip to content

Commit bca8573

Browse files
committed
wip test
1 parent 831bf1b commit bca8573

File tree

6 files changed

+150
-4
lines changed

6 files changed

+150
-4
lines changed

actors/evm/src/interpreter/instructions/call.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ pub fn call_generic<RT: Runtime>(
272272
caller: state.caller,
273273
value: state.value_received.clone(),
274274
};
275-
system
275+
eprintln!("begin delegate call");
276+
let res = system
276277
.send(
277278
&system.rt.message().receiver(),
278279
Method::InvokeContractDelegate as u64,
@@ -281,7 +282,9 @@ pub fn call_generic<RT: Runtime>(
281282
Some(effective_gas_limit(system, gas)),
282283
SendFlags::default(),
283284
)
284-
.map_err(|mut ae| ae.take_data())
285+
.map_err(|mut ae| ae.take_data());
286+
eprintln!("end delegate call");
287+
res
285288
} else {
286289
// If it doesn't have code, short-circuit and return immediately.
287290
Ok(None)

actors/evm/src/interpreter/system.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ impl<'r, RT: Runtime> System<'r, RT> {
244244
send_flags: SendFlags,
245245
) -> Result<Result<Response, ErrorNumber>, ActorError> {
246246
self.flush()?;
247+
eprintln!("begin send");
247248
let result = self.rt.send(to, method, params, value, gas_limit, send_flags);
249+
eprintln!("end send");
248250

249251
// Reload on success, and only on success.
250252
match &result {
@@ -290,6 +292,7 @@ impl<'r, RT: Runtime> System<'r, RT> {
290292

291293
self.rt.set_state_root(&new_root)?;
292294
self.saved_state_root = Some(new_root);
295+
eprintln!("flushed");
293296
Ok(())
294297
}
295298

@@ -318,6 +321,17 @@ impl<'r, RT: Runtime> System<'r, RT> {
318321
self.saved_state_root = Some(root);
319322
self.bytecode = Some(EvmBytecode::new(state.bytecode, state.bytecode_hash));
320323
self.tombstone = state.tombstone;
324+
eprintln!("reloaded");
325+
self.slots
326+
.for_each(|k, v| {
327+
eprintln!(
328+
"reloaded slot: {} = {}",
329+
hex::encode(k.to_bytes()),
330+
hex::encode(v.to_bytes()),
331+
);
332+
Ok(())
333+
})
334+
.unwrap();
321335
Ok(())
322336
}
323337

@@ -357,16 +371,32 @@ impl<'r, RT: Runtime> System<'r, RT> {
357371

358372
/// Get value of a storage key.
359373
pub fn get_storage(&mut self, key: U256) -> Result<U256, ActorError> {
360-
Ok(self
374+
let value = self
361375
.slots
362376
.get(&key)
363377
.context_code(ExitCode::USR_ILLEGAL_STATE, "failed to clear storage slot")?
364378
.cloned()
365-
.unwrap_or_default())
379+
.unwrap_or_default();
380+
381+
let whoami = self.rt.message().receiver();
382+
383+
eprintln!(
384+
"{whoami}: load {} = {}",
385+
hex::encode(key.to_bytes()),
386+
hex::encode(value.to_bytes())
387+
);
388+
Ok(value)
366389
}
367390

368391
/// Set value of a storage key.
369392
pub fn set_storage(&mut self, key: U256, value: U256) -> Result<(), ActorError> {
393+
let whoami = self.rt.message().receiver();
394+
395+
eprintln!(
396+
"{whoami}: store {} = {}",
397+
hex::encode(key.to_bytes()),
398+
hex::encode(value.to_bytes())
399+
);
370400
let changed = if value.is_zero() {
371401
self.slots
372402
.delete(&key)

integration_tests/src/tests/evm_test.rs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,109 @@ pub fn evm_staticcall_delegatecall_test(v: &dyn VM) {
725725
}
726726
}
727727

728+
#[allow(non_snake_case)]
729+
#[vm_test]
730+
pub fn evm_mint_test(v: &dyn VM) {
731+
const IMP_INITCODE: &str = include_str!("./mint_contract/imp.hex");
732+
const PROXY_INITCODE: &str = include_str!("./mint_contract/proxy.hex");
733+
734+
// Create accounts for deployment
735+
let accounts = create_accounts(v, 2, &TokenAmount::from_whole(10_000));
736+
let deployer = &accounts[0];
737+
738+
eprintln!(">> deploying impl");
739+
740+
// 1. Deploy the implementation contract
741+
let imp_bytecode = hex::decode(IMP_INITCODE).unwrap();
742+
let imp_deploy_result = v
743+
.execute_message(
744+
deployer,
745+
&EAM_ACTOR_ADDR,
746+
&TokenAmount::zero(),
747+
fil_actor_eam::Method::CreateExternal as u64,
748+
Some(serialize_ok(&fil_actor_eam::CreateExternalParams(imp_bytecode))),
749+
)
750+
.unwrap();
751+
752+
assert!(
753+
imp_deploy_result.code.is_success(),
754+
"Failed to deploy implementation contract: {}",
755+
imp_deploy_result.message
756+
);
757+
758+
let imp_return: fil_actor_eam::CreateExternalReturn = imp_deploy_result
759+
.ret
760+
.unwrap()
761+
.deserialize()
762+
.expect("Failed to decode implementation deployment results");
763+
764+
// Make sure we deployed an EVM actor
765+
assert_eq!(&v.actor(&Address::new_id(imp_return.actor_id)).unwrap().code, &*EVM_ACTOR_CODE_ID);
766+
767+
let implementation_eth_addr = imp_return.eth_address;
768+
769+
// 2. Deploy the proxy contract with implementation address in constructor
770+
let proxy_initcode_fixed = PROXY_INITCODE.replace(
771+
"606fa930c2f5eae4116ac5c1c93e1dbbe9957113",
772+
&hex::encode(implementation_eth_addr.0),
773+
);
774+
let proxy_initcode = hex::decode(proxy_initcode_fixed).unwrap();
775+
776+
eprintln!(">> deploying proxy");
777+
778+
let proxy_deploy_result = v
779+
.execute_message(
780+
deployer,
781+
&EAM_ACTOR_ADDR,
782+
&TokenAmount::zero(),
783+
fil_actor_eam::Method::CreateExternal as u64,
784+
Some(serialize_ok(&fil_actor_eam::CreateExternalParams(proxy_initcode))),
785+
)
786+
.unwrap();
787+
788+
assert!(
789+
proxy_deploy_result.code.is_success(),
790+
"Failed to deploy proxy contract: {}",
791+
proxy_deploy_result.message
792+
);
793+
794+
let proxy_return: fil_actor_eam::CreateExternalReturn = proxy_deploy_result
795+
.ret
796+
.unwrap()
797+
.deserialize()
798+
.expect("Failed to decode proxy deployment results");
799+
800+
let proxy_robust_addr = proxy_return.robust_address.unwrap();
801+
802+
eprintln!(">> checking role");
803+
804+
// Check if deployer has the admin role, it should!
805+
// I can confirm that the admin role hash below is correct because it shows up in 3 storage slots, see:
806+
// https://github.com/recallnet/contracts/blob/06ec52342ffe6cd29cb9c06ebf5a785f4a057c0e/src/token/Recall.sol#L54-L56
807+
const PARAMS_PREFIX: &str = "91d14854a49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775000000000000000000000000";
808+
let mut has_role_params = hex::decode(PARAMS_PREFIX).unwrap();
809+
has_role_params.extend_from_slice(&id_to_eth(deployer.id().unwrap()).0[..]);
810+
811+
let has_role_result = v
812+
.execute_message(
813+
&deployer,
814+
&proxy_robust_addr,
815+
&TokenAmount::zero(),
816+
fil_actor_evm::Method::InvokeContract as u64,
817+
Some(serialize_ok(&ContractParams(has_role_params))),
818+
)
819+
.unwrap();
820+
821+
assert!(has_role_result.code.is_success(), "Failed to check role: {}", has_role_result.message);
822+
let BytesDe(return_value) =
823+
has_role_result.ret.unwrap().deserialize().expect("failed to deserialize results");
824+
assert_eq!(
825+
hex::encode(return_value),
826+
"0000000000000000000000000000000000000000000000000000000000000001"
827+
);
828+
}
829+
830+
#[allow(non_snake_case)]
728831
#[vm_test]
729832
pub fn evm_init_revert_data_test(v: &dyn VM) {
730833
let account = create_accounts(v, 1, &TokenAmount::from_whole(10_000))[0];

integration_tests/src/tests/mint_contract/imp.hex

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
60806040526102a88038038061001481610168565b92833981016040828203126101645781516001600160a01b03811692909190838303610164576020810151906001600160401b03821161016457019281601f8501121561016457835161006e610069826101a1565b610168565b9481865260208601936020838301011161016457815f926020809301865e86010152823b15610152577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b031916821790557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b5f80a282511561013a575f8091610122945190845af43d15610132573d91610113610069846101a1565b9283523d5f602085013e6101bc565b505b604051608d908161021b8239f35b6060916101bc565b50505034156101245763b398979f60e01b5f5260045ffd5b634c9c8ce360e01b5f5260045260245ffd5b5f80fd5b6040519190601f01601f191682016001600160401b0381118382101761018d57604052565b634e487b7160e01b5f52604160045260245ffd5b6001600160401b03811161018d57601f01601f191660200190565b906101e057508051156101d157805190602001fd5b630a12f52160e11b5f5260045ffd5b81511580610211575b6101f1575090565b639996b31560e01b5f9081526001600160a01b0391909116600452602490fd5b50803b156101e956fe60806040525f8073ffffffffffffffffffffffffffffffffffffffff7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5416368280378136915af43d5f803e156053573d5ff35b3d5ffdfea264697066735822122030c28b2107e8964fdd1443848d1ee8bca67e339954e46faf8c26c065c85a3f3664736f6c634300081a0033000000000000000000000000606fa930c2f5eae4116ac5c1c93e1dbbe995711300000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000044be13f47c000000000000000000000000b5fb4be02232b1bba4dc8f81dc24c26980de9e3c341bb76302c76fb57d6fe6c003c4fc68e56cbe5c5a4c04bedf1522a15c7e41a000000000000000000000000000000000000000000000000000000000

test_vm/tests/suite/evm_test.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ fn evm_staticcall_delegatecall() {
5454
evm_staticcall_delegatecall_test(&v);
5555
}
5656

57+
#[test]
58+
fn evm_mint() {
59+
use fil_actors_integration_tests::tests::evm_mint_test;
60+
let store = MemoryBlockstore::new();
61+
let v = TestVM::new_with_singletons(store);
62+
evm_mint_test(&v);
63+
}
64+
5765
#[test]
5866
fn evm_init_revert_data() {
5967
let store = MemoryBlockstore::new();

0 commit comments

Comments
 (0)