-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
2,475 additions
and
368 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
_deploy/p/demo/gnoswap/uint256/gs_overflow_calculation_test.gno
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package pool | ||
|
||
import ( | ||
"std" | ||
|
||
"gno.land/r/demo/bar" | ||
"gno.land/r/demo/baz" | ||
"gno.land/r/demo/foo" | ||
"gno.land/r/demo/obl" | ||
"gno.land/r/demo/qux" | ||
) | ||
|
||
func init() { | ||
std.TestSetPrevAddr(test1) | ||
|
||
// GIVE 100_000_000_000(u) ≈ 100_000 | ||
for i := 0; i < 100; i++ { | ||
foo.Faucet() | ||
bar.Faucet() | ||
baz.Faucet() | ||
qux.Faucet() | ||
obl.Faucet() | ||
//gns.Faucet() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
package pool | ||
|
||
import ( | ||
"std" | ||
"testing" | ||
|
||
"gno.land/p/demo/testutils" | ||
|
||
"gno.land/r/demo/foo" | ||
|
||
"gno.land/r/demo/bar" | ||
|
||
"gno.land/r/demo/baz" | ||
|
||
"gno.land/r/demo/qux" | ||
|
||
"gno.land/r/demo/wugnot" | ||
|
||
"gno.land/r/demo/obl" | ||
|
||
"gno.land/r/demo/gns" | ||
|
||
"gno.land/r/demo/gnoswap/consts" | ||
|
||
pusers "gno.land/p/demo/users" | ||
) | ||
|
||
type FooToken struct{} | ||
|
||
func (FooToken) Transfer() func(to pusers.AddressOrName, amount uint64) { | ||
return foo.Transfer | ||
} | ||
func (FooToken) TransferFrom() func(from, to pusers.AddressOrName, amount uint64) { | ||
return foo.TransferFrom | ||
} | ||
func (FooToken) BalanceOf() func(owner pusers.AddressOrName) uint64 { | ||
return foo.BalanceOf | ||
} | ||
func (FooToken) Approve() func(spender pusers.AddressOrName, amount uint64) { | ||
return foo.Approve | ||
} | ||
|
||
type BarToken struct{} | ||
|
||
func (BarToken) Transfer() func(to pusers.AddressOrName, amount uint64) { | ||
return bar.Transfer | ||
} | ||
func (BarToken) TransferFrom() func(from, to pusers.AddressOrName, amount uint64) { | ||
return bar.TransferFrom | ||
} | ||
func (BarToken) BalanceOf() func(owner pusers.AddressOrName) uint64 { | ||
return bar.BalanceOf | ||
} | ||
func (BarToken) Approve() func(spender pusers.AddressOrName, amount uint64) { | ||
return bar.Approve | ||
} | ||
|
||
type BazToken struct{} | ||
|
||
func (BazToken) Transfer() func(to pusers.AddressOrName, amount uint64) { | ||
return baz.Transfer | ||
} | ||
func (BazToken) TransferFrom() func(from, to pusers.AddressOrName, amount uint64) { | ||
return baz.TransferFrom | ||
} | ||
func (BazToken) BalanceOf() func(owner pusers.AddressOrName) uint64 { | ||
return baz.BalanceOf | ||
} | ||
func (BazToken) Approve() func(spender pusers.AddressOrName, amount uint64) { | ||
return baz.Approve | ||
} | ||
|
||
type QuxToken struct{} | ||
|
||
func (QuxToken) Transfer() func(to pusers.AddressOrName, amount uint64) { | ||
return qux.Transfer | ||
} | ||
func (QuxToken) TransferFrom() func(from, to pusers.AddressOrName, amount uint64) { | ||
return qux.TransferFrom | ||
} | ||
func (QuxToken) BalanceOf() func(owner pusers.AddressOrName) uint64 { | ||
return qux.BalanceOf | ||
} | ||
func (QuxToken) Approve() func(spender pusers.AddressOrName, amount uint64) { | ||
return qux.Approve | ||
} | ||
|
||
type WugnotToken struct{} | ||
|
||
func (WugnotToken) Transfer() func(to pusers.AddressOrName, amount uint64) { | ||
return wugnot.Transfer | ||
} | ||
func (WugnotToken) TransferFrom() func(from, to pusers.AddressOrName, amount uint64) { | ||
return wugnot.TransferFrom | ||
} | ||
func (WugnotToken) BalanceOf() func(owner pusers.AddressOrName) uint64 { | ||
return wugnot.BalanceOf | ||
} | ||
func (WugnotToken) Approve() func(spender pusers.AddressOrName, amount uint64) { | ||
return wugnot.Approve | ||
} | ||
|
||
type OBLToken struct{} | ||
|
||
func (OBLToken) Transfer() func(to pusers.AddressOrName, amount uint64) { | ||
return obl.Transfer | ||
} | ||
func (OBLToken) TransferFrom() func(from, to pusers.AddressOrName, amount uint64) { | ||
return obl.TransferFrom | ||
} | ||
func (OBLToken) BalanceOf() func(owner pusers.AddressOrName) uint64 { | ||
return obl.BalanceOf | ||
} | ||
func (OBLToken) Approve() func(spender pusers.AddressOrName, amount uint64) { | ||
return obl.Approve | ||
} | ||
|
||
type GNSToken struct{} | ||
|
||
func (GNSToken) Transfer() func(to pusers.AddressOrName, amount uint64) { | ||
return gns.Transfer | ||
} | ||
|
||
func (GNSToken) TransferFrom() func(from, to pusers.AddressOrName, amount uint64) { | ||
return gns.TransferFrom | ||
} | ||
|
||
func (GNSToken) BalanceOf() func(owner pusers.AddressOrName) uint64 { | ||
return gns.BalanceOf | ||
} | ||
|
||
func (GNSToken) Approve() func(spender pusers.AddressOrName, amount uint64) { | ||
return gns.Approve | ||
} | ||
|
||
func init() { | ||
std.TestSetOrigCaller(consts.GNOSWAP_ADMIN) | ||
|
||
RegisterGRC20Interface("gno.land/r/demo/bar", BarToken{}) | ||
RegisterGRC20Interface("gno.land/r/demo/foo", FooToken{}) | ||
RegisterGRC20Interface("gno.land/r/demo/baz", BazToken{}) | ||
RegisterGRC20Interface("gno.land/r/demo/qux", QuxToken{}) | ||
RegisterGRC20Interface("gno.land/r/demo/wugnot", WugnotToken{}) | ||
RegisterGRC20Interface("gno.land/r/demo/obl", OBLToken{}) | ||
RegisterGRC20Interface("gno.land/r/demo/gns", GNSToken{}) | ||
} | ||
|
||
func TestGetRegisteredTokens(t *testing.T) { | ||
shouldEQ(t, len(GetRegisteredTokens()), 7) | ||
} | ||
|
||
func TestRegisterGRC20Interface(t *testing.T) { | ||
shouldPanic(t, | ||
func() { | ||
RegisterGRC20Interface("gno.land/r/demo/bar", BarToken{}) | ||
}, | ||
) | ||
} | ||
|
||
func TestUnregisterGRC20Interface(t *testing.T) { | ||
dummy := testutils.TestAddress("dummy") | ||
std.TestSetOrigCaller(dummy) | ||
|
||
shouldPanic(t, | ||
func() { | ||
UnregisterGRC20Interface("gno.land/r/demo/bar") | ||
}, | ||
) | ||
|
||
shouldEQ(t, len(GetRegisteredTokens()), 7) | ||
|
||
std.TestSetOrigCaller(consts.GNOSWAP_ADMIN) | ||
UnregisterGRC20Interface("gno.land/r/demo/bar") | ||
shouldEQ(t, len(GetRegisteredTokens()), 6) | ||
|
||
// re-register to avoid panic in other tests | ||
RegisterGRC20Interface("gno.land/r/demo/bar", BarToken{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package pool | ||
|
||
import ( | ||
"std" | ||
"testing" | ||
|
||
"gno.land/r/demo/gnoswap/consts" | ||
) | ||
|
||
var ( | ||
gsa std.Address = consts.GNOSWAP_ADMIN | ||
test1 std.Address = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") | ||
|
||
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" | ||
|
||
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 | ||
|
||
fee100 uint32 = 100 | ||
fee500 uint32 = 500 | ||
fee3000 uint32 = 3000 | ||
|
||
maxApprove uint64 = 18446744073709551615 | ||
) | ||
|
||
/* HELPER */ | ||
func shouldEQ(t *testing.T, got, expected interface{}) { | ||
if got != expected { | ||
t.Errorf("got %v, expected %v", got, expected) | ||
} | ||
} | ||
|
||
func shouldNEQ(t *testing.T, got, expected interface{}) { | ||
if got == expected { | ||
t.Errorf("got %v, didn't expected %v", got, expected) | ||
} | ||
} | ||
|
||
func shouldGT(t *testing.T, l, r interface{}) { | ||
if !(l < r) { | ||
t.Errorf("expected %v < %v", l, r) | ||
} | ||
} | ||
|
||
func shouldLT(t *testing.T, l, r interface{}) { | ||
if !(l > r) { | ||
t.Errorf("expected %v > %v", l, r) | ||
} | ||
} | ||
|
||
func shouldPanic(t *testing.T, f func()) { | ||
defer func() { | ||
if r := recover(); r == nil { | ||
t.Errorf("expected panic") | ||
} | ||
}() | ||
f() | ||
} | ||
|
||
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) | ||
} |
Oops, something went wrong.