Patch for concurrent iterator & others (onto v1.11.6) #386
@ -793,8 +793,13 @@ func (b *SimulatedBackend) AdjustTime(adjustment time.Duration) error {
|
|||||||
if len(b.pendingBlock.Transactions()) != 0 {
|
if len(b.pendingBlock.Transactions()) != 0 {
|
||||||
return errors.New("Could not adjust time on non-empty block")
|
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, block, ethash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) {
|
||||||
block.OffsetTime(int64(adjustment.Seconds()))
|
block.OffsetTime(int64(adjustment.Seconds()))
|
||||||
})
|
})
|
||||||
stateDB, _ := b.blockchain.State()
|
stateDB, _ := b.blockchain.State()
|
||||||
|
@ -1377,3 +1377,23 @@ func TestCommitReturnValue(t *testing.T) {
|
|||||||
t.Error("Could not retrieve the just created block (side-chain)")
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user