Skip to content

Commit

Permalink
feat/use-TestSetRealm-in-testcases (#239)
Browse files Browse the repository at this point in the history
* feat: apply gno new testing api `TestSetRealm`
* fix: typo filename
  • Loading branch information
r3v4s committed Jun 19, 2024
1 parent 0aed9f6 commit f4cf494
Show file tree
Hide file tree
Showing 60 changed files with 735 additions and 701 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ $ export WORKDIR=~/work

### Build Gno.land for Gnoswap

Clone the `gno` repository from `gnoswap-labs`. And switch to the `master_20240401` branch. You will be able to clone the repository and build it after running the following commands:
Clone the `gno` repository from `gnoswap-labs`. And switch to the `master_240619` branch. You will be able to clone the repository and build it after running the following commands:

```
$ cd $WORKDIR
$ git clone https://github.com/gnoswap-labs/gno.git gno
$ cd gno
$ git checkout master_gs
$ git checkout master_240619
$ make install
```

Expand Down
29 changes: 0 additions & 29 deletions go.mod

This file was deleted.

140 changes: 0 additions & 140 deletions go.sum

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ var (
maxApprove uint64 = 18446744073709551615
)

// Realms to mock frames
var (
gsaRealm = std.NewUserRealm(gsa)
posRealm = std.NewCodeRealm(consts.POSITION_PATH)
rouRealm = std.NewCodeRealm(consts.ROUTER_PATH)
)

/* HELPER */
func shouldEQ(t *testing.T, got, expected interface{}) {
if got != expected {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ var (
t *testing.T
)

var (
gsaRealm = std.NewUserRealm(gsa)
posRealm = std.NewCodeRealm(consts.POSITION_PATH)
rouRealm = std.NewCodeRealm(consts.ROUTER_PATH)
)

type FooToken struct{}

func (FooToken) Transfer() func(to pusers.AddressOrName, amount uint64) {
Expand Down Expand Up @@ -149,10 +155,12 @@ func (GNSToken) Approve() func(spender pusers.AddressOrName, amount uint64) {
}

func init() {
std.TestSetPrevAddr(gsa)
std.TestSetRealm(gsaRealm)

// TOKEN REGISTER
std.TestSetPrevAddr(gsa)
std.TestSetRealm(gsaRealm)
std.TestSetOrigCaller(gsa)

pl.RegisterGRC20Interface("gno.land/r/demo/bar", FooToken{})
pl.RegisterGRC20Interface("gno.land/r/demo/foo", BarToken{})
pl.RegisterGRC20Interface("gno.land/r/demo/baz", BazToken{})
Expand All @@ -173,7 +181,7 @@ func main() {
}

func createFooBarPool() {
std.TestSetPrevAddr(gsa)
std.TestSetRealm(gsaRealm)

gns.Approve(a2u(consts.POOL_ADDR), consts.POOL_CREATION_FEE)
std.TestSkipHeights(1)
Expand All @@ -186,7 +194,7 @@ func createFooBarPool() {
}

func createBarBazPool() {
std.TestSetPrevAddr(gsa)
std.TestSetRealm(gsaRealm)

gns.Approve(a2u(consts.POOL_ADDR), consts.POOL_CREATION_FEE)
std.TestSkipHeights(1)
Expand All @@ -199,12 +207,12 @@ func createBarBazPool() {
}

func mintFooBar() {
std.TestSetPrevAddr(gsa)
std.TestSetRealm(gsaRealm)
foo.Approve(a2u(consts.POOL_ADDR), consts.UINT64_MAX)
bar.Approve(a2u(consts.POOL_ADDR), consts.UINT64_MAX)
std.TestSkipHeights(2)

//std.TestSetPrevRealm(consts.POSITION_PATH)
//std.TestSetRealm(posRealm)
//std.TestSetOrigCaller(gsa)
amount0, amount1 := pl.Mint(
barPath,
Expand All @@ -224,12 +232,12 @@ func mintFooBar() {
}

func mintBarBaz() {
std.TestSetPrevAddr(gsa)
std.TestSetRealm(gsaRealm)
bar.Approve(a2u(consts.POOL_ADDR), consts.UINT64_MAX)
baz.Approve(a2u(consts.POOL_ADDR), consts.UINT64_MAX)
std.TestSkipHeights(2)

//std.TestSetPrevRealm(consts.POSITION_PATH)
//std.TestSetRealm(posRealm)
//std.TestSetOrigCaller(gsa)
amount0, amount1 := pl.Mint(
barPath,
Expand Down
Loading

0 comments on commit f4cf494

Please sign in to comment.