Skip to content

Commit

Permalink
Add transition tests for TXCREATE called from wrong type of transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Apr 18, 2024
1 parent 51977c0 commit 1ce87e6
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions test/unittests/state_transition_eof_create_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1953,3 +1953,59 @@ TEST_F(state_transition, create2_nested_in_txcreate)
expect.post[*tx.to].nonce = pre.get(*tx.to).nonce;
expect.post[*tx.to].storage[0x01_bytes32] = 0x00_bytes32;
}

TEST_F(state_transition, txcreate_from_legacy_tx)
{
rev = EVMC_PRAGUE;
tx.type = Transaction::Type::legacy;

const auto factory_code = sstore(0, txcreate().initcode(keccak256({})).input(0, 0).salt(Salt)) +
sstore(1, 1) + OP_STOP;
const auto factory_container = eof_bytecode(factory_code, 5);

tx.to = To;
pre.insert(*tx.to, {.nonce = 1, .code = factory_container});

expect.post[tx.sender].nonce = pre.get(tx.sender).nonce + 1;
expect.post[*tx.to].nonce = pre.get(*tx.to).nonce; // CREATE caller's nonce must not be bumped
expect.post[*tx.to].storage[0x00_bytes32] = 0x00_bytes32; // CREATE must fail
expect.post[*tx.to].storage[0x01_bytes32] = 0x01_bytes32;
}

TEST_F(state_transition, txcreate_from_1559_tx)
{
rev = EVMC_PRAGUE;
tx.type = Transaction::Type::eip1559;

const auto factory_code = sstore(0, txcreate().initcode(keccak256({})).input(0, 0).salt(Salt)) +
sstore(1, 1) + OP_STOP;
const auto factory_container = eof_bytecode(factory_code, 5);

tx.to = To;
pre.insert(*tx.to, {.nonce = 1, .code = factory_container});

expect.post[tx.sender].nonce = pre.get(tx.sender).nonce + 1;
expect.post[*tx.to].nonce = pre.get(*tx.to).nonce; // CREATE caller's nonce must not be bumped
expect.post[*tx.to].storage[0x00_bytes32] = 0x00_bytes32; // CREATE must fail
expect.post[*tx.to].storage[0x01_bytes32] = 0x01_bytes32;
}

TEST_F(state_transition, txcreate_from_blob_tx)
{
rev = EVMC_PRAGUE;
tx.type = Transaction::Type::blob;
tx.blob_hashes.push_back(
0x0100000000000000000000000000000000000000000000000000000000000007_bytes32);

const auto factory_code = sstore(0, txcreate().initcode(keccak256({})).input(0, 0).salt(Salt)) +
sstore(1, 1) + OP_STOP;
const auto factory_container = eof_bytecode(factory_code, 5);

tx.to = To;
pre.insert(*tx.to, {.nonce = 1, .code = factory_container});

expect.post[tx.sender].nonce = pre.get(tx.sender).nonce + 1;
expect.post[*tx.to].nonce = pre.get(*tx.to).nonce; // CREATE caller's nonce must not be bumped
expect.post[*tx.to].storage[0x00_bytes32] = 0x00_bytes32; // CREATE must fail
expect.post[*tx.to].storage[0x01_bytes32] = 0x01_bytes32;
}

0 comments on commit 1ce87e6

Please sign in to comment.