@@ -143,8 +143,7 @@ func TestSimulatedBackend_AdjustTime(t *testing.T) {
143143 defer sim .Close ()
144144
145145 prevTime := sim .pendingBlock .Time ()
146- err := sim .AdjustTime (time .Second )
147- if err != nil {
146+ if err := sim .AdjustTime (time .Second ); err != nil {
148147 t .Error (err )
149148 }
150149 newTime := sim .pendingBlock .Time ()
@@ -154,6 +153,44 @@ func TestSimulatedBackend_AdjustTime(t *testing.T) {
154153 }
155154}
156155
156+ func TestNewSimulatedBackend_AdjustTimeFail (t * testing.T ) {
157+ testAddr := crypto .PubkeyToAddress (testKey .PublicKey )
158+ sim := simTestBackend (testAddr )
159+ // Create tx and send
160+ tx := types .NewTransaction (0 , testAddr , big .NewInt (1000 ), params .TxGas , big .NewInt (1 ), nil )
161+ signedTx , err := types .SignTx (tx , types.HomesteadSigner {}, testKey )
162+ if err != nil {
163+ t .Errorf ("could not sign tx: %v" , err )
164+ }
165+ sim .SendTransaction (context .Background (), signedTx )
166+ // AdjustTime should fail on non-empty block
167+ if err := sim .AdjustTime (time .Second ); err == nil {
168+ t .Error ("Expected adjust time to error on non-empty block" )
169+ }
170+ sim .Commit ()
171+
172+ prevTime := sim .pendingBlock .Time ()
173+ if err := sim .AdjustTime (time .Minute ); err != nil {
174+ t .Error (err )
175+ }
176+ newTime := sim .pendingBlock .Time ()
177+ if newTime - prevTime != uint64 (time .Minute .Seconds ()) {
178+ t .Errorf ("adjusted time not equal to a minute. prev: %v, new: %v" , prevTime , newTime )
179+ }
180+ // Put a transaction after adjusting time
181+ tx2 := types .NewTransaction (1 , testAddr , big .NewInt (1000 ), params .TxGas , big .NewInt (1 ), nil )
182+ signedTx2 , err := types .SignTx (tx2 , types.HomesteadSigner {}, testKey )
183+ if err != nil {
184+ t .Errorf ("could not sign tx: %v" , err )
185+ }
186+ sim .SendTransaction (context .Background (), signedTx2 )
187+ sim .Commit ()
188+ newTime = sim .pendingBlock .Time ()
189+ if newTime - prevTime >= uint64 (time .Minute .Seconds ()) {
190+ t .Errorf ("time adjusted, but shouldn't be: prev: %v, new: %v" , prevTime , newTime )
191+ }
192+ }
193+
157194func TestSimulatedBackend_BalanceAt (t * testing.T ) {
158195 testAddr := crypto .PubkeyToAddress (testKey .PublicKey )
159196 expectedBal := big .NewInt (10000000000 )
0 commit comments