diff --git a/docs/assets/how-to-guides/porting-solidity-to-gno/porting-12.gno b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-12.gno index 55817537298..c43a5798306 100644 --- a/docs/assets/how-to-guides/porting-solidity-to-gno/porting-12.gno +++ b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-12.gno @@ -5,7 +5,7 @@ func TestAuctionEnd(t *testing.T) { // Auction ends highestBid = 3 - std.TestSkipHeights(500) + t.SkipHeights(500) shouldNoPanic(t, AuctionEnd) shouldEqual(t, ended, true) diff --git a/docs/assets/how-to-guides/porting-solidity-to-gno/porting-13.gno b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-13.gno index e2cc3355d66..cfec84f060e 100644 --- a/docs/assets/how-to-guides/porting-solidity-to-gno/porting-13.gno +++ b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-13.gno @@ -61,11 +61,11 @@ func TestFull(t *testing.T) { // Auction ends { - std.TestSkipHeights(150) + t.SkipHeights(150) shouldPanic(t, AuctionEnd) shouldEqual(t, ended, false) - std.TestSkipHeights(301) + t.SkipHeights(301) shouldNoPanic(t, AuctionEnd) shouldEqual(t, ended, true) diff --git a/docs/how-to-guides/porting-solidity-to-gno.md b/docs/how-to-guides/porting-solidity-to-gno.md index 35b7403da4b..da3e7dee1c1 100644 --- a/docs/how-to-guides/porting-solidity-to-gno.md +++ b/docs/how-to-guides/porting-solidity-to-gno.md @@ -583,7 +583,7 @@ func TestAuctionEnd(t *testing.T) { // Auction ends highestBid = 3 - std.TestSkipHeights(500) + t.SkipHeights(500) shouldNoPanic(t, AuctionEnd) shouldEqual(t, ended, true) @@ -666,11 +666,11 @@ func TestFull(t *testing.T) { // Auction ends { - std.TestSkipHeights(150) + t.SkipHeights(150) shouldPanic(t, AuctionEnd) shouldEqual(t, ended, false) - std.TestSkipHeights(301) + t.SkipHeights(301) shouldNoPanic(t, AuctionEnd) shouldEqual(t, ended, true) diff --git a/examples/gno.land/p/demo/entropy/entropy_test.gno b/examples/gno.land/p/demo/entropy/entropy_test.gno index 895bfd1e394..d12a142332b 100644 --- a/examples/gno.land/p/demo/entropy/entropy_test.gno +++ b/examples/gno.land/p/demo/entropy/entropy_test.gno @@ -24,7 +24,7 @@ func TestInstanceValue(t *testing.T) { t.Errorf("should have the same result: new=%s, base=%s", sameHeightResult, baseResult) } - std.TestSkipHeights(1) + t.SkipHeights(1) differentHeightEntropy := New() differentHeightResult := computeValue(t, differentHeightEntropy) @@ -44,7 +44,7 @@ func TestInstanceValue64(t *testing.T) { t.Errorf("should have the same result: new=%s, base=%s", sameHeightResult, baseResult) } - std.TestSkipHeights(1) + t.SkipHeights(1) differentHeightEntropy := New() differentHeightResult := computeValue64(t, differentHeightEntropy) diff --git a/examples/gno.land/p/demo/entropy/z_filetest.gno b/examples/gno.land/p/demo/entropy/z_filetest.gno index ddee29b22fd..137232ee027 100644 --- a/examples/gno.land/p/demo/entropy/z_filetest.gno +++ b/examples/gno.land/p/demo/entropy/z_filetest.gno @@ -2,6 +2,7 @@ package main import ( "std" + "testing" "gno.land/p/demo/entropy" ) @@ -27,7 +28,7 @@ func main() { println(r.Value()) println(r.Value64()) - std.TestSkipHeights(1) + testing.SkipHeights(1) println("---") r = entropy.New() println(r.Value()) diff --git a/examples/gno.land/p/moul/memo/memo_test.gno b/examples/gno.land/p/moul/memo/memo_test.gno index 44dde5df640..002b9fb7574 100644 --- a/examples/gno.land/p/moul/memo/memo_test.gno +++ b/examples/gno.land/p/moul/memo/memo_test.gno @@ -140,7 +140,7 @@ func TestMemoizeWithValidator(t *testing.T) { } // Wait - std.TestSkipHeights(10) + t.SkipHeights(10) // Second call result = m.MemoizeWithValidator(tt.key, fn, isValid) diff --git a/examples/gno.land/r/sys/validators/v2/validators_test.gno b/examples/gno.land/r/sys/validators/v2/validators_test.gno index 177d84144cb..44e687f2800 100644 --- a/examples/gno.land/r/sys/validators/v2/validators_test.gno +++ b/examples/gno.land/r/sys/validators/v2/validators_test.gno @@ -1,9 +1,8 @@ package validators import ( - "testing" - "std" + "testing" "gno.land/p/demo/avl" "gno.land/p/demo/testutils" @@ -45,7 +44,7 @@ func TestValidators_AddRemove(t *testing.T) { // Make sure the validator is added uassert.True(t, vp.IsValidator(val.Address)) - std.TestSkipHeights(1) + t.SkipHeights(1) } for i := initialHeight; i < initialHeight+int64(len(vals)); i++ { @@ -79,7 +78,7 @@ func TestValidators_AddRemove(t *testing.T) { // Make sure the validator is removed uassert.False(t, vp.IsValidator(val.Address)) - std.TestSkipHeights(1) + t.SkipHeights(1) } for i := initialRemoveHeight; i < initialRemoveHeight+int64(len(vals)); i++ { 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 index 52670a5626b..b71542e3e62 100644 --- 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 @@ -14,7 +14,7 @@ func TestSkipHeights(t *testing.T) { shouldEQ(t, oldNow, 1234567890) // skip 3 blocks == 15 seconds - std.TestSkipHeights(3) + t.SkipHeights(3) shouldEQ(t, std.GetHeight()-oldHeight, 3) shouldEQ(t, time.Now().Unix()-oldNow, 15) diff --git a/gnovm/stdlibs/testing/testing.gno b/gnovm/stdlibs/testing/testing.gno index 86e54ee46a5..9e81bf662ff 100644 --- a/gnovm/stdlibs/testing/testing.gno +++ b/gnovm/stdlibs/testing/testing.gno @@ -8,6 +8,7 @@ import ( "std" "strconv" "strings" + "time" ) // ---------------------------------------- @@ -220,15 +221,19 @@ func (t *T) SetContext(ctx Context) { } func (t *T) SetPreviousRealm(prevRealm std.Realm) { - t.SetContext(Context{PreviousRealm: prevRealm}) + SetPreviousRealm(prevRealm) } func (t *T) SetOriginSend(send std.Coins, spend std.Coins) { - t.SetContext(Context{OriginSend: send, OriginSpend: spend}) + SetOriginSend(send, spend) } func (t *T) SetOriginPkgAddress(addr std.Address) { - t.SetContext(Context{OriginPkgAddress: addr}) + SetOriginPkgAddress(addr) +} + +func (t *T) SkipHeights(count int64) { + SkipHeights(count) } func (t *T) log(s string) { @@ -414,7 +419,7 @@ func TestSetContext(ctx Context) { if !ctx.Time.IsZero() { timestamp = ctx.Time.Unix() - timestampNano = ctx.Time.UnixNano() + timestampNano = 0 } testSetContext( @@ -443,3 +448,9 @@ func SetOriginSend(send std.Coins, spend std.Coins) { func SetOriginPkgAddress(addr std.Address) { TestSetContext(Context{OriginPkgAddress: addr}) } + +func SkipHeights(count int64) { + toHeight := std.GetHeight() + count + toTime := time.Now().Unix() + (count * 5) + TestSetContext(Context{Height: toHeight, Time: time.Unix(toTime, 0)}) +} diff --git a/gnovm/tests/stdlibs/generated.go b/gnovm/tests/stdlibs/generated.go index e50ac9df18c..055a5ed9d66 100644 --- a/gnovm/tests/stdlibs/generated.go +++ b/gnovm/tests/stdlibs/generated.go @@ -63,28 +63,6 @@ var nativeFuncs = [...]NativeFunc{ )) }, }, - { - "std", - "TestSkipHeights", - []gno.FieldTypeExpr{ - {Name: gno.N("p0"), Type: gno.X("int64")}, - }, - []gno.FieldTypeExpr{}, - true, - func(m *gno.Machine) { - b := m.LastBlock() - var ( - p0 int64 - rp0 = reflect.ValueOf(&p0).Elem() - ) - - gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 0, "")).TV, rp0) - - testlibs_std.TestSkipHeights( - m, - p0) - }, - }, { "std", "callerAt", diff --git a/gnovm/tests/stdlibs/std/std.gno b/gnovm/tests/stdlibs/std/std.gno index a7dd289dcb9..bef97a459d8 100644 --- a/gnovm/tests/stdlibs/std/std.gno +++ b/gnovm/tests/stdlibs/std/std.gno @@ -1,8 +1,7 @@ package std -func AssertOriginCall() // injected -func IsOriginCall() bool // injected -func TestSkipHeights(count int64) // injected +func AssertOriginCall() // injected +func IsOriginCall() bool // injected // TestSetRealm sets the realm for the current frame. // After calling TestSetRealm, calling CurrentRealm() in the test function will yield the value of diff --git a/gnovm/tests/stdlibs/std/std.go b/gnovm/tests/stdlibs/std/std.go index fe469a49111..f96c44da273 100644 --- a/gnovm/tests/stdlibs/std/std.go +++ b/gnovm/tests/stdlibs/std/std.go @@ -62,13 +62,6 @@ func IsOriginCall(m *gno.Machine) bool { panic("unable to determine if test is a _test or a _filetest") } -func TestSkipHeights(m *gno.Machine, count int64) { - ctx := m.Context.(*TestExecContext) - ctx.Height += count - ctx.Timestamp += (count * 5) - m.Context = ctx -} - func X_callerAt(m *gno.Machine, n int) string { if n <= 0 { m.Panic(typedString("GetCallerAt requires positive arg"))