good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
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
Downloads
Patches
Plain Diff
core: add blockchain test too for revert cornercase
parent
223b9509
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/blockchain_test.go
+75
-0
75 additions, 0 deletions
core/blockchain_test.go
with
75 additions
and
0 deletions
core/blockchain_test.go
+
75
−
0
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.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment