Skip to content
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

test: Add some mising State Test export features #807

Merged
merged 3 commits into from
Feb 28, 2024
Merged

Conversation

chfast
Copy link
Member

@chfast chfast commented Feb 2, 2024

Add support for exporting state transition tests:

  • with legacy transactions (pre EIP-1559)
  • with access list
  • support EVMC spelling of revisions

@chfast chfast requested review from gumb0 and rodiazet February 2, 2024 09:24
Copy link

codecov bot commented Feb 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.98%. Comparing base (a980168) to head (11cfcf6).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #807      +/-   ##
==========================================
+ Coverage   97.93%   97.98%   +0.04%     
==========================================
  Files         116      116              
  Lines       11309    11370      +61     
==========================================
+ Hits        11076    11141      +65     
+ Misses        233      229       -4     
Flag Coverage Δ
blockchaintests 59.75% <ø> (ø)
statetests 62.23% <ø> (ø)
statetests-silkpre 24.22% <2.85%> (-0.12%) ⬇️
unittests 96.25% <100.00%> (+0.19%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
test/unittests/state_transition.cpp 97.43% <100.00%> (-0.37%) ⬇️
test/unittests/state_transition.hpp 0.00% <ø> (ø)
test/unittests/state_transition_eof_test.cpp 100.00% <100.00%> (ø)
test/unittests/state_transition_tx_test.cpp 100.00% <100.00%> (ø)
test/utils/utils.cpp 78.37% <100.00%> (+10.81%) ⬆️

... and 1 file with indirect coverage changes

@@ -79,7 +79,7 @@ class state_transition : public ExportableFixture
Transaction tx{
.gas_limit = block.gas_limit,
.max_gas_price = block.base_fee + 1,
.max_priority_gas_price = 1,
.max_priority_gas_price = block.base_fee + 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this change? This transaction field in the spec is called max_priority_fee_per_gas and is what is added on top of block base fee.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I guess because default is legacy transaction? It's confusing that Transaction has this field for legacy.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Legacy transaction requires these values to be the same. So I made the default agree as well.

Maybe this is not great for clarity of tests, but EIP-1559 calculations work for legacy transactions if these two fields have the same value of legacy gas price.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is not great for clarity of tests, but EIP-1559 calculations work for legacy transactions if these two fields have the same value of legacy gas price.

Can't these calculations check transaction type and ignore this field (i.e. consider it equal max_gas_price) for legacy?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or another idea is that Transaction constructor for legacy should enforce this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes they can, but there is no time to do this change now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then at least add

assert(tx.type != Legacy || tx.max_priority_gas_price == tx.max_gas_price);

to state transition.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it also can be just

if (tx.type == Legacy)
  tx.max_priority_gas_price = tx.max_gas_price;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I improved the asserts in TearDown() a bit.

It looks to me that we should have something like TestBlock with every field std::optional and set default values only after test definition. Otherwise, the test definitions must fight with defaults.

@@ -79,7 +79,7 @@ class state_transition : public ExportableFixture
Transaction tx{
.gas_limit = block.gas_limit,
.max_gas_price = block.base_fee + 1,
.max_priority_gas_price = 1,
.max_priority_gas_price = block.base_fee + 1,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Legacy transaction requires these values to be the same. So I made the default agree as well.

Maybe this is not great for clarity of tests, but EIP-1559 calculations work for legacy transactions if these two fields have the same value of legacy gas price.

@@ -13,9 +13,9 @@ evmc_revision to_rev(std::string_view s)
return EVMC_FRONTIER;
if (s == "Homestead")
return EVMC_HOMESTEAD;
if (s == "EIP150")
if (s == "Tangerine Whistle" || s == "EIP150")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not be the best idea because e.g. geth doesn't understand "Tangerine Whistle".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to export as EIP150 and EIP158... We still accept full revision names.

rev = EVMC_SPURIOUS_DRAGON;

block_reward = 0;
block.base_fee = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a valid block?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess for old forks it is.

auto& jstorage_keys = je["storageKeys"] = json::json::array();
for (const auto& k : storage_keys)
jstorage_keys.push_back(hex0x(k));
ja.push_back(je);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe makes sense to std::move(je)

expect.tx_error = INSUFFICIENT_FUNDS;
}

TEST_F(state_transition, blob_tx_insuficient_funds)
{
rev = EVMC_CANCUN;
block.base_fee = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@winsvega usually says it should be at least 7 in tests, but I'm not sure exactly why

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the minimal value by the spec.

@chfast chfast merged commit 0de1555 into master Feb 28, 2024
25 checks passed
@chfast chfast deleted the test/export branch February 28, 2024 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants