diff --git a/contribs/gnodev/pkg/browser/model_tasks.go b/contribs/gnodev/pkg/browser/model_tasks.go index 553d0168b6d..56d9010abf3 100644 --- a/contribs/gnodev/pkg/browser/model_tasks.go +++ b/contribs/gnodev/pkg/browser/model_tasks.go @@ -50,6 +50,7 @@ func (m LoaderModel) Update(msg tea.Msg) (LoaderModel, tea.Cmd) { func (m LoaderModel) tick() tea.Cmd { return tea.Tick(m.spinner.FPS, func(t time.Time) tea.Msg { + t.Unix() return SpinnerTickMsg(t) }) } 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 0e5f2d57de9..1e5a1e40478 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 @@ -15,22 +15,23 @@ func TestFull(t *testing.T) { // Send two or more types of coins { - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 0}, {"test", 1}}, nil) + t.SetOriginCaller(bidder01) + + t.SetOriginSend(std.Coins{{"ugnot", 0}, {"test", 1}}) shouldPanic(t, Bid) } // Send less than the highest bid { - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 0}}, nil) + t.SetOriginCaller(bidder01) + t.SetOriginSend(std.Coins{{"ugnot", 0}}) shouldPanic(t, Bid) } // Send more than the highest bid { - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil) + t.SetOriginCaller(bidder01) + t.SetOriginSend(std.Coins{{"ugnot", 1}}) shouldNoPanic(t, Bid) shouldEqual(t, pendingReturns.Size(), 0) @@ -42,13 +43,13 @@ func TestFull(t *testing.T) { { // Send less amount than the current highest bid (current: 1) - std.TestSetOrigCaller(bidder02) - std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil) + t.SetOriginCaller(bidder02) + t.SetOriginSend(std.Coins{{"ugnot", 1}}) shouldPanic(t, Bid) // Send more amount than the current highest bid (exceeded) - std.TestSetOrigCaller(bidder02) - std.TestSetOrigSend(std.Coins{{"ugnot", 2}}, nil) + t.SetOriginCaller(bidder02) + t.SetOriginSend(std.Coins{{"ugnot", 2}}) shouldNoPanic(t, Bid) shouldEqual(t, highestBid, 2) @@ -60,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/assets/how-to-guides/porting-solidity-to-gno/porting-6.gno b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-6.gno index b544d0017c4..e2509d089e2 100644 --- a/docs/assets/how-to-guides/porting-solidity-to-gno/porting-6.gno +++ b/docs/assets/how-to-guides/porting-solidity-to-gno/porting-6.gno @@ -1,39 +1,39 @@ // Bid Function Test - Send Coin func TestBidCoins(t *testing.T) { // Sending two types of coins - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 0}, {"test", 1}}, nil) + t.SetOriginCaller(bidder01) + t.SetOriginSend(std.Coins{{"ugnot", 0}, {"test", 1}}) shouldPanic(t, Bid) // Sending lower amount than the current highest bid - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 0}}, nil) + t.SetOriginCaller(bidder01) + t.SetOriginSend(std.Coins{{"ugnot", 0}}) shouldPanic(t, Bid) // Sending more amount than the current highest bid (exceeded) - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil) + t.SetOriginCaller(bidder01) + t.SetOriginSend(std.Coins{{"ugnot", 1}}) shouldNoPanic(t, Bid) } // Bid Function Test - Bid by two or more people func TestBidCoins(t *testing.T) { // bidder01 bidding with 1 coin - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil) + t.SetOriginCaller(bidder01) + t.SetOriginSend(std.Coins{{"ugnot", 1}}) shouldNoPanic(t, Bid) shouldEqual(t, highestBid, 1) shouldEqual(t, highestBidder, bidder01) shouldEqual(t, pendingReturns.Size(), 0) // bidder02 bidding with 1 coin - std.TestSetOrigCaller(bidder02) - std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil) + t.SetOriginCaller(bidder02) + t.SetOriginSend(std.Coins{{"ugnot", 1}}) shouldPanic(t, Bid) // bidder02 bidding with 2 coins - std.TestSetOrigCaller(bidder02) - std.TestSetOrigSend(std.Coins{{"ugnot", 2}}, nil) + t.SetOriginCaller(bidder02) + t.SetOriginSend(std.Coins{{"ugnot", 2}}) shouldNoPanic(t, Bid) shouldEqual(t, highestBid, 2) shouldEqual(t, highestBidder, bidder02) diff --git a/docs/how-to-guides/porting-solidity-to-gno.md b/docs/how-to-guides/porting-solidity-to-gno.md index 85c426c4c83..80f3e11e7e0 100644 --- a/docs/how-to-guides/porting-solidity-to-gno.md +++ b/docs/how-to-guides/porting-solidity-to-gno.md @@ -387,39 +387,40 @@ func Bid() { // Bid Function Test - Send Coin func TestBidCoins(t *testing.T) { // Sending two types of coins - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 0}, {"test", 1}}, nil) + t.SetOriginCaller(bidder01) + + t.SetOriginSend(std.Coins{{"ugnot", 0}, {"test", 1}}) shouldPanic(t, Bid) // Sending lower amount than the current highest bid - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 0}}, nil) + t.SetOriginCaller(bidder01) + t.SetOriginSend(std.Coins{{"ugnot", 0}}) shouldPanic(t, Bid) // Sending more amount than the current highest bid (exceeded) - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil) + t.SetOriginCaller(bidder01) + t.SetOriginSend(std.Coins{{"ugnot", 1}}) shouldNoPanic(t, Bid) } // Bid Function Test - Bid by two or more people func TestBidCoins(t *testing.T) { // bidder01 bidding with 1 coin - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil) + t.SetOriginCaller(bidder01) + t.SetOriginSend(std.Coins{{"ugnot", 1}}) shouldNoPanic(t, Bid) shouldEqual(t, highestBid, 1) shouldEqual(t, highestBidder, bidder01) shouldEqual(t, pendingReturns.Size(), 0) // bidder02 bidding with 1 coin - std.TestSetOrigCaller(bidder02) - std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil) + t.SetOriginCaller(bidder02) + t.SetOriginSend(std.Coins{{"ugnot", 1}}) shouldPanic(t, Bid) // bidder02 bidding with 2 coins - std.TestSetOrigCaller(bidder02) - std.TestSetOrigSend(std.Coins{{"ugnot", 2}}, nil) + t.SetOriginCaller(bidder02) + t.SetOriginSend(std.Coins{{"ugnot", 2}}) shouldNoPanic(t, Bid) shouldEqual(t, highestBid, 2) shouldEqual(t, highestBidder, bidder02) @@ -582,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) @@ -620,22 +621,22 @@ func TestFull(t *testing.T) { // Send two or more types of coins { - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 0}, {"test", 1}}, nil) + t.SetOriginCaller(bidder01) + t.SetOriginSend(std.Coins{{"ugnot", 0}, {"test", 1}}) shouldPanic(t, Bid) } // Send less than the highest bid { - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 0}}, nil) + t.SetOriginCaller(bidder01) + t.SetOriginSend(std.Coins{{"ugnot", 0}}) shouldPanic(t, Bid) } // Send more than the highest bid { - std.TestSetOrigCaller(bidder01) - std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil) + t.SetOriginCaller(bidder01) + t.SetOriginSend(std.Coins{{"ugnot", 1}}) shouldNoPanic(t, Bid) shouldEqual(t, pendingReturns.Size(), 0) @@ -647,13 +648,13 @@ func TestFull(t *testing.T) { { // Send less amount than the current highest bid (current: 1) - std.TestSetOrigCaller(bidder02) - std.TestSetOrigSend(std.Coins{{"ugnot", 1}}, nil) + t.SetOriginCaller(bidder02) + t.SetOriginSend(std.Coins{{"ugnot", 1}}) shouldPanic(t, Bid) // Send more amount than the current highest bid (exceeded) - std.TestSetOrigCaller(bidder02) - std.TestSetOrigSend(std.Coins{{"ugnot", 2}}, nil) + t.SetOriginCaller(bidder02) + t.SetOriginSend(std.Coins{{"ugnot", 2}}) shouldNoPanic(t, Bid) shouldEqual(t, highestBid, 2) @@ -665,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..d4cbbf1ed04 100644 --- a/examples/gno.land/p/demo/entropy/entropy_test.gno +++ b/examples/gno.land/p/demo/entropy/entropy_test.gno @@ -1,7 +1,6 @@ package entropy import ( - "std" "strconv" "testing" ) @@ -24,7 +23,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 +43,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..d855c8de4a5 100644 --- a/examples/gno.land/p/demo/entropy/z_filetest.gno +++ b/examples/gno.land/p/demo/entropy/z_filetest.gno @@ -1,7 +1,7 @@ package main import ( - "std" + "testing" "gno.land/p/demo/entropy" ) @@ -27,7 +27,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/demo/grc/grc20/tellers_test.gno b/examples/gno.land/p/demo/grc/grc20/tellers_test.gno index 2a724964edc..ed15d150308 100644 --- a/examples/gno.land/p/demo/grc/grc20/tellers_test.gno +++ b/examples/gno.land/p/demo/grc/grc20/tellers_test.gno @@ -1,7 +1,6 @@ package grc20 import ( - "std" "testing" "gno.land/p/demo/testutils" @@ -115,12 +114,12 @@ func TestCallerTeller(t *testing.T) { checkBalances(1000, 0, 0) checkAllowances(0, 0, 0, 0, 0, 0) - std.TestSetOrigCaller(alice) + t.SetOriginCaller(alice) urequire.NoError(t, teller.Approve(bob, 600)) checkBalances(1000, 0, 0) checkAllowances(600, 0, 0, 0, 0, 0) - std.TestSetOrigCaller(bob) + t.SetOriginCaller(bob) urequire.Error(t, teller.TransferFrom(alice, carl, 700)) checkBalances(1000, 0, 0) checkAllowances(600, 0, 0, 0, 0, 0) diff --git a/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno b/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno index 0481bf6b268..4af8463a24c 100644 --- a/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno +++ b/examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno @@ -259,7 +259,7 @@ func TestSetTokenURI(t *testing.T) { addr2 := std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") tokenURI := "http://example.com/token" - std.TestSetOrigCaller(std.Address(addr1)) // addr1 + t.SetOriginCaller(addr1) // addr1 dummy.mint(addr1, TokenID("1")) _, derr := dummy.SetTokenURI(TokenID("1"), TokenURI(tokenURI)) @@ -269,13 +269,13 @@ func TestSetTokenURI(t *testing.T) { _, err := dummy.SetTokenURI(TokenID("3"), TokenURI(tokenURI)) uassert.ErrorIs(t, err, ErrInvalidTokenId) - std.TestSetOrigCaller(std.Address(addr2)) // addr2 + t.SetOriginCaller(addr2) // addr2 _, cerr := dummy.SetTokenURI(TokenID("1"), TokenURI(tokenURI)) // addr2 trying to set URI for token 1 uassert.ErrorIs(t, cerr, ErrCallerIsNotOwner) // Test case: Retrieving TokenURI - std.TestSetOrigCaller(std.Address(addr1)) // addr1 + t.SetOriginCaller(addr1) // addr1 dummyTokenURI, err := dummy.TokenURI(TokenID("1")) uassert.NoError(t, err, "TokenURI error") diff --git a/examples/gno.land/p/demo/grc/grc721/grc721_metadata_test.gno b/examples/gno.land/p/demo/grc/grc721/grc721_metadata_test.gno index ad002a7c98e..c126dbd2dab 100644 --- a/examples/gno.land/p/demo/grc/grc721/grc721_metadata_test.gno +++ b/examples/gno.land/p/demo/grc/grc721/grc721_metadata_test.gno @@ -1,7 +1,6 @@ package grc721 import ( - "std" "testing" "gno.land/p/demo/testutils" @@ -31,7 +30,7 @@ func TestSetMetadata(t *testing.T) { youtubeURL := "test" // Set the original caller to addr1 - std.TestSetOrigCaller(addr1) // addr1 + t.SetOriginCaller(addr1) // addr1 // Mint a new token for addr1 dummy.mint(addr1, TokenID("1")) @@ -69,7 +68,7 @@ func TestSetMetadata(t *testing.T) { uassert.ErrorIs(t, err, ErrInvalidTokenId) // Set the original caller to addr2 - std.TestSetOrigCaller(addr2) // addr2 + t.SetOriginCaller(addr2) // addr2 // Try to set metadata for token 1 from addr2 (should fail) cerr := dummy.SetTokenMetadata(TokenID("1"), Metadata{ @@ -88,7 +87,7 @@ func TestSetMetadata(t *testing.T) { uassert.ErrorIs(t, cerr, ErrCallerIsNotOwner) // Set the original caller back to addr1 - std.TestSetOrigCaller(addr1) // addr1 + t.SetOriginCaller(addr1) // addr1 // Retrieve metadata for token 1 dummyMetadata, err := dummy.TokenMetadata(TokenID("1")) diff --git a/examples/gno.land/p/demo/grc/grc721/grc721_royalty_test.gno b/examples/gno.land/p/demo/grc/grc721/grc721_royalty_test.gno index af5b4d3b239..3b6c897977f 100644 --- a/examples/gno.land/p/demo/grc/grc721/grc721_royalty_test.gno +++ b/examples/gno.land/p/demo/grc/grc721/grc721_royalty_test.gno @@ -21,7 +21,7 @@ func TestSetTokenRoyalty(t *testing.T) { salePrice := uint64(1000) expectRoyaltyAmount := uint64(100) - std.TestSetOrigCaller(addr1) // addr1 + t.SetOriginCaller(addr1) // addr1 dummy.mint(addr1, TokenID("1")) @@ -38,7 +38,7 @@ func TestSetTokenRoyalty(t *testing.T) { }) uassert.ErrorIs(t, derr, ErrInvalidTokenId) - std.TestSetOrigCaller(addr2) // addr2 + t.SetOriginCaller(addr2) // addr2 cerr := dummy.SetTokenRoyalty(TokenID("1"), RoyaltyInfo{ PaymentAddress: paymentAddress, @@ -61,7 +61,7 @@ func TestSetTokenRoyalty(t *testing.T) { uassert.ErrorIs(t, perr, ErrInvalidRoyaltyPercentage) // Test case: Retrieving Royalty Info - std.TestSetOrigCaller(addr1) // addr1 + t.SetOriginCaller(addr1) // addr1 dummyPaymentAddress, dummyRoyaltyAmount, rerr := dummy.RoyaltyInfo(TokenID("1"), salePrice) uassert.NoError(t, rerr, "RoyaltyInfo error") diff --git a/examples/gno.land/p/demo/membstore/membstore_test.gno b/examples/gno.land/p/demo/membstore/membstore_test.gno index 2181adde077..b977d903a46 100644 --- a/examples/gno.land/p/demo/membstore/membstore_test.gno +++ b/examples/gno.land/p/demo/membstore/membstore_test.gno @@ -1,9 +1,8 @@ package membstore import ( - "testing" - "std" + "testing" "gno.land/p/demo/testutils" "gno.land/p/demo/uassert" @@ -155,7 +154,7 @@ func TestMembStore_AddMember(t *testing.T) { r = std.NewCodeRealm(daoPkgPath) ) - std.TestSetRealm(r) + t.SetRealm(r) // Create a non-empty store members := generateMembers(t, 1) @@ -174,7 +173,7 @@ func TestMembStore_AddMember(t *testing.T) { r = std.NewCodeRealm(daoPkgPath) ) - std.TestSetRealm(r) + t.SetRealm(r) // Create an empty store members := generateMembers(t, 1) @@ -234,7 +233,7 @@ func TestMembStore_UpdateMember(t *testing.T) { r = std.NewCodeRealm(daoPkgPath) ) - std.TestSetRealm(r) + t.SetRealm(r) // Create an empty store members := generateMembers(t, 1) @@ -253,7 +252,7 @@ func TestMembStore_UpdateMember(t *testing.T) { r = std.NewCodeRealm(daoPkgPath) ) - std.TestSetRealm(r) + t.SetRealm(r) // Create a non-empty store members := generateMembers(t, 2) @@ -272,7 +271,7 @@ func TestMembStore_UpdateMember(t *testing.T) { r = std.NewCodeRealm(daoPkgPath) ) - std.TestSetRealm(r) + t.SetRealm(r) // Create a non-empty store members := generateMembers(t, 1) @@ -299,7 +298,7 @@ func TestMembStore_UpdateMember(t *testing.T) { r = std.NewCodeRealm(daoPkgPath) ) - std.TestSetRealm(r) + t.SetRealm(r) // Create a non-empty store members := generateMembers(t, 1) diff --git a/examples/gno.land/p/demo/memeland/memeland_test.gno b/examples/gno.land/p/demo/memeland/memeland_test.gno index 95065b8cd64..6ced26558f0 100644 --- a/examples/gno.land/p/demo/memeland/memeland_test.gno +++ b/examples/gno.land/p/demo/memeland/memeland_test.gno @@ -1,7 +1,6 @@ package memeland import ( - "std" "strings" "testing" "time" @@ -122,7 +121,8 @@ func TestGetPostsInRangeByUpvote(t *testing.T) { m.Upvote(id2) // Change caller so avoid double upvote panic - std.TestSetOrigCaller(testutils.TestAddress("alice")) + alice := testutils.TestAddress("alice") + t.SetOriginCaller(alice) m.Upvote(id1) // Final upvote count: @@ -236,21 +236,21 @@ func TestUpvote(t *testing.T) { func TestDelete(t *testing.T) { alice := testutils.TestAddress("alice") - std.TestSetOrigCaller(alice) + t.SetOriginCaller(alice) // Alice is admin m := NewMemeland() // Set caller to Bob bob := testutils.TestAddress("bob") - std.TestSetOrigCaller(bob) + t.SetOriginCaller(bob) // Bob adds post to Memeland now := time.Now() postID := m.PostMeme("Meme #1", now.Unix()) // Alice removes Bob's post - std.TestSetOrigCaller(alice) + t.SetOriginCaller(alice) id := m.RemovePost(postID) uassert.Equal(t, postID, id, "post IDs not matching") @@ -259,7 +259,7 @@ func TestDelete(t *testing.T) { func TestDeleteByNonAdmin(t *testing.T) { alice := testutils.TestAddress("alice") - std.TestSetOrigCaller(alice) + t.SetOriginCaller(alice) m := NewMemeland() @@ -269,7 +269,7 @@ func TestDeleteByNonAdmin(t *testing.T) { // Bob will try to delete meme posted by Alice, which should fail bob := testutils.TestAddress("bob") - std.TestSetOrigCaller(bob) + t.SetOriginCaller(bob) defer func() { if r := recover(); r == nil { diff --git a/examples/gno.land/p/demo/ownable/exts/authorizable/authorizable_test.gno b/examples/gno.land/p/demo/ownable/exts/authorizable/authorizable_test.gno index 10a5e411bdb..5573bf10c74 100644 --- a/examples/gno.land/p/demo/ownable/exts/authorizable/authorizable_test.gno +++ b/examples/gno.land/p/demo/ownable/exts/authorizable/authorizable_test.gno @@ -1,7 +1,6 @@ package authorizable import ( - "std" "testing" "gno.land/p/demo/testutils" @@ -15,8 +14,7 @@ var ( ) func TestNewAuthorizable(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) // TODO(bug, issue #2371): should not be needed + t.SetOriginCaller(alice) a := NewAuthorizable() got := a.Owner() @@ -38,8 +36,7 @@ func TestNewAuthorizableWithAddress(t *testing.T) { func TestCallerOnAuthList(t *testing.T) { a := NewAuthorizableWithAddress(alice) - std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) + t.SetOriginCaller(alice) if err := a.CallerOnAuthList(); err == ErrNotInAuthList { t.Fatalf("expected alice to be on the list") @@ -48,8 +45,7 @@ func TestCallerOnAuthList(t *testing.T) { func TestNotCallerOnAuthList(t *testing.T) { a := NewAuthorizableWithAddress(alice) - std.TestSetRealm(std.NewUserRealm(bob)) - std.TestSetOrigCaller(bob) + t.SetOriginCaller(bob) if err := a.CallerOnAuthList(); err == nil { t.Fatalf("expected bob to not be on the list") @@ -58,15 +54,13 @@ func TestNotCallerOnAuthList(t *testing.T) { func TestAddToAuthList(t *testing.T) { a := NewAuthorizableWithAddress(alice) - std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) + t.SetOriginCaller(alice) if err := a.AddToAuthList(bob); err != nil { t.Fatalf("Expected no error, got %v", err) } - std.TestSetRealm(std.NewUserRealm(bob)) - std.TestSetOrigCaller(bob) + t.SetOriginCaller(bob) if err := a.AddToAuthList(bob); err == nil { t.Fatalf("Expected AddToAuth to error while bob called it, but it didn't") @@ -75,8 +69,7 @@ func TestAddToAuthList(t *testing.T) { func TestDeleteFromList(t *testing.T) { a := NewAuthorizableWithAddress(alice) - std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) + t.SetOriginCaller(alice) if err := a.AddToAuthList(bob); err != nil { t.Fatalf("Expected no error, got %v", err) @@ -86,16 +79,14 @@ func TestDeleteFromList(t *testing.T) { t.Fatalf("Expected no error, got %v", err) } - std.TestSetRealm(std.NewUserRealm(bob)) - std.TestSetOrigCaller(bob) + t.SetOriginCaller(bob) // Try an unauthorized deletion if err := a.DeleteFromAuthList(alice); err == nil { t.Fatalf("Expected DelFromAuth to error with %v", err) } - std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) + t.SetOriginCaller(alice) if err := a.DeleteFromAuthList(charlie); err != nil { t.Fatalf("Expected no error, got %v", err) @@ -103,12 +94,11 @@ func TestDeleteFromList(t *testing.T) { } func TestAssertOnList(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) + t.SetOriginCaller(alice) + a := NewAuthorizableWithAddress(alice) - std.TestSetRealm(std.NewUserRealm(bob)) - std.TestSetOrigCaller(bob) + t.SetOriginCaller(bob) uassert.PanicsWithMessage(t, ErrNotInAuthList.Error(), func() { a.AssertOnAuthList() diff --git a/examples/gno.land/p/demo/ownable/ownable_test.gno b/examples/gno.land/p/demo/ownable/ownable_test.gno index d8b7f9a8e3a..db13ceaf5c2 100644 --- a/examples/gno.land/p/demo/ownable/ownable_test.gno +++ b/examples/gno.land/p/demo/ownable/ownable_test.gno @@ -15,8 +15,7 @@ var ( ) func TestNew(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) // TODO(bug): should not be needed + t.SetOriginCaller(alice) o := New() got := o.Owner() @@ -31,7 +30,7 @@ func TestNewWithAddress(t *testing.T) { } func TestTransferOwnership(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetOriginCaller(alice) o := New() @@ -44,19 +43,18 @@ func TestTransferOwnership(t *testing.T) { } func TestCallerIsOwner(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetRealm(std.NewUserRealm(alice)) o := New() unauthorizedCaller := bob - std.TestSetRealm(std.NewUserRealm(unauthorizedCaller)) - std.TestSetOrigCaller(unauthorizedCaller) // TODO(bug): should not be needed + t.SetOriginCaller(unauthorizedCaller) uassert.False(t, o.CallerIsOwner()) } func TestDropOwnership(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetRealm(std.NewUserRealm(alice)) o := New() @@ -70,20 +68,18 @@ func TestDropOwnership(t *testing.T) { // Errors func TestErrUnauthorized(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) // TODO(bug): should not be needed + t.SetOriginCaller(alice) o := New() - std.TestSetRealm(std.NewUserRealm(bob)) - std.TestSetOrigCaller(bob) // TODO(bug): should not be needed + t.SetOriginCaller(bob) uassert.ErrorContains(t, o.TransferOwnership(alice), ErrUnauthorized.Error()) uassert.ErrorContains(t, o.DropOwnership(), ErrUnauthorized.Error()) } func TestErrInvalidAddress(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetOriginCaller(alice) o := New() @@ -95,8 +91,8 @@ func TestErrInvalidAddress(t *testing.T) { } func TestAssertCallerIsOwner(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) + t.SetRealm(std.NewUserRealm(alice)) + t.SetOriginCaller(alice) o := New() @@ -104,8 +100,8 @@ func TestAssertCallerIsOwner(t *testing.T) { o.AssertCallerIsOwner() // Should panic when caller is not owner - std.TestSetRealm(std.NewUserRealm(bob)) - std.TestSetOrigCaller(bob) + t.SetRealm(std.NewUserRealm(bob)) + t.SetOriginCaller(bob) defer func() { r := recover() diff --git a/examples/gno.land/p/demo/pausable/pausable_test.gno b/examples/gno.land/p/demo/pausable/pausable_test.gno index 47028cd85c8..5c3ad8fda5c 100644 --- a/examples/gno.land/p/demo/pausable/pausable_test.gno +++ b/examples/gno.land/p/demo/pausable/pausable_test.gno @@ -15,14 +15,14 @@ var ( ) func TestNewFromOwnable(t *testing.T) { - std.TestSetOrigCaller(firstCaller) - + t.SetOriginCaller(firstCaller) result := NewFromOwnable(o) + urequire.Equal(t, firstCaller.String(), result.Ownable().Owner().String()) } func TestSetUnpaused(t *testing.T) { - std.TestSetOrigCaller(firstCaller) + t.SetOriginCaller(firstCaller) result := NewFromOwnable(o) result.Unpause() @@ -30,7 +30,7 @@ func TestSetUnpaused(t *testing.T) { } func TestSetPaused(t *testing.T) { - std.TestSetOrigCaller(firstCaller) + t.SetOriginCaller(firstCaller) result := NewFromOwnable(o) result.Pause() @@ -41,7 +41,7 @@ func TestIsPaused(t *testing.T) { result := NewFromOwnable(o) urequire.False(t, result.IsPaused(), "Expected result to be unpaused") - std.TestSetOrigCaller(firstCaller) + t.SetOriginCaller(firstCaller) result.Pause() uassert.True(t, result.IsPaused(), "Expected result to be paused") } diff --git a/examples/gno.land/p/demo/simpledao/dao_test.gno b/examples/gno.land/p/demo/simpledao/dao_test.gno index 275455d1479..df6a8ccdf7a 100644 --- a/examples/gno.land/p/demo/simpledao/dao_test.gno +++ b/examples/gno.land/p/demo/simpledao/dao_test.gno @@ -74,7 +74,7 @@ func TestSimpleDAO_Propose(t *testing.T) { s = New(ms) ) - std.TestSetOrigSend(sentCoins, std.Coins{}) + t.SetOriginSend(sentCoins) _, err := s.Propose(dao.ProposalRequest{ Executor: ex, @@ -121,7 +121,7 @@ func TestSimpleDAO_Propose(t *testing.T) { // Set the sent coins to be lower // than the proposal fee - std.TestSetOrigSend(sentCoins, std.Coins{}) + t.SetOriginSend(sentCoins) _, err := s.Propose(dao.ProposalRequest{ Executor: ex, @@ -171,8 +171,8 @@ func TestSimpleDAO_Propose(t *testing.T) { // Set the sent coins to be enough // to cover the fee - std.TestSetOrigSend(sentCoins, std.Coins{}) - std.TestSetOrigCaller(proposer) + t.SetOriginSend(sentCoins) + t.SetOriginCaller(proposer) // Make sure the proposal was added id, err := s.Propose(dao.ProposalRequest{ @@ -221,7 +221,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { s = New(ms) ) - std.TestSetOrigCaller(voter) + t.SetOriginCaller(voter) // Attempt to vote on the proposal uassert.ErrorContains( @@ -251,7 +251,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { s = New(ms) ) - std.TestSetOrigCaller(voter) + t.SetOriginCaller(voter) // Attempt to vote on the proposal uassert.ErrorContains( @@ -285,7 +285,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { } ) - std.TestSetOrigCaller(voter) + t.SetOriginCaller(voter) // Add an initial proposal id, err := s.addProposal(prop) @@ -327,7 +327,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { } ) - std.TestSetOrigCaller(voter) + t.SetOriginCaller(voter) // Cast the initial vote urequire.NoError(t, prop.tally.castVote(member, dao.YesVote)) @@ -386,7 +386,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { majorityIndex := (len(members)*2)/3 + 1 // 2/3+ for _, m := range members[:majorityIndex] { - std.TestSetOrigCaller(m.Address) + t.SetOriginCaller(m.Address) // Attempt to vote on the proposal urequire.NoError( @@ -441,7 +441,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { majorityIndex := (len(members)*2)/3 + 1 // 2/3+ for _, m := range members[:majorityIndex] { - std.TestSetOrigCaller(m.Address) + t.SetOriginCaller(m.Address) // Attempt to vote on the proposal urequire.NoError( @@ -496,7 +496,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { majorityIndex := (len(members)*2)/3 + 1 // 2/3+ for _, m := range members[:majorityIndex] { - std.TestSetOrigCaller(m.Address) + t.SetOriginCaller(m.Address) // Attempt to vote on the proposal urequire.NoError( @@ -551,7 +551,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { // The first half votes yes for _, m := range members[:len(members)/2] { - std.TestSetOrigCaller(m.Address) + t.SetOriginCaller(m.Address) // Attempt to vote on the proposal urequire.NoError( @@ -562,7 +562,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { // The other half votes no for _, m := range members[len(members)/2:] { - std.TestSetOrigCaller(m.Address) + t.SetOriginCaller(m.Address) // Attempt to vote on the proposal urequire.NoError( @@ -618,7 +618,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { // The first quarter votes yes for _, m := range members[:len(members)/4] { - std.TestSetOrigCaller(m.Address) + t.SetOriginCaller(m.Address) // Attempt to vote on the proposal urequire.NoError( @@ -629,7 +629,7 @@ func TestSimpleDAO_VoteOnProposal(t *testing.T) { // The second quarter votes no for _, m := range members[len(members)/4 : len(members)/2] { - std.TestSetOrigCaller(m.Address) + t.SetOriginCaller(m.Address) // Attempt to vote on the proposal urequire.NoError( @@ -668,7 +668,7 @@ func TestSimpleDAO_ExecuteProposal(t *testing.T) { // Set the sent coins to be lower // than the execute fee - std.TestSetOrigSend(sentCoins, std.Coins{}) + t.SetOriginSend(sentCoins) uassert.ErrorIs( t, @@ -699,7 +699,7 @@ func TestSimpleDAO_ExecuteProposal(t *testing.T) { // Set the sent coins to be enough // so the execution can take place - std.TestSetOrigSend(sentCoins, std.Coins{}) + t.SetOriginSend(sentCoins) uassert.ErrorContains( t, @@ -726,7 +726,7 @@ func TestSimpleDAO_ExecuteProposal(t *testing.T) { } ) - std.TestSetOrigCaller(voter) + t.SetOriginCaller(voter) // Add an initial proposal id, err := s.addProposal(prop) @@ -776,7 +776,7 @@ func TestSimpleDAO_ExecuteProposal(t *testing.T) { } ) - std.TestSetOrigCaller(voter) + t.SetOriginCaller(voter) // Add an initial proposal id, err := s.addProposal(prop) @@ -820,7 +820,7 @@ func TestSimpleDAO_ExecuteProposal(t *testing.T) { } ) - std.TestSetOrigCaller(voter) + t.SetOriginCaller(voter) // Add an initial proposal id, err := s.addProposal(prop) @@ -864,7 +864,7 @@ func TestSimpleDAO_ExecuteProposal(t *testing.T) { } ) - std.TestSetOrigCaller(voter) + t.SetOriginCaller(voter) // Add an initial proposal id, err := s.addProposal(prop) diff --git a/examples/gno.land/p/demo/subscription/lifetime/lifetime_test.gno b/examples/gno.land/p/demo/subscription/lifetime/lifetime_test.gno index efbae90c11c..d66accc7aa6 100644 --- a/examples/gno.land/p/demo/subscription/lifetime/lifetime_test.gno +++ b/examples/gno.land/p/demo/subscription/lifetime/lifetime_test.gno @@ -15,10 +15,10 @@ var ( ) func TestLifetimeSubscription(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetRealm(std.NewUserRealm(alice)) ls := NewLifetimeSubscription(1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}) err := ls.Subscribe() uassert.NoError(t, err, "Expected ProcessPayment to succeed") @@ -27,10 +27,10 @@ func TestLifetimeSubscription(t *testing.T) { } func TestLifetimeSubscriptionGift(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetRealm(std.NewUserRealm(alice)) ls := NewLifetimeSubscription(1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}) err := ls.GiftSubscription(bob) uassert.NoError(t, err, "Expected ProcessPaymentGift to succeed for Bob") @@ -42,45 +42,45 @@ func TestLifetimeSubscriptionGift(t *testing.T) { } func TestUpdateAmountAuthorization(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetOriginCaller(alice) ls := NewLifetimeSubscription(1000) err := ls.UpdateAmount(2000) uassert.NoError(t, err, "Expected Alice to succeed in updating amount") - std.TestSetOrigCaller(bob) + t.SetOriginCaller(bob) err = ls.UpdateAmount(3000) uassert.Error(t, err, "Expected Bob to fail when updating amount") } func TestIncorrectPaymentAmount(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetOriginCaller(alice) ls := NewLifetimeSubscription(1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 500}}, nil) + t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 500}}) err := ls.Subscribe() uassert.Error(t, err, "Expected payment to fail with incorrect amount") } func TestMultipleSubscriptionAttempts(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetOriginCaller(alice) ls := NewLifetimeSubscription(1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}) err := ls.Subscribe() uassert.NoError(t, err, "Expected first subscription to succeed") - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}) err = ls.Subscribe() uassert.Error(t, err, "Expected second subscription to fail as Alice is already subscribed") } func TestGiftSubscriptionWithIncorrectAmount(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetOriginCaller(alice) ls := NewLifetimeSubscription(1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 500}}, nil) + t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 500}}) err := ls.GiftSubscription(bob) uassert.Error(t, err, "Expected gift subscription to fail with incorrect amount") @@ -89,17 +89,17 @@ func TestGiftSubscriptionWithIncorrectAmount(t *testing.T) { } func TestUpdateAmountEffectiveness(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetOriginCaller(alice) ls := NewLifetimeSubscription(1000) err := ls.UpdateAmount(2000) uassert.NoError(t, err, "Expected Alice to succeed in updating amount") - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}) err = ls.Subscribe() uassert.Error(t, err, "Expected subscription to fail with old amount after update") - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 2000}}, nil) + t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 2000}}) err = ls.Subscribe() uassert.NoError(t, err, "Expected subscription to succeed with new amount") } diff --git a/examples/gno.land/p/demo/subscription/recurring/recurring_test.gno b/examples/gno.land/p/demo/subscription/recurring/recurring_test.gno index 0b458b716ec..4009a23e195 100644 --- a/examples/gno.land/p/demo/subscription/recurring/recurring_test.gno +++ b/examples/gno.land/p/demo/subscription/recurring/recurring_test.gno @@ -16,10 +16,10 @@ var ( ) func TestRecurringSubscription(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetRealm(std.NewUserRealm(alice)) rs := NewRecurringSubscription(time.Hour*24, 1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}) err := rs.Subscribe() uassert.NoError(t, err, "Expected ProcessPayment to succeed for Alice") @@ -31,10 +31,10 @@ func TestRecurringSubscription(t *testing.T) { } func TestRecurringSubscriptionGift(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetRealm(std.NewUserRealm(alice)) rs := NewRecurringSubscription(time.Hour*24, 1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}) err := rs.GiftSubscription(bob) uassert.NoError(t, err, "Expected ProcessPaymentGift to succeed for Bob") @@ -46,10 +46,10 @@ func TestRecurringSubscriptionGift(t *testing.T) { } func TestRecurringSubscriptionExpiration(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetRealm(std.NewUserRealm(alice)) rs := NewRecurringSubscription(time.Hour, 1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}) err := rs.Subscribe() uassert.NoError(t, err, "Expected ProcessPayment to succeed for Alice") @@ -64,19 +64,19 @@ func TestRecurringSubscriptionExpiration(t *testing.T) { } func TestUpdateAmountAuthorization(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetOriginCaller(alice) rs := NewRecurringSubscription(time.Hour*24, 1000) err := rs.UpdateAmount(2000) uassert.NoError(t, err, "Expected Alice to succeed in updating amount") - std.TestSetOrigCaller(bob) + t.SetOriginCaller(bob) err = rs.UpdateAmount(3000) uassert.Error(t, err, "Expected Bob to fail when updating amount") } func TestGetAmount(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetOriginCaller(alice) rs := NewRecurringSubscription(time.Hour*24, 1000) amount := rs.GetAmount() @@ -90,32 +90,32 @@ func TestGetAmount(t *testing.T) { } func TestIncorrectPaymentAmount(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetOriginCaller(alice) rs := NewRecurringSubscription(time.Hour*24, 1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 500}}, nil) + t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 500}}) err := rs.Subscribe() uassert.Error(t, err, "Expected payment with incorrect amount to fail") } func TestMultiplePaymentsForSameUser(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetOriginCaller(alice) rs := NewRecurringSubscription(time.Hour*24, 1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}) err := rs.Subscribe() uassert.NoError(t, err, "Expected first ProcessPayment to succeed for Alice") - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}) err = rs.Subscribe() uassert.Error(t, err, "Expected second ProcessPayment to fail for Alice due to existing subscription") } func TestRecurringSubscriptionWithMultiplePayments(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetOriginCaller(alice) rs := NewRecurringSubscription(time.Hour, 1000) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}) err := rs.Subscribe() uassert.NoError(t, err, "Expected first ProcessPayment to succeed for Alice") @@ -125,7 +125,7 @@ func TestRecurringSubscriptionWithMultiplePayments(t *testing.T) { expiration := time.Now().Add(-time.Hour * 2) rs.subs.Set(std.PrevRealm().Addr().String(), expiration) - std.TestSetOrigSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}, nil) + t.SetOriginSend([]std.Coin{{Denom: "ugnot", Amount: 1000}}) err = rs.Subscribe() uassert.NoError(t, err, "Expected second ProcessPayment to succeed for Alice") diff --git a/examples/gno.land/p/gov/executor/proposal_test.gno b/examples/gno.land/p/gov/executor/proposal_test.gno index 3a70fc40596..5b332cd4e51 100644 --- a/examples/gno.land/p/gov/executor/proposal_test.gno +++ b/examples/gno.land/p/gov/executor/proposal_test.gno @@ -53,7 +53,7 @@ func TestExecutor_Callback(t *testing.T) { // Execute as the /r/gov/dao caller r := std.NewCodeRealm(daoPkgPath) - std.TestSetRealm(r) + t.SetRealm(r) uassert.NoError(t, e.Execute()) uassert.True(t, called, "expected proposal to execute") @@ -79,7 +79,7 @@ func TestExecutor_Callback(t *testing.T) { // Execute as the /r/gov/dao caller r := std.NewCodeRealm(daoPkgPath) - std.TestSetRealm(r) + t.SetRealm(r) uassert.ErrorIs(t, e.Execute(), expectedErr) uassert.True(t, called, "expected proposal to execute") @@ -137,7 +137,7 @@ func TestExecutor_Context(t *testing.T) { // Execute as the /r/gov/dao caller r := std.NewCodeRealm(daoPkgPath) - std.TestSetRealm(r) + t.SetRealm(r) urequire.NoError(t, e.Execute()) uassert.True(t, called, "expected proposal to execute") @@ -167,7 +167,7 @@ func TestExecutor_Context(t *testing.T) { // Execute as the /r/gov/dao caller r := std.NewCodeRealm(daoPkgPath) - std.TestSetRealm(r) + t.SetRealm(r) uassert.NotPanics(t, func() { err := e.Execute() diff --git a/examples/gno.land/p/moul/memo/memo_test.gno b/examples/gno.land/p/moul/memo/memo_test.gno index 44dde5df640..bb435666bf0 100644 --- a/examples/gno.land/p/moul/memo/memo_test.gno +++ b/examples/gno.land/p/moul/memo/memo_test.gno @@ -1,7 +1,6 @@ package memo import ( - "std" "testing" "time" ) @@ -140,7 +139,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/p/moul/realmpath/realmpath_test.gno b/examples/gno.land/p/moul/realmpath/realmpath_test.gno index a638b40d3ca..8fd581370cf 100644 --- a/examples/gno.land/p/moul/realmpath/realmpath_test.gno +++ b/examples/gno.land/p/moul/realmpath/realmpath_test.gno @@ -11,7 +11,7 @@ import ( ) func TestExample(t *testing.T) { - std.TestSetRealm(std.NewCodeRealm("gno.land/r/lorem/ipsum")) + t.SetRealm(std.NewCodeRealm("gno.land/r/lorem/ipsum")) // initial parsing path := "hello/world?foo=bar&baz=foobar" @@ -32,7 +32,7 @@ func TestExample(t *testing.T) { } func TestParse(t *testing.T) { - std.TestSetRealm(std.NewCodeRealm("gno.land/r/lorem/ipsum")) + t.SetRealm(std.NewCodeRealm("gno.land/r/lorem/ipsum")) tests := []struct { rawPath string diff --git a/examples/gno.land/p/n2p5/loci/loci_test.gno b/examples/gno.land/p/n2p5/loci/loci_test.gno index 6df6d4f9b2d..4e6db335dc4 100644 --- a/examples/gno.land/p/n2p5/loci/loci_test.gno +++ b/examples/gno.land/p/n2p5/loci/loci_test.gno @@ -1,7 +1,6 @@ package loci import ( - "std" "testing" "gno.land/p/demo/testutils" @@ -15,7 +14,7 @@ func TestLociStore(t *testing.T) { m1 := []byte("hello") m2 := []byte("world") - std.TestSetOrigCaller(u1) + t.SetOriginCaller(u1) // Ensure that the value is nil before setting it. r1 := store.Get(u1) @@ -47,11 +46,11 @@ func TestLociStore(t *testing.T) { m2 := []byte("world") m3 := []byte("goodbye") - std.TestSetOrigCaller(u1) + t.SetOriginCaller(u1) store.Set(m1) - std.TestSetOrigCaller(u2) + t.SetOriginCaller(u2) store.Set(m2) - std.TestSetOrigCaller(u3) + t.SetOriginCaller(u3) store.Set(m3) // Ensure that the value is correct after setting it. @@ -75,5 +74,4 @@ func TestLociStore(t *testing.T) { t.Errorf("expected value to be 'goodbye', got '%s'", r3) } }) - } diff --git a/examples/gno.land/p/n2p5/mgroup/mgroup_test.gno b/examples/gno.land/p/n2p5/mgroup/mgroup_test.gno index cd02db98683..5d15764e8e9 100644 --- a/examples/gno.land/p/n2p5/mgroup/mgroup_test.gno +++ b/examples/gno.land/p/n2p5/mgroup/mgroup_test.gno @@ -21,7 +21,7 @@ func TestManagedGroup(t *testing.T) { g := New(u1) // happy path { - std.TestSetOrigCaller(u1) + t.SetOriginCaller(u1) err := g.AddBackupOwner(u2) if err != nil { t.Errorf("expected nil, got %v", err.Error()) @@ -29,7 +29,7 @@ func TestManagedGroup(t *testing.T) { } // ensure checking for authorized caller { - std.TestSetOrigCaller(u2) + t.SetOriginCaller(u2) err := g.AddBackupOwner(u3) if err != ownable.ErrUnauthorized { t.Errorf("expected %v, got %v", ErrNotBackupOwner.Error(), err.Error()) @@ -37,7 +37,7 @@ func TestManagedGroup(t *testing.T) { } // ensure invalid address is caught { - std.TestSetOrigCaller(u1) + t.SetOriginCaller(u1) var badAddr std.Address err := g.AddBackupOwner(badAddr) if err != ErrInvalidAddress { @@ -50,7 +50,7 @@ func TestManagedGroup(t *testing.T) { g := New(u1) // happy path { - std.TestSetOrigCaller(u1) + t.SetOriginCaller(u1) g.AddBackupOwner(u2) err := g.RemoveBackupOwner(u2) if err != nil { @@ -59,7 +59,7 @@ func TestManagedGroup(t *testing.T) { } // running this twice should not error. { - std.TestSetOrigCaller(u1) + t.SetOriginCaller(u1) err := g.RemoveBackupOwner(u2) if err != nil { t.Errorf("expected nil, got %v", err.Error()) @@ -67,14 +67,14 @@ func TestManagedGroup(t *testing.T) { } // ensure checking for authorized caller { - std.TestSetOrigCaller(u2) + t.SetOriginCaller(u2) err := g.RemoveBackupOwner(u3) if err != ownable.ErrUnauthorized { t.Errorf("expected %v, got %v", ErrNotBackupOwner.Error(), err.Error()) } } { - std.TestSetOrigCaller(u1) + t.SetOriginCaller(u1) var badAddr std.Address err := g.RemoveBackupOwner(badAddr) if err != ErrInvalidAddress { @@ -82,7 +82,7 @@ func TestManagedGroup(t *testing.T) { } } { - std.TestSetOrigCaller(u1) + t.SetOriginCaller(u1) err := g.RemoveBackupOwner(u1) if err != ErrCannotRemoveOwner { t.Errorf("expected %v, got %v", ErrCannotRemoveOwner.Error(), err.Error()) @@ -95,7 +95,7 @@ func TestManagedGroup(t *testing.T) { g.AddBackupOwner(u2) // happy path { - std.TestSetOrigCaller(u2) + t.SetOriginCaller(u2) err := g.ClaimOwnership() if err != nil { t.Errorf("expected nil, got %v", err.Error()) @@ -109,7 +109,7 @@ func TestManagedGroup(t *testing.T) { } // running this twice should not error. { - std.TestSetOrigCaller(u2) + t.SetOriginCaller(u2) err := g.ClaimOwnership() if err != nil { t.Errorf("expected nil, got %v", err.Error()) @@ -117,7 +117,7 @@ func TestManagedGroup(t *testing.T) { } // ensure checking for authorized caller { - std.TestSetOrigCaller(u3) + t.SetOriginCaller(u3) err := g.ClaimOwnership() if err != ErrNotMember { t.Errorf("expected %v, got %v", ErrNotMember.Error(), err.Error()) @@ -129,7 +129,7 @@ func TestManagedGroup(t *testing.T) { g := New(u1) // happy path { - std.TestSetOrigCaller(u1) + t.SetOriginCaller(u1) err := g.AddMember(u2) if err != nil { t.Errorf("expected nil, got %v", err.Error()) @@ -140,7 +140,7 @@ func TestManagedGroup(t *testing.T) { } // ensure checking for authorized caller { - std.TestSetOrigCaller(u2) + t.SetOriginCaller(u2) err := g.AddMember(u3) if err != ownable.ErrUnauthorized { t.Errorf("expected %v, got %v", ownable.ErrUnauthorized.Error(), err.Error()) @@ -148,7 +148,7 @@ func TestManagedGroup(t *testing.T) { } // ensure invalid address is caught { - std.TestSetOrigCaller(u1) + t.SetOriginCaller(u1) var badAddr std.Address err := g.AddMember(badAddr) if err != ErrInvalidAddress { @@ -161,7 +161,7 @@ func TestManagedGroup(t *testing.T) { g := New(u1) // happy path { - std.TestSetOrigCaller(u1) + t.SetOriginCaller(u1) g.AddMember(u2) err := g.RemoveMember(u2) if err != nil { @@ -173,7 +173,7 @@ func TestManagedGroup(t *testing.T) { } // running this twice should not error. { - std.TestSetOrigCaller(u1) + t.SetOriginCaller(u1) err := g.RemoveMember(u2) if err != nil { t.Errorf("expected nil, got %v", err.Error()) @@ -181,7 +181,7 @@ func TestManagedGroup(t *testing.T) { } // ensure checking for authorized caller { - std.TestSetOrigCaller(u2) + t.SetOriginCaller(u2) err := g.RemoveMember(u3) if err != ownable.ErrUnauthorized { t.Errorf("expected %v, got %v", ownable.ErrUnauthorized.Error(), err.Error()) @@ -189,7 +189,7 @@ func TestManagedGroup(t *testing.T) { } // ensure invalid address is caught { - std.TestSetOrigCaller(u1) + t.SetOriginCaller(u1) var badAddr std.Address err := g.RemoveMember(badAddr) if err != ErrInvalidAddress { @@ -198,7 +198,7 @@ func TestManagedGroup(t *testing.T) { } // ensure owner cannot be removed { - std.TestSetOrigCaller(u1) + t.SetOriginCaller(u1) err := g.RemoveMember(u1) if err != ErrCannotRemoveOwner { t.Errorf("expected %v, got %v", ErrCannotRemoveOwner.Error(), err.Error()) @@ -281,7 +281,7 @@ func TestManagedGroup(t *testing.T) { if g.Owner() != u1 { t.Errorf("expected %v, got %v", u1, g.Owner()) } - std.TestSetOrigCaller(u2) + t.SetOriginCaller(u2) g.ClaimOwnership() if g.Owner() != u2 { t.Errorf("expected %v, got %v", u2, g.Owner()) @@ -289,7 +289,7 @@ func TestManagedGroup(t *testing.T) { }) t.Run("BackupOwners", func(t *testing.T) { t.Parallel() - std.TestSetOrigCaller(u1) + t.SetOriginCaller(u1) g := New(u1) g.AddBackupOwner(u2) g.AddBackupOwner(u3) @@ -309,7 +309,7 @@ func TestManagedGroup(t *testing.T) { }) t.Run("Members", func(t *testing.T) { t.Parallel() - std.TestSetOrigCaller(u1) + t.SetOriginCaller(u1) g := New(u1) g.AddMember(u2) g.AddMember(u3) diff --git a/examples/gno.land/p/oxtekgrinder/ownable2step/ownable_test.gno b/examples/gno.land/p/oxtekgrinder/ownable2step/ownable_test.gno index 4cca03b6ef5..e633dac1c3e 100644 --- a/examples/gno.land/p/oxtekgrinder/ownable2step/ownable_test.gno +++ b/examples/gno.land/p/oxtekgrinder/ownable2step/ownable_test.gno @@ -1,7 +1,6 @@ package ownable2step import ( - "std" "testing" "gno.land/p/demo/testutils" @@ -15,8 +14,7 @@ var ( ) func TestNew(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) + t.SetOriginCaller(alice) o := New() got := o.Owner() @@ -37,8 +35,7 @@ func TestNewWithAddress(t *testing.T) { } func TestInitiateTransferOwnership(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) + t.SetOriginCaller(alice) o := New() @@ -53,8 +50,7 @@ func TestInitiateTransferOwnership(t *testing.T) { } func TestTransferOwnership(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) + t.SetOriginCaller(alice) o := New() @@ -67,8 +63,7 @@ func TestTransferOwnership(t *testing.T) { uassert.Equal(t, owner, alice) uassert.Equal(t, pendingOwner, bob) - std.TestSetRealm(std.NewUserRealm(bob)) - std.TestSetOrigCaller(bob) + t.SetOriginCaller(bob) err = o.AcceptOwnership() urequire.NoError(t, err) @@ -81,20 +76,18 @@ func TestTransferOwnership(t *testing.T) { } func TestCallerIsOwner(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) + t.SetOriginCaller(alice) o := New() unauthorizedCaller := bob - std.TestSetRealm(std.NewUserRealm(unauthorizedCaller)) - std.TestSetOrigCaller(unauthorizedCaller) + t.SetOriginCaller(unauthorizedCaller) uassert.False(t, o.CallerIsOwner()) } func TestDropOwnership(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetOriginCaller(alice) o := New() @@ -108,20 +101,18 @@ func TestDropOwnership(t *testing.T) { // Errors func TestErrUnauthorized(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) + t.SetOriginCaller(alice) o := New() - std.TestSetRealm(std.NewUserRealm(bob)) - std.TestSetOrigCaller(bob) + t.SetOriginCaller(bob) uassert.ErrorContains(t, o.TransferOwnership(alice), ErrUnauthorized.Error()) uassert.ErrorContains(t, o.DropOwnership(), ErrUnauthorized.Error()) } func TestErrInvalidAddress(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetOriginCaller(alice) o := New() @@ -133,7 +124,7 @@ func TestErrInvalidAddress(t *testing.T) { } func TestErrNoPendingOwner(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetOriginCaller(alice) o := New() @@ -142,14 +133,14 @@ func TestErrNoPendingOwner(t *testing.T) { } func TestErrPendingUnauthorized(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetOriginCaller(alice) o := New() err := o.TransferOwnership(bob) urequire.NoError(t, err) - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetOriginCaller(alice) err = o.AcceptOwnership() uassert.ErrorContains(t, err, ErrPendingUnauthorized.Error()) diff --git a/examples/gno.land/r/demo/atomicswap/atomicswap_test.gno b/examples/gno.land/r/demo/atomicswap/atomicswap_test.gno index 0bcf6a1342d..60d0ff1b844 100644 --- a/examples/gno.land/r/demo/atomicswap/atomicswap_test.gno +++ b/examples/gno.land/r/demo/atomicswap/atomicswap_test.gno @@ -28,8 +28,8 @@ func TestNewCustomCoinSwap_Claim(t *testing.T) { timelock := time.Now().Add(1 * time.Hour) // Create a new swap - std.TestSetRealm(std.NewUserRealm(sender)) - std.TestSetOrigSend(amount, nil) + t.SetRealm(std.NewUserRealm(sender)) + t.SetOriginSend(amount) id, swap := NewCustomCoinSwap(recipient, hashlockHex, timelock) uassert.Equal(t, 1, id) @@ -53,7 +53,7 @@ func TestNewCustomCoinSwap_Claim(t *testing.T) { uassert.False(t, swap.refunded, "expected refunded to be false") // Test claim - std.TestSetRealm(std.NewUserRealm(recipient)) + t.SetRealm(std.NewUserRealm(recipient)) uassert.PanicsWithMessage(t, "invalid preimage", func() { swap.Claim("invalid") }) swap.Claim("secret") uassert.True(t, swap.claimed, "expected claimed to be true") @@ -85,8 +85,8 @@ func TestNewCustomCoinSwap_Refund(t *testing.T) { timelock := time.Now().Add(1 * time.Hour) // Create a new swap - std.TestSetRealm(std.NewUserRealm(sender)) - std.TestSetOrigSend(amount, nil) + t.SetRealm(std.NewUserRealm(sender)) + t.SetOriginSend(amount) id, swap := NewCustomCoinSwap(recipient, hashlockHex, timelock) // Create a new swap uassert.Equal(t, 1, id) @@ -102,8 +102,8 @@ func TestNewCustomCoinSwap_Refund(t *testing.T) { // Test Refund pkgAddr := std.DerivePkgAddr("gno.land/r/demo/atomicswap") - std.TestSetOrigPkgAddr(pkgAddr) - std.TestIssueCoins(pkgAddr, std.Coins{{"ugnot", 100000000}}) + t.SetOriginPkgAddress(pkgAddr) + t.IssueCoins(pkgAddr, std.Coins{{"ugnot", 100000000}}) uassert.PanicsWithMessage(t, "timelock not expired", swap.Refund) swap.timelock = time.Now().Add(-1 * time.Hour) // override timelock swap.Refund() @@ -134,7 +134,7 @@ func TestNewCustomGRC20Swap_Claim(t *testing.T) { test20.PrivateLedger.Approve(sender, rlm, 70_000) // Create a new swap - std.TestSetRealm(std.NewUserRealm(sender)) + t.SetRealm(std.NewUserRealm(sender)) id, swap := NewCustomGRC20Swap(recipient, hashlockHex, timelock, test20.Token) uassert.Equal(t, 1, id) @@ -165,7 +165,7 @@ func TestNewCustomGRC20Swap_Claim(t *testing.T) { uassert.False(t, swap.refunded, "expected refunded to be false") // Test claim - std.TestSetRealm(std.NewUserRealm(recipient)) + t.SetRealm(std.NewUserRealm(recipient)) uassert.PanicsWithMessage(t, "invalid preimage", func() { swap.Claim("invalid") }) swap.Claim("secret") uassert.True(t, swap.claimed, "expected claimed to be true") @@ -207,7 +207,7 @@ func TestNewCustomGRC20Swap_Refund(t *testing.T) { test20.PrivateLedger.Approve(sender, rlm, 70_000) // Create a new swap - std.TestSetRealm(std.NewUserRealm(sender)) + t.SetRealm(std.NewUserRealm(sender)) id, swap := NewCustomGRC20Swap(recipient, hashlockHex, timelock, test20.Token) uassert.Equal(t, 1, id) @@ -233,8 +233,8 @@ func TestNewCustomGRC20Swap_Refund(t *testing.T) { // Test Refund pkgAddr := std.DerivePkgAddr("gno.land/r/demo/atomicswap") - std.TestSetOrigPkgAddr(pkgAddr) - std.TestIssueCoins(pkgAddr, std.Coins{{"ugnot", 100000000}}) + t.SetOriginPkgAddress(pkgAddr) + t.IssueCoins(pkgAddr, std.Coins{{"ugnot", 100000000}}) uassert.PanicsWithMessage(t, "timelock not expired", swap.Refund) swap.timelock = time.Now().Add(-1 * time.Hour) // override timelock swap.Refund() @@ -273,7 +273,7 @@ func TestNewGRC20Swap_Claim(t *testing.T) { test20.PrivateLedger.Approve(sender, rlm, 70_000) // Create a new swap - std.TestSetRealm(std.NewUserRealm(sender)) + t.SetRealm(std.NewUserRealm(sender)) id, swap := NewGRC20Swap(recipient, hashlockHex, "gno.land/r/demo/tests/test20") uassert.Equal(t, 1, id) @@ -304,7 +304,7 @@ func TestNewGRC20Swap_Claim(t *testing.T) { uassert.False(t, swap.refunded, "expected refunded to be false") // Test claim - std.TestSetRealm(std.NewUserRealm(recipient)) + t.SetRealm(std.NewUserRealm(recipient)) uassert.PanicsWithMessage(t, "invalid preimage", func() { swap.Claim("invalid") }) swap.Claim("secret") uassert.True(t, swap.claimed, "expected claimed to be true") @@ -346,7 +346,7 @@ func TestNewGRC20Swap_Refund(t *testing.T) { test20.PrivateLedger.Approve(sender, rlm, 70_000) // Create a new swap - std.TestSetRealm(std.NewUserRealm(sender)) + t.SetRealm(std.NewUserRealm(sender)) id, swap := NewGRC20Swap(recipient, hashlockHex, "gno.land/r/demo/tests/test20") uassert.Equal(t, 1, id) @@ -372,8 +372,8 @@ func TestNewGRC20Swap_Refund(t *testing.T) { // Test Refund pkgAddr := std.DerivePkgAddr("gno.land/r/demo/atomicswap") - std.TestSetOrigPkgAddr(pkgAddr) - std.TestIssueCoins(pkgAddr, std.Coins{{"ugnot", 100000000}}) + t.SetOriginPkgAddress(pkgAddr) + t.IssueCoins(pkgAddr, std.Coins{{"ugnot", 100000000}}) uassert.PanicsWithMessage(t, "timelock not expired", swap.Refund) swap.timelock = time.Now().Add(-1 * time.Hour) // override timelock swap.Refund() @@ -410,7 +410,7 @@ func TestRender(t *testing.T) { timelock := time.Now().Add(1 * time.Hour) test20.PrivateLedger.Mint(alice, 100_000) - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetRealm(std.NewUserRealm(alice)) userTeller := test20.Token.CallerTeller() userTeller.Approve(rlm, 10_000) @@ -419,7 +419,7 @@ func TestRender(t *testing.T) { userTeller.Approve(rlm, 20_000) _, _ = NewCustomGRC20Swap(charly, hashlockHex, timelock, test20.Token) - std.TestSetRealm(std.NewUserRealm(bob)) + t.SetRealm(std.NewUserRealm(bob)) bobSwap.Claim("secret") expected := `- 2: g1v9kxjcm9ta047h6lta047h6lta047h6lzd40gh -(20000TST)> g1vd5xzunv09047h6lta047h6lta047h6lhsyveh - active diff --git a/examples/gno.land/r/demo/banktest/z_0_filetest.gno b/examples/gno.land/r/demo/banktest/z_0_filetest.gno index 5a8c8d70a48..8f9f2850687 100644 --- a/examples/gno.land/r/demo/banktest/z_0_filetest.gno +++ b/examples/gno.land/r/demo/banktest/z_0_filetest.gno @@ -9,6 +9,7 @@ package bank1 import ( "std" + "testing" "gno.land/r/demo/banktest" ) @@ -17,8 +18,8 @@ func main() { // set up main address and banktest addr. banktestAddr := std.DerivePkgAddr("gno.land/r/demo/banktest") mainaddr := std.DerivePkgAddr("gno.land/r/demo/bank1") - std.TestSetOrigCaller(mainaddr) - std.TestSetOrigPkgAddr(banktestAddr) + testing.SetOriginCaller(mainaddr) + testing.SetOriginPkgAddress(banktestAddr) // get and print balance of mainaddr. // with the SEND, + 200 gnot given by the TestContext, main should have 300gnot. @@ -28,7 +29,7 @@ func main() { // simulate a Deposit call. use Send + OrigSend to simulate -send. banker.SendCoins(mainaddr, banktestAddr, std.Coins{{"ugnot", 100_000_000}}) - std.TestSetOrigSend(std.Coins{{"ugnot", 100_000_000}}, nil) + testing.SetOriginSend(std.Coins{{"ugnot", 100_000_000}}) res := banktest.Deposit("ugnot", 50_000_000) println("Deposit():", res) diff --git a/examples/gno.land/r/demo/banktest/z_1_filetest.gno b/examples/gno.land/r/demo/banktest/z_1_filetest.gno index 39682d26330..d6362a56ad7 100644 --- a/examples/gno.land/r/demo/banktest/z_1_filetest.gno +++ b/examples/gno.land/r/demo/banktest/z_1_filetest.gno @@ -7,6 +7,7 @@ package bank1 import ( "std" + "testing" "gno.land/r/demo/banktest" ) @@ -15,9 +16,9 @@ func main() { banktestAddr := std.DerivePkgAddr("gno.land/r/demo/banktest") // simulate a Deposit call. - std.TestSetOrigPkgAddr(banktestAddr) - std.TestIssueCoins(banktestAddr, std.Coins{{"ugnot", 100000000}}) - std.TestSetOrigSend(std.Coins{{"ugnot", 100000000}}, nil) + testing.SetOriginPkgAddress(banktestAddr) + testing.IssueCoins(banktestAddr, std.Coins{{"ugnot", 100000000}}) + testing.SetOriginSend(std.Coins{{"ugnot", 100000000}}) res := banktest.Deposit("ugnot", 101000000) println(res) } diff --git a/examples/gno.land/r/demo/banktest/z_2_filetest.gno b/examples/gno.land/r/demo/banktest/z_2_filetest.gno index e839f60354a..24227a36505 100644 --- a/examples/gno.land/r/demo/banktest/z_2_filetest.gno +++ b/examples/gno.land/r/demo/banktest/z_2_filetest.gno @@ -7,6 +7,7 @@ package bank1 import ( "std" + "testing" "gno.land/r/demo/banktest" ) @@ -16,16 +17,16 @@ func main() { // print main balance before. mainaddr := std.DerivePkgAddr("gno.land/r/demo/bank1") - std.TestSetOrigCaller(mainaddr) + testing.SetOriginCaller(mainaddr) banker := std.GetBanker(std.BankerTypeReadonly) mainbal := banker.GetCoins(mainaddr) println("main before:", mainbal) // plus OrigSend equals 300. // simulate a Deposit call. - std.TestSetOrigPkgAddr(banktestAddr) - std.TestIssueCoins(banktestAddr, std.Coins{{"ugnot", 100000000}}) - std.TestSetOrigSend(std.Coins{{"ugnot", 100000000}}, nil) + testing.SetOriginPkgAddress(banktestAddr) + testing.IssueCoins(banktestAddr, std.Coins{{"ugnot", 100000000}}) + testing.SetOriginSend(std.Coins{{"ugnot", 100000000}}) res := banktest.Deposit("ugnot", 55000000) println("Deposit():", res) diff --git a/examples/gno.land/r/demo/banktest/z_3_filetest.gno b/examples/gno.land/r/demo/banktest/z_3_filetest.gno index 7b6758c3e4f..6ce679ebead 100644 --- a/examples/gno.land/r/demo/banktest/z_3_filetest.gno +++ b/examples/gno.land/r/demo/banktest/z_3_filetest.gno @@ -7,18 +7,18 @@ package bank1 import ( "std" + "testing" ) func main() { banktestAddr := std.DerivePkgAddr("gno.land/r/demo/banktest") mainaddr := std.DerivePkgAddr("gno.land/r/demo/bank1") - std.TestSetOrigCaller(mainaddr) + testing.SetOriginCaller(mainaddr) banker := std.GetBanker(std.BankerTypeRealmSend) send := std.Coins{{"ugnot", 123}} banker.SendCoins(banktestAddr, mainaddr, send) - } // Error: diff --git a/examples/gno.land/r/demo/bar20/bar20_test.gno b/examples/gno.land/r/demo/bar20/bar20_test.gno index 0561d13c865..de160bebc4a 100644 --- a/examples/gno.land/r/demo/bar20/bar20_test.gno +++ b/examples/gno.land/r/demo/bar20/bar20_test.gno @@ -1,7 +1,6 @@ package bar20 import ( - "std" "testing" "gno.land/p/demo/testutils" @@ -10,8 +9,7 @@ import ( func TestPackage(t *testing.T) { alice := testutils.TestAddress("alice") - std.TestSetRealm(std.NewUserRealm(alice)) - std.TestSetOrigCaller(alice) // XXX: should not need this + t.SetOriginCaller(alice) urequire.Equal(t, UserTeller.BalanceOf(alice), uint64(0)) urequire.Equal(t, Faucet(), "OK") diff --git a/examples/gno.land/r/demo/boards/z_12_a_filetest.gno b/examples/gno.land/r/demo/boards/z_12_a_filetest.gno index 909be880efa..fc48cceadd9 100644 --- a/examples/gno.land/r/demo/boards/z_12_a_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_12_a_filetest.gno @@ -5,6 +5,7 @@ package boards_test import ( "std" + "testing" "gno.land/p/demo/testutils" "gno.land/r/demo/boards" @@ -20,8 +21,8 @@ func main() { // create a repost via anon user test2 := testutils.TestAddress("test2") - std.TestSetOrigCaller(test2) - std.TestSetOrigSend(std.Coins{{"ugnot", 9000000}}, nil) + testing.SetOriginCaller(test2) + testing.SetOriginSend(std.Coins{{"ugnot", 9000000}}) rid := boards.CreateRepost(bid1, pid, "", "Check this out", bid2) println(rid) diff --git a/examples/gno.land/r/demo/boards/z_5_b_filetest.gno b/examples/gno.land/r/demo/boards/z_5_b_filetest.gno index e79da5c3677..34d13783420 100644 --- a/examples/gno.land/r/demo/boards/z_5_b_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_5_b_filetest.gno @@ -5,6 +5,7 @@ package main import ( "std" "strconv" + "testing" "gno.land/p/demo/testutils" "gno.land/r/demo/boards" @@ -20,8 +21,8 @@ func main() { // create post via anon user test2 := testutils.TestAddress("test2") - std.TestSetOrigCaller(test2) - std.TestSetOrigSend(std.Coins{{"ugnot", 9000000}}, nil) + testing.SetOriginCaller(test2) + testing.SetOriginSend(std.Coins{{"ugnot", 9000000}}) pid := boards.CreateThread(bid, "First Post (title)", "Body of the first post. (body)") println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) diff --git a/examples/gno.land/r/demo/boards/z_5_c_filetest.gno b/examples/gno.land/r/demo/boards/z_5_c_filetest.gno index 723e6a10204..c8650bf0d0b 100644 --- a/examples/gno.land/r/demo/boards/z_5_c_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_5_c_filetest.gno @@ -5,6 +5,7 @@ package main import ( "std" "strconv" + "testing" "gno.land/p/demo/testutils" "gno.land/r/demo/boards" @@ -20,8 +21,8 @@ func main() { // create post via anon user test2 := testutils.TestAddress("test2") - std.TestSetOrigCaller(test2) - std.TestSetOrigSend(std.Coins{{"ugnot", 101000000}}, nil) + testing.SetOriginCaller(test2) + testing.SetOriginSend(std.Coins{{"ugnot", 101000000}}) pid := boards.CreateThread(bid, "First Post (title)", "Body of the first post. (body)") boards.CreateReply(bid, pid, pid, "Reply of the first post") diff --git a/examples/gno.land/r/demo/boards/z_5_d_filetest.gno b/examples/gno.land/r/demo/boards/z_5_d_filetest.gno index 54cfe49eec6..eef44502400 100644 --- a/examples/gno.land/r/demo/boards/z_5_d_filetest.gno +++ b/examples/gno.land/r/demo/boards/z_5_d_filetest.gno @@ -5,6 +5,7 @@ package main import ( "std" "strconv" + "testing" "gno.land/p/demo/testutils" "gno.land/r/demo/boards" @@ -21,8 +22,8 @@ func main() { // create reply via anon user test2 := testutils.TestAddress("test2") - std.TestSetOrigCaller(test2) - std.TestSetOrigSend(std.Coins{{"ugnot", 9000000}}, nil) + testing.SetOriginCaller(test2) + testing.SetOriginSend(std.Coins{{"ugnot", 9000000}}) boards.CreateReply(bid, pid, pid, "Reply of the first post") println(boards.Render("test_board/" + strconv.Itoa(int(pid)))) diff --git a/examples/gno.land/r/demo/btree_dao/btree_dao_test.gno b/examples/gno.land/r/demo/btree_dao/btree_dao_test.gno index 0514f52f7b4..d28ee964b24 100644 --- a/examples/gno.land/r/demo/btree_dao/btree_dao_test.gno +++ b/examples/gno.land/r/demo/btree_dao/btree_dao_test.gno @@ -12,7 +12,7 @@ import ( ) func setupTest() { - std.TestSetOrigCaller(std.Address("g1ej0qca5ptsw9kfr64ey8jvfy9eacga6mpj2z0y")) + testing.SetOriginCaller(std.Address("g1ej0qca5ptsw9kfr64ey8jvfy9eacga6mpj2z0y")) members = btree.New() } diff --git a/examples/gno.land/r/demo/disperse/z_0_filetest.gno b/examples/gno.land/r/demo/disperse/z_0_filetest.gno index ca1e9ea0ce8..d4b277434fe 100644 --- a/examples/gno.land/r/demo/disperse/z_0_filetest.gno +++ b/examples/gno.land/r/demo/disperse/z_0_filetest.gno @@ -6,6 +6,7 @@ package main import ( "std" + "testing" "gno.land/r/demo/disperse" ) @@ -14,8 +15,8 @@ func main() { disperseAddr := std.DerivePkgAddr("gno.land/r/demo/disperse") mainaddr := std.DerivePkgAddr("gno.land/r/demo/main") - std.TestSetOrigPkgAddr(disperseAddr) - std.TestSetOrigCaller(mainaddr) + testing.SetOriginPkgAddress(disperseAddr) + testing.SetOriginCaller(mainaddr) banker := std.GetBanker(std.BankerTypeRealmSend) diff --git a/examples/gno.land/r/demo/disperse/z_1_filetest.gno b/examples/gno.land/r/demo/disperse/z_1_filetest.gno index 4c27c50749f..7b569e7ef4b 100644 --- a/examples/gno.land/r/demo/disperse/z_1_filetest.gno +++ b/examples/gno.land/r/demo/disperse/z_1_filetest.gno @@ -6,6 +6,7 @@ package main import ( "std" + "testing" "gno.land/r/demo/disperse" ) @@ -14,8 +15,8 @@ func main() { disperseAddr := std.DerivePkgAddr("gno.land/r/demo/disperse") mainaddr := std.DerivePkgAddr("gno.land/r/demo/main") - std.TestSetOrigPkgAddr(disperseAddr) - std.TestSetOrigCaller(mainaddr) + testing.SetOriginPkgAddress(disperseAddr) + testing.SetOriginCaller(mainaddr) banker := std.GetBanker(std.BankerTypeRealmSend) diff --git a/examples/gno.land/r/demo/disperse/z_2_filetest.gno b/examples/gno.land/r/demo/disperse/z_2_filetest.gno index 79e8d81e2b1..83ffe790093 100644 --- a/examples/gno.land/r/demo/disperse/z_2_filetest.gno +++ b/examples/gno.land/r/demo/disperse/z_2_filetest.gno @@ -6,6 +6,7 @@ package main import ( "std" + "testing" "gno.land/r/demo/disperse" ) @@ -14,8 +15,8 @@ func main() { disperseAddr := std.DerivePkgAddr("gno.land/r/demo/disperse") mainaddr := std.DerivePkgAddr("gno.land/r/demo/main") - std.TestSetOrigPkgAddr(disperseAddr) - std.TestSetOrigCaller(mainaddr) + testing.SetOriginPkgAddress(disperseAddr) + testing.SetOriginCaller(mainaddr) banker := std.GetBanker(std.BankerTypeRealmSend) diff --git a/examples/gno.land/r/demo/disperse/z_3_filetest.gno b/examples/gno.land/r/demo/disperse/z_3_filetest.gno index 7cb7ffbe71d..ceb588e55c2 100644 --- a/examples/gno.land/r/demo/disperse/z_3_filetest.gno +++ b/examples/gno.land/r/demo/disperse/z_3_filetest.gno @@ -6,6 +6,7 @@ package main import ( "std" + "testing" "gno.land/r/demo/disperse" tokens "gno.land/r/demo/grc20factory" @@ -17,8 +18,8 @@ func main() { beneficiary1 := std.Address("g1dmt3sa5ucvecxuhf3j6ne5r0e3z4x7h6c03xc0") beneficiary2 := std.Address("g1akeqsvhucjt8gf5yupyzjxsjd29wv8fayng37c") - std.TestSetOrigPkgAddr(disperseAddr) - std.TestSetOrigCaller(mainaddr) + testing.SetOriginPkgAddress(disperseAddr) + testing.SetOriginCaller(mainaddr) banker := std.GetBanker(std.BankerTypeRealmSend) diff --git a/examples/gno.land/r/demo/disperse/z_4_filetest.gno b/examples/gno.land/r/demo/disperse/z_4_filetest.gno index 4dafb780e83..e1e92a75446 100644 --- a/examples/gno.land/r/demo/disperse/z_4_filetest.gno +++ b/examples/gno.land/r/demo/disperse/z_4_filetest.gno @@ -6,6 +6,7 @@ package main import ( "std" + "testing" "gno.land/r/demo/disperse" tokens "gno.land/r/demo/grc20factory" @@ -17,8 +18,8 @@ func main() { beneficiary1 := std.Address("g1dmt3sa5ucvecxuhf3j6ne5r0e3z4x7h6c03xc0") beneficiary2 := std.Address("g1akeqsvhucjt8gf5yupyzjxsjd29wv8fayng37c") - std.TestSetOrigPkgAddr(disperseAddr) - std.TestSetOrigCaller(mainaddr) + testing.SetOriginPkgAddress(disperseAddr) + testing.SetOriginCaller(mainaddr) banker := std.GetBanker(std.BankerTypeRealmSend) diff --git a/examples/gno.land/r/demo/foo20/foo20_test.gno b/examples/gno.land/r/demo/foo20/foo20_test.gno index d24faef279c..b97204e00e9 100644 --- a/examples/gno.land/r/demo/foo20/foo20_test.gno +++ b/examples/gno.land/r/demo/foo20/foo20_test.gno @@ -37,7 +37,7 @@ func TestReadOnlyPublicMethods(t *testing.T) { } // bob uses the faucet. - std.TestSetOrigCaller(bob) + t.SetOriginCaller(bob) Faucet() // check balances #2. diff --git a/examples/gno.land/r/demo/games/dice_roller/dice_roller_test.gno b/examples/gno.land/r/demo/games/dice_roller/dice_roller_test.gno index 4697b03bf66..39da95aac99 100644 --- a/examples/gno.land/r/demo/games/dice_roller/dice_roller_test.gno +++ b/examples/gno.land/r/demo/games/dice_roller/dice_roller_test.gno @@ -1,7 +1,6 @@ package dice_roller import ( - "std" "testing" "gno.land/p/demo/avl" @@ -27,7 +26,7 @@ func resetGameState() { func TestNewGame(t *testing.T) { resetGameState() - std.TestSetOrigCaller(player1) + t.SetOriginCaller(player1) gameID := NewGame(player2) // Verify that the game has been correctly initialized @@ -43,7 +42,7 @@ func TestNewGame(t *testing.T) { func TestPlay(t *testing.T) { resetGameState() - std.TestSetOrigCaller(player1) + t.SetOriginCaller(player1) gameID := NewGame(player2) g, err := getGame(gameID) @@ -58,7 +57,7 @@ func TestPlay(t *testing.T) { urequire.Equal(t, 0, g.roll2) // Player 2 hasn't rolled yet // Simulate rolling dice for player 2 - std.TestSetOrigCaller(player2) + t.SetOriginCaller(player2) roll2 := Play(gameID) // Verify player 2's roll @@ -71,7 +70,7 @@ func TestPlay(t *testing.T) { func TestPlayAgainstSelf(t *testing.T) { resetGameState() - std.TestSetOrigCaller(player1) + t.SetOriginCaller(player1) gameID := NewGame(player1) // Simulate rolling dice twice by the same player @@ -88,11 +87,11 @@ func TestPlayAgainstSelf(t *testing.T) { func TestPlayInvalidPlayer(t *testing.T) { resetGameState() - std.TestSetOrigCaller(player1) + t.SetOriginCaller(player1) gameID := NewGame(player1) // Attempt to play as an invalid player - std.TestSetOrigCaller(unknownPlayer) + t.SetOriginCaller(unknownPlayer) urequire.PanicsWithMessage(t, "invalid player", func() { Play(gameID) }) @@ -102,7 +101,7 @@ func TestPlayInvalidPlayer(t *testing.T) { func TestPlayAlreadyPlayed(t *testing.T) { resetGameState() - std.TestSetOrigCaller(player1) + t.SetOriginCaller(player1) gameID := NewGame(player2) // Player 1 rolls @@ -118,13 +117,13 @@ func TestPlayAlreadyPlayed(t *testing.T) { func TestPlayBeyondGameEnd(t *testing.T) { resetGameState() - std.TestSetOrigCaller(player1) + t.SetOriginCaller(player1) gameID := NewGame(player2) // Play for both players - std.TestSetOrigCaller(player1) + t.SetOriginCaller(player1) Play(gameID) - std.TestSetOrigCaller(player2) + t.SetOriginCaller(player2) Play(gameID) // Check if the game is over @@ -132,7 +131,7 @@ func TestPlayBeyondGameEnd(t *testing.T) { urequire.NoError(t, err) // Attempt to play more should fail - std.TestSetOrigCaller(player1) + t.SetOriginCaller(player1) urequire.PanicsWithMessage(t, "game over", func() { Play(gameID) }) diff --git a/examples/gno.land/r/demo/grc20factory/grc20factory_test.gno b/examples/gno.land/r/demo/grc20factory/grc20factory_test.gno index 46fc07fabf2..a5b0e8eff9b 100644 --- a/examples/gno.land/r/demo/grc20factory/grc20factory_test.gno +++ b/examples/gno.land/r/demo/grc20factory/grc20factory_test.gno @@ -1,7 +1,6 @@ package foo20 import ( - "std" "testing" "gno.land/p/demo/testutils" @@ -10,7 +9,7 @@ import ( ) func TestReadOnlyPublicMethods(t *testing.T) { - std.TestSetOrigPkgAddr("gno.land/r/demo/grc20factory") + testing.SetOriginPkgAddress("gno.land/r/demo/grc20factory") admin := testutils.TestAddress("admin") bob := testutils.TestAddress("bob") carl := testutils.TestAddress("carl") @@ -36,8 +35,7 @@ func TestReadOnlyPublicMethods(t *testing.T) { } // admin creates FOO and BAR. - std.TestSetOrigCaller(admin) - std.TestSetRealm(std.NewUserRealm(admin)) + t.SetOriginCaller(admin) NewWithAdmin("Foo", "FOO", 3, 1_111_111_000, 5_555, admin) NewWithAdmin("Bar", "BAR", 3, 2_222_000, 6_666, admin) checkBalances("step1", 1_111_111_000, 1_111_111_000, 0, 0, 0) @@ -47,26 +45,22 @@ func TestReadOnlyPublicMethods(t *testing.T) { checkBalances("step2", 1_444_444_000, 1_111_111_000, 333_333_000, 0, 0) // carl uses the faucet. - std.TestSetOrigCaller(carl) - std.TestSetRealm(std.NewUserRealm(carl)) + t.SetOriginCaller(carl) Faucet("FOO") checkBalances("step3", 1_444_449_555, 1_111_111_000, 333_333_000, 0, 5_555) // admin gives to bob some allowance. - std.TestSetOrigCaller(admin) - std.TestSetRealm(std.NewUserRealm(admin)) + t.SetOriginCaller(admin) Approve("FOO", bob, 1_000_000) checkBalances("step4", 1_444_449_555, 1_111_111_000, 333_333_000, 1_000_000, 5_555) // bob uses a part of the allowance. - std.TestSetOrigCaller(bob) - std.TestSetRealm(std.NewUserRealm(bob)) + t.SetOriginCaller(bob) TransferFrom("FOO", admin, carl, 400_000) checkBalances("step5", 1_444_449_555, 1_110_711_000, 333_333_000, 600_000, 405_555) // bob uses a part of the allowance. - std.TestSetOrigCaller(bob) - std.TestSetRealm(std.NewUserRealm(bob)) + t.SetOriginCaller(bob) TransferFrom("FOO", admin, carl, 600_000) checkBalances("step6", 1_444_449_555, 1_110_111_000, 333_333_000, 0, 1_005_555) } diff --git a/examples/gno.land/r/demo/grc20reg/grc20reg_test.gno b/examples/gno.land/r/demo/grc20reg/grc20reg_test.gno index c93365ff7a1..9481f716f49 100644 --- a/examples/gno.land/r/demo/grc20reg/grc20reg_test.gno +++ b/examples/gno.land/r/demo/grc20reg/grc20reg_test.gno @@ -10,7 +10,7 @@ import ( ) func TestRegistry(t *testing.T) { - std.TestSetRealm(std.NewCodeRealm("gno.land/r/demo/foo")) + t.SetRealm(std.NewCodeRealm("gno.land/r/demo/foo")) realmAddr := std.CurrentRealm().PkgPath() token, ledger := grc20.NewToken("TestToken", "TST", 4) ledger.Mint(std.CurrentRealm().Addr(), 1234567) diff --git a/examples/gno.land/r/demo/groups/z_1_a_filetest.gno b/examples/gno.land/r/demo/groups/z_1_a_filetest.gno index 71da1b966ec..596628013f5 100644 --- a/examples/gno.land/r/demo/groups/z_1_a_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_1_a_filetest.gno @@ -5,6 +5,7 @@ package groups_test import ( "std" + "testing" "gno.land/p/demo/testutils" "gno.land/r/demo/groups" @@ -19,40 +20,40 @@ func main() { caller := std.GetOrigCaller() // main users.Register("", "gnouser0", "my profile 1") - std.TestSetOrigCaller(admin) + testing.SetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + testing.SetOriginCaller(caller) // invite another addr test1 := testutils.TestAddress("gnouser1") users.Invite(test1.String()) // switch to test1 - std.TestSetOrigCaller(test1) + testing.SetOriginCaller(test1) users.Register(caller, "gnouser1", "my other profile 1") - std.TestSetOrigCaller(admin) + testing.SetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + testing.SetOriginCaller(caller) // invite another addr test2 := testutils.TestAddress("gnouser2") users.Invite(test2.String()) // switch to test1 - std.TestSetOrigCaller(test2) + testing.SetOriginCaller(test2) users.Register(caller, "gnouser2", "my other profile 2") - std.TestSetOrigCaller(admin) + testing.SetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + testing.SetOriginCaller(caller) // invite another addr test3 := testutils.TestAddress("gnouser3") users.Invite(test3.String()) // switch to test1 - std.TestSetOrigCaller(test3) + testing.SetOriginCaller(test3) users.Register(caller, "gnouser3", "my other profile 3") - std.TestSetOrigCaller(caller) + testing.SetOriginCaller(caller) gid = groups.CreateGroup("test_group") println(gid) diff --git a/examples/gno.land/r/demo/groups/z_1_c_filetest.gno b/examples/gno.land/r/demo/groups/z_1_c_filetest.gno index 6eaabb07cdf..9c34c6c108c 100644 --- a/examples/gno.land/r/demo/groups/z_1_c_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_1_c_filetest.gno @@ -5,6 +5,7 @@ package groups_test import ( "std" + "testing" "gno.land/p/demo/testutils" "gno.land/r/demo/groups" @@ -18,8 +19,8 @@ func main() { // add member via anon user test2 := testutils.TestAddress("test2") - std.TestSetOrigCaller(test2) - std.TestSetOrigSend(std.Coins{{"ugnot", 9000000}}, nil) + testing.SetOriginCaller(test2) + testing.SetOriginSend(std.Coins{{"ugnot", 9000000}}) groups.AddMember(gid, test2.String(), 42, "metadata3") } diff --git a/examples/gno.land/r/demo/groups/z_2_a_filetest.gno b/examples/gno.land/r/demo/groups/z_2_a_filetest.gno index 0c482e1b52f..55e167f509d 100644 --- a/examples/gno.land/r/demo/groups/z_2_a_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_2_a_filetest.gno @@ -5,6 +5,7 @@ package groups_test import ( "std" + "testing" "gno.land/p/demo/testutils" "gno.land/r/demo/groups" @@ -19,40 +20,40 @@ func main() { caller := std.GetOrigCaller() // main users.Register("", "gnouser0", "my profile 1") - std.TestSetOrigCaller(admin) + testing.SetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + testing.SetOriginCaller(caller) // invite another addr test1 := testutils.TestAddress("gnouser1") users.Invite(test1.String()) // switch to test1 - std.TestSetOrigCaller(test1) + testing.SetOriginCaller(test1) users.Register(caller, "gnouser1", "my other profile 1") - std.TestSetOrigCaller(admin) + testing.SetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + testing.SetOriginCaller(caller) // invite another addr test2 := testutils.TestAddress("gnouser2") users.Invite(test2.String()) // switch to test1 - std.TestSetOrigCaller(test2) + testing.SetOriginCaller(test2) users.Register(caller, "gnouser2", "my other profile 2") - std.TestSetOrigCaller(admin) + testing.SetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + testing.SetOriginCaller(caller) // invite another addr test3 := testutils.TestAddress("gnouser3") users.Invite(test3.String()) // switch to test1 - std.TestSetOrigCaller(test3) + testing.SetOriginCaller(test3) users.Register(caller, "gnouser3", "my other profile 3") - std.TestSetOrigCaller(caller) + testing.SetOriginCaller(caller) gid = groups.CreateGroup("test_group") println(gid) diff --git a/examples/gno.land/r/demo/groups/z_2_d_filetest.gno b/examples/gno.land/r/demo/groups/z_2_d_filetest.gno index 3caa726cbd3..a9fb976625f 100644 --- a/examples/gno.land/r/demo/groups/z_2_d_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_2_d_filetest.gno @@ -5,6 +5,7 @@ package groups_test import ( "std" + "testing" "gno.land/p/demo/testutils" "gno.land/r/demo/groups" @@ -20,8 +21,8 @@ func main() { // delete member via anon user test2 := testutils.TestAddress("test2") - std.TestSetOrigCaller(test2) - std.TestSetOrigSend(std.Coins{{"ugnot", 9000000}}, nil) + testing.SetOriginCaller(test2) + testing.SetOriginSend(std.Coins{{"ugnot", 9000000}}) groups.DeleteMember(gid, 0) println(groups.Render("")) diff --git a/examples/gno.land/r/demo/groups/z_2_g_filetest.gno b/examples/gno.land/r/demo/groups/z_2_g_filetest.gno index 6230b110c74..eefba66f04c 100644 --- a/examples/gno.land/r/demo/groups/z_2_g_filetest.gno +++ b/examples/gno.land/r/demo/groups/z_2_g_filetest.gno @@ -5,6 +5,7 @@ package groups_test import ( "std" + "testing" "gno.land/p/demo/testutils" "gno.land/r/demo/groups" @@ -20,8 +21,8 @@ func main() { // delete group via anon user test2 := testutils.TestAddress("test2") - std.TestSetOrigCaller(test2) - std.TestSetOrigSend(std.Coins{{"ugnot", 9000000}}, nil) + testing.SetOriginCaller(test2) + testing.SetOriginSend(std.Coins{{"ugnot", 9000000}}) groups.DeleteGroup(gid) println(groups.Render("")) diff --git a/examples/gno.land/r/demo/keystore/keystore_test.gno b/examples/gno.land/r/demo/keystore/keystore_test.gno index 03b61e79663..ee7f9c1cb8c 100644 --- a/examples/gno.land/r/demo/keystore/keystore_test.gno +++ b/examples/gno.land/r/demo/keystore/keystore_test.gno @@ -62,7 +62,7 @@ func TestRender(t *testing.T) { } p = strings.TrimSuffix(p, ":") t.Run(p, func(t *testing.T) { - std.TestSetOrigCaller(tc.caller) + t.SetOriginCaller(tc.caller) var act string if len(tc.ps) > 0 && tc.ps[0] == "set" { act = strings.TrimSpace(Set(tc.ps[1], tc.ps[2])) diff --git a/examples/gno.land/r/demo/microblog/microblog_test.gno b/examples/gno.land/r/demo/microblog/microblog_test.gno index 9ad98d3cbfe..0d70b2cfd01 100644 --- a/examples/gno.land/r/demo/microblog/microblog_test.gno +++ b/examples/gno.land/r/demo/microblog/microblog_test.gno @@ -15,7 +15,7 @@ func TestMicroblog(t *testing.T) { author2 std.Address = testutils.TestAddress("author2") ) - std.TestSetOrigCaller(author1) + t.SetOriginCaller(author1) urequire.Equal(t, "404", Render("/wrongpath"), "rendering not giving 404") urequire.NotEqual(t, "404", Render(""), "rendering / should not give 404") @@ -27,7 +27,7 @@ func TestMicroblog(t *testing.T) { _, err = m.GetPage("no such author") urequire.Error(t, err, "silo should not exist") - std.TestSetOrigCaller(author2) + t.SetOriginCaller(author2) urequire.NoError(t, m.NewPost("hello, web3"), "could not create post") urequire.NoError(t, m.NewPost("hello again, web3"), "could not create post") diff --git a/examples/gno.land/r/demo/profile/profile_test.gno b/examples/gno.land/r/demo/profile/profile_test.gno index 3947897289e..63901b5355d 100644 --- a/examples/gno.land/r/demo/profile/profile_test.gno +++ b/examples/gno.land/r/demo/profile/profile_test.gno @@ -21,7 +21,7 @@ var ( ) func TestStringFields(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(alice)) + t.SetRealm(std.NewUserRealm(alice)) // Get before setting name := GetStringField(alice, DisplayName, "anon") @@ -48,7 +48,7 @@ func TestStringFields(t *testing.T) { } func TestIntFields(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(bob)) + t.SetRealm(std.NewUserRealm(bob)) // Get before setting age := GetIntField(bob, Age, 25) @@ -68,7 +68,7 @@ func TestIntFields(t *testing.T) { } func TestBoolFields(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(charlie)) + t.SetRealm(std.NewUserRealm(charlie)) // Get before setting hiring := GetBoolField(charlie, AvailableForHiring, false) @@ -89,19 +89,19 @@ func TestBoolFields(t *testing.T) { func TestMultipleProfiles(t *testing.T) { // Set profile for user1 - std.TestSetRealm(std.NewUserRealm(user1)) + t.SetRealm(std.NewUserRealm(user1)) updated := SetStringField(DisplayName, "User One") uassert.Equal(t, updated, false) // Set profile for user2 - std.TestSetRealm(std.NewUserRealm(user2)) + t.SetRealm(std.NewUserRealm(user2)) updated = SetStringField(DisplayName, "User Two") uassert.Equal(t, updated, false) // Get profiles - std.TestSetRealm(std.NewUserRealm(user1)) // Switch back to user1 + t.SetRealm(std.NewUserRealm(user1)) // Switch back to user1 name1 := GetStringField(user1, DisplayName, "anon") - std.TestSetRealm(std.NewUserRealm(user2)) // Switch back to user2 + t.SetRealm(std.NewUserRealm(user2)) // Switch back to user2 name2 := GetStringField(user2, DisplayName, "anon") uassert.Equal(t, "User One", name1) @@ -109,7 +109,7 @@ func TestMultipleProfiles(t *testing.T) { } func TestArbitraryStringField(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(user1)) + t.SetRealm(std.NewUserRealm(user1)) // Set arbitrary string field updated := SetStringField("MyEmail", "my@email.com") @@ -120,7 +120,7 @@ func TestArbitraryStringField(t *testing.T) { } func TestArbitraryIntField(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(user1)) + t.SetRealm(std.NewUserRealm(user1)) // Set arbitrary int field updated := SetIntField("MyIncome", 100_000) @@ -131,7 +131,7 @@ func TestArbitraryIntField(t *testing.T) { } func TestArbitraryBoolField(t *testing.T) { - std.TestSetRealm(std.NewUserRealm(user1)) + t.SetRealm(std.NewUserRealm(user1)) // Set arbitrary int field updated := SetBoolField("IsWinner", true) diff --git a/examples/gno.land/r/demo/tests/nestedpkg_test.gno b/examples/gno.land/r/demo/tests/nestedpkg_test.gno index 904e8cc71a7..7f9ae6b8d4c 100644 --- a/examples/gno.land/r/demo/tests/nestedpkg_test.gno +++ b/examples/gno.land/r/demo/tests/nestedpkg_test.gno @@ -8,7 +8,7 @@ import ( func TestNestedPkg(t *testing.T) { // direct child cur := "gno.land/r/demo/tests/foo" - std.TestSetRealm(std.NewCodeRealm(cur)) + t.SetRealm(std.NewCodeRealm(cur)) if !IsCallerSubPath() { t.Errorf(cur + " should be a sub path") } @@ -21,7 +21,7 @@ func TestNestedPkg(t *testing.T) { // grand-grand-child cur = "gno.land/r/demo/tests/foo/bar/baz" - std.TestSetRealm(std.NewCodeRealm(cur)) + t.SetRealm(std.NewCodeRealm(cur)) if !IsCallerSubPath() { t.Errorf(cur + " should be a sub path") } @@ -34,7 +34,7 @@ func TestNestedPkg(t *testing.T) { // direct parent cur = "gno.land/r/demo" - std.TestSetRealm(std.NewCodeRealm(cur)) + t.SetRealm(std.NewCodeRealm(cur)) if IsCallerSubPath() { t.Errorf(cur + " should not be a sub path") } @@ -47,7 +47,7 @@ func TestNestedPkg(t *testing.T) { // fake parent (prefix) cur = "gno.land/r/dem" - std.TestSetRealm(std.NewCodeRealm(cur)) + t.SetRealm(std.NewCodeRealm(cur)) if IsCallerSubPath() { t.Errorf(cur + " should not be a sub path") } @@ -60,7 +60,7 @@ func TestNestedPkg(t *testing.T) { // different namespace cur = "gno.land/r/foo" - std.TestSetRealm(std.NewCodeRealm(cur)) + t.SetRealm(std.NewCodeRealm(cur)) if IsCallerSubPath() { t.Errorf(cur + " should not be a sub path") } diff --git a/examples/gno.land/r/demo/tests/z2_filetest.gno b/examples/gno.land/r/demo/tests/z2_filetest.gno index 147d2c12c6c..225210be242 100644 --- a/examples/gno.land/r/demo/tests/z2_filetest.gno +++ b/examples/gno.land/r/demo/tests/z2_filetest.gno @@ -2,6 +2,7 @@ package main import ( "std" + "testing" "gno.land/p/demo/testutils" "gno.land/r/demo/tests" @@ -14,7 +15,7 @@ func main() { eoa = testutils.TestAddress("someone") rTestsAddr = std.DerivePkgAddr("gno.land/r/demo/tests") ) - std.TestSetOrigCaller(eoa) + testing.SetOriginCaller(eoa) println("tests.GetPrevRealm().Addr(): ", tests.GetPrevRealm().Addr()) println("tests.GetRSubtestsPrevRealm().Addr(): ", tests.GetRSubtestsPrevRealm().Addr()) } diff --git a/examples/gno.land/r/demo/tests/z3_filetest.gno b/examples/gno.land/r/demo/tests/z3_filetest.gno index 5430e7f7151..0620092cde6 100644 --- a/examples/gno.land/r/demo/tests/z3_filetest.gno +++ b/examples/gno.land/r/demo/tests/z3_filetest.gno @@ -3,6 +3,7 @@ package test_test import ( "std" + "testing" "gno.land/p/demo/testutils" "gno.land/r/demo/tests" @@ -13,7 +14,7 @@ func main() { eoa = testutils.TestAddress("someone") rTestsAddr = std.DerivePkgAddr("gno.land/r/demo/tests") ) - std.TestSetOrigCaller(eoa) + testing.SetOriginCaller(eoa) // Contrarily to z2_filetest.gno we EXPECT GetPrevRealms != eoa (#1704) if addr := tests.GetPrevRealm().Addr(); addr != eoa { println("want tests.GetPrevRealm().Addr ==", eoa, "got", addr) diff --git a/examples/gno.land/r/demo/users/z_0_filetest.gno b/examples/gno.land/r/demo/users/z_0_filetest.gno index cbb2e9209f4..0cf4531a9cd 100644 --- a/examples/gno.land/r/demo/users/z_0_filetest.gno +++ b/examples/gno.land/r/demo/users/z_0_filetest.gno @@ -2,12 +2,13 @@ package main import ( "std" + "testing" "gno.land/r/demo/users" ) func main() { - std.TestSetOrigSend(std.Coins{std.NewCoin("dontcare", 1)}, nil) + testing.SetOriginSend(std.Coins{std.NewCoin("dontcare", 1)}) users.Register("", "gnouser", "my profile") println("done") } diff --git a/examples/gno.land/r/demo/users/z_10_filetest.gno b/examples/gno.land/r/demo/users/z_10_filetest.gno index afeecffcc42..603a89516cc 100644 --- a/examples/gno.land/r/demo/users/z_10_filetest.gno +++ b/examples/gno.land/r/demo/users/z_10_filetest.gno @@ -3,6 +3,7 @@ package users_test import ( "std" + "testing" "gno.land/p/demo/testutils" "gno.land/r/demo/users" @@ -14,17 +15,17 @@ func init() { caller := std.GetOrigCaller() // main test2 := testutils.TestAddress("test2") // as admin, invite gnouser and test2 - std.TestSetOrigCaller(admin) + testing.SetOriginCaller(admin) users.Invite(caller.String() + "\n" + test2.String()) // register as caller - std.TestSetOrigCaller(caller) + testing.SetOriginCaller(caller) users.Register(admin, "gnouser", "my profile") } func main() { // register as test2 test2 := testutils.TestAddress("test2") - std.TestSetOrigCaller(test2) + testing.SetOriginCaller(test2) users.Register(admin, "test222", "my profile 2") println("done") } diff --git a/examples/gno.land/r/demo/users/z_11_filetest.gno b/examples/gno.land/r/demo/users/z_11_filetest.gno index 27c7e9813da..3bbde91cb2a 100644 --- a/examples/gno.land/r/demo/users/z_11_filetest.gno +++ b/examples/gno.land/r/demo/users/z_11_filetest.gno @@ -4,6 +4,7 @@ package main import ( "std" + "testing" "gno.land/r/demo/users" ) @@ -12,11 +13,11 @@ const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { caller := std.GetOrigCaller() // main - std.TestSetOrigCaller(admin) + testing.SetOriginCaller(admin) users.AdminAddRestrictedName("superrestricted") // test restricted name - std.TestSetOrigCaller(caller) + testing.SetOriginCaller(caller) users.Register("", "superrestricted", "my profile") println("done") } diff --git a/examples/gno.land/r/demo/users/z_11b_filetest.gno b/examples/gno.land/r/demo/users/z_11b_filetest.gno index be508963911..9c8eb2082f7 100644 --- a/examples/gno.land/r/demo/users/z_11b_filetest.gno +++ b/examples/gno.land/r/demo/users/z_11b_filetest.gno @@ -4,6 +4,7 @@ package main import ( "std" + "testing" "gno.land/r/demo/users" ) @@ -12,13 +13,13 @@ const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { caller := std.GetOrigCaller() // main - std.TestSetOrigCaller(admin) + testing.SetOriginCaller(admin) // add restricted name users.AdminAddRestrictedName("superrestricted") // grant invite to caller users.Invite(caller.String()) // set back caller - std.TestSetOrigCaller(caller) + testing.SetOriginCaller(caller) // register restricted name with admin invite users.Register(admin, "superrestricted", "my profile") println("done") diff --git a/examples/gno.land/r/demo/users/z_2_filetest.gno b/examples/gno.land/r/demo/users/z_2_filetest.gno index c1b92790f8b..8cda98c66d3 100644 --- a/examples/gno.land/r/demo/users/z_2_filetest.gno +++ b/examples/gno.land/r/demo/users/z_2_filetest.gno @@ -4,6 +4,7 @@ package main import ( "std" + "testing" "gno.land/p/demo/testutils" "gno.land/r/demo/users" @@ -15,15 +16,15 @@ func main() { caller := std.GetOrigCaller() // main users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser - std.TestSetOrigCaller(admin) + testing.SetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + testing.SetOriginCaller(caller) // invite another addr test1 := testutils.TestAddress("test1") users.Invite(test1.String()) // switch to test1 - std.TestSetOrigCaller(test1) + testing.SetOriginCaller(test1) users.Register(caller, "satoshi", "my other profile") println("done") } diff --git a/examples/gno.land/r/demo/users/z_3_filetest.gno b/examples/gno.land/r/demo/users/z_3_filetest.gno index 5402235e03d..af8e6826276 100644 --- a/examples/gno.land/r/demo/users/z_3_filetest.gno +++ b/examples/gno.land/r/demo/users/z_3_filetest.gno @@ -4,6 +4,7 @@ package main import ( "std" + "testing" "gno.land/p/demo/testutils" "gno.land/r/demo/users" @@ -15,16 +16,16 @@ func main() { caller := std.GetOrigCaller() // main users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser - std.TestSetOrigCaller(admin) + testing.SetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + testing.SetOriginCaller(caller) // invite another addr test1 := testutils.TestAddress("test1") users.Invite(test1.String()) // switch to test1 - std.TestSetOrigCaller(test1) - std.TestSetOrigSend(std.Coins{{"dontcare", 1}}, nil) + testing.SetOriginCaller(test1) + testing.SetOriginSend(std.Coins{{"dontcare", 1}}) users.Register(caller, "satoshi", "my other profile") println("done") } diff --git a/examples/gno.land/r/demo/users/z_4_filetest.gno b/examples/gno.land/r/demo/users/z_4_filetest.gno index 613fadf9625..ac2a4940929 100644 --- a/examples/gno.land/r/demo/users/z_4_filetest.gno +++ b/examples/gno.land/r/demo/users/z_4_filetest.gno @@ -4,6 +4,7 @@ package main import ( "std" + "testing" "gno.land/p/demo/testutils" "gno.land/r/demo/users" @@ -15,17 +16,17 @@ func main() { caller := std.GetOrigCaller() // main users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser - std.TestSetOrigCaller(admin) + testing.SetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + testing.SetOriginCaller(caller) // invite another addr test1 := testutils.TestAddress("test1") test2 := testutils.TestAddress("test2") users.Invite(test1.String()) // switch to test2 (not test1) - std.TestSetOrigCaller(test2) - std.TestSetOrigSend(std.Coins{{"dontcare", 1}}, nil) + testing.SetOriginCaller(test2) + testing.SetOriginSend(std.Coins{{"dontcare", 1}}) users.Register(caller, "satoshi", "my other profile") println("done") } diff --git a/examples/gno.land/r/demo/users/z_5_filetest.gno b/examples/gno.land/r/demo/users/z_5_filetest.gno index 6465cc9c378..3a5b2c430d8 100644 --- a/examples/gno.land/r/demo/users/z_5_filetest.gno +++ b/examples/gno.land/r/demo/users/z_5_filetest.gno @@ -4,6 +4,7 @@ package main import ( "std" + "testing" "gno.land/p/demo/testutils" "gno.land/r/demo/users" @@ -15,16 +16,16 @@ func main() { caller := std.GetOrigCaller() // main users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser - std.TestSetOrigCaller(admin) + testing.SetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + testing.SetOriginCaller(caller) // invite another addr test1 := testutils.TestAddress("test1") users.Invite(test1.String()) // switch to test1 - std.TestSetOrigCaller(test1) - std.TestSetOrigSend(std.Coins{{"dontcare", 1}}, nil) + testing.SetOriginCaller(test1) + testing.SetOriginSend(std.Coins{{"dontcare", 1}}) users.Register(caller, "satoshi", "my other profile") println(users.Render("")) println("========================================") diff --git a/examples/gno.land/r/demo/users/z_6_filetest.gno b/examples/gno.land/r/demo/users/z_6_filetest.gno index 919088088a2..b3201bf11f5 100644 --- a/examples/gno.land/r/demo/users/z_6_filetest.gno +++ b/examples/gno.land/r/demo/users/z_6_filetest.gno @@ -2,6 +2,7 @@ package main import ( "std" + "testing" "gno.land/r/demo/users" ) @@ -11,7 +12,7 @@ const admin = std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") func main() { caller := std.GetOrigCaller() // as admin, grant invites to unregistered user. - std.TestSetOrigCaller(admin) + testing.SetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") println("done") } diff --git a/examples/gno.land/r/demo/users/z_7_filetest.gno b/examples/gno.land/r/demo/users/z_7_filetest.gno index 1d3c9e3a917..d083850f6d0 100644 --- a/examples/gno.land/r/demo/users/z_7_filetest.gno +++ b/examples/gno.land/r/demo/users/z_7_filetest.gno @@ -4,6 +4,7 @@ package main import ( "std" + "testing" "gno.land/p/demo/testutils" "gno.land/r/demo/users" @@ -15,19 +16,19 @@ func main() { caller := std.GetOrigCaller() // main users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser - std.TestSetOrigCaller(admin) + testing.SetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + testing.SetOriginCaller(caller) // invite another addr test1 := testutils.TestAddress("test1") users.Invite(test1.String()) // switch to test1 - std.TestSetOrigCaller(test1) - std.TestSetOrigSend(std.Coins{{"dontcare", 1}}, nil) + testing.SetOriginCaller(test1) + testing.SetOriginSend(std.Coins{{"dontcare", 1}}) users.Register(caller, "satoshi", "my other profile") // as admin, grant invites to gnouser(again) and satoshi. - std.TestSetOrigCaller(admin) + testing.SetOriginCaller(admin) users.GrantInvites(caller.String() + ":1\n" + test1.String() + ":1") println("done") } diff --git a/examples/gno.land/r/demo/users/z_7b_filetest.gno b/examples/gno.land/r/demo/users/z_7b_filetest.gno index 09c15bb135d..5c6fc3e030f 100644 --- a/examples/gno.land/r/demo/users/z_7b_filetest.gno +++ b/examples/gno.land/r/demo/users/z_7b_filetest.gno @@ -4,6 +4,7 @@ package main import ( "std" + "testing" "gno.land/p/demo/testutils" "gno.land/r/demo/users" @@ -15,19 +16,19 @@ func main() { caller := std.GetOrigCaller() // main users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser - std.TestSetOrigCaller(admin) + testing.SetOriginCaller(admin) users.GrantInvites(caller.String() + ":1\n") // switch back to caller - std.TestSetOrigCaller(caller) + testing.SetOriginCaller(caller) // invite another addr test1 := testutils.TestAddress("test1") users.Invite(test1.String()) // switch to test1 - std.TestSetOrigCaller(test1) - std.TestSetOrigSend(std.Coins{{"dontcare", 1}}, nil) + testing.SetOriginCaller(test1) + testing.SetOriginSend(std.Coins{{"dontcare", 1}}) users.Register(caller, "satoshi", "my other profile") // as admin, grant invites to gnouser(again) and satoshi. - std.TestSetOrigCaller(admin) + testing.SetOriginCaller(admin) users.GrantInvites(caller.String() + ":1\n" + test1.String() + ":1") println("done") } diff --git a/examples/gno.land/r/demo/users/z_8_filetest.gno b/examples/gno.land/r/demo/users/z_8_filetest.gno index 78fada74a71..dbf081144c5 100644 --- a/examples/gno.land/r/demo/users/z_8_filetest.gno +++ b/examples/gno.land/r/demo/users/z_8_filetest.gno @@ -4,6 +4,7 @@ package main import ( "std" + "testing" "gno.land/p/demo/testutils" "gno.land/r/demo/users" @@ -15,19 +16,19 @@ func main() { caller := std.GetOrigCaller() // main users.Register("", "gnouser", "my profile") // as admin, grant invites to gnouser - std.TestSetOrigCaller(admin) + testing.SetOriginCaller(admin) users.GrantInvites(caller.String() + ":1") // switch back to caller - std.TestSetOrigCaller(caller) + testing.SetOriginCaller(caller) // invite another addr test1 := testutils.TestAddress("test1") users.Invite(test1.String()) // switch to test1 - std.TestSetOrigCaller(test1) - std.TestSetOrigSend(std.Coins{{"dontcare", 1}}, nil) + testing.SetOriginCaller(test1) + testing.SetOriginSend(std.Coins{{"dontcare", 1}}) users.Register(caller, "satoshi", "my other profile") // as admin, grant invites to gnouser(again) and nonexistent user. - std.TestSetOrigCaller(admin) + testing.SetOriginCaller(admin) test2 := testutils.TestAddress("test2") users.GrantInvites(caller.String() + ":1\n" + test2.String() + ":1") println("done") diff --git a/examples/gno.land/r/demo/users/z_9_filetest.gno b/examples/gno.land/r/demo/users/z_9_filetest.gno index c73c685aebd..084a4642fcf 100644 --- a/examples/gno.land/r/demo/users/z_9_filetest.gno +++ b/examples/gno.land/r/demo/users/z_9_filetest.gno @@ -2,6 +2,7 @@ package main import ( "std" + "testing" "gno.land/p/demo/testutils" "gno.land/r/demo/users" @@ -13,13 +14,13 @@ func main() { caller := std.GetOrigCaller() // main test2 := testutils.TestAddress("test2") // as admin, invite gnouser and test2 - std.TestSetOrigCaller(admin) + testing.SetOriginCaller(admin) users.Invite(caller.String() + "\n" + test2.String()) // register as caller - std.TestSetOrigCaller(caller) + testing.SetOriginCaller(caller) users.Register(admin, "gnouser", "my profile") // register as test2 - std.TestSetOrigCaller(test2) + testing.SetOriginCaller(test2) users.Register(admin, "test222", "my profile 2") println("done") } diff --git a/examples/gno.land/r/demo/wugnot/z0_filetest.gno b/examples/gno.land/r/demo/wugnot/z0_filetest.gno index ff2ea86bc0d..a5702515345 100644 --- a/examples/gno.land/r/demo/wugnot/z0_filetest.gno +++ b/examples/gno.land/r/demo/wugnot/z0_filetest.gno @@ -4,6 +4,7 @@ package wugnot_test import ( "fmt" "std" + "testing" "gno.land/p/demo/testutils" "gno.land/r/demo/wugnot" @@ -16,19 +17,19 @@ var ( ) func main() { - std.TestSetOrigPkgAddr(addrc) - std.TestIssueCoins(addrc, std.Coins{{"ugnot", 100000001}}) // TODO: remove this + testing.SetOriginPkgAddress(addrc) + testing.IssueCoins(addrc, std.Coins{{"ugnot", 100000001}}) // TODO: remove this // issue ugnots - std.TestIssueCoins(addr1, std.Coins{{"ugnot", 100000001}}) + testing.IssueCoins(addr1, std.Coins{{"ugnot", 100000001}}) // print initial state printBalances() // println(wugnot.Render("queues")) // println("A -", wugnot.Render("")) - std.TestSetOrigCaller(addr1) - std.TestSetOrigSend(std.Coins{{"ugnot", 123_400}}, nil) + testing.SetOriginCaller(addr1) + testing.SetOriginSend(std.Coins{{"ugnot", 123_400}}) wugnot.Deposit() printBalances() wugnot.Withdraw(4242) @@ -38,7 +39,7 @@ func main() { func printBalances() { printSingleBalance := func(name string, addr std.Address) { wugnotBal := wugnot.BalanceOf(addr) - std.TestSetOrigCaller(addr) + testing.SetOriginCaller(addr) robanker := std.GetBanker(std.BankerTypeReadonly) coins := robanker.GetCoins(addr).AmountOf("ugnot") fmt.Printf("| %-13s | addr=%s | wugnot=%-5d | ugnot=%-9d |\n", diff --git a/examples/gno.land/r/gnoland/blog/gnoblog_test.gno b/examples/gno.land/r/gnoland/blog/gnoblog_test.gno index d046eb80f42..dac24fae376 100644 --- a/examples/gno.land/r/gnoland/blog/gnoblog_test.gno +++ b/examples/gno.land/r/gnoland/blog/gnoblog_test.gno @@ -7,7 +7,7 @@ import ( ) func TestPackage(t *testing.T) { - std.TestSetOrigCaller(std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5")) + t.SetOriginCaller(std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5")) // by default, no posts. { got := Render("") diff --git a/examples/gno.land/r/gnoland/events/events_test.gno b/examples/gno.land/r/gnoland/events/events_test.gno index 1d79b754ee4..59ead6d453b 100644 --- a/examples/gno.land/r/gnoland/events/events_test.gno +++ b/examples/gno.land/r/gnoland/events/events_test.gno @@ -18,8 +18,7 @@ var ( ) func TestAddEvent(t *testing.T) { - std.TestSetOrigCaller(su) - std.TestSetRealm(suRealm) + t.SetRealm(suRealm) e1Start := parsedTimeNow.Add(time.Hour * 24 * 5) e1End := e1Start.Add(time.Hour * 4) @@ -61,8 +60,7 @@ func TestAddEvent(t *testing.T) { } func TestAddEventErrors(t *testing.T) { - std.TestSetOrigCaller(su) - std.TestSetRealm(suRealm) + t.SetRealm(suRealm) _, err := AddEvent("", "sample desc", "gno.land", "gnome land", "2009-02-13T23:31:31Z", "2009-02-13T23:33:31Z") uassert.ErrorIs(t, err, ErrEmptyName) @@ -85,8 +83,7 @@ func TestAddEventErrors(t *testing.T) { } func TestDeleteEvent(t *testing.T) { - std.TestSetOrigCaller(su) - std.TestSetRealm(suRealm) + t.SetRealm(suRealm) e1Start := parsedTimeNow.Add(time.Hour * 24 * 5) e1End := e1Start.Add(time.Hour * 4) @@ -108,8 +105,7 @@ func TestDeleteEvent(t *testing.T) { } func TestEditEvent(t *testing.T) { - std.TestSetOrigCaller(su) - std.TestSetRealm(suRealm) + t.SetRealm(suRealm) e1Start := parsedTimeNow.Add(time.Hour * 24 * 5) e1End := e1Start.Add(time.Hour * 4) @@ -138,8 +134,7 @@ func TestEditEvent(t *testing.T) { } func TestInvalidEdit(t *testing.T) { - std.TestSetOrigCaller(su) - std.TestSetRealm(suRealm) + t.SetRealm(suRealm) uassert.PanicsWithMessage(t, ErrNoSuchID.Error(), func() { EditEvent("123123", "", "", "", "", "", "") @@ -165,8 +160,7 @@ func TestParseTimes(t *testing.T) { } func TestRenderEventWidget(t *testing.T) { - std.TestSetOrigCaller(su) - std.TestSetRealm(suRealm) + t.SetRealm(suRealm) // No events yet events = nil diff --git a/examples/gno.land/r/gnoland/faucet/faucet_test.gno b/examples/gno.land/r/gnoland/faucet/faucet_test.gno index 5672f317469..22e46a5a163 100644 --- a/examples/gno.land/r/gnoland/faucet/faucet_test.gno +++ b/examples/gno.land/r/gnoland/faucet/faucet_test.gno @@ -27,26 +27,26 @@ func TestPackage(t *testing.T) { test1addr = testutils.TestAddress("test1") ) // deposit 1000gnot to faucet contract - std.TestIssueCoins(faucetaddr, std.Coins{{"ugnot", 1000000000}}) + testing.IssueCoins(faucetaddr, std.Coins{{"ugnot", 1000000000}}) assertBalance(t, faucetaddr, 1000000000) // by default, balance is empty, and as a user I cannot call Transfer, or Admin commands. assertBalance(t, test1addr, 0) - std.TestSetOrigCaller(test1addr) + t.SetOriginCaller(test1addr) assertErr(t, faucet.Transfer(test1addr, 1000000)) assertErr(t, faucet.AdminAddController(controlleraddr1)) - std.TestSetOrigCaller(controlleraddr1) + t.SetOriginCaller(controlleraddr1) assertErr(t, faucet.Transfer(test1addr, 1000000)) // as an admin, add the controller to contract and deposit more 2000gnot to contract - std.TestSetOrigCaller(adminaddr) + t.SetOriginCaller(adminaddr) assertNoErr(t, faucet.AdminAddController(controlleraddr1)) assertBalance(t, faucetaddr, 1000000000) // now, send some tokens as controller. - std.TestSetOrigCaller(controlleraddr1) + t.SetOriginCaller(controlleraddr1) assertNoErr(t, faucet.Transfer(test1addr, 1000000)) assertBalance(t, test1addr, 1000000) assertNoErr(t, faucet.Transfer(test1addr, 1000000)) @@ -55,13 +55,13 @@ func TestPackage(t *testing.T) { // remove controller // as an admin, remove controller - std.TestSetOrigCaller(adminaddr) + t.SetOriginCaller(adminaddr) assertNoErr(t, faucet.AdminRemoveController(controlleraddr1)) - std.TestSetOrigCaller(controlleraddr1) + t.SetOriginCaller(controlleraddr1) assertErr(t, faucet.Transfer(test1addr, 1000000)) // duplicate controller - std.TestSetOrigCaller(adminaddr) + t.SetOriginCaller(adminaddr) assertNoErr(t, faucet.AdminAddController(controlleraddr1)) assertErr(t, faucet.AdminAddController(controlleraddr1)) // add more than more than allowed controllers @@ -77,13 +77,13 @@ func TestPackage(t *testing.T) { assertErr(t, faucet.AdminAddController(controlleraddr11)) // send more than per transfer limit - std.TestSetOrigCaller(adminaddr) + t.SetOriginCaller(adminaddr) faucet.AdminSetTransferLimit(300000000) - std.TestSetOrigCaller(controlleraddr1) + t.SetOriginCaller(controlleraddr1) assertErr(t, faucet.Transfer(test1addr, 301000000)) // block transefer from the address not on the controllers list. - std.TestSetOrigCaller(controlleraddr11) + t.SetOriginCaller(controlleraddr11) assertErr(t, faucet.Transfer(test1addr, 1000000)) } diff --git a/examples/gno.land/r/gnoland/faucet/z0_filetest.gno b/examples/gno.land/r/gnoland/faucet/z0_filetest.gno index 7e729bdd358..5e169f0a81f 100644 --- a/examples/gno.land/r/gnoland/faucet/z0_filetest.gno +++ b/examples/gno.land/r/gnoland/faucet/z0_filetest.gno @@ -2,6 +2,7 @@ package main import ( "std" + "testing" "gno.land/r/gnoland/faucet" ) @@ -9,7 +10,7 @@ import ( // mints ugnot to current realm func init() { facuetaddr := std.DerivePkgAddr("gno.land/r/gnoland/faucet") - std.TestIssueCoins(facuetaddr, std.Coins{{"ugnot", 200000000}}) + testing.IssueCoins(facuetaddr, std.Coins{{"ugnot", 200000000}}) } // assert render with empty path and no controllers diff --git a/examples/gno.land/r/gnoland/faucet/z1_filetest.gno b/examples/gno.land/r/gnoland/faucet/z1_filetest.gno index c6fd6298488..15c83c66e14 100644 --- a/examples/gno.land/r/gnoland/faucet/z1_filetest.gno +++ b/examples/gno.land/r/gnoland/faucet/z1_filetest.gno @@ -2,6 +2,7 @@ package main import ( "std" + "testing" "gno.land/r/gnoland/faucet" ) @@ -9,7 +10,7 @@ import ( // mints ugnot to current realm func init() { facuetaddr := std.DerivePkgAddr("gno.land/r/gnoland/faucet") - std.TestIssueCoins(facuetaddr, std.Coins{{"ugnot", 200000000}}) + testing.IssueCoins(facuetaddr, std.Coins{{"ugnot", 200000000}}) } // assert render with a path and no controllers diff --git a/examples/gno.land/r/gnoland/faucet/z2_filetest.gno b/examples/gno.land/r/gnoland/faucet/z2_filetest.gno index d0616b3afcd..7282adcb372 100644 --- a/examples/gno.land/r/gnoland/faucet/z2_filetest.gno +++ b/examples/gno.land/r/gnoland/faucet/z2_filetest.gno @@ -2,6 +2,7 @@ package main import ( "std" + "testing" "gno.land/p/demo/testutils" "gno.land/r/gnoland/faucet" @@ -10,7 +11,7 @@ import ( // mints ugnot to current realm func init() { facuetaddr := std.DerivePkgAddr("gno.land/r/gnoland/faucet") - std.TestIssueCoins(facuetaddr, std.Coins{{"ugnot", 200000000}}) + testing.IssueCoins(facuetaddr, std.Coins{{"ugnot", 200000000}}) } // assert render with empty path and 2 controllers @@ -20,7 +21,7 @@ func main() { controlleraddr1 = testutils.TestAddress("controller1") controlleraddr2 = testutils.TestAddress("controller2") ) - std.TestSetOrigCaller(adminaddr) + testing.SetOriginCaller(adminaddr) err := faucet.AdminAddController(controlleraddr1) if err != "" { panic(err) diff --git a/examples/gno.land/r/gnoland/faucet/z3_filetest.gno b/examples/gno.land/r/gnoland/faucet/z3_filetest.gno index 0da06593710..76252d6b4a9 100644 --- a/examples/gno.land/r/gnoland/faucet/z3_filetest.gno +++ b/examples/gno.land/r/gnoland/faucet/z3_filetest.gno @@ -2,6 +2,7 @@ package main import ( "std" + "testing" "gno.land/p/demo/testutils" "gno.land/r/gnoland/faucet" @@ -10,7 +11,7 @@ import ( // mints coints to current realm func init() { facuetaddr := std.DerivePkgAddr("gno.land/r/gnoland/faucet") - std.TestIssueCoins(facuetaddr, std.Coins{{"ugnot", 200000000}}) + testing.IssueCoins(facuetaddr, std.Coins{{"ugnot", 200000000}}) } // assert render with 2 controllers and 2 transfers @@ -22,7 +23,7 @@ func main() { testaddr1 = testutils.TestAddress("test1") testaddr2 = testutils.TestAddress("test2") ) - std.TestSetOrigCaller(adminaddr) + testing.SetOriginCaller(adminaddr) err := faucet.AdminAddController(controlleraddr1) if err != "" { panic(err) @@ -31,12 +32,12 @@ func main() { if err != "" { panic(err) } - std.TestSetOrigCaller(controlleraddr1) + testing.SetOriginCaller(controlleraddr1) err = faucet.Transfer(testaddr1, 1000000) if err != "" { panic(err) } - std.TestSetOrigCaller(controlleraddr2) + testing.SetOriginCaller(controlleraddr2) err = faucet.Transfer(testaddr1, 2000000) if err != "" { panic(err) diff --git a/examples/gno.land/r/gnoland/ghverify/contract_test.gno b/examples/gno.land/r/gnoland/ghverify/contract_test.gno index 5c0be0afcb1..961ef94ec36 100644 --- a/examples/gno.land/r/gnoland/ghverify/contract_test.gno +++ b/examples/gno.land/r/gnoland/ghverify/contract_test.gno @@ -19,7 +19,7 @@ func TestVerificationLifecycle(t *testing.T) { } // Make a verification request with the created user. - std.TestSetOrigCaller(user1Address) + t.SetOriginCaller(user1Address) RequestVerification("deelawn") // A subsequent request from the same address should panic because there is @@ -44,13 +44,13 @@ func TestVerificationLifecycle(t *testing.T) { } // Make a verification request with the created user. - std.TestSetOrigCaller(user2Address) + t.SetOriginCaller(user2Address) RequestVerification("omarsy") // Set the caller back to the whitelisted user and verify that the feed data // returned matches what should have been created by the `RequestVerification` // invocation. - std.TestSetOrigCaller(defaultAddress) + t.SetOriginCaller(defaultAddress) result = GnorkleEntrypoint("request") expResult := `[{"id":"` + string(user1Address) + `","type":"0","value_type":"string","tasks":[{"gno_address":"` + string(user1Address) + `","github_handle":"deelawn"}]},` + @@ -61,7 +61,7 @@ func TestVerificationLifecycle(t *testing.T) { } // Try to trigger feed ingestion from the non-authorized user. - std.TestSetOrigCaller(user1Address) + t.SetOriginCaller(user1Address) func() { defer func() { if r := recover(); r != nil { @@ -75,7 +75,7 @@ func TestVerificationLifecycle(t *testing.T) { } // Set the caller back to the whitelisted user and transfer contract ownership. - std.TestSetOrigCaller(defaultAddress) + t.SetOriginCaller(defaultAddress) SetOwner(defaultAddress) // Now trigger the feed ingestion from the user and new owner and only whitelisted address. diff --git a/examples/gno.land/r/gnoland/home/overide_filetest.gno b/examples/gno.land/r/gnoland/home/overide_filetest.gno index be7e33501d6..ecd93179918 100644 --- a/examples/gno.land/r/gnoland/home/overide_filetest.gno +++ b/examples/gno.land/r/gnoland/home/overide_filetest.gno @@ -2,13 +2,14 @@ package main import ( "std" + "testing" "gno.land/p/demo/testutils" "gno.land/r/gnoland/home" ) func main() { - std.TestSetOrigCaller("g1manfred47kzduec920z88wfr64ylksmdcedlf5") + testing.SetOriginCaller(std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5")) home.AdminSetOverride("Hello World!") println(home.Render("")) home.AdminTransferOwnership(testutils.TestAddress("newAdmin")) diff --git a/examples/gno.land/r/gov/dao/bridge/bridge_test.gno b/examples/gno.land/r/gov/dao/bridge/bridge_test.gno index 38b5d4be257..c6337f0e924 100644 --- a/examples/gno.land/r/gov/dao/bridge/bridge_test.gno +++ b/examples/gno.land/r/gov/dao/bridge/bridge_test.gno @@ -3,8 +3,6 @@ package bridge import ( "testing" - "std" - "gno.land/p/demo/dao" "gno.land/p/demo/ownable" "gno.land/p/demo/testutils" @@ -47,7 +45,7 @@ func TestBridge_SetDAO(t *testing.T) { } ) - std.TestSetOrigCaller(addr) + t.SetOriginCaller(addr) b.Ownable = ownable.NewWithAddress(addr) diff --git a/examples/gno.land/r/leon/hof/hof_test.gno b/examples/gno.land/r/leon/hof/hof_test.gno index 4d6f70eab88..0c3cc9d7751 100644 --- a/examples/gno.land/r/leon/hof/hof_test.gno +++ b/examples/gno.land/r/leon/hof/hof_test.gno @@ -20,27 +20,27 @@ var ( func TestRegister(t *testing.T) { // Test user realm register aliceRealm := std.NewUserRealm(alice) - std.TestSetRealm(aliceRealm) + t.SetRealm(aliceRealm) Register() uassert.False(t, itemExists(t, rlmPath)) // Test register while paused - std.TestSetRealm(adminRealm) + t.SetRealm(adminRealm) Pausable.Pause() // Set legitimate caller - std.TestSetRealm(std.NewCodeRealm(rlmPath)) + t.SetRealm(std.NewCodeRealm(rlmPath)) Register() uassert.False(t, itemExists(t, rlmPath)) // Unpause - std.TestSetRealm(adminRealm) + t.SetRealm(adminRealm) Pausable.Unpause() // Set legitimate caller - std.TestSetRealm(std.NewCodeRealm(rlmPath)) + t.SetRealm(std.NewCodeRealm(rlmPath)) Register() // Find registered items @@ -57,7 +57,7 @@ func TestUpvote(t *testing.T) { // 0 upvotes by default urequire.Equal(t, item.upvote.Size(), 0) - std.TestSetRealm(adminRealm) + t.SetRealm(adminRealm) urequire.NotPanics(t, func() { Upvote(rlmPath) @@ -84,7 +84,7 @@ func TestDownvote(t *testing.T) { urequire.Equal(t, item.downvote.Size(), 0) userRealm := std.NewUserRealm(alice) - std.TestSetRealm(userRealm) + t.SetRealm(userRealm) urequire.NotPanics(t, func() { Downvote(rlmPath) @@ -102,8 +102,8 @@ func TestDownvote(t *testing.T) { func TestDelete(t *testing.T) { userRealm := std.NewUserRealm(admin) - std.TestSetRealm(userRealm) - std.TestSetOrigCaller(admin) + t.SetRealm(userRealm) + t.SetOriginCaller(admin) uassert.PanicsWithMessage(t, ErrNoSuchItem.Error(), func() { Delete("nonexistentpkgpath") diff --git a/examples/gno.land/r/matijamarjanovic/home/home_test.gno b/examples/gno.land/r/matijamarjanovic/home/home_test.gno index 8cc6e6e5608..782bda1d736 100644 --- a/examples/gno.land/r/matijamarjanovic/home/home_test.gno +++ b/examples/gno.land/r/matijamarjanovic/home/home_test.gno @@ -11,7 +11,7 @@ import ( // Helper function to set up test environment func setupTest() { - std.TestSetOrigCaller(std.Address("g1ej0qca5ptsw9kfr64ey8jvfy9eacga6mpj2z0y")) + testing.SetOriginCaller(std.Address("g1ej0qca5ptsw9kfr64ey8jvfy9eacga6mpj2z0y")) } func TestUpdatePFP(t *testing.T) { @@ -41,7 +41,8 @@ func TestVoteModern(t *testing.T) { coinsSent := std.NewCoins(std.NewCoin("ugnot", 75000000)) coinsSpent := std.NewCoins(std.NewCoin("ugnot", 1)) - std.TestSetOrigSend(coinsSent, coinsSpent) + t.SetOriginSend(coinsSent) + t.SetOriginSpend(coinsSpent) VoteModern() uassert.Equal(t, int64(75000000), modernVotes, "Modern votes should be calculated correctly") @@ -55,7 +56,8 @@ func TestVoteClassic(t *testing.T) { coinsSent := std.NewCoins(std.NewCoin("ugnot", 75000000)) coinsSpent := std.NewCoins(std.NewCoin("ugnot", 1)) - std.TestSetOrigSend(coinsSent, coinsSpent) + t.SetOriginSend(coinsSent) + t.SetOriginSpend(coinsSpent) VoteClassic() uassert.Equal(t, int64(75000000), classicVotes, "Classic votes should be calculated correctly") @@ -69,7 +71,8 @@ func TestVoteMinimal(t *testing.T) { coinsSent := std.NewCoins(std.NewCoin("ugnot", 75000000)) coinsSpent := std.NewCoins(std.NewCoin("ugnot", 1)) - std.TestSetOrigSend(coinsSent, coinsSpent) + t.SetOriginSend(coinsSent) + t.SetOriginSpend(coinsSpent) VoteMinimal() uassert.Equal(t, int64(75000000), minimalVotes, "Minimal votes should be calculated correctly") diff --git a/examples/gno.land/r/morgan/guestbook/guestbook_test.gno b/examples/gno.land/r/morgan/guestbook/guestbook_test.gno index b14fee45b42..3ac876ba486 100644 --- a/examples/gno.land/r/morgan/guestbook/guestbook_test.gno +++ b/examples/gno.land/r/morgan/guestbook/guestbook_test.gno @@ -13,10 +13,10 @@ func TestSign(t *testing.T) { guestbook = avl.Tree{} hasSigned = avl.Tree{} - std.TestSetRealm(std.NewUserRealm("g1user")) + t.SetRealm(std.NewUserRealm("g1user")) Sign("Hello!") - std.TestSetRealm(std.NewUserRealm("g1user2")) + t.SetRealm(std.NewUserRealm("g1user2")) Sign("Hello2!") res := Render("") @@ -33,7 +33,7 @@ func TestSign(t *testing.T) { } func TestSign_FromRealm(t *testing.T) { - std.TestSetRealm(std.NewCodeRealm("gno.land/r/demo/users")) + t.SetRealm(std.NewCodeRealm("gno.land/r/demo/users")) defer func() { rec := recover() @@ -55,7 +55,7 @@ func TestSign_Double(t *testing.T) { guestbook = avl.Tree{} hasSigned = avl.Tree{} - std.TestSetRealm(std.NewUserRealm("g1user")) + t.SetRealm(std.NewUserRealm("g1user")) Sign("Hello!") defer func() { @@ -79,7 +79,7 @@ func TestSign_InvalidMessage(t *testing.T) { guestbook = avl.Tree{} hasSigned = avl.Tree{} - std.TestSetRealm(std.NewUserRealm("g1user")) + t.SetRealm(std.NewUserRealm("g1user")) defer func() { rec := recover() @@ -107,7 +107,7 @@ func TestAdminDelete(t *testing.T) { owner = ownable.NewWithAddress(adminAddr) signatureID = 0 - std.TestSetRealm(std.NewUserRealm(userAddr)) + t.SetRealm(std.NewUserRealm(userAddr)) const bad = "Very Bad Message! Nyeh heh heh!" Sign(bad) @@ -116,7 +116,7 @@ func TestAdminDelete(t *testing.T) { t.Fatal("render does not contain bad message", rnd) } - std.TestSetRealm(std.NewUserRealm(adminAddr)) + t.SetRealm(std.NewUserRealm(adminAddr)) AdminDelete(signatureID.String()) if rnd := Render(""); strings.Contains(rnd, bad) { diff --git a/examples/gno.land/r/moul/home/z2_filetest.gno b/examples/gno.land/r/moul/home/z2_filetest.gno index f471280d8ef..285113814c3 100644 --- a/examples/gno.land/r/moul/home/z2_filetest.gno +++ b/examples/gno.land/r/moul/home/z2_filetest.gno @@ -2,12 +2,13 @@ package main import ( "std" + "testing" "gno.land/r/moul/home" ) func main() { - std.TestSetOrigCaller("g1manfred47kzduec920z88wfr64ylksmdcedlf5") + testing.SetOriginCaller(std.Address("g1manfred47kzduec920z88wfr64ylksmdcedlf5")) home.AddTodo("aaa") home.AddTodo("bbb") home.AddTodo("ccc") diff --git a/examples/gno.land/r/n2p5/haystack/haystack_test.gno b/examples/gno.land/r/n2p5/haystack/haystack_test.gno index 52dadf8bf9e..c485ad8aef9 100644 --- a/examples/gno.land/r/n2p5/haystack/haystack_test.gno +++ b/examples/gno.land/r/n2p5/haystack/haystack_test.gno @@ -2,7 +2,6 @@ package haystack import ( "encoding/hex" - "std" "testing" "gno.land/p/demo/testutils" @@ -31,14 +30,14 @@ func TestHaystack(t *testing.T) { n2, _ := genNeedleHex(2) n3, _ := genNeedleHex(3) - std.TestSetOrigCaller(u1) + t.SetOriginCaller(u1) urequire.NotPanics(t, func() { Add(n1) }) urequire.PanicsWithMessage(t, haystack.ErrorDuplicateNeedle.Error(), func() { Add(n1) }) - std.TestSetOrigCaller(u2) + t.SetOriginCaller(u2) urequire.NotPanics(t, func() { Add(n2) }) urequire.NotPanics(t, func() { Add(n3) }) }) @@ -49,14 +48,14 @@ func TestHaystack(t *testing.T) { n1, h1 := genNeedleHex(4) _, h2 := genNeedleHex(5) - std.TestSetOrigCaller(u1) + t.SetOriginCaller(u1) urequire.NotPanics(t, func() { Add(n1) }) urequire.NotPanics(t, func() { result := Get(h1) urequire.Equal(t, n1, result) }) - std.TestSetOrigCaller(u2) + t.SetOriginCaller(u2) urequire.NotPanics(t, func() { result := Get(h1) urequire.Equal(t, n1, result) diff --git a/examples/gno.land/r/stefann/fomo3d/fomo3d_test.gno b/examples/gno.land/r/stefann/fomo3d/fomo3d_test.gno index 29f2a9b07a9..66c2114c6f5 100644 --- a/examples/gno.land/r/stefann/fomo3d/fomo3d_test.gno +++ b/examples/gno.land/r/stefann/fomo3d/fomo3d_test.gno @@ -36,12 +36,12 @@ func TestOwnership(t *testing.T) { nonOwner := testutils.TestAddress("nonOwner") // Set up initial owner - std.TestSetOrigCaller(owner) - std.TestSetOrigPkgAddr(owner) + t.SetOriginCaller(owner) + t.SetOriginPkgAddress(owner) setupTestGame(t) // Transfer ownership to nonOwner first to test ownership functions - std.TestSetOrigCaller(owner) + t.SetOriginCaller(owner) urequire.NotPanics(t, func() { Ownable.TransferOwnership(nonOwner) }) @@ -49,10 +49,10 @@ func TestOwnership(t *testing.T) { // Test fee accumulation StartGame() payment := MIN_KEY_PRICE * 10 - std.TestSetOrigCaller(owner) - std.TestSetOrigSend(std.Coins{{"ugnot", payment}}, nil) - std.TestIssueCoins(owner, std.Coins{{"ugnot", payment}}) - std.TestIssueCoins(std.GetOrigPkgAddr(), std.Coins{{"ugnot", payment}}) + t.SetOriginCaller(owner) + t.SetOriginSend(std.Coins{{"ugnot", payment}}) + t.IssueCoins(owner, std.Coins{{"ugnot", payment}}) + t.IssueCoins(std.GetOrigPkgAddr(), std.Coins{{"ugnot", payment}}) BuyKeys() // Verify fee accumulation @@ -61,13 +61,13 @@ func TestOwnership(t *testing.T) { urequire.Equal(t, expectedFees, fees) // Test unauthorized fee claim (using old owner) - std.TestSetOrigCaller(owner) + t.SetOriginCaller(owner) urequire.PanicsWithMessage(t, "ownable: caller is not owner", ClaimOwnerFee) // Test authorized fee claim (using new owner) - std.TestSetOrigCaller(nonOwner) + t.SetOriginCaller(nonOwner) initialBalance := std.GetBanker(std.BankerTypeRealmSend).GetCoins(nonOwner) - std.TestIssueCoins(std.CurrentRealm().Addr(), std.Coins{{"ugnot", expectedFees}}) + t.IssueCoins(std.CurrentRealm().Addr(), std.Coins{{"ugnot", expectedFees}}) urequire.NotPanics(t, ClaimOwnerFee) // Verify fees were claimed @@ -99,16 +99,16 @@ func TestFullGameFlow(t *testing.T) { t.Run("buying keys", func(t *testing.T) { // Test insufficient payment - std.TestSetOrigCaller(player1) - std.TestIssueCoins(player1, std.Coins{{"ugnot", MIN_KEY_PRICE - 1}}) - std.TestSetOrigSend(std.Coins{{"ugnot", MIN_KEY_PRICE - 1}}, nil) - std.TestIssueCoins(std.GetOrigPkgAddr(), std.Coins{{"ugnot", MIN_KEY_PRICE - 1}}) + t.SetOriginCaller(player1) + t.IssueCoins(player1, std.Coins{{"ugnot", MIN_KEY_PRICE - 1}}) + t.SetOriginSend(std.Coins{{"ugnot", MIN_KEY_PRICE - 1}}) + t.IssueCoins(std.GetOrigPkgAddr(), std.Coins{{"ugnot", MIN_KEY_PRICE - 1}}) urequire.PanicsWithMessage(t, ErrInsufficientPayment.Error(), BuyKeys) // Test successful key purchase payment := MIN_KEY_PRICE * 3 - std.TestSetOrigSend(std.Coins{{"ugnot", payment}}, nil) - std.TestIssueCoins(std.GetOrigPkgAddr(), std.Coins{{"ugnot", payment}}) + t.SetOriginSend(std.Coins{{"ugnot", payment}}) + t.IssueCoins(std.GetOrigPkgAddr(), std.Coins{{"ugnot", payment}}) currentBlock := std.GetHeight() urequire.NotPanics(t, BuyKeys) @@ -139,10 +139,10 @@ func TestFullGameFlow(t *testing.T) { t.Run("dividend distribution and claiming", func(t *testing.T) { // Player 2 buys keys - std.TestSetOrigCaller(player2) + t.SetOriginCaller(player2) payment := gameState.KeyPrice * 2 // Buy 2 keys using current keyPrice - std.TestSetOrigSend(std.Coins{{"ugnot", payment}}, nil) - std.TestIssueCoins(std.GetOrigPkgAddr(), std.Coins{{"ugnot", payment}}) + t.SetOriginSend(std.Coins{{"ugnot", payment}}) + t.IssueCoins(std.GetOrigPkgAddr(), std.Coins{{"ugnot", payment}}) urequire.NotPanics(t, BuyKeys) // Check player1 received dividends @@ -155,7 +155,7 @@ func TestFullGameFlow(t *testing.T) { // Test claiming dividends { // Player1 claims dividends - std.TestSetOrigCaller(player1) + t.SetOriginCaller(player1) initialBalance := std.GetBanker(std.BankerTypeRealmSend).GetCoins(player1) urequire.NotPanics(t, ClaimDividends) @@ -174,7 +174,7 @@ func TestFullGameFlow(t *testing.T) { // Skip to end of current time window currentEndBlock := gameState.EndBlock - std.TestSkipHeights(currentEndBlock - std.GetHeight() + 1) + t.SkipHeights(currentEndBlock - std.GetHeight() + 1) // End game successfully urequire.NotPanics(t, EndGame) @@ -237,30 +237,30 @@ func TestBuyKeys(t *testing.T) { StartGame() player := testutils.TestAddress("player") - std.TestSetOrigCaller(player) + t.SetOriginCaller(player) // Test invalid coin denomination - std.TestIssueCoins(player, std.Coins{{"invalid", MIN_KEY_PRICE}}) - std.TestSetOrigSend(std.Coins{{"invalid", MIN_KEY_PRICE}}, nil) - std.TestIssueCoins(std.GetOrigPkgAddr(), std.Coins{{"invalid", MIN_KEY_PRICE}}) + t.IssueCoins(player, std.Coins{{"invalid", MIN_KEY_PRICE}}) + t.SetOriginSend(std.Coins{{"invalid", MIN_KEY_PRICE}}) + t.IssueCoins(std.GetOrigPkgAddr(), std.Coins{{"invalid", MIN_KEY_PRICE}}) urequire.PanicsWithMessage(t, ErrInvalidPayment.Error(), BuyKeys) // Test multiple coin types - std.TestIssueCoins(player, std.Coins{{"ugnot", MIN_KEY_PRICE}, {"other", 100}}) - std.TestSetOrigSend(std.Coins{{"ugnot", MIN_KEY_PRICE}, {"other", 100}}, nil) - std.TestIssueCoins(std.GetOrigPkgAddr(), std.Coins{{"ugnot", MIN_KEY_PRICE}, {"other", 100}}) + t.IssueCoins(player, std.Coins{{"ugnot", MIN_KEY_PRICE}, {"other", 100}}) + t.SetOriginSend(std.Coins{{"ugnot", MIN_KEY_PRICE}, {"other", 100}}) + t.IssueCoins(std.GetOrigPkgAddr(), std.Coins{{"ugnot", MIN_KEY_PRICE}, {"other", 100}}) urequire.PanicsWithMessage(t, ErrInvalidPayment.Error(), BuyKeys) // Test insufficient payment - std.TestIssueCoins(player, std.Coins{{"ugnot", MIN_KEY_PRICE - 1}}) - std.TestSetOrigSend(std.Coins{{"ugnot", MIN_KEY_PRICE - 1}}, nil) - std.TestIssueCoins(std.GetOrigPkgAddr(), std.Coins{{"ugnot", MIN_KEY_PRICE - 1}}) + t.IssueCoins(player, std.Coins{{"ugnot", MIN_KEY_PRICE - 1}}) + t.SetOriginSend(std.Coins{{"ugnot", MIN_KEY_PRICE - 1}}) + t.IssueCoins(std.GetOrigPkgAddr(), std.Coins{{"ugnot", MIN_KEY_PRICE - 1}}) urequire.PanicsWithMessage(t, ErrInsufficientPayment.Error(), BuyKeys) // Test successful purchase - std.TestIssueCoins(player, std.Coins{{"ugnot", MIN_KEY_PRICE * 2}}) - std.TestSetOrigSend(std.Coins{{"ugnot", MIN_KEY_PRICE * 2}}, nil) - std.TestIssueCoins(std.GetOrigPkgAddr(), std.Coins{{"ugnot", MIN_KEY_PRICE * 2}}) + t.IssueCoins(player, std.Coins{{"ugnot", MIN_KEY_PRICE * 2}}) + t.SetOriginSend(std.Coins{{"ugnot", MIN_KEY_PRICE * 2}}) + t.IssueCoins(std.GetOrigPkgAddr(), std.Coins{{"ugnot", MIN_KEY_PRICE * 2}}) urequire.NotPanics(t, BuyKeys) } @@ -269,26 +269,26 @@ func TestClaimDividends(t *testing.T) { StartGame() player := testutils.TestAddress("player") - std.TestSetOrigCaller(player) + t.SetOriginCaller(player) // Test claiming with no dividends urequire.PanicsWithMessage(t, ErrNoDividendsToClaim.Error(), ClaimDividends) // Setup player with dividends - std.TestIssueCoins(player, std.Coins{{"ugnot", MIN_KEY_PRICE}}) - std.TestSetOrigSend(std.Coins{{"ugnot", MIN_KEY_PRICE}}, nil) - std.TestIssueCoins(std.GetOrigPkgAddr(), std.Coins{{"ugnot", MIN_KEY_PRICE}}) + t.IssueCoins(player, std.Coins{{"ugnot", MIN_KEY_PRICE}}) + t.SetOriginSend(std.Coins{{"ugnot", MIN_KEY_PRICE}}) + t.IssueCoins(std.GetOrigPkgAddr(), std.Coins{{"ugnot", MIN_KEY_PRICE}}) BuyKeys() // Have another player buy to generate dividends player2 := testutils.TestAddress("player2") - std.TestSetOrigCaller(player2) - std.TestIssueCoins(player2, std.Coins{{"ugnot", MIN_KEY_PRICE * 2}}) - std.TestSetOrigSend(std.Coins{{"ugnot", MIN_KEY_PRICE * 2}}, nil) - std.TestIssueCoins(std.GetOrigPkgAddr(), std.Coins{{"ugnot", MIN_KEY_PRICE * 2}}) + t.SetOriginCaller(player2) + t.IssueCoins(player2, std.Coins{{"ugnot", MIN_KEY_PRICE * 2}}) + t.SetOriginSend(std.Coins{{"ugnot", MIN_KEY_PRICE * 2}}) + t.IssueCoins(std.GetOrigPkgAddr(), std.Coins{{"ugnot", MIN_KEY_PRICE * 2}}) BuyKeys() // Test successful claim - std.TestSetOrigCaller(player) + t.SetOriginCaller(player) urequire.NotPanics(t, ClaimDividends) } diff --git a/examples/gno.land/r/stefann/home/home_test.gno b/examples/gno.land/r/stefann/home/home_test.gno index b8ea88670a6..63eb58785c6 100644 --- a/examples/gno.land/r/stefann/home/home_test.gno +++ b/examples/gno.land/r/stefann/home/home_test.gno @@ -10,8 +10,8 @@ import ( ) func TestUpdateAboutMe(t *testing.T) { - var owner = std.Address("g1sd5ezmxt4rwpy52u6wl3l3y085n8x0p6nllxm8") - std.TestSetOrigCaller(owner) + owner := std.Address("g1sd5ezmxt4rwpy52u6wl3l3y085n8x0p6nllxm8") + t.SetOriginCaller(owner) profile.aboutMe = []string{} @@ -31,8 +31,8 @@ func TestUpdateAboutMe(t *testing.T) { } func TestUpdateCities(t *testing.T) { - var owner = std.Address("g1sd5ezmxt4rwpy52u6wl3l3y085n8x0p6nllxm8") - std.TestSetOrigCaller(owner) + owner := std.Address("g1sd5ezmxt4rwpy52u6wl3l3y085n8x0p6nllxm8") + t.SetOriginCaller(owner) travel.cities = []City{} @@ -53,8 +53,8 @@ func TestUpdateCities(t *testing.T) { } func TestUpdateJarLink(t *testing.T) { - var owner = std.Address("g1sd5ezmxt4rwpy52u6wl3l3y085n8x0p6nllxm8") - std.TestSetOrigCaller(owner) + owner := std.Address("g1sd5ezmxt4rwpy52u6wl3l3y085n8x0p6nllxm8") + t.SetOriginCaller(owner) travel.jarLink = "" @@ -66,8 +66,8 @@ func TestUpdateJarLink(t *testing.T) { } func TestUpdateMaxSponsors(t *testing.T) { - var owner = std.Address("g1sd5ezmxt4rwpy52u6wl3l3y085n8x0p6nllxm8") - std.TestSetOrigCaller(owner) + owner := std.Address("g1sd5ezmxt4rwpy52u6wl3l3y085n8x0p6nllxm8") + t.SetOriginCaller(owner) sponsorship.maxSponsors = 0 @@ -86,8 +86,8 @@ func TestUpdateMaxSponsors(t *testing.T) { } func TestAddCities(t *testing.T) { - var owner = std.Address("g1sd5ezmxt4rwpy52u6wl3l3y085n8x0p6nllxm8") - std.TestSetOrigCaller(owner) + owner := std.Address("g1sd5ezmxt4rwpy52u6wl3l3y085n8x0p6nllxm8") + t.SetOriginCaller(owner) travel.cities = []City{} @@ -114,8 +114,8 @@ func TestAddCities(t *testing.T) { } func TestAddAboutMeRows(t *testing.T) { - var owner = std.Address("g1sd5ezmxt4rwpy52u6wl3l3y085n8x0p6nllxm8") - std.TestSetOrigCaller(owner) + owner := std.Address("g1sd5ezmxt4rwpy52u6wl3l3y085n8x0p6nllxm8") + t.SetOriginCaller(owner) profile.aboutMe = []string{} @@ -139,8 +139,8 @@ func TestAddAboutMeRows(t *testing.T) { } func TestDonate(t *testing.T) { - var user = testutils.TestAddress("user") - std.TestSetOrigCaller(user) + user := testutils.TestAddress("user") + t.SetOriginCaller(user) sponsorship.sponsors = avl.NewTree() sponsorship.DonationsCount = 0 @@ -148,7 +148,7 @@ func TestDonate(t *testing.T) { travel.currentCityIndex = 0 coinsSent := std.NewCoins(std.NewCoin("ugnot", 500)) - std.TestSetOrigSend(coinsSent, std.NewCoins()) + t.SetOriginSend(coinsSent) Donate() existingAmount, exists := sponsorship.sponsors.Get(string(user)) @@ -173,7 +173,7 @@ func TestDonate(t *testing.T) { } coinsSent = std.NewCoins(std.NewCoin("ugnot", 300)) - std.TestSetOrigSend(coinsSent, std.NewCoins()) + t.SetOriginSend(coinsSent) Donate() existingAmount, exists = sponsorship.sponsors.Get(string(user)) @@ -195,8 +195,8 @@ func TestDonate(t *testing.T) { } func TestGetTopSponsors(t *testing.T) { - var user = testutils.TestAddress("user") - std.TestSetOrigCaller(user) + user := testutils.TestAddress("user") + t.SetOriginCaller(user) sponsorship.sponsors = avl.NewTree() sponsorship.sponsorsCount = 0 @@ -226,8 +226,8 @@ func TestGetTopSponsors(t *testing.T) { } func TestGetTotalDonations(t *testing.T) { - var user = testutils.TestAddress("user") - std.TestSetOrigCaller(user) + user := testutils.TestAddress("user") + t.SetOriginCaller(user) sponsorship.sponsors = avl.NewTree() sponsorship.sponsorsCount = 0 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/ursulovic/home/home.gno b/examples/gno.land/r/ursulovic/home/home.gno index cc420df5e6e..3f989fbdf21 100644 --- a/examples/gno.land/r/ursulovic/home/home.gno +++ b/examples/gno.land/r/ursulovic/home/home.gno @@ -76,7 +76,7 @@ func UpdateSelectedImage(url string) { sentCoins := std.GetOrigSend() - if len(sentCoins) != 1 && sentCoins.AmountOf("ugnot") == imageUpdatePrice { + if len(sentCoins) != 1 || sentCoins.AmountOf("ugnot") != imageUpdatePrice { panic("Please send exactly " + strconv.Itoa(int(imageUpdatePrice)) + " ugnot") } diff --git a/examples/gno.land/r/ursulovic/home/home_test.gno b/examples/gno.land/r/ursulovic/home/home_test.gno index ff3f763d62a..7bf393513ad 100644 --- a/examples/gno.land/r/ursulovic/home/home_test.gno +++ b/examples/gno.land/r/ursulovic/home/home_test.gno @@ -9,7 +9,7 @@ import ( func TestUpdateGithubUrl(t *testing.T) { caller := std.Address("g1d24j8fwnc0w5q427fauyey4gdd30qgu69k6n0x") - std.TestSetOrigCaller(caller) + t.SetOriginCaller(caller) newUrl := "https://github.com/example" @@ -22,7 +22,7 @@ func TestUpdateGithubUrl(t *testing.T) { func TestUpdateLinkedinUrl(t *testing.T) { caller := std.Address("g1d24j8fwnc0w5q427fauyey4gdd30qgu69k6n0x") - std.TestSetOrigCaller(caller) + t.SetOriginCaller(caller) newUrl := "https://www.linkedin.com/in/example" @@ -35,7 +35,7 @@ func TestUpdateLinkedinUrl(t *testing.T) { func TestUpdateAboutMe(t *testing.T) { caller := std.Address("g1d24j8fwnc0w5q427fauyey4gdd30qgu69k6n0x") - std.TestSetOrigCaller(caller) + t.SetOriginCaller(caller) newAboutMe := "This is new description!" @@ -47,13 +47,13 @@ func TestUpdateAboutMe(t *testing.T) { } func TestUpdateSelectedImage(t *testing.T) { - var user = testutils.TestAddress("user") - std.TestSetOrigCaller(user) + user := testutils.TestAddress("user") + t.SetOriginCaller(user) validImageUrl := "https://i.ibb.co/hLtmnX0/beautiful-rain-forest-ang-ka-nature-trail-doi-inthanon-national-park-thailand-36703721.webp" coinsSent := std.NewCoins(std.NewCoin("ugnot", 5000000)) // Update to match the price expected by your function - std.TestSetOrigSend(coinsSent, std.NewCoins()) + t.SetOriginSend(coinsSent) UpdateSelectedImage(validImageUrl) @@ -72,7 +72,7 @@ func TestUpdateSelectedImage(t *testing.T) { UpdateSelectedImage(invalidImageUrl) invalidCoins := std.NewCoins(std.NewCoin("ugnot", 1000000)) - std.TestSetOrigSend(invalidCoins, std.NewCoins()) + t.SetOriginSend(invalidCoins) defer func() { if r := recover(); r == nil { @@ -85,7 +85,7 @@ func TestUpdateSelectedImage(t *testing.T) { func TestUpdateImagePrice(t *testing.T) { caller := std.Address("g1d24j8fwnc0w5q427fauyey4gdd30qgu69k6n0x") - std.TestSetOrigCaller(caller) + t.SetOriginCaller(caller) var newImageUpdatePrice int64 = 3000000 diff --git a/examples/gno.land/r/x/nir1218_evaluation_proposal/committee_test.gno b/examples/gno.land/r/x/nir1218_evaluation_proposal/committee_test.gno index 8a3d16fd7f7..36fa7238090 100644 --- a/examples/gno.land/r/x/nir1218_evaluation_proposal/committee_test.gno +++ b/examples/gno.land/r/x/nir1218_evaluation_proposal/committee_test.gno @@ -36,7 +36,7 @@ func TestCategoryEvaluationCriteria(t *testing.T) { c.DesignateMembers([]std.Address{member}) t.Run("Add First Committee Category and Evaluation Criteria", func(t *testing.T) { - std.TestSetOrigCaller(member) + t.SetOriginCaller(member) c.AddCategory(category, criteria) value, exists := c.categories.Get(category) if !exists { @@ -49,7 +49,7 @@ func TestCategoryEvaluationCriteria(t *testing.T) { }) t.Run("Add Second Committee Category and Evaluation Criteria", func(t *testing.T) { - std.TestSetOrigCaller(member) + t.SetOriginCaller(member) c.AddCategory(category2, criteria2) value2, exists2 := c.categories.Get(category2) if !exists2 { @@ -62,7 +62,7 @@ func TestCategoryEvaluationCriteria(t *testing.T) { }) t.Run("Approve First Committee Category", func(t *testing.T) { - std.TestSetOrigCaller(member) + t.SetOriginCaller(member) approved := c.ApproveCategory(category, VoteYes) if !approved { value, exists := c.categories.Get(category) 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/generated.go b/gnovm/stdlibs/generated.go index 6bd45de3589..ffc0689d2c7 100644 --- a/gnovm/stdlibs/generated.go +++ b/gnovm/stdlibs/generated.go @@ -838,6 +838,106 @@ var nativeFuncs = [...]NativeFunc{ )) }, }, + { + "testing", + "testSetContext", + []gno.FieldTypeExpr{ + {Name: gno.N("p0"), Type: gno.X("bool")}, + {Name: gno.N("p1"), Type: gno.X("string")}, + {Name: gno.N("p2"), Type: gno.X("string")}, + {Name: gno.N("p3"), Type: gno.X("string")}, + {Name: gno.N("p4"), Type: gno.X("string")}, + {Name: gno.N("p5"), Type: gno.X("[]string")}, + {Name: gno.N("p6"), Type: gno.X("[]int64")}, + {Name: gno.N("p7"), Type: gno.X("[]string")}, + {Name: gno.N("p8"), Type: gno.X("[]int64")}, + {Name: gno.N("p9"), Type: gno.X("string")}, + {Name: gno.N("p10"), Type: gno.X("int64")}, + {Name: gno.N("p11"), Type: gno.X("int64")}, + {Name: gno.N("p12"), Type: gno.X("int64")}, + }, + []gno.FieldTypeExpr{}, + true, + func(m *gno.Machine) { + b := m.LastBlock() + var ( + p0 bool + rp0 = reflect.ValueOf(&p0).Elem() + p1 string + rp1 = reflect.ValueOf(&p1).Elem() + p2 string + rp2 = reflect.ValueOf(&p2).Elem() + p3 string + rp3 = reflect.ValueOf(&p3).Elem() + p4 string + rp4 = reflect.ValueOf(&p4).Elem() + p5 []string + rp5 = reflect.ValueOf(&p5).Elem() + p6 []int64 + rp6 = reflect.ValueOf(&p6).Elem() + p7 []string + rp7 = reflect.ValueOf(&p7).Elem() + p8 []int64 + rp8 = reflect.ValueOf(&p8).Elem() + p9 string + rp9 = reflect.ValueOf(&p9).Elem() + p10 int64 + rp10 = reflect.ValueOf(&p10).Elem() + p11 int64 + rp11 = reflect.ValueOf(&p11).Elem() + p12 int64 + rp12 = reflect.ValueOf(&p12).Elem() + ) + + gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 0, "")).TV, rp0) + gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 1, "")).TV, rp1) + gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 2, "")).TV, rp2) + gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 3, "")).TV, rp3) + gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 4, "")).TV, rp4) + gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 5, "")).TV, rp5) + gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 6, "")).TV, rp6) + gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 7, "")).TV, rp7) + gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 8, "")).TV, rp8) + gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 9, "")).TV, rp9) + gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 10, "")).TV, rp10) + gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 11, "")).TV, rp11) + gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 12, "")).TV, rp12) + + libs_testing.X_testSetContext( + m, + p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12) + }, + }, + { + "testing", + "testIssueCoins", + []gno.FieldTypeExpr{ + {Name: gno.N("p0"), Type: gno.X("string")}, + {Name: gno.N("p1"), Type: gno.X("[]string")}, + {Name: gno.N("p2"), Type: gno.X("[]int64")}, + }, + []gno.FieldTypeExpr{}, + true, + func(m *gno.Machine) { + b := m.LastBlock() + var ( + p0 string + rp0 = reflect.ValueOf(&p0).Elem() + p1 []string + rp1 = reflect.ValueOf(&p1).Elem() + p2 []int64 + rp2 = reflect.ValueOf(&p2).Elem() + ) + + gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 0, "")).TV, rp0) + gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 1, "")).TV, rp1) + gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 2, "")).TV, rp2) + + libs_testing.X_testIssueCoins( + m, + p0, p1, p2) + }, + }, { "time", "now", @@ -942,8 +1042,8 @@ var initOrder = [...]string{ "regexp/syntax", "regexp", "std", - "testing", "time", + "testing", "unicode/utf16", } diff --git a/gnovm/stdlibs/testing/context.gno b/gnovm/stdlibs/testing/context.gno new file mode 100644 index 00000000000..4865db3fd30 --- /dev/null +++ b/gnovm/stdlibs/testing/context.gno @@ -0,0 +1,20 @@ +package testing + +import ( + "std" + "time" +) + +type Context struct { + IsOrigin bool + CurrentRealm std.Realm + OriginCaller std.Address + OriginPkgAddress std.Address + OriginSend std.Coins + OriginSpend std.Coins + ChainID string + Height int64 + Time time.Time + Banker bool // TODO + Logger bool // TODO +} diff --git a/gnovm/stdlibs/testing/testing.gno b/gnovm/stdlibs/testing/testing.gno index 08082894178..f3d26322c1a 100644 --- a/gnovm/stdlibs/testing/testing.gno +++ b/gnovm/stdlibs/testing/testing.gno @@ -5,8 +5,10 @@ import ( "encoding/json" "fmt" "os" + "std" "strconv" "strings" + "time" ) // ---------------------------------------- @@ -203,6 +205,54 @@ func (t *T) TempDir() string { func (t *T) Helper() { } +func expandNative(coins std.Coins) (denoms []string, amounts []int64) { + denoms = make([]string, len(coins)) + amounts = make([]int64, len(coins)) + + for i, coin := range coins { + denoms[i] = coin.Denom + amounts[i] = coin.Amount + } + return denoms, amounts +} + +func (t *T) SetContext(ctx Context) { + TestSetContext(ctx) +} + +// SetRealm sets the realm for the current frame. +// After calling SetRealm, calling CurrentRealm() in the test function will yield the value of +// rlm, while if a realm function is called, using PrevRealm() will yield rlm. +func (t *T) SetRealm(rlm std.Realm) { + // NODE: We should not call SetRealm like other methods because it changes the frames stack + // so for this method we have to use TestSetContext instead. + TestSetContext(Context{CurrentRealm: rlm}) +} + +func (t *T) SetOriginCaller(addr std.Address) { + SetOriginCaller(addr) +} + +func (t *T) SetOriginSend(send std.Coins) { + SetOriginSend(send) +} + +func (t *T) SetOriginSpend(spend std.Coins) { + SetOriginSpend(spend) +} + +func (t *T) SetOriginPkgAddress(addr std.Address) { + SetOriginPkgAddress(addr) +} + +func (t *T) SkipHeights(count int64) { + SkipHeights(count) +} + +func (t *T) IssueCoins(addr std.Address, coins std.Coins) { + IssueCoins(addr, coins) +} + func (t *T) log(s string) { if t.verbose { // verbose, print immediately @@ -363,3 +413,79 @@ func tRunner(t *T, fn testingFunc, verbose bool) { fn(t) } + +func testSetContext( + isOrigin bool, + originCaller string, + originPkgAddress string, + currRealmAddr string, currRealmPkgPath string, + origSendDenoms []string, origSendAmounts []int64, + origSpendDenoms []string, origSpendAmounts []int64, + chainID string, + height int64, + timeUnix int64, timeNano int64, +) + +func testIssueCoins(addr string, denom []string, amt []int64) + +func TestSetContext(ctx Context) { + originSendDenom, originSendAmount := expandNative(ctx.OriginSend) + originSpendDenom, originSpendAmount := expandNative(ctx.OriginSpend) + + var timestamp, timestampNano int64 = 0, 0 + + if !ctx.Time.IsZero() { + timestamp = ctx.Time.Unix() + timestampNano = 0 + } + + testSetContext( + ctx.IsOrigin, + ctx.OriginCaller.String(), + ctx.OriginPkgAddress.String(), + ctx.CurrentRealm.Addr().String(), ctx.CurrentRealm.PkgPath(), + originSendDenom, originSendAmount, + originSpendDenom, originSpendAmount, + ctx.ChainID, + ctx.Height, + timestamp, timestampNano, + ) +} + +func SetOriginCaller(origCaller std.Address) { + TestSetContext(Context{OriginCaller: origCaller}) +} + +func SetOriginSend(send std.Coins) { + TestSetContext(Context{OriginSend: send}) +} + +func SetOriginSpend(spend std.Coins) { + TestSetContext(Context{OriginSpend: spend}) +} + +func SetOriginPkgAddress(addr std.Address) { + TestSetContext(Context{OriginPkgAddress: addr}) +} + +func SetHeight(height int64) { + TestSetContext(Context{Height: height}) +} + +// SetRealm sets the realm for the current frame. +// After calling SetRealm, calling CurrentRealm() in the test function will yield the value of +// rlm, while if a realm function is called, using PrevRealm() will yield rlm. +func SetRealm(rlm std.Realm) { + TestSetContext(Context{CurrentRealm: rlm}) +} + +func SkipHeights(count int64) { + toHeight := std.GetHeight() + count + toTime := time.Now().Unix() + (count * 5) + TestSetContext(Context{Height: toHeight, Time: time.Unix(toTime, 0)}) +} + +func IssueCoins(addr std.Address, coins std.Coins) { + denom, amt := expandNative(coins) + testIssueCoins(addr.String(), denom, amt) +} diff --git a/gnovm/stdlibs/testing/testing.go b/gnovm/stdlibs/testing/testing.go index b7408b7cceb..58c4f62f769 100644 --- a/gnovm/stdlibs/testing/testing.go +++ b/gnovm/stdlibs/testing/testing.go @@ -2,6 +2,11 @@ package testing import ( "errors" + + gno "github.com/gnolang/gno/gnovm/pkg/gnolang" + "github.com/gnolang/gno/gnovm/stdlibs/std" + teststd "github.com/gnolang/gno/gnovm/tests/stdlibs/std" + "github.com/gnolang/gno/tm2/pkg/crypto" ) func X_unixNano() int64 { @@ -9,6 +14,88 @@ func X_unixNano() int64 { return 0 } +func X_testSetContext( + m *gno.Machine, + isOrigin bool, + originCaller string, + originPkgAddress string, + currRealmAddr string, currRealmPkgPath string, + origSendDenoms []string, origSendAmounts []int64, + origSpendDenoms []string, origSpendAmounts []int64, + chainID string, + height int64, + timeUnix int64, timeNano int64, +) { + ctx := m.Context.(*teststd.TestExecContext) + + if chainID != "" { + ctx.ChainID = chainID + } + + if height != 0 { + ctx.Height = height + } + + if timeUnix != 0 { + ctx.Timestamp = timeUnix + } + + if timeNano != 0 { + ctx.TimestampNano = timeNano + } + + if originCaller != "" { + ctx.OrigCaller = crypto.Bech32Address(originCaller) + } + + if originPkgAddress != "" { + ctx.OrigPkgAddr = crypto.Bech32Address(originPkgAddress) + } + + if currRealmAddr != "" { + // Associate the given Realm with the caller's frame. + var frame *gno.Frame + // NOTE: the frames are different from when calling std.TestSetRealm (has been refactored to this code) + // + // When calling this function from Gno, the 3 top frames are the following: + // #7: [FRAME FUNC:testSetContext RECV:(undefined) (15 args) 11/3/0/6/4 LASTPKG:testing ...] + // #6: [FRAME FUNC:TestSetContext RECV:(undefined) (1 args) 8/2/0/4/3 LASTPKG:testing ...] + // #5: [FRAME FUNC:SetRealm RECV:(undefined) (1 args) 5/1/0/2/2 LASTPKG:gno.land/r/demo/groups ...] + // We want to set the Realm of the frame where t/testing.SetRealm is being called, hence -4. + for i := m.NumFrames() - 4; i >= 0; i-- { + // Must be a frame from calling a function. + if fr := m.Frames[i]; fr.Func != nil { + frame = fr + break + } + } + + ctx.RealmFrames[frame] = teststd.RealmOverride{ + Addr: crypto.Bech32Address(currRealmAddr), + PkgPath: currRealmPkgPath, + } + } + + if len(origSendDenoms) > 0 && len(origSendDenoms) == len(origSendAmounts) { + ctx.OrigSend = std.CompactCoins(origSendDenoms, origSendAmounts) + } + + if len(origSpendDenoms) > 0 && len(origSpendDenoms) == len(origSpendAmounts) { + coins := std.CompactCoins(origSpendDenoms, origSpendAmounts) + ctx.OrigSendSpent = &coins + } + + m.Context = ctx +} + +func X_testIssueCoins(m *gno.Machine, addr string, denom []string, amt []int64) { + ctx := m.Context.(*teststd.TestExecContext) + banker := ctx.Banker + for i := range denom { + banker.IssueCoin(crypto.Bech32Address(addr), denom[i], amt[i]) + } +} + func X_matchString(pat, str string) (result bool, err error) { return false, errors.New("only implemented in testing stdlibs") } diff --git a/gnovm/tests/files/stdbanker.gno b/gnovm/tests/files/stdbanker.gno index d0872dd38e6..a9002c6e904 100644 --- a/gnovm/tests/files/stdbanker.gno +++ b/gnovm/tests/files/stdbanker.gno @@ -1,12 +1,15 @@ package main -import "std" +import ( + "std" + "testing" +) func main() { defer func() { println(recover()) }() - std.TestSetRealm(std.NewCodeRealm("gno.land/p/demo/users")) + testing.SetRealm(std.NewCodeRealm("gno.land/p/demo/users")) } // Output: diff --git a/gnovm/tests/files/zrealm_crossrealm13.gno b/gnovm/tests/files/zrealm_crossrealm13.gno index 4daeb6de366..ae40829511d 100644 --- a/gnovm/tests/files/zrealm_crossrealm13.gno +++ b/gnovm/tests/files/zrealm_crossrealm13.gno @@ -2,17 +2,18 @@ package main import ( "std" + "testing" ) func main() { PrintRealm() println(pad("CurrentRealm:"), std.CurrentRealm()) println(pad("PrevRealm:"), std.PrevRealm()) - std.TestSetRealm(std.NewUserRealm("g1user")) + testing.SetRealm(std.NewUserRealm("g1user")) PrintRealm() println(pad("CurrentRealm:"), std.CurrentRealm()) println(pad("PrevRealm:"), std.PrevRealm()) - std.TestSetRealm(std.NewCodeRealm("gno.land/r/demo/users")) + testing.SetRealm(std.NewCodeRealm("gno.land/r/demo/users")) PrintRealm() println(pad("CurrentRealm:"), std.CurrentRealm()) println(pad("PrevRealm:"), std.PrevRealm()) diff --git a/gnovm/tests/files/zrealm_crossrealm13a.gno b/gnovm/tests/files/zrealm_crossrealm13a.gno index 2fc37804fce..7d77144660b 100644 --- a/gnovm/tests/files/zrealm_crossrealm13a.gno +++ b/gnovm/tests/files/zrealm_crossrealm13a.gno @@ -3,17 +3,18 @@ package groups import ( "std" + "testing" ) func main() { PrintRealm() println(pad("CurrentRealm:"), std.CurrentRealm()) println(pad("PrevRealm:"), std.PrevRealm()) - std.TestSetRealm(std.NewUserRealm("g1user")) + testing.SetRealm(std.NewUserRealm("g1user")) PrintRealm() println(pad("CurrentRealm:"), std.CurrentRealm()) println(pad("PrevRealm:"), std.PrevRealm()) - std.TestSetRealm(std.NewCodeRealm("gno.land/r/demo/users")) + testing.SetRealm(std.NewCodeRealm("gno.land/r/demo/users")) PrintRealm() println(pad("CurrentRealm:"), std.CurrentRealm()) println(pad("PrevRealm:"), std.PrevRealm()) diff --git a/gnovm/tests/stdlibs/generated.go b/gnovm/tests/stdlibs/generated.go index 4445d2467e8..d22a094401d 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", @@ -115,110 +93,6 @@ var nativeFuncs = [...]NativeFunc{ )) }, }, - { - "std", - "testSetOrigCaller", - []gno.FieldTypeExpr{ - {Name: gno.N("p0"), Type: gno.X("string")}, - }, - []gno.FieldTypeExpr{}, - true, - func(m *gno.Machine) { - b := m.LastBlock() - var ( - p0 string - rp0 = reflect.ValueOf(&p0).Elem() - ) - - gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 0, "")).TV, rp0) - - testlibs_std.X_testSetOrigCaller( - m, - p0) - }, - }, - { - "std", - "testSetOrigPkgAddr", - []gno.FieldTypeExpr{ - {Name: gno.N("p0"), Type: gno.X("string")}, - }, - []gno.FieldTypeExpr{}, - true, - func(m *gno.Machine) { - b := m.LastBlock() - var ( - p0 string - rp0 = reflect.ValueOf(&p0).Elem() - ) - - gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 0, "")).TV, rp0) - - testlibs_std.X_testSetOrigPkgAddr( - m, - p0) - }, - }, - { - "std", - "testSetRealm", - []gno.FieldTypeExpr{ - {Name: gno.N("p0"), Type: gno.X("string")}, - {Name: gno.N("p1"), Type: gno.X("string")}, - }, - []gno.FieldTypeExpr{}, - true, - func(m *gno.Machine) { - b := m.LastBlock() - var ( - p0 string - rp0 = reflect.ValueOf(&p0).Elem() - p1 string - rp1 = reflect.ValueOf(&p1).Elem() - ) - - gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 0, "")).TV, rp0) - gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 1, "")).TV, rp1) - - testlibs_std.X_testSetRealm( - m, - p0, p1) - }, - }, - { - "std", - "testSetOrigSend", - []gno.FieldTypeExpr{ - {Name: gno.N("p0"), Type: gno.X("[]string")}, - {Name: gno.N("p1"), Type: gno.X("[]int64")}, - {Name: gno.N("p2"), Type: gno.X("[]string")}, - {Name: gno.N("p3"), Type: gno.X("[]int64")}, - }, - []gno.FieldTypeExpr{}, - true, - func(m *gno.Machine) { - b := m.LastBlock() - var ( - p0 []string - rp0 = reflect.ValueOf(&p0).Elem() - p1 []int64 - rp1 = reflect.ValueOf(&p1).Elem() - p2 []string - rp2 = reflect.ValueOf(&p2).Elem() - p3 []int64 - rp3 = reflect.ValueOf(&p3).Elem() - ) - - gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 0, "")).TV, rp0) - gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 1, "")).TV, rp1) - gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 2, "")).TV, rp2) - gno.Gno2GoValue(b.GetPointerTo(nil, gno.NewValuePathBlock(1, 3, "")).TV, rp3) - - testlibs_std.X_testSetOrigSend( - m, - p0, p1, p2, p3) - }, - }, { "std", "testIssueCoins", diff --git a/gnovm/tests/stdlibs/std/std.gno b/gnovm/tests/stdlibs/std/std.gno index dcb5a64dbb3..8f16dcd898b 100644 --- a/gnovm/tests/stdlibs/std/std.gno +++ b/gnovm/tests/stdlibs/std/std.gno @@ -1,24 +1,7 @@ package std -func AssertOriginCall() // injected -func IsOriginCall() bool // injected -func TestSkipHeights(count int64) // injected - -func TestSetOrigCaller(addr Address) { testSetOrigCaller(string(addr)) } -func TestSetOrigPkgAddr(addr Address) { testSetOrigPkgAddr(string(addr)) } - -// TestSetRealm sets the realm for the current frame. -// After calling TestSetRealm, calling CurrentRealm() in the test function will yield the value of -// rlm, while if a realm function is called, using PrevRealm() will yield rlm. -func TestSetRealm(rlm Realm) { - testSetRealm(string(rlm.addr), rlm.pkgPath) -} - -func TestSetOrigSend(sent, spent Coins) { - sentDenom, sentAmt := sent.expandNative() - spentDenom, spentAmt := spent.expandNative() - testSetOrigSend(sentDenom, sentAmt, spentDenom, spentAmt) -} +func AssertOriginCall() // injected +func IsOriginCall() bool // injected func TestIssueCoins(addr Address, coins Coins) { denom, amt := coins.expandNative() @@ -29,12 +12,6 @@ func TestIssueCoins(addr Address, coins Coins) { func callerAt(n int) string // native bindings -func testSetOrigCaller(s string) -func testSetOrigPkgAddr(s string) -func testSetRealm(addr, pkgPath string) -func testSetOrigSend( - sentDenom []string, sentAmt []int64, - spentDenom []string, spentAmt []int64) func testIssueCoins(addr string, denom []string, amt []int64) func getRealm(height int) (address string, pkgPath string) func isRealm(pkgPath string) bool diff --git a/gnovm/tests/stdlibs/std/std.go b/gnovm/tests/stdlibs/std/std.go index 675194b252f..60615f20515 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")) @@ -91,40 +84,6 @@ func X_callerAt(m *gno.Machine, n int) string { return string(m.MustLastCallFrame(n).LastPackage.GetPkgAddr().Bech32()) } -func X_testSetOrigCaller(m *gno.Machine, addr string) { - ctx := m.Context.(*TestExecContext) - ctx.OrigCaller = crypto.Bech32Address(addr) - m.Context = ctx -} - -func X_testSetOrigPkgAddr(m *gno.Machine, addr string) { - ctx := m.Context.(*TestExecContext) - ctx.OrigPkgAddr = crypto.Bech32Address(addr) - m.Context = ctx -} - -func X_testSetRealm(m *gno.Machine, addr, pkgPath string) { - // Associate the given Realm with the caller's frame. - var frame *gno.Frame - // When calling this function from Gno, the two top frames are the following: - // #6 [FRAME FUNC:testSetRealm RECV:(undefined) (2 args) 17/6/0/10/8 LASTPKG:std ...] - // #5 [FRAME FUNC:TestSetRealm RECV:(undefined) (1 args) 14/5/0/8/7 LASTPKG:gno.land/r/tyZ1Vcsta ...] - // We want to set the Realm of the frame where TestSetRealm is being called, hence -3. - for i := m.NumFrames() - 3; i >= 0; i-- { - // Must be a frame from calling a function. - if fr := m.Frames[i]; fr.Func != nil { - frame = fr - break - } - } - - ctx := m.Context.(*TestExecContext) - ctx.RealmFrames[frame] = RealmOverride{ - Addr: crypto.Bech32Address(addr), - PkgPath: pkgPath, - } -} - func X_getRealm(m *gno.Machine, height int) (address string, pkgPath string) { // NOTE: keep in sync with stdlibs/std.getRealm @@ -168,17 +127,6 @@ func X_isRealm(m *gno.Machine, pkgPath string) bool { return gno.IsRealmPath(pkgPath) } -func X_testSetOrigSend(m *gno.Machine, - sentDenom []string, sentAmt []int64, - spentDenom []string, spentAmt []int64, -) { - ctx := m.Context.(*TestExecContext) - ctx.OrigSend = std.CompactCoins(sentDenom, sentAmt) - spent := std.CompactCoins(spentDenom, spentAmt) - ctx.OrigSendSpent = &spent - m.Context = ctx -} - // TestBanker is a banker that can be used as a mock banker in test contexts. type TestBanker struct { CoinTable map[crypto.Bech32Address]tm2std.Coins