Skip to content

Commit

Permalink
feat: TestSkipHeights skip 5 seconds per every height
Browse files Browse the repository at this point in the history
  • Loading branch information
r3v4s committed Mar 18, 2024
1 parent 01e91be commit d7af82e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package skiptime
27 changes: 27 additions & 0 deletions examples/gno.land/r/x/skip_height_to_skip_time/skiptime_test.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package skiptime

import (
"std"
"testing"
"time"
)

func TestSkipHeights(t *testing.T) {
oldHeight := std.GetHeight()
shouldEQ(t, oldHeight, 123)

oldNow := time.Now().Unix()
shouldEQ(t, oldNow, 1234567890)

// skip 3 blocks == 15 seconds
std.TestSkipHeights(3)

shouldEQ(t, std.GetHeight()-oldHeight, 3)
shouldEQ(t, time.Now().Unix()-oldNow, 15)
}

func shouldEQ(t *testing.T, got, expected int64) {
if got != expected {
t.Fatalf("expected %d, got %d.", expected, got)
}
}
1 change: 1 addition & 0 deletions gnovm/tests/stdlibs/std/std.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func TestCurrentRealm(m *gno.Machine) string {
func TestSkipHeights(m *gno.Machine, count int64) {
ctx := m.Context.(std.ExecContext)
ctx.Height += count
ctx.Timestamp += (count * 5)
m.Context = ctx
}

Expand Down

0 comments on commit d7af82e

Please sign in to comment.