Skip to content

Commit

Permalink
Merge pull request #183 from gnoswap-labs/GSW-880-feat-test-case-init…
Browse files Browse the repository at this point in the history
…-its-own-state

GSW-880 feat: test case init its own state
  • Loading branch information
r3v4s authored Feb 28, 2024
2 parents 19124a6 + eda794d commit 3b96c31
Show file tree
Hide file tree
Showing 75 changed files with 2,394 additions and 2,341 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package swap_scenario

import (
"std"

"gno.land/r/demo/foo"

"gno.land/r/demo/bar"
Expand All @@ -15,6 +17,8 @@ import (

"gno.land/r/demo/gns"

"gno.land/r/demo/consts"

"gno.land/r/demo/users"

pl "gno.land/r/demo/pool"
Expand Down Expand Up @@ -131,30 +135,32 @@ func (GNSToken) Approve() func(spender users.AddressOrName, amount uint64) {
}

func init() {
std.TestSetOrigCaller(consts.GNOSWAP_ADMIN)

// POOL
pl.RegisterGRC20Interface("gno.land/r/demo/bar", BarToken{})
pl.RegisterGRC20Interface("gno.land/r/demo/foo", FooToken{})
pl.RegisterGRC20Interface("gno.land/r/demo/bar", BarToken{})
pl.RegisterGRC20Interface("gno.land/r/demo/baz", BazToken{})
pl.RegisterGRC20Interface("gno.land/r/demo/qux", QuxToken{})
pl.RegisterGRC20Interface("gno.land/r/demo/wugnot", WugnotToken{})
pl.RegisterGRC20Interface("gno.land/r/demo/obl", OBLToken{})
pl.RegisterGRC20Interface("gno.land/r/demo/gns", GNSToken{})

// STAKER
sr.RegisterGRC20Interface("gno.land/r/demo/bar", BarToken{})
sr.RegisterGRC20Interface("gno.land/r/demo/foo", FooToken{})
sr.RegisterGRC20Interface("gno.land/r/demo/baz", BazToken{})
sr.RegisterGRC20Interface("gno.land/r/demo/qux", QuxToken{})
sr.RegisterGRC20Interface("gno.land/r/demo/wugnot", WugnotToken{})
sr.RegisterGRC20Interface("gno.land/r/demo/obl", OBLToken{})
sr.RegisterGRC20Interface("gno.land/r/demo/gns", GNSToken{})

// ROUTER
rr.RegisterGRC20Interface("gno.land/r/demo/bar", BarToken{})
rr.RegisterGRC20Interface("gno.land/r/demo/foo", FooToken{})
rr.RegisterGRC20Interface("gno.land/r/demo/bar", BarToken{})
rr.RegisterGRC20Interface("gno.land/r/demo/baz", BazToken{})
rr.RegisterGRC20Interface("gno.land/r/demo/qux", QuxToken{})
rr.RegisterGRC20Interface("gno.land/r/demo/wugnot", WugnotToken{})
rr.RegisterGRC20Interface("gno.land/r/demo/obl", OBLToken{})
rr.RegisterGRC20Interface("gno.land/r/demo/gns", GNSToken{})

// STAKER
sr.RegisterGRC20Interface("gno.land/r/demo/foo", FooToken{})
sr.RegisterGRC20Interface("gno.land/r/demo/bar", BarToken{})
sr.RegisterGRC20Interface("gno.land/r/demo/baz", BazToken{})
sr.RegisterGRC20Interface("gno.land/r/demo/qux", QuxToken{})
sr.RegisterGRC20Interface("gno.land/r/demo/wugnot", WugnotToken{})
sr.RegisterGRC20Interface("gno.land/r/demo/obl", OBLToken{})
sr.RegisterGRC20Interface("gno.land/r/demo/gns", GNSToken{})
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,74 +5,71 @@ import (
"strconv"
"testing"

"gno.land/p/demo/grc/grc20"
"gno.land/p/demo/grc/grc721"
"gno.land/r/demo/users"

"gno.land/r/demo/consts"

"gno.land/r/demo/bar"
"gno.land/r/demo/baz"
"gno.land/r/demo/foo"
"gno.land/r/demo/gns"
"gno.land/r/demo/obl"
"gno.land/r/demo/qux"

"gno.land/r/demo/wugnot"
)

const (
MAX_TIMEOUT bigint = 9999999999
"gno.land/r/demo/users"
)

var (
test1 std.Address
gsa std.Address = consts.GNOSWAP_ADMIN
test1 std.Address = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")

barPath = "gno.land/r/demo/bar"
barObj = bar.GetGRC20()
fooPath string = "gno.land/r/demo/foo"
barPath string = "gno.land/r/demo/bar"
bazPath string = "gno.land/r/demo/baz"
quxPath string = "gno.land/r/demo/qux"

bazPath = "gno.land/r/demo/baz"
bazObj = baz.GetGRC20()
oblPath string = "gno.land/r/demo/obl"
// wugnotPath string = "gno.land/r/demo/wugnot" // from consts
// gnsPath string = "gno.land/r/demo/gns" // from consts

fooPath = "gno.land/r/demo/foo"
fooObj = foo.GetGRC20()
fee100 uint16 = 100
fee500 uint16 = 500
fee3000 uint16 = 3000

quxPath = "gno.land/r/demo/qux"
quxObj = qux.GetGRC20()

wugnotPath = "gno.land/r/demo/wugnot"
// wugnotObj = wugnot.GetGRC20()

gnsPath = "gno.land/r/demo/gns"
gnsObj = gns.GetGRC20()

oblPath = "gno.land/r/demo/obl"
oblObj = obl.GetGRC20()

fee100 = uint16(100)
fee500 = uint16(500)
fee3000 = uint16(3000)
max_timeout bigint = 9999999999
)

func init() {
test1 = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
// prepare ugnot
/* UTIL */
func ugnotBalanceOf(addr std.Address) uint64 {
testBanker := std.GetBanker(std.BankerTypeRealmIssue)
testBanker.IssueCoin(test1, "ugnot", 500_000_000_000_000)

std.TestSetPrevAddr(test1)
coins := testBanker.GetCoins(addr)
if len(coins) == 0 {
return 0
}

gns.Approve(a2u(consts.POOL_ADDR), 500_000_000_000_000)
return uint64(testBanker.GetCoins(addr)[0].Amount)
}

bar.Approve(a2u(consts.POOL_ADDR), 500_000_000_000_000)
baz.Approve(a2u(consts.POOL_ADDR), 500_000_000_000_000)
foo.Approve(a2u(consts.POOL_ADDR), 500_000_000_000_000)
func a2u(addr std.Address) users.AddressOrName {
return users.AddressOrName(addr)
}

wugnot.Approve(a2u(consts.POOL_ADDR), 500_000_000_000_000)
func tid(tokenId interface{}) grc721.TokenID {
if tokenId == nil {
panic("tid() || tokenId is nil")
}

switch tokenId.(type) {
case bigint:
return grc721.TokenID(string(tokenId.(bigint)))
case string:
return grc721.TokenID(tokenId.(string))
case int:
return grc721.TokenID(strconv.Itoa(tokenId.(int)))
case uint64:
return grc721.TokenID(strconv.Itoa(int(tokenId.(uint64))))
case grc721.TokenID:
return tokenId.(grc721.TokenID)
default:
panic("[STAKER] utils.gno__tid() || unsupported tokenId type")
}
}

/* HELPER */
/* TEST HELPER */
func shouldEQ(t *testing.T, got, expected interface{}) {
if got != expected {
t.Errorf("got %v, expected %v", got, expected)
Expand Down Expand Up @@ -118,52 +115,3 @@ func shouldPanicWithMsg(t *testing.T, f func(), msg string) {
}()
f()
}

func balanceOf(token *grc20.AdminToken, addr std.Address) uint64 {
balance, err := token.BalanceOf(addr)
if err != nil {
panic(err)
}

return balance
}

func a2u(addr std.Address) users.AddressOrName {
return users.AddressOrName(addr)
}

func tid(tokenId interface{}) grc721.TokenID {
if tokenId == nil {
panic("tid() || tokenId is nil")
}

switch tokenId.(type) {
case bigint:
return grc721.TokenID(string(tokenId.(bigint)))
case string:
return grc721.TokenID(tokenId.(string))
case int:
return grc721.TokenID(strconv.Itoa(tokenId.(int)))
case uint64:
return grc721.TokenID(strconv.Itoa(int(tokenId.(uint64))))
case grc721.TokenID:
return tokenId.(grc721.TokenID)
default:
panic("[STAKER] utils.gno__tid() || unsupported tokenId type")
}
}

func ugnotBalanceOf(addr std.Address) uint64 {
testBanker := std.GetBanker(std.BankerTypeRealmIssue)

coins := testBanker.GetCoins(addr)
if len(coins) == 0 {
return 0
}

return uint64(testBanker.GetCoins(addr)[0].Amount)
}

func wugnotBalanceOf(addr std.Address) uint64 {
return wugnot.BalanceOf(a2u(addr))
}
Loading

0 comments on commit 3b96c31

Please sign in to comment.