Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
f49d6e5e
Unverified
Commit
f49d6e5e
authored
5 years ago
by
Martin Holst Swende
Committed by
Péter Szilágyi
5 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: add blockchain test too for revert cornercase
parent
223b9509
master
v1.10.12
v1.10.12-modified
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
0 deletions
+75
-0
blockchain_test.go
core/blockchain_test.go
+75
-0
No files found.
core/blockchain_test.go
View file @
f49d6e5e
...
...
@@ -2287,3 +2287,78 @@ func TestSideImportPrunedBlocks(t *testing.T) {
t
.
Errorf
(
"Got error, %v"
,
err
)
}
}
// TestDeleteCreateRevert tests a weird state transition corner case that we hit
// while changing the internals of statedb. The workflow is that a contract is
// self destructed, then in a followup transaction (but same block) it's created
// again and the transaction reverted.
//
// The original statedb implementation flushed dirty objects to the tries after
// each transaction, so this works ok. The rework accumulated writes in memory
// first, but the journal wiped the entire state object on create-revert.
func
TestDeleteCreateRevert
(
t
*
testing
.
T
)
{
var
(
aa
=
common
.
HexToAddress
(
"0x000000000000000000000000000000000000aaaa"
)
bb
=
common
.
HexToAddress
(
"0x000000000000000000000000000000000000bbbb"
)
// Generate a canonical chain to act as the main dataset
engine
=
ethash
.
NewFaker
()
db
=
rawdb
.
NewMemoryDatabase
()
// A sender who makes transactions, has some funds
key
,
_
=
crypto
.
HexToECDSA
(
"b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291"
)
address
=
crypto
.
PubkeyToAddress
(
key
.
PublicKey
)
funds
=
big
.
NewInt
(
1000000000
)
gspec
=
&
Genesis
{
Config
:
params
.
TestChainConfig
,
Alloc
:
GenesisAlloc
{
address
:
{
Balance
:
funds
},
// The address 0xAAAAA selfdestructs if called
aa
:
{
// Code needs to just selfdestruct
Code
:
[]
byte
{
byte
(
vm
.
PC
),
0xFF
},
Nonce
:
1
,
Balance
:
big
.
NewInt
(
0
),
},
// The address 0xBBBB send 1 wei to 0xAAAA, then reverts
bb
:
{
Code
:
[]
byte
{
byte
(
vm
.
PC
),
// [0]
byte
(
vm
.
DUP1
),
// [0,0]
byte
(
vm
.
DUP1
),
// [0,0,0]
byte
(
vm
.
DUP1
),
// [0,0,0,0]
byte
(
vm
.
PUSH1
),
0x01
,
// [0,0,0,0,1] (value)
byte
(
vm
.
PUSH2
),
0xaa
,
0xaa
,
// [0,0,0,0,1, 0xaaaa]
byte
(
vm
.
GAS
),
byte
(
vm
.
CALL
),
byte
(
vm
.
REVERT
),
},
Balance
:
big
.
NewInt
(
1
),
},
},
}
genesis
=
gspec
.
MustCommit
(
db
)
)
blocks
,
_
:=
GenerateChain
(
params
.
TestChainConfig
,
genesis
,
engine
,
db
,
1
,
func
(
i
int
,
b
*
BlockGen
)
{
b
.
SetCoinbase
(
common
.
Address
{
1
})
// One transaction to AAAA
tx
,
_
:=
types
.
SignTx
(
types
.
NewTransaction
(
0
,
aa
,
big
.
NewInt
(
0
),
50000
,
big
.
NewInt
(
1
),
nil
),
types
.
HomesteadSigner
{},
key
)
b
.
AddTx
(
tx
)
// One transaction to BBBB
tx
,
_
=
types
.
SignTx
(
types
.
NewTransaction
(
1
,
bb
,
big
.
NewInt
(
0
),
100000
,
big
.
NewInt
(
1
),
nil
),
types
.
HomesteadSigner
{},
key
)
b
.
AddTx
(
tx
)
})
// Import the canonical chain
diskdb
:=
rawdb
.
NewMemoryDatabase
()
gspec
.
MustCommit
(
diskdb
)
chain
,
err
:=
NewBlockChain
(
diskdb
,
nil
,
params
.
TestChainConfig
,
engine
,
vm
.
Config
{},
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to create tester chain: %v"
,
err
)
}
if
n
,
err
:=
chain
.
InsertChain
(
blocks
);
err
!=
nil
{
t
.
Fatalf
(
"block %d: failed to insert into chain: %v"
,
n
,
err
)
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment