diff --git a/pool/_helper_test.gno b/pool/_helper_test.gno index ce061a777..5fc7ed5b9 100644 --- a/pool/_helper_test.gno +++ b/pool/_helper_test.gno @@ -45,123 +45,6 @@ const ( addr02 = testutils.TestAddress("addr02") ) -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 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 -} - -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 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 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 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 -} - -func init() { - std.TestSetRealm(std.NewUserRealm(consts.TOKEN_REGISTER)) - - RegisterGRC20Interface(wugnotPath, WugnotToken{}) - RegisterGRC20Interface(gnsPath, GNSToken{}) - RegisterGRC20Interface(barPath, BarToken{}) - RegisterGRC20Interface(bazPath, BazToken{}) - RegisterGRC20Interface(fooPath, FooToken{}) - RegisterGRC20Interface(oblPath, OBLToken{}) - RegisterGRC20Interface(quxPath, QuxToken{}) -} - var ( admin = pusers.AddressOrName(consts.ADMIN) alice = pusers.AddressOrName(testutils.TestAddress("alice")) diff --git a/pool/pool_manager_test.gno b/pool/pool_manager_test.gno index da1eed7c1..0a9776dcf 100644 --- a/pool/pool_manager_test.gno +++ b/pool/pool_manager_test.gno @@ -74,13 +74,13 @@ func TestNewPoolParams(t *testing.T) { } func TestGetPoolPath(t *testing.T) { - path := GetPoolPath("tokenA", "tokenB", 500) - expected := "tokenA:tokenB:500" + path := GetPoolPath("gno.land/r/onbloc/bar", "gno.land/r/onbloc/foo", 500) + expected := "gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:500" if path != expected { t.Errorf("Expected path %s, got %s", expected, path) } - path = GetPoolPath("tokenB", "tokenA", 500) + path = GetPoolPath("gno.land/r/onbloc/foo", "gno.land/r/onbloc/bar", 500) if path != expected { t.Errorf("Expected tokens to be sorted, expected %s, got %s", expected, path) } @@ -118,37 +118,37 @@ func TestCreatePool(t *testing.T) { }{ { name: "success - normal token pair", - token0Path: "test/token0", - token1Path: "test/token1", + token0Path: "gno.land/r/onbloc/bar", + token1Path: "gno.land/r/onbloc/foo", fee: 3000, sqrtPrice: "4295128740", }, { name: "fail - same tokens", - token0Path: "test/token0", - token1Path: "test/token0", + token0Path: "gno.land/r/onbloc/bar", + token1Path: "gno.land/r/onbloc/bar", fee: 3000, sqrtPrice: "4295128740", shouldPanic: true, - panicMsg: "[GNOSWAP-POOL-011] same token used in single pool || pool_manager.gno__CreatePool() || expected token0Path(test/token0) != token1Path(test/token0", + panicMsg: "[GNOSWAP-POOL-011] same token used in single pool || pool_manager.gno__CreatePool() || expected token0Path(gno.land/r/onbloc/bar) != token1Path(gno.land/r/onbloc/bar", }, { name: "fail - tokens not in order", - token0Path: "test/tokenB", - token1Path: "test/tokenA", + token0Path: "gno.land/r/onbloc/foo", + token1Path: "gno.land/r/onbloc/bar", fee: 3000, sqrtPrice: "4295128740", shouldPanic: true, - panicMsg: "[GNOSWAP-POOL-012] tokens must be in lexicographical order || pool_manager.gno__CreatePool() || expected token0Path(test/tokenB) < token1Path(test/tokenA)", + panicMsg: "[GNOSWAP-POOL-012] tokens must be in lexicographical order || pool_manager.gno__CreatePool() || expected token0Path(gno.land/r/onbloc/foo) < token1Path(gno.land/r/onbloc/bar)", }, { name: "fail - pool already exists", - token0Path: "test/token0", - token1Path: "test/token1", + token0Path: "gno.land/r/onbloc/bar", + token1Path: "gno.land/r/onbloc/foo", fee: 3000, sqrtPrice: "4295128740", shouldPanic: true, - panicMsg: "[GNOSWAP-POOL-013] pool already created || pool_manager.gno__CreatePool() || expected poolPath(test/token0:test/token1:3000) not to exist", + panicMsg: "[GNOSWAP-POOL-013] pool already created || pool_manager.gno__CreatePool() || expected poolPath(gno.land/r/onbloc/bar:gno.land/r/onbloc/foo:3000) not to exist", }, } @@ -199,4 +199,6 @@ func TestCreatePool(t *testing.T) { } }) } + + resetObject(t) } diff --git a/pool/protocol_fee_withdrawal_test.gno b/pool/protocol_fee_withdrawal_test.gno index 6cbec74e9..241459d91 100644 --- a/pool/protocol_fee_withdrawal_test.gno +++ b/pool/protocol_fee_withdrawal_test.gno @@ -1,16 +1,17 @@ package pool import ( + "std" + "strconv" + "strings" + "testing" + "gno.land/p/demo/testutils" "gno.land/p/demo/uassert" pusers "gno.land/p/demo/users" "gno.land/r/demo/users" "gno.land/r/gnoswap/v1/consts" pn "gno.land/r/gnoswap/v1/position" - "std" - "strconv" - "strings" - "testing" ) func TestHandleWithdrawalFee(t *testing.T) { @@ -32,7 +33,7 @@ func TestHandleWithdrawalFee(t *testing.T) { name: "Panic if caller is not position contract", action: func(t *testing.T) { std.TestSetOrigCaller(users.Resolve(admin)) - HandleWithdrawalFee(0, "", "0", "", "0", "", users.Resolve(admin)) + HandleWithdrawalFee(0, "gno.land/r/onbloc/foo", "0", "gno.land/r/onbloc/foo", "0", "", users.Resolve(admin)) }, verify: nil, expected: "[GNOSWAP-POOL-001] caller has no permission || withdrawal_fee.gno__HandleWithdrawalFee() || only position(g1q646ctzhvn60v492x8ucvyqnrj2w30cwh6efk5) can call this function, called from g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d", @@ -45,7 +46,7 @@ func TestHandleWithdrawalFee(t *testing.T) { HandleWithdrawalFee(0, "pkgPath", "1000", "pkgPath", "1000", "poolPath", users.Resolve(admin)) }, verify: nil, - expected: "[GNOSWAP-POOL-002] not registered token || token_register.gno__transferFromByRegisterCall() || token(pkgPath) not registered", + expected: "[GNOSWAP-COMMON-004] token is not registered || token(pkgPath) is not registered", shouldPanic: true, }, { @@ -63,7 +64,7 @@ func TestHandleWithdrawalFee(t *testing.T) { HandleWithdrawalFee(1, wugnotPath, "1000", gnsPath, "1000", poolPath, users.Resolve(alice)) }, verify: nil, - expected: "insufficient allowance", + expected: "[GNOSWAP-POOL-021] token transfer failed || insufficient allowance", shouldPanic: true, }, {