aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/abi/bind/backends/simulated.go
diff options
context:
space:
mode:
authorDave Appleton <calistralabs@gmail.com>2017-09-15 21:20:29 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-09-15 21:20:29 +0800
commit019dca9ba2f0ad91047129b95d91b95a9e71650e (patch)
treec8bcd1748bfb8bf30b994d2b91ec0e3f134aa359 /accounts/abi/bind/backends/simulated.go
parentc197d805f71ea45eaed7f8c692401502ba92d978 (diff)
downloaddexon-019dca9ba2f0ad91047129b95d91b95a9e71650e.tar
dexon-019dca9ba2f0ad91047129b95d91b95a9e71650e.tar.gz
dexon-019dca9ba2f0ad91047129b95d91b95a9e71650e.tar.bz2
dexon-019dca9ba2f0ad91047129b95d91b95a9e71650e.tar.lz
dexon-019dca9ba2f0ad91047129b95d91b95a9e71650e.tar.xz
dexon-019dca9ba2f0ad91047129b95d91b95a9e71650e.tar.zst
dexon-019dca9ba2f0ad91047129b95d91b95a9e71650e.zip
accounts/abi/backends: add AdjustTime (#15077)
Diffstat (limited to 'accounts/abi/bind/backends/simulated.go')
-rw-r--r--accounts/abi/bind/backends/simulated.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go
index 88fb3331e..d6d16eb3f 100644
--- a/accounts/abi/bind/backends/simulated.go
+++ b/accounts/abi/bind/backends/simulated.go
@@ -22,6 +22,7 @@ import (
"fmt"
"math/big"
"sync"
+ "time"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
@@ -284,6 +285,22 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
return nil
}
+// JumpTimeInSeconds adds skip seconds to the clock
+func (b *SimulatedBackend) AdjustTime(adjustment time.Duration) error {
+ b.mu.Lock()
+ defer b.mu.Unlock()
+ blocks, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), b.database, 1, func(number int, block *core.BlockGen) {
+ for _, tx := range b.pendingBlock.Transactions() {
+ block.AddTx(tx)
+ }
+ block.OffsetTime(int64(adjustment.Seconds()))
+ })
+ b.pendingBlock = blocks[0]
+ b.pendingState, _ = state.New(b.pendingBlock.Root(), state.NewDatabase(b.database))
+
+ return nil
+}
+
// callmsg implements core.Message to allow passing it as a transaction simulator.
type callmsg struct {
ethereum.CallMsg