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

Blockchain tests support: Do not expect tx sender always exist #684

Merged
merged 3 commits into from
Aug 26, 2023

Conversation

rodiazet
Copy link
Collaborator

@rodiazet rodiazet commented Aug 9, 2023

Properly handle the case when the account of transaction sender doesn't
exist. In pre-Byzantium revisions such transaction could be valid with
gas price 0. In any case the transaction validation should not crash.

Fixes #692.

@rodiazet rodiazet requested review from chfast and gumb0 August 9, 2023 14:17
@codecov
Copy link

codecov bot commented Aug 10, 2023

Codecov Report

Merging #684 (0f72852) into master (ebeb258) will increase coverage by 0.06%.
The diff coverage is 98.11%.

❗ Current head 0f72852 differs from pull request most recent head e3d028c. Consider uploading reports for the commit e3d028c to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #684      +/-   ##
==========================================
+ Coverage   97.56%   97.62%   +0.06%     
==========================================
  Files          88       89       +1     
  Lines        8338     8388      +50     
==========================================
+ Hits         8135     8189      +54     
+ Misses        203      199       -4     
Flag Coverage Δ
blockchaintests 63.05% <ø> (ø)
statetests 74.11% <100.00%> (-0.01%) ⬇️
statetests-silkpre 22.89% <9.75%> (-0.10%) ⬇️
unittests 95.48% <98.11%> (+0.09%) ⬆️

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

Files Changed Coverage Δ
test/unittests/state_transition.hpp 0.00% <ø> (ø)
test/unittests/state_transition.cpp 95.55% <90.00%> (-1.67%) ⬇️
test/state/state.cpp 98.68% <100.00%> (+0.68%) ⬆️
test/unittests/state_transition_tx_test.cpp 100.00% <100.00%> (ø)
test/unittests/state_tx_test.cpp 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

@rodiazet rodiazet changed the title Blockchain tests fixing: Allow 0 gas price tx for pre-London Blockchain tests support: Allow 0 gas price tx for pre-London Aug 17, 2023
@rodiazet rodiazet force-pushed the gas-price-0-allowed branch 3 times, most recently from 5e8cd03 to e859c59 Compare August 18, 2023 12:12
test/t8n/t8n.cpp Outdated
if (sender_acc_ptr == nullptr)
{
// It's possible to send tx from non-existent account before London fork.
// TODO: This should be handled in `validate_transaction` but it requires
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure. We should not assume the sender account exist.

Try changing in transition():

auto& sender_acc = state.get(tx.sender);

to

auto& sender_acc = state.get_or_insert(tx.sender);

@rodiazet rodiazet force-pushed the gas-price-0-allowed branch 4 times, most recently from bdd54d2 to 4ab740c Compare August 22, 2023 11:14
@rodiazet rodiazet requested a review from chfast August 22, 2023 11:16
@chfast chfast changed the title Blockchain tests support: Allow 0 gas price tx for pre-London Blockchain tests support: Do not expect tx sender always exist Aug 24, 2023
@chfast
Copy link
Collaborator

chfast commented Aug 24, 2023

Added request for more tests: ethereum/tests#1286.


if (expect.tx_error != SUCCESS)
{
ASSERT_TRUE(holds_alternative<std::error_code>(res));
Copy link
Member

Choose a reason for hiding this comment

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

Why is this assertion and not proper check, what if implementation mistakenly does successful transition for invalid transaction?

Copy link
Collaborator

Choose a reason for hiding this comment

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

There is another old check after this block which checks the other part. But probably make sense to rework this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm... I'm not sure how to do this better. Any suggestions?

Copy link
Member

Choose a reason for hiding this comment

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

Actually I confused this with normal assertion. It think this is fine then, maybe just add a better message

ASSERT_TRUE(holds_alternative<std::error_code>(res))) << "tx expected to be invalid with error: " << expected.message();

@@ -43,6 +44,10 @@ class state_transition : public testing::Test

struct Expectation
{
/// The transaction is invalid because of the given error.
/// The rest of Expectation is ignored if the error is expected.
Copy link
Member

Choose a reason for hiding this comment

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

It could be expressed with std::variant<Expectation, ErrorCode>

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good idea, but expect.post[tx.sender].nonce stops working because expect is variant now and does not have .post any more.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah the only solution that I can think of is adding expect() and tx_error() helpers that would set a variant when called, but perhaps this is too awkward.

@@ -17,8 +17,26 @@ void state_transition::SetUp()

void state_transition::TearDown()
{
auto& state = pre;
auto state = pre;
Copy link
Member

Choose a reason for hiding this comment

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

Why is this copied now?

Copy link
Collaborator

Choose a reason for hiding this comment

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

To compare if the state is unchanged in case of invalid transaction.

chfast and others added 3 commits August 25, 2023 17:14
Properly handle the case when the account of transaction sender doesn't
exist. In pre-Byzantium revisions such transaction could be valid with
gas price 0. In any case the transaction validation should not crash.

Fixes #692.
@chfast chfast merged commit ab6ed91 into master Aug 26, 2023
23 checks passed
@chfast chfast deleted the gas-price-0-allowed branch August 26, 2023 06:32
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.

evmone-statetest crashes when the transaction sender account does not exist
3 participants