Эх сурвалжийг харах

accounts/abi/backends: add AdjustTime (#15077)

Dave Appleton 8 жил өмнө
parent
commit
019dca9ba2

+ 17 - 0
accounts/abi/bind/backends/simulated.go

@@ -22,6 +22,7 @@ import (
 	"fmt"
 	"fmt"
 	"math/big"
 	"math/big"
 	"sync"
 	"sync"
+	"time"
 
 
 	"github.com/ethereum/go-ethereum"
 	"github.com/ethereum/go-ethereum"
 	"github.com/ethereum/go-ethereum/accounts/abi/bind"
 	"github.com/ethereum/go-ethereum/accounts/abi/bind"
@@ -284,6 +285,22 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
 	return nil
 	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.
 // callmsg implements core.Message to allow passing it as a transaction simulator.
 type callmsg struct {
 type callmsg struct {
 	ethereum.CallMsg
 	ethereum.CallMsg