forked from ethereum/evmone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
state_transition_tx_test.cpp
104 lines (88 loc) · 2.8 KB
/
state_transition_tx_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2023 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0
#include "state_transition.hpp"
#include <test/utils/bytecode.hpp>
using namespace evmc::literals;
using namespace evmone::test;
TEST_F(state_transition, tx_legacy)
{
rev = EVMC_ISTANBUL;
block.base_fee = 0; // should be 0 before London
tx.to = To;
expect.post.at(Sender).nonce = pre.get(Sender).nonce + 1;
}
TEST_F(state_transition, tx_non_existing_sender)
{
rev = EVMC_BERLIN;
block.base_fee = 0; // should be 0 before London
tx.to = To;
tx.max_gas_price = 0;
tx.max_priority_gas_price = 0;
tx.nonce = 0;
pre.erase(Sender);
expect.status = EVMC_SUCCESS;
expect.post.at(Sender).nonce = 1;
expect.post[Coinbase].exists = false;
}
TEST_F(state_transition, invalid_tx_non_existing_sender)
{
rev = EVMC_BERLIN;
block.base_fee = 0; // should be 0 before London
tx.to = To;
tx.max_gas_price = 1;
tx.max_priority_gas_price = 1;
tx.nonce = 0;
pre.erase(Sender);
expect.tx_error = INSUFFICIENT_FUNDS;
expect.post[Sender].exists = false;
}
TEST_F(state_transition, tx_blob_gas_price)
{
rev = EVMC_CANCUN;
tx.to = To;
tx.gas_limit = 25000;
tx.max_gas_price = block.base_fee; // minimal gas price to make it
tx.max_priority_gas_price = 0;
tx.nonce = 1;
tx.type = Transaction::Type::blob;
tx.blob_hashes.emplace_back(
0x0100000000000000000000000000000000000000000000000000000000000000_bytes32);
tx.max_blob_gas_price = 1;
pre.get(tx.sender).balance = 0x20000 + tx.gas_limit * tx.max_gas_price;
expect.post[Coinbase].exists = false; // all gas is burned, Coinbase gets nothing
expect.status = EVMC_SUCCESS;
}
TEST_F(state_transition, empty_coinbase_fee_0_sd)
{
rev = EVMC_SPURIOUS_DRAGON;
block_reward = 0;
block.base_fee = 0; // should be 0 before London
tx.max_gas_price = 0;
tx.max_priority_gas_price = 0;
tx.to = To;
pre.insert(Coinbase, {});
expect.post[To].exists = false;
expect.post[Coinbase].exists = false;
}
TEST_F(state_transition, empty_coinbase_fee_0_tw)
{
rev = EVMC_TANGERINE_WHISTLE;
block_reward = 0;
block.base_fee = 0; // should be 0 before London
tx.max_gas_price = 0;
tx.max_priority_gas_price = 0;
tx.to = To;
pre.insert(Coinbase, {});
expect.post[To].exists = true;
expect.post[Coinbase].balance = 0;
}
TEST_F(state_transition, access_list_storage)
{
tx.to = To;
tx.access_list = {{To, {0x01_bytes32}}};
pre.insert(To, {.storage = {{0x01_bytes32, 0x01_bytes32}}, .code = sstore(2, sload(1))});
expect.post[To].storage[0x01_bytes32] = 0x01_bytes32;
expect.post[To].storage[0x02_bytes32] = 0x01_bytes32;
expect.gas_used = 47506; // Without access list: 45206
}