Skip to content

Commit c318ab4

Browse files
authored
test: Convert example tests to TestState API (ethereum#968)
1 parent b2d0672 commit c318ab4

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

test/unittests/state_transition_call_test.cpp

+22-22
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ TEST_F(state_transition, call_value_to_empty)
1313
rev = EVMC_LONDON;
1414
static constexpr auto BENEFICIARY = 0xbe_address;
1515
tx.to = To;
16-
pre.insert(*tx.to, {.balance = 1, .code = call(BENEFICIARY).value(1)});
17-
pre.insert(BENEFICIARY, {});
16+
pre[To] = {.balance = 1, .code = call(BENEFICIARY).value(1)};
17+
pre[BENEFICIARY] = {};
1818

1919
expect.post[To].balance = 0;
2020
expect.post[BENEFICIARY].balance = 1;
@@ -24,29 +24,29 @@ TEST_F(state_transition, delegatecall_static_legacy)
2424
{
2525
rev = EVMC_PRAGUE;
2626
// Checks if DELEGATECALL forwards the "static" flag.
27-
constexpr auto callee1 = 0xca11ee01_address;
28-
constexpr auto callee2 = 0xca11ee02_address;
29-
pre.insert(callee2, {
30-
.storage = {{0x01_bytes32, 0xdd_bytes32}},
31-
.code = sstore(1, 0xcc_bytes32),
32-
});
33-
pre.insert(callee1, {
34-
.storage = {{0x01_bytes32, 0xdd_bytes32}},
35-
.code = ret(delegatecall(callee2).gas(100'000)),
36-
});
37-
27+
static constexpr auto CALLEE1 = 0xca11ee01_address;
28+
static constexpr auto CALLEE2 = 0xca11ee02_address;
29+
pre[CALLEE2] = {
30+
.storage = {{0x01_bytes32, 0xdd_bytes32}},
31+
.code = sstore(1, 0xcc_bytes32),
32+
};
33+
pre[CALLEE1] = {
34+
.storage = {{0x01_bytes32, 0xdd_bytes32}},
35+
.code = ret(delegatecall(CALLEE2).gas(100'000)),
36+
};
3837
tx.to = To;
39-
pre.insert(*tx.to, {
40-
.storage = {{0x01_bytes32, 0xdd_bytes32}, {0x02_bytes32, 0xdd_bytes32}},
41-
.code = sstore(1, staticcall(callee1).gas(200'000)) +
42-
sstore(2, returndatacopy(0, 0, returndatasize()) + mload(0)),
43-
});
38+
pre[To] = {
39+
.storage = {{0x01_bytes32, 0xdd_bytes32}, {0x02_bytes32, 0xdd_bytes32}},
40+
.code = sstore(1, staticcall(CALLEE1).gas(200'000)) +
41+
sstore(2, returndatacopy(0, 0, returndatasize()) + mload(0)),
42+
};
43+
4444
expect.gas_used = 131480;
4545
// Outer call - success.
46-
expect.post[*tx.to].storage[0x01_bytes32] = 0x01_bytes32;
46+
expect.post[To].storage[0x01_bytes32] = 0x01_bytes32;
4747
// Inner call - no success.
48-
expect.post[*tx.to].storage[0x02_bytes32] = 0x00_bytes32;
48+
expect.post[To].storage[0x02_bytes32] = 0x00_bytes32;
4949
// SSTORE failed.
50-
expect.post[callee1].storage[0x01_bytes32] = 0xdd_bytes32;
51-
expect.post[callee2].storage[0x01_bytes32] = 0xdd_bytes32;
50+
expect.post[CALLEE1].storage[0x01_bytes32] = 0xdd_bytes32;
51+
expect.post[CALLEE2].storage[0x01_bytes32] = 0xdd_bytes32;
5252
}

0 commit comments

Comments
 (0)