Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: manipulate entire context instead of TestSetXXX #3582

Open
wants to merge 72 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
bf223d8
wip: add setContext bridge from gno => go
Jan 22, 2025
1d76555
wip: refactoring test for ursulovic tests
hthieu1110 Jan 23, 2025
c10bab8
wip: refactor std.TestSetOrigCaller => t.SetPreviousRealm
hthieu1110 Jan 24, 2025
e2fac62
chore: merge master
hthieu1110 Jan 25, 2025
16ba3fb
chore: removed unused import
hthieu1110 Jan 25, 2025
3379e89
fix: fix tests
hthieu1110 Jan 25, 2025
cc67dd5
refactor: convert std.TestSetOrigCaller => testing.SetPrevRealm
hthieu1110 Jan 25, 2025
0488bc6
refactor: remove TestSetOrigCaller + X_testSetOrigCaller
hthieu1110 Jan 25, 2025
8975f59
refactor: std.TestSetOrigSend => t.SetOriginSend, testing.SetOriginSe…
hthieu1110 Jan 25, 2025
e4b36e9
fix: fix tests
hthieu1110 Jan 25, 2025
b983356
refactor: std.TestSetOrigPkgAddr => t/testing.SetOrignalPkgAddress + …
hthieu1110 Jan 25, 2025
055cad0
Merge remote-tracking branch 'remote/master' into refactor/manipulate…
hthieu1110 Feb 1, 2025
c8b4af7
refactor: TestSkipHeights => t.SkipHeights + remove TestSkipHeights
hthieu1110 Feb 1, 2025
56b66e5
refactor: refactor new TestSetOrigCaller => SetPreviousRealm with new…
hthieu1110 Feb 1, 2025
7037eee
chore: merge with master + fix tests
Feb 3, 2025
aa2a55c
refactor: SetPreviousRealm => SetOriginCaller
Feb 3, 2025
0ebe557
fix: fix SetOriginCaller func
Feb 3, 2025
64a53ae
refactor: add missing unsaved files for SetPrevRealm => SetOriginCaller
Feb 3, 2025
0210aae
refactor: std.TestSetRealm => t/testing.SetRealm + remove X_testSetRealm
Feb 3, 2025
947caa5
fix: fix refactor errors
Feb 3, 2025
3699046
fix: fmt
hthieu1110 Feb 3, 2025
7679403
chore: merge with master
hthieu1110 Feb 3, 2025
02546fa
refactor: refactor new merged code
hthieu1110 Feb 3, 2025
eb4170c
refactor: split SetOriginSend => SetOriginSend + SetOriginSpend
hthieu1110 Feb 4, 2025
5f46ff7
refactor: std.TestIssueCoin => t/testing.IssueCoins
hthieu1110 Feb 4, 2025
f89408f
chore: merged with master and refactor new merged code
hthieu1110 Feb 12, 2025
89d157d
fix: fix new refactored code from new merge
hthieu1110 Feb 12, 2025
38bca55
chore: format docs + files
hthieu1110 Feb 12, 2025
285511e
fix: fix tests
hthieu1110 Feb 12, 2025
430bbb1
chore: merge with master
Feb 24, 2025
5ac72be
fix: fix tests
Feb 24, 2025
c9d8810
fix: fix tests
Feb 24, 2025
6a75e30
fix: fix tests
Feb 24, 2025
2b6fb12
fix: fix tests
Feb 24, 2025
abd6a85
Merge branch 'master' into refactor/manipulate-contexts-instead-of-te…
hthieu1110 Feb 24, 2025
100e68d
Merge branch 'master' into refactor/manipulate-contexts-instead-of-te…
thehowl Feb 24, 2025
8bc9046
commit suggestions
thehowl Feb 25, 2025
a161edc
fix: addressed review
hthieu1110 Feb 25, 2025
7fe900e
Merge remote-tracking branch 'remote/master' into refactor/manipulate…
Feb 26, 2025
8bb3894
fix: addressed all reviews
Feb 26, 2025
116a6bf
chore: fix fmt
Feb 26, 2025
79ec6fc
fix: fix tests
Feb 26, 2025
ba7aaf5
refactor: merge with and refactor from master
hthieu1110 Mar 3, 2025
84b5f65
chore: refactor new merged code
hthieu1110 Mar 6, 2025
43b9fca
fix: not expose expandNative
hthieu1110 Mar 6, 2025
bca0743
chore: add missing file
hthieu1110 Mar 6, 2025
29d6ede
wip
hthieu1110 Mar 6, 2025
fb79d19
refactor: reactor set/getContext => tests/stblibs/
hthieu1110 Mar 6, 2025
8013402
chore: add missing files
hthieu1110 Mar 6, 2025
9a864b2
fix: fmt
hthieu1110 Mar 6, 2025
d5b5cae
Merge remote-tracking branch 'remote/master' into refactor/manipulate…
hthieu1110 Mar 6, 2025
cb75706
Update gnovm/tests/stdlibs/testing/context_testing.gno
hthieu1110 Mar 7, 2025
6656305
fix: get timestampNano
hthieu1110 Mar 7, 2025
1e05adc
merge with master
hthieu1110 Mar 7, 2025
02dc11d
chore: removed files
hthieu1110 Mar 7, 2025
8a9e6f1
fix: test
hthieu1110 Mar 8, 2025
7092733
Merge remote-tracking branch 'remote/master' into refactor/manipulate…
hthieu1110 Mar 10, 2025
a1f8bb4
fox: fix tests
hthieu1110 Mar 10, 2025
3a92f49
chore: removed uneeded comments
hthieu1110 Mar 10, 2025
cdb0d24
fix: fmt
hthieu1110 Mar 10, 2025
a0b857b
fix: generated files
hthieu1110 Mar 10, 2025
b721cab
fix: generated file
hthieu1110 Mar 10, 2025
5da5243
fix: fix testfile output
hthieu1110 Mar 10, 2025
ef65d3f
fix: fix tests
hthieu1110 Mar 10, 2025
1b8555b
fix: fix docs linting
hthieu1110 Mar 10, 2025
b8ddf28
chore: merged with master
hthieu1110 Mar 10, 2025
40d8f36
Merge remote-tracking branch 'remote/master' into refactor/manipulate…
hthieu1110 Mar 10, 2025
a09d24b
Merge branch 'master' into refactor/manipulate-contexts-instead-of-te…
thehowl Mar 10, 2025
c1740af
Merge branch 'master' into refactor/manipulate-contexts-instead-of-te…
thehowl Mar 10, 2025
9daec25
Merge remote-tracking branch 'remote/master' into refactor/manipulate…
hthieu1110 Mar 11, 2025
2aa3ac3
fix: tests
hthieu1110 Mar 11, 2025
ff43f91
fix: fix lint
hthieu1110 Mar 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/_assets/minisocial/posts_test-0.gno
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestCreatePostSingle(t *testing.T) {
// Get a test address for alice
aliceAddr := testutils.TestAddress("alice")
// TestSetRealm sets the realm caller, in this case Alice
std.TestSetRealm(std.NewUserRealm(aliceAddr))
testing.SetRealm(std.NewUserRealm(aliceAddr))

text1 := "Hello World!"
err := CreatePost(text1)
Expand Down
4 changes: 2 additions & 2 deletions docs/_assets/minisocial/posts_test-1.gno
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestCreatePostSingle(t *testing.T) {
// Get a test address for alice
aliceAddr := testutils.TestAddress("alice")
// TestSetRealm sets the realm caller, in this case Alice
std.TestSetRealm(std.NewUserRealm(aliceAddr))
testing.SetRealm(std.NewUserRealm(aliceAddr))

text1 := "Hello World!"
err := CreatePost(text1)
Expand Down Expand Up @@ -44,7 +44,7 @@ func TestCreatePostMultiple(t *testing.T) {
for _, p := range posts {
// Set the appropriate caller realm based on the author
authorAddr := testutils.TestAddress(p.author)
std.TestSetRealm(std.NewUserRealm(authorAddr))
testing.SetRealm(std.NewUserRealm(authorAddr))

// Create the post
err := CreatePost(p.text)
Expand Down
4 changes: 2 additions & 2 deletions docs/builders/example-minisocial-dapp.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func TestCreatePostSingle(t *testing.T) {
// Get a test address for alice
aliceAddr := testutils.TestAddress("alice")
// TestSetRealm sets the realm caller, in this case Alice
std.TestSetRealm(std.NewUserRealm(aliceAddr))
testing.SetRealm(std.NewUserRealm(aliceAddr))

text1 := "Hello World!"
err := CreatePost(text1)
Expand Down Expand Up @@ -332,7 +332,7 @@ func TestCreatePostMultiple(t *testing.T) {
for _, p := range posts {
// Set the appropriate caller realm based on the author
authorAddr := testutils.TestAddress(p.author)
std.TestSetRealm(std.NewUserRealm(authorAddr))
testing.SetRealm(std.NewUserRealm(authorAddr))

// Create the post
err := CreatePost(p.text)
Expand Down
8 changes: 4 additions & 4 deletions docs/resources/gno-stdlibs.md
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ Sets the current caller of the transaction to **addr**.

#### Usage
```go
std.TestSetOriginCaller(std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"))
testing.SetOriginCaller(std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"))
```
---

Expand All @@ -844,7 +844,7 @@ Sets the sent & spent coins for the current context.

#### Usage
```go
std.TestSetOriginSend(sent, spent Coins)
testing.SetOriginSend(sent, spent Coins)
```
---

Expand Down Expand Up @@ -882,9 +882,9 @@ Should be used in combination with [`NewUserRealm`](#newuserrealm) &
#### Usage
```go
addr := std.Address("g1ecely4gjy0yl6s9kt409ll330q9hk2lj9ls3ec")
std.TestSetRealm(std.NewUserRealm(""))
testing.SetRealm(std.NewUserRealm(""))
// or
std.TestSetRealm(std.NewCodeRealm("gno.land/r/demo/users"))
testing.SetRealm(std.NewCodeRealm("gno.land/r/demo/users"))
```

---
Expand Down
3 changes: 1 addition & 2 deletions examples/gno.land/p/agherasie/forms/create_test.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package forms

import (
"std"
"testing"

"gno.land/p/demo/testutils"
Expand All @@ -10,7 +9,7 @@ import (

func TestCreateForm(t *testing.T) {
alice := testutils.TestAddress("alice")
std.TestSetOriginCaller(alice)
testing.SetOriginCaller(alice)
db := NewDB()
title := "Simple Form"
description := "This is a form"
Expand Down
5 changes: 2 additions & 3 deletions examples/gno.land/p/demo/entropy/entropy_test.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package entropy

import (
"std"
"strconv"
"testing"
)
Expand All @@ -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)
testing.SkipHeights(1)
differentHeightEntropy := New()
differentHeightResult := computeValue(t, differentHeightEntropy)

Expand All @@ -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)
testing.SkipHeights(1)
differentHeightEntropy := New()
differentHeightResult := computeValue64(t, differentHeightEntropy)

Expand Down
4 changes: 2 additions & 2 deletions examples/gno.land/p/demo/entropy/z_filetest.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"std"
"testing"

"gno.land/p/demo/entropy"
)
Expand All @@ -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())
Expand Down
5 changes: 2 additions & 3 deletions examples/gno.land/p/demo/grc/grc20/tellers_test.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package grc20

import (
"std"
"testing"

"gno.land/p/demo/testutils"
Expand Down Expand Up @@ -115,12 +114,12 @@ func TestCallerTeller(t *testing.T) {
checkBalances(1000, 0, 0)
checkAllowances(0, 0, 0, 0, 0, 0)

std.TestSetOriginCaller(alice)
testing.SetOriginCaller(alice)
urequire.NoError(t, teller.Approve(bob, 600))
checkBalances(1000, 0, 0)
checkAllowances(600, 0, 0, 0, 0, 0)

std.TestSetOriginCaller(bob)
testing.SetOriginCaller(bob)
urequire.Error(t, teller.TransferFrom(alice, carl, 700))
checkBalances(1000, 0, 0)
checkAllowances(600, 0, 0, 0, 0, 0)
Expand Down
6 changes: 3 additions & 3 deletions examples/gno.land/p/demo/grc/grc721/basic_nft_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func TestSetTokenURI(t *testing.T) {
addr2 := std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")
tokenURI := "http://example.com/token"

std.TestSetOriginCaller(std.Address(addr1)) // addr1
testing.SetOriginCaller(addr1) // addr1

dummy.mint(addr1, TokenID("1"))
_, derr := dummy.SetTokenURI(TokenID("1"), TokenURI(tokenURI))
Expand All @@ -269,13 +269,13 @@ func TestSetTokenURI(t *testing.T) {
_, err := dummy.SetTokenURI(TokenID("3"), TokenURI(tokenURI))
uassert.ErrorIs(t, err, ErrInvalidTokenId)

std.TestSetOriginCaller(std.Address(addr2)) // addr2
testing.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.TestSetOriginCaller(std.Address(addr1)) // addr1
testing.SetOriginCaller(addr1) // addr1

dummyTokenURI, err := dummy.TokenURI(TokenID("1"))
uassert.NoError(t, err, "TokenURI error")
Expand Down
7 changes: 3 additions & 4 deletions examples/gno.land/p/demo/grc/grc721/grc721_metadata_test.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package grc721

import (
"std"
"testing"

"gno.land/p/demo/testutils"
Expand Down Expand Up @@ -31,7 +30,7 @@ func TestSetMetadata(t *testing.T) {
youtubeURL := "test"

// Set the original caller to addr1
std.TestSetOriginCaller(addr1) // addr1
testing.SetOriginCaller(addr1) // addr1

// Mint a new token for addr1
dummy.mint(addr1, TokenID("1"))
Expand Down Expand Up @@ -69,7 +68,7 @@ func TestSetMetadata(t *testing.T) {
uassert.ErrorIs(t, err, ErrInvalidTokenId)

// Set the original caller to addr2
std.TestSetOriginCaller(addr2) // addr2
testing.SetOriginCaller(addr2) // addr2

// Try to set metadata for token 1 from addr2 (should fail)
cerr := dummy.SetTokenMetadata(TokenID("1"), Metadata{
Expand All @@ -88,7 +87,7 @@ func TestSetMetadata(t *testing.T) {
uassert.ErrorIs(t, cerr, ErrCallerIsNotOwner)

// Set the original caller back to addr1
std.TestSetOriginCaller(addr1) // addr1
testing.SetOriginCaller(addr1) // addr1

// Retrieve metadata for token 1
dummyMetadata, err := dummy.TokenMetadata(TokenID("1"))
Expand Down
6 changes: 3 additions & 3 deletions examples/gno.land/p/demo/grc/grc721/grc721_royalty_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestSetTokenRoyalty(t *testing.T) {
salePrice := uint64(1000)
expectRoyaltyAmount := uint64(100)

std.TestSetOriginCaller(addr1) // addr1
testing.SetOriginCaller(addr1) // addr1

dummy.mint(addr1, TokenID("1"))

Expand All @@ -38,7 +38,7 @@ func TestSetTokenRoyalty(t *testing.T) {
})
uassert.ErrorIs(t, derr, ErrInvalidTokenId)

std.TestSetOriginCaller(addr2) // addr2
testing.SetOriginCaller(addr2) // addr2

cerr := dummy.SetTokenRoyalty(TokenID("1"), RoyaltyInfo{
PaymentAddress: paymentAddress,
Expand All @@ -61,7 +61,7 @@ func TestSetTokenRoyalty(t *testing.T) {
uassert.ErrorIs(t, perr, ErrInvalidRoyaltyPercentage)

// Test case: Retrieving Royalty Info
std.TestSetOriginCaller(addr1) // addr1
testing.SetOriginCaller(addr1) // addr1

dummyPaymentAddress, dummyRoyaltyAmount, rerr := dummy.RoyaltyInfo(TokenID("1"), salePrice)
uassert.NoError(t, rerr, "RoyaltyInfo error")
Expand Down
15 changes: 7 additions & 8 deletions examples/gno.land/p/demo/membstore/membstore_test.gno
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package membstore

import (
"testing"

"std"
"testing"

"gno.land/p/demo/testutils"
"gno.land/p/demo/uassert"
Expand Down Expand Up @@ -155,7 +154,7 @@ func TestMembStore_AddMember(t *testing.T) {
r = std.NewCodeRealm(daoPkgPath)
)

std.TestSetRealm(r)
testing.SetRealm(r)

// Create a non-empty store
members := generateMembers(t, 1)
Expand All @@ -174,7 +173,7 @@ func TestMembStore_AddMember(t *testing.T) {
r = std.NewCodeRealm(daoPkgPath)
)

std.TestSetRealm(r)
testing.SetRealm(r)

// Create an empty store
members := generateMembers(t, 1)
Expand Down Expand Up @@ -234,7 +233,7 @@ func TestMembStore_UpdateMember(t *testing.T) {
r = std.NewCodeRealm(daoPkgPath)
)

std.TestSetRealm(r)
testing.SetRealm(r)

// Create an empty store
members := generateMembers(t, 1)
Expand All @@ -253,7 +252,7 @@ func TestMembStore_UpdateMember(t *testing.T) {
r = std.NewCodeRealm(daoPkgPath)
)

std.TestSetRealm(r)
testing.SetRealm(r)

// Create a non-empty store
members := generateMembers(t, 2)
Expand All @@ -272,7 +271,7 @@ func TestMembStore_UpdateMember(t *testing.T) {
r = std.NewCodeRealm(daoPkgPath)
)

std.TestSetRealm(r)
testing.SetRealm(r)

// Create a non-empty store
members := generateMembers(t, 1)
Expand All @@ -299,7 +298,7 @@ func TestMembStore_UpdateMember(t *testing.T) {
r = std.NewCodeRealm(daoPkgPath)
)

std.TestSetRealm(r)
testing.SetRealm(r)

// Create a non-empty store
members := generateMembers(t, 1)
Expand Down
14 changes: 7 additions & 7 deletions examples/gno.land/p/demo/memeland/memeland_test.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package memeland

import (
"std"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -122,7 +121,8 @@ func TestGetPostsInRangeByUpvote(t *testing.T) {
m.Upvote(id2)

// Change caller so avoid double upvote panic
std.TestSetOriginCaller(testutils.TestAddress("alice"))
alice := testutils.TestAddress("alice")
testing.SetOriginCaller(alice)
m.Upvote(id1)

// Final upvote count:
Expand Down Expand Up @@ -236,21 +236,21 @@ func TestUpvote(t *testing.T) {

func TestDelete(t *testing.T) {
alice := testutils.TestAddress("alice")
std.TestSetOriginCaller(alice)
testing.SetOriginCaller(alice)

// Alice is admin
m := NewMemeland()

// Set caller to Bob
bob := testutils.TestAddress("bob")
std.TestSetOriginCaller(bob)
testing.SetOriginCaller(bob)

// Bob adds post to Memeland
now := time.Now()
postID := m.PostMeme("Meme #1", now.Unix())

// Alice removes Bob's post
std.TestSetOriginCaller(alice)
testing.SetOriginCaller(alice)

id := m.RemovePost(postID)
uassert.Equal(t, postID, id, "post IDs not matching")
Expand All @@ -259,7 +259,7 @@ func TestDelete(t *testing.T) {

func TestDeleteByNonAdmin(t *testing.T) {
alice := testutils.TestAddress("alice")
std.TestSetOriginCaller(alice)
testing.SetOriginCaller(alice)

m := NewMemeland()

Expand All @@ -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.TestSetOriginCaller(bob)
testing.SetOriginCaller(bob)

defer func() {
if r := recover(); r == nil {
Expand Down
Loading
Loading