From d7af82ebc44f5e3f2efd7f52a9855a39d6ebfac5 Mon Sep 17 00:00:00 2001 From: n3wbie Date: Mon, 18 Mar 2024 19:28:56 +0900 Subject: [PATCH 1/3] feat: `TestSkipHeights` skip 5 seconds per every height --- .../r/x/skip_height_to_skip_time/skiptime.gno | 1 + .../skiptime_test.gno | 27 +++++++++++++++++++ gnovm/tests/stdlibs/std/std.go | 1 + 3 files changed, 29 insertions(+) create mode 100644 examples/gno.land/r/x/skip_height_to_skip_time/skiptime.gno create mode 100644 examples/gno.land/r/x/skip_height_to_skip_time/skiptime_test.gno diff --git a/examples/gno.land/r/x/skip_height_to_skip_time/skiptime.gno b/examples/gno.land/r/x/skip_height_to_skip_time/skiptime.gno new file mode 100644 index 00000000000..524e6f58ad9 --- /dev/null +++ b/examples/gno.land/r/x/skip_height_to_skip_time/skiptime.gno @@ -0,0 +1 @@ +package skiptime diff --git a/examples/gno.land/r/x/skip_height_to_skip_time/skiptime_test.gno b/examples/gno.land/r/x/skip_height_to_skip_time/skiptime_test.gno new file mode 100644 index 00000000000..52670a5626b --- /dev/null +++ b/examples/gno.land/r/x/skip_height_to_skip_time/skiptime_test.gno @@ -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) + } +} diff --git a/gnovm/tests/stdlibs/std/std.go b/gnovm/tests/stdlibs/std/std.go index 27ad079b4a6..b49aa24218b 100644 --- a/gnovm/tests/stdlibs/std/std.go +++ b/gnovm/tests/stdlibs/std/std.go @@ -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 } From cb8d0a0b491240648713e6504d65816abcda8b72 Mon Sep 17 00:00:00 2001 From: n3wbie Date: Tue, 7 May 2024 12:56:06 +0900 Subject: [PATCH 2/3] fix: ci failing --- examples/gno.land/p/demo/rand/rand0_filetest.gno | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/gno.land/p/demo/rand/rand0_filetest.gno b/examples/gno.land/p/demo/rand/rand0_filetest.gno index c5c138924fc..446e04b696d 100644 --- a/examples/gno.land/p/demo/rand/rand0_filetest.gno +++ b/examples/gno.land/p/demo/rand/rand0_filetest.gno @@ -49,8 +49,8 @@ func main() { // 177 // 802 // --- -// 450 -// 78 -// 777 -// 15 -// 339 +// 269 +// 233 +// 591 +// 936 +// 908 From d4c8776603401e174af229304e4ea5c99f262b2c Mon Sep 17 00:00:00 2001 From: n3wbie Date: Wed, 5 Jun 2024 12:29:35 +0900 Subject: [PATCH 3/3] docs: update TestSkipHeights --- docs/reference/stdlibs/std/testing.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/reference/stdlibs/std/testing.md b/docs/reference/stdlibs/std/testing.md index 8c9146c81a1..fd42ddac9b5 100644 --- a/docs/reference/stdlibs/std/testing.md +++ b/docs/reference/stdlibs/std/testing.md @@ -31,6 +31,8 @@ func TestSkipHeights(count int64) ``` Modifies the block height variable by skipping **count** blocks. +It also increases block timestamp by 5 seconds for every single count + #### Usage ```go std.TestSkipHeights(100)