diff --git a/daemon/algod/api/client/restClient.go b/daemon/algod/api/client/restClient.go index 2a7e539050..829e7c68ec 100644 --- a/daemon/algod/api/client/restClient.go +++ b/daemon/algod/api/client/restClient.go @@ -753,3 +753,15 @@ func (client RestClient) GetLedgerStateDelta(round uint64) (response model.Ledge err = client.get(&response, fmt.Sprintf("/v2/deltas/%d", round), nil) return } + +// SetBlockTimestampOffset sets the offset in seconds to add to the block timestamp when in devmode +func (client RestClient) SetBlockTimestampOffset(offset uint64) (err error) { + err = client.post(nil, fmt.Sprintf("/v2/devmode/blocks/offset/%d", offset), nil, nil, true) + return +} + +// GetBlockTimestampOffset gets the offset in seconds which is being added to devmode blocks +func (client RestClient) GetBlockTimestampOffset() (response model.GetBlockTimeStampOffsetResponse, err error) { + err = client.get(&response, "/v2/devmode/blocks/offset", nil) + return +} diff --git a/test/e2e-go/features/devmode/devmode_test.go b/test/e2e-go/features/devmode/devmode_test.go index ec1fa692bc..728155ad3a 100644 --- a/test/e2e-go/features/devmode/devmode_test.go +++ b/test/e2e-go/features/devmode/devmode_test.go @@ -32,7 +32,6 @@ import ( func TestDevMode(t *testing.T) { partitiontest.PartitionTest(t) - t.Skipf("Skipping flaky test. Re-enable with #3267") if testing.Short() { t.Skip() @@ -50,18 +49,29 @@ func TestDevMode(t *testing.T) { txn := fixture.SendMoneyAndWait(0, 100000, 1000, sender.Address, receiver.String(), "") require.NotNil(t, txn.ConfirmedRound) firstRound := *txn.ConfirmedRound + 1 - start := time.Now() + blk, err := fixture.AlgodClient.Block(*txn.ConfirmedRound) + require.NoError(t, err) + seconds := int64(blk.Block["ts"].(float64)) + prevTime := time.Unix(seconds, 0) + // Set Block timestamp offset to test that consecutive txns properly get their block time set + const blkOffset = uint64(1_000_000) + err = fixture.AlgodClient.SetBlockTimestampOffset(blkOffset) + require.NoError(t, err) + resp, err := fixture.AlgodClient.GetBlockTimestampOffset() + require.NoError(t, err) + require.Equal(t, blkOffset, resp.Offset) // 2 transactions should be sent within one normal confirmation time. for i := uint64(0); i < 2; i++ { - txn = fixture.SendMoneyAndWait(firstRound+i, 100000, 1000, sender.Address, receiver.String(), "") - require.Equal(t, firstRound+i, txn.Txn.Txn.FirstValid) + round := firstRound + i + txn = fixture.SendMoneyAndWait(round, 100001, 1000, sender.Address, receiver.String(), "") + // SendMoneyAndWait subtracts 1 from firstValid + require.Equal(t, round-1, uint64(txn.Txn.Txn.FirstValid)) + newBlk, err := fixture.AlgodClient.Block(round) + require.NoError(t, err) + newBlkSeconds := int64(newBlk.Block["ts"].(float64)) + currTime := time.Unix(newBlkSeconds, 0) + require.Equal(t, currTime, prevTime.Add(1_000_000*time.Second)) + prevTime = currTime } - require.True(t, time.Since(start) < 8*time.Second, "Transactions should be quickly confirmed faster than usual.") - - // Without transactions there should be no rounds even after a normal confirmation time. - time.Sleep(10 * time.Second) - status, err := fixture.LibGoalClient.Status() - require.NoError(t, err) - require.Equal(t, txn.ConfirmedRound, status.LastRound, "There should be no rounds without a transaction.") }