-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
statetest: Reuse Transaction loading in TestMultiTransaction #556
Changes from all commits
50c2108
f43158f
b4ab2f2
8749c51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// evmone: Fast Ethereum Virtual Machine implementation | ||
// Copyright 2023 The evmone Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include <gtest/gtest.h> | ||
#include <test/statetest/statetest.hpp> | ||
|
||
using namespace evmone; | ||
|
||
TEST(statetest_loader, tx_create_legacy) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably add a test where both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What should happen then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just fail, pushed my version. |
||
{ | ||
constexpr std::string_view input = R"({ | ||
"input": "b0b1", | ||
"gas": "9091", | ||
"value": "0xe0e1", | ||
"sender": "a0a1", | ||
"to": "", | ||
"gasPrice": "0x7071" | ||
})"; | ||
|
||
const auto tx = test::from_json<state::Transaction>(json::json::parse(input)); | ||
EXPECT_EQ(tx.kind, state::Transaction::Kind::legacy); | ||
EXPECT_EQ(tx.data, (bytes{0xb0, 0xb1})); | ||
EXPECT_EQ(tx.gas_limit, 0x9091); | ||
EXPECT_EQ(tx.value, 0xe0e1); | ||
EXPECT_EQ(tx.sender, 0xa0a1_address); | ||
EXPECT_FALSE(tx.to.has_value()); | ||
EXPECT_EQ(tx.max_gas_price, 0x7071); | ||
EXPECT_EQ(tx.max_priority_gas_price, 0x7071); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, are these correct? Are they both set to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It turns out you can you EIP-1559 logic this way also for legacy transactions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the logic is as simple as that in https://eips.ethereum.org/EIPS/eip-1559: def normalize_transaction(self, transaction: Transaction, signer_address: int) -> NormalizedTransaction:
# legacy transactions
if isinstance(transaction, TransactionLegacy):
return NormalizedTransaction(
signer_address = signer_address,
signer_nonce = transaction.signer_nonce,
gas_limit = transaction.gas_limit,
max_priority_fee_per_gas = transaction.gas_price,
max_fee_per_gas = transaction.gas_price,
destination = transaction.destination,
amount = transaction.amount,
payload = transaction.payload,
access_list = [],
) |
||
EXPECT_TRUE(tx.access_list.empty()); | ||
} | ||
|
||
TEST(statetest_loader, tx_eip1559) | ||
{ | ||
constexpr std::string_view input = R"({ | ||
"input": "b0b1", | ||
"gas": "9091", | ||
"value": "0xe0e1", | ||
"sender": "a0a1", | ||
"to": "c0c1", | ||
"maxFeePerGas": "0x7071", | ||
"maxPriorityFeePerGas": "0x6061", | ||
"accessList": [] | ||
})"; | ||
|
||
const auto tx = test::from_json<state::Transaction>(json::json::parse(input)); | ||
EXPECT_EQ(tx.kind, state::Transaction::Kind::eip1559); | ||
EXPECT_EQ(tx.data, (bytes{0xb0, 0xb1})); | ||
EXPECT_EQ(tx.gas_limit, 0x9091); | ||
EXPECT_EQ(tx.value, 0xe0e1); | ||
EXPECT_EQ(tx.sender, 0xa0a1_address); | ||
EXPECT_EQ(tx.to, 0xc0c1_address); | ||
EXPECT_EQ(tx.max_gas_price, 0x7071); | ||
EXPECT_EQ(tx.max_priority_gas_price, 0x6061); | ||
EXPECT_TRUE(tx.access_list.empty()); | ||
} | ||
|
||
TEST(statetest_loader, tx_access_list) | ||
{ | ||
constexpr std::string_view input = R"({ | ||
"input": "", | ||
"gas": "0", | ||
"value": "0", | ||
"sender": "", | ||
"to": "", | ||
"maxFeePerGas": "0", | ||
"maxPriorityFeePerGas": "0", | ||
"accessList": [ | ||
{"address": "ac01", "storageKeys": []}, | ||
{"address": "ac02", "storageKeys": ["fe", "00"]} | ||
] | ||
})"; | ||
|
||
const auto tx = test::from_json<state::Transaction>(json::json::parse(input)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically could add the checks for each of the zero values. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extended tests. |
||
EXPECT_EQ(tx.kind, state::Transaction::Kind::eip1559); | ||
EXPECT_TRUE(tx.data.empty()); | ||
EXPECT_EQ(tx.gas_limit, 0); | ||
EXPECT_EQ(tx.value, 0); | ||
EXPECT_EQ(tx.sender, address{}); // TODO: use 0x0_address? | ||
EXPECT_FALSE(tx.to.has_value()); | ||
EXPECT_EQ(tx.max_gas_price, 0); | ||
EXPECT_EQ(tx.max_priority_gas_price, 0); | ||
ASSERT_EQ(tx.access_list.size(), 2); | ||
EXPECT_EQ(tx.access_list[0].first, 0xac01_address); | ||
EXPECT_EQ(tx.access_list[0].second.size(), 0); | ||
EXPECT_EQ(tx.access_list[1].first, 0xac02_address); | ||
EXPECT_EQ(tx.access_list[1].second, (std::vector{0xfe_bytes32, 0x00_bytes32})); | ||
} | ||
|
||
TEST(statetest_loader, tx_confusing) | ||
{ | ||
constexpr std::string_view input = R"({ | ||
"input": "b0b1", | ||
"gas": "9091", | ||
"value": "0xe0e1", | ||
"sender": "a0a1", | ||
"to": "c0c1", | ||
"gasPrice": "0x8081", | ||
"maxFeePerGas": "0x7071", | ||
"maxPriorityFeePerGas": "0x6061", | ||
"accessList": [] | ||
})"; | ||
|
||
EXPECT_THROW( | ||
test::from_json<state::Transaction>(json::json::parse(input)), std::invalid_argument); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be in braces {}, because multi-line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.