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
1743e611
Unverified
Commit
1743e611
authored
2 years ago
by
lightclient
Committed by
GitHub
2 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accounts/abi/bind/backends: fix AdjustTime to respect Fork (#25225)
parent
456b1878
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
1 deletion
+26
-1
simulated.go
accounts/abi/bind/backends/simulated.go
+6
-1
simulated_test.go
accounts/abi/bind/backends/simulated_test.go
+20
-0
No files found.
accounts/abi/bind/backends/simulated.go
View file @
1743e611
...
...
@@ -793,8 +793,13 @@ func (b *SimulatedBackend) AdjustTime(adjustment time.Duration) error {
if
len
(
b
.
pendingBlock
.
Transactions
())
!=
0
{
return
errors
.
New
(
"Could not adjust time on non-empty block"
)
}
// Get the last block
block
:=
b
.
blockchain
.
GetBlockByHash
(
b
.
pendingBlock
.
ParentHash
())
if
block
==
nil
{
return
fmt
.
Errorf
(
"could not find parent"
)
}
blocks
,
_
:=
core
.
GenerateChain
(
b
.
config
,
b
.
blockchain
.
CurrentBlock
()
,
ethash
.
NewFaker
(),
b
.
database
,
1
,
func
(
number
int
,
block
*
core
.
BlockGen
)
{
blocks
,
_
:=
core
.
GenerateChain
(
b
.
config
,
b
lock
,
ethash
.
NewFaker
(),
b
.
database
,
1
,
func
(
number
int
,
block
*
core
.
BlockGen
)
{
block
.
OffsetTime
(
int64
(
adjustment
.
Seconds
()))
})
stateDB
,
_
:=
b
.
blockchain
.
State
()
...
...
This diff is collapsed.
Click to expand it.
accounts/abi/bind/backends/simulated_test.go
View file @
1743e611
...
...
@@ -1377,3 +1377,23 @@ func TestCommitReturnValue(t *testing.T) {
t
.
Error
(
"Could not retrieve the just created block (side-chain)"
)
}
}
// TestAdjustTimeAfterFork ensures that after a fork, AdjustTime uses the pending fork
// block's parent rather than the canonical head's parent.
func
TestAdjustTimeAfterFork
(
t
*
testing
.
T
)
{
testAddr
:=
crypto
.
PubkeyToAddress
(
testKey
.
PublicKey
)
sim
:=
simTestBackend
(
testAddr
)
defer
sim
.
Close
()
sim
.
Commit
()
// h1
h1
:=
sim
.
blockchain
.
CurrentHeader
()
.
Hash
()
sim
.
Commit
()
// h2
sim
.
Fork
(
context
.
Background
(),
h1
)
sim
.
AdjustTime
(
1
*
time
.
Second
)
sim
.
Commit
()
head
:=
sim
.
blockchain
.
CurrentHeader
()
if
head
.
Number
==
common
.
Big2
&&
head
.
ParentHash
!=
h1
{
t
.
Errorf
(
"failed to build block on fork"
)
}
}
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