|
|
@ -143,8 +143,7 @@ func TestSimulatedBackend_AdjustTime(t *testing.T) { |
|
|
|
defer sim.Close() |
|
|
|
defer sim.Close() |
|
|
|
|
|
|
|
|
|
|
|
prevTime := sim.pendingBlock.Time() |
|
|
|
prevTime := sim.pendingBlock.Time() |
|
|
|
err := sim.AdjustTime(time.Second) |
|
|
|
if err := sim.AdjustTime(time.Second); err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
t.Error(err) |
|
|
|
} |
|
|
|
} |
|
|
|
newTime := sim.pendingBlock.Time() |
|
|
|
newTime := sim.pendingBlock.Time() |
|
|
@ -154,6 +153,44 @@ func TestSimulatedBackend_AdjustTime(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestNewSimulatedBackend_AdjustTimeFail(t *testing.T) { |
|
|
|
|
|
|
|
testAddr := crypto.PubkeyToAddress(testKey.PublicKey) |
|
|
|
|
|
|
|
sim := simTestBackend(testAddr) |
|
|
|
|
|
|
|
// Create tx and send
|
|
|
|
|
|
|
|
tx := types.NewTransaction(0, testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil) |
|
|
|
|
|
|
|
signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Errorf("could not sign tx: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
sim.SendTransaction(context.Background(), signedTx) |
|
|
|
|
|
|
|
// AdjustTime should fail on non-empty block
|
|
|
|
|
|
|
|
if err := sim.AdjustTime(time.Second); err == nil { |
|
|
|
|
|
|
|
t.Error("Expected adjust time to error on non-empty block") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
sim.Commit() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prevTime := sim.pendingBlock.Time() |
|
|
|
|
|
|
|
if err := sim.AdjustTime(time.Minute); err != nil { |
|
|
|
|
|
|
|
t.Error(err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
newTime := sim.pendingBlock.Time() |
|
|
|
|
|
|
|
if newTime-prevTime != uint64(time.Minute.Seconds()) { |
|
|
|
|
|
|
|
t.Errorf("adjusted time not equal to a minute. prev: %v, new: %v", prevTime, newTime) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Put a transaction after adjusting time
|
|
|
|
|
|
|
|
tx2 := types.NewTransaction(1, testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil) |
|
|
|
|
|
|
|
signedTx2, err := types.SignTx(tx2, types.HomesteadSigner{}, testKey) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Errorf("could not sign tx: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
sim.SendTransaction(context.Background(), signedTx2) |
|
|
|
|
|
|
|
sim.Commit() |
|
|
|
|
|
|
|
newTime = sim.pendingBlock.Time() |
|
|
|
|
|
|
|
if newTime-prevTime >= uint64(time.Minute.Seconds()) { |
|
|
|
|
|
|
|
t.Errorf("time adjusted, but shouldn't be: prev: %v, new: %v", prevTime, newTime) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestSimulatedBackend_BalanceAt(t *testing.T) { |
|
|
|
func TestSimulatedBackend_BalanceAt(t *testing.T) { |
|
|
|
testAddr := crypto.PubkeyToAddress(testKey.PublicKey) |
|
|
|
testAddr := crypto.PubkeyToAddress(testKey.PublicKey) |
|
|
|
expectedBal := big.NewInt(10000000000) |
|
|
|
expectedBal := big.NewInt(10000000000) |
|
|
|