Skip to content

Commit 003ac8f

Browse files
authored
IPC-506: Fix GetCode and GetStorageAt for ethaccount (#511)
1 parent 0c5f8f7 commit 003ac8f

2 files changed

Lines changed: 30 additions & 12 deletions

File tree

fendermint/fendermint/eth/api/examples/ethers.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -601,27 +601,38 @@ where
601601
// We could calculate the storage location of the balance of the owner of the contract,
602602
// but let's just see what it returns with at slot 0. See an example at
603603
// https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getstorageat
604+
let storage_location = {
605+
let mut bz = [0u8; 32];
606+
U256::zero().to_big_endian(&mut bz);
607+
H256::from_slice(&bz)
608+
};
609+
604610
request(
605611
"eth_getStorageAt",
606-
mw.get_storage_at(
607-
contract.address(),
608-
{
609-
let mut bz = [0u8; 32];
610-
U256::zero().to_big_endian(&mut bz);
611-
H256::from_slice(&bz)
612-
},
613-
None,
614-
)
615-
.await,
612+
mw.get_storage_at(contract.address(), storage_location, None)
613+
.await,
616614
|_| true,
617615
)?;
618616

619617
request(
620-
"eth_code",
618+
"eth_getStorageAt /w account",
619+
mw.get_storage_at(from.eth_addr, storage_location, None)
620+
.await,
621+
|_| true,
622+
)?;
623+
624+
request(
625+
"eth_getCode",
621626
mw.get_code(contract.address(), None).await,
622627
|bz| *bz == deployed_bytecode,
623628
)?;
624629

630+
request(
631+
"eth_getCode /w account",
632+
mw.get_code(from.eth_addr, None).await,
633+
|bz| bz.is_empty(),
634+
)?;
635+
625636
request("eth_syncing", mw.syncing().await, |s| {
626637
*s == SyncingStatus::IsFalse // There is only one node.
627638
})?;

fendermint/fendermint/eth/api/src/state.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,14 @@ where
371371
.context("failed to call contract")?;
372372

373373
if result.value.code.is_err() {
374-
return error(ExitCode::new(result.value.code.value()), result.value.info);
374+
return match ExitCode::new(result.value.code.value()) {
375+
ExitCode::USR_UNHANDLED_MESSAGE => {
376+
// If the account is an ETHACCOUNT then it doesn't handle certain methods like `GetCode`.
377+
// Let's make it work the same way as a PLACEHOLDER and return nothing.
378+
Ok(None)
379+
}
380+
other => error(other, result.value.info),
381+
};
375382
}
376383

377384
tracing::debug!(addr = ?address, method_num, data = hex::encode(&result.value.data), "evm actor response");

0 commit comments

Comments
 (0)