Skip to content

Commit 019dca9

Browse files
DaveAppletonfjl
authored andcommitted
accounts/abi/backends: add AdjustTime (#15077)
1 parent c197d80 commit 019dca9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

accounts/abi/bind/backends/simulated.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"fmt"
2323
"math/big"
2424
"sync"
25+
"time"
2526

2627
"github.com/ethereum/go-ethereum"
2728
"github.com/ethereum/go-ethereum/accounts/abi/bind"
@@ -284,6 +285,22 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
284285
return nil
285286
}
286287

288+
// JumpTimeInSeconds adds skip seconds to the clock
289+
func (b *SimulatedBackend) AdjustTime(adjustment time.Duration) error {
290+
b.mu.Lock()
291+
defer b.mu.Unlock()
292+
blocks, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), b.database, 1, func(number int, block *core.BlockGen) {
293+
for _, tx := range b.pendingBlock.Transactions() {
294+
block.AddTx(tx)
295+
}
296+
block.OffsetTime(int64(adjustment.Seconds()))
297+
})
298+
b.pendingBlock = blocks[0]
299+
b.pendingState, _ = state.New(b.pendingBlock.Root(), state.NewDatabase(b.database))
300+
301+
return nil
302+
}
303+
287304
// callmsg implements core.Message to allow passing it as a transaction simulator.
288305
type callmsg struct {
289306
ethereum.CallMsg

0 commit comments

Comments
 (0)