-
Notifications
You must be signed in to change notification settings - Fork 744
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
Add test for checkpoint/revert #3320
Open
yann300
wants to merge
1
commit into
ethereumjs:master
Choose a base branch
from
yann300:checkpoint_revert
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,179 @@ describe('runTx() -> successful API parameter usage', async () => { | |
await simpleRun(vm, 'goerli (PoA), london HF, default SM - should run without errors') | ||
}) | ||
|
||
it('simple run and revert', async () => { | ||
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) | ||
const vm = await VM.create({ | ||
common, | ||
blockchain: await Blockchain.create({ validateConsensus: false, validateBlocks: false }), | ||
}) | ||
/* | ||
pragma solidity >=0.8.2 <0.9.0; | ||
contract Storage { | ||
|
||
uint256 public number; | ||
|
||
function incr() public { | ||
number++; | ||
} | ||
} | ||
*/ | ||
const bytecode = | ||
'0x608060405234801561001057600080fd5b50610164806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063119fbbd41461003b5780638381f58a14610045575b600080fd5b610043610063565b005b61004d61007c565b60405161005a9190610091565b60405180910390f35b600080815480929190610075906100b6565b9190505550565b60005481565b61008b816100ac565b82525050565b60006020820190506100a66000830184610082565b92915050565b6000819050919050565b60006100c1826100ac565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156100f4576100f36100ff565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fdfea26469706673582212209406edd37c93969bf043c9479e8dd9d97cb54f94deb6c31567a70e62288f9df764736f6c63430008070033' | ||
let tx = getTransaction( | ||
vm.common, | ||
TransactionType.FeeMarketEIP1559, | ||
true, | ||
'', | ||
true, | ||
0, | ||
bytecode, | ||
undefined, | ||
200000, | ||
1 | ||
) | ||
|
||
const caller = tx.getSenderAddress() | ||
const acc = createAccount(BigInt(0), BigInt(1000000000)) | ||
await vm.stateManager.putAccount(caller, acc) | ||
|
||
let block = Block.fromBlockData( | ||
{ | ||
header: { | ||
number: 0, | ||
gasLimit: 8000000, | ||
baseFeePerGas: '0x1', | ||
}, | ||
transactions: [tx], | ||
}, | ||
{ common } | ||
) | ||
// 1 - contract deployment | ||
let resBlock = await vm.runBlock({ | ||
block, | ||
generate: true, | ||
skipNonce: true, | ||
skipBlockValidation: true, | ||
skipBalance: false, | ||
}) | ||
let res = resBlock.results[0] | ||
const contractAddress = res.createdAddress?.toString() | ||
|
||
// 2 - checkpoint | ||
// at time of checkpoint, "number" is 0 | ||
await vm.evm.journal.checkpoint() | ||
|
||
// 3 - call to "incr" | ||
// after this tx, number is 1 | ||
tx = getTransaction( | ||
vm.common, | ||
TransactionType.FeeMarketEIP1559, | ||
true, | ||
'', | ||
false, | ||
1, | ||
'0x119fbbd4', | ||
contractAddress | ||
) | ||
block = Block.fromBlockData( | ||
{ | ||
header: { | ||
number: 1, | ||
gasLimit: 8000000, | ||
baseFeePerGas: '0x1', | ||
}, | ||
transactions: [tx], | ||
}, | ||
{ common } | ||
) | ||
resBlock = await vm.runBlock({ | ||
block, | ||
generate: true, | ||
skipNonce: true, | ||
skipBlockValidation: true, | ||
skipBalance: false, | ||
}) | ||
|
||
// 4 - call to "number" | ||
// this should return 1 | ||
tx = getTransaction( | ||
vm.common, | ||
TransactionType.FeeMarketEIP1559, | ||
true, | ||
'', | ||
false, | ||
1, | ||
'0x8381f58a', | ||
contractAddress | ||
) | ||
block = Block.fromBlockData( | ||
{ | ||
header: { | ||
number: 2, | ||
gasLimit: 8000000, | ||
baseFeePerGas: '0x1', | ||
}, | ||
transactions: [tx], | ||
}, | ||
{ common } | ||
) | ||
resBlock = await vm.runBlock({ | ||
block, | ||
generate: true, | ||
skipNonce: true, | ||
skipBlockValidation: true, | ||
skipBalance: false, | ||
}) | ||
res = resBlock.results[0] | ||
|
||
// return value should be '0x0000000000000000000000000000000000000000000000000000000000000001', because incr has been called. | ||
assert.equal( | ||
bytesToHex(res.execResult.returnValue), | ||
'0x0000000000000000000000000000000000000000000000000000000000000001' | ||
) | ||
|
||
// 5 -revert | ||
await vm.evm.journal.revert() | ||
|
||
// 6 - call to "number" | ||
// this should return 1 | ||
tx = getTransaction( | ||
vm.common, | ||
TransactionType.FeeMarketEIP1559, | ||
true, | ||
'', | ||
false, | ||
1, | ||
'0x8381f58a', | ||
contractAddress | ||
) | ||
block = Block.fromBlockData( | ||
{ | ||
header: { | ||
number: 2, | ||
gasLimit: 8000000, | ||
baseFeePerGas: '0x1', | ||
}, | ||
transactions: [tx], | ||
}, | ||
{ common } | ||
) | ||
resBlock = await vm.runBlock({ | ||
block, | ||
generate: true, | ||
skipNonce: true, | ||
skipBlockValidation: true, | ||
skipBalance: false, | ||
}) | ||
res = resBlock.results[0] | ||
|
||
// return value should be "0x0000000000000000000000000000000000000000000000000000000000000000" as the state is at this point reverted. | ||
assert.equal( | ||
bytesToHex(res.execResult.returnValue), | ||
'0x0000000000000000000000000000000000000000000000000000000000000000' | ||
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. Could you state by adding a "should do x..." comment along |
||
) | ||
}) | ||
|
||
it('test successful hardfork matching', async () => { | ||
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) | ||
const vm = await VM.create({ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I would expect some
assert()
here (at least additionally, before doing another thing (runBlock()
again) since it is therevert()
what you seem to want to test?