Skip to content

Commit

Permalink
test: Convert example tests to TestState API (#968)
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast authored Aug 8, 2024
1 parent b2d0672 commit c318ab4
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions test/unittests/state_transition_call_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ TEST_F(state_transition, call_value_to_empty)
rev = EVMC_LONDON;
static constexpr auto BENEFICIARY = 0xbe_address;
tx.to = To;
pre.insert(*tx.to, {.balance = 1, .code = call(BENEFICIARY).value(1)});
pre.insert(BENEFICIARY, {});
pre[To] = {.balance = 1, .code = call(BENEFICIARY).value(1)};
pre[BENEFICIARY] = {};

expect.post[To].balance = 0;
expect.post[BENEFICIARY].balance = 1;
Expand All @@ -24,29 +24,29 @@ TEST_F(state_transition, delegatecall_static_legacy)
{
rev = EVMC_PRAGUE;
// Checks if DELEGATECALL forwards the "static" flag.
constexpr auto callee1 = 0xca11ee01_address;
constexpr auto callee2 = 0xca11ee02_address;
pre.insert(callee2, {
.storage = {{0x01_bytes32, 0xdd_bytes32}},
.code = sstore(1, 0xcc_bytes32),
});
pre.insert(callee1, {
.storage = {{0x01_bytes32, 0xdd_bytes32}},
.code = ret(delegatecall(callee2).gas(100'000)),
});

static constexpr auto CALLEE1 = 0xca11ee01_address;
static constexpr auto CALLEE2 = 0xca11ee02_address;
pre[CALLEE2] = {
.storage = {{0x01_bytes32, 0xdd_bytes32}},
.code = sstore(1, 0xcc_bytes32),
};
pre[CALLEE1] = {
.storage = {{0x01_bytes32, 0xdd_bytes32}},
.code = ret(delegatecall(CALLEE2).gas(100'000)),
};
tx.to = To;
pre.insert(*tx.to, {
.storage = {{0x01_bytes32, 0xdd_bytes32}, {0x02_bytes32, 0xdd_bytes32}},
.code = sstore(1, staticcall(callee1).gas(200'000)) +
sstore(2, returndatacopy(0, 0, returndatasize()) + mload(0)),
});
pre[To] = {
.storage = {{0x01_bytes32, 0xdd_bytes32}, {0x02_bytes32, 0xdd_bytes32}},
.code = sstore(1, staticcall(CALLEE1).gas(200'000)) +
sstore(2, returndatacopy(0, 0, returndatasize()) + mload(0)),
};

expect.gas_used = 131480;
// Outer call - success.
expect.post[*tx.to].storage[0x01_bytes32] = 0x01_bytes32;
expect.post[To].storage[0x01_bytes32] = 0x01_bytes32;
// Inner call - no success.
expect.post[*tx.to].storage[0x02_bytes32] = 0x00_bytes32;
expect.post[To].storage[0x02_bytes32] = 0x00_bytes32;
// SSTORE failed.
expect.post[callee1].storage[0x01_bytes32] = 0xdd_bytes32;
expect.post[callee2].storage[0x01_bytes32] = 0xdd_bytes32;
expect.post[CALLEE1].storage[0x01_bytes32] = 0xdd_bytes32;
expect.post[CALLEE2].storage[0x01_bytes32] = 0xdd_bytes32;
}

0 comments on commit c318ab4

Please sign in to comment.