diff --git a/contract/r/gnoswap/gns/gns.gno b/contract/r/gnoswap/gns/gns.gno index 8dff35b46..c3069176f 100644 --- a/contract/r/gnoswap/gns/gns.gno +++ b/contract/r/gnoswap/gns/gns.gno @@ -49,6 +49,10 @@ func init() { burnAmount = uint64(0) } +func TotalSupply() uint64 { + return Token.TotalSupply() +} + func GetName() string { return Token.GetName() } @@ -61,35 +65,16 @@ func GetDecimals() uint { return Token.GetDecimals() } -func TotalSupply() uint64 { - return Token.TotalSupply() -} - func KnownAccounts() int { return Token.KnownAccounts() } -func BalanceOfAddress(owner std.Address) uint64 { - common.AssertValidAddr(owner) - return Token.BalanceOf(owner) -} - -func AllowanceOfAddress(owner, spender std.Address) uint64 { - common.AssertValidAddr(owner) - common.AssertValidAddr(spender) - return Token.Allowance(owner, spender) -} - func BalanceOf(owner std.Address) uint64 { - return UserTeller.BalanceOf(owner) + return Token.BalanceOf(owner) } func Allowance(owner, spender std.Address) uint64 { - return UserTeller.Allowance(owner, spender) -} - -func SpendAllowance(owner, spender std.Address, amount uint64) { - checkErr(privateLedger.SpendAllowance(owner, spender, amount)) + return Token.Allowance(owner, spender) } func MintGns(address std.Address) uint64 { @@ -173,7 +158,7 @@ func Render(path string) string { return Token.RenderHome() case c == 2 && parts[0] == "balance": owner := std.Address(parts[1]) - balance := UserTeller.BalanceOf(owner) + balance := Token.BalanceOf(owner) return ufmt.Sprintf("%d\n", balance) default: return "404\n" diff --git a/contract/r/gnoswap/gns/gns_test.gno b/contract/r/gnoswap/gns/gns_test.gno index 0cc34c747..7937d9591 100644 --- a/contract/r/gnoswap/gns/gns_test.gno +++ b/contract/r/gnoswap/gns/gns_test.gno @@ -39,102 +39,18 @@ func TestGetDecimals(t *testing.T) { uassert.Equal(t, uint(6), GetDecimals()) } -func TestTotalSupply(t *testing.T) { - - uassert.Equal(t, INITIAL_MINT_AMOUNT, TotalSupply()) -} - func TestKnownAccounts(t *testing.T) { uassert.Equal(t, int(1), KnownAccounts()) } -func TestBalanceOfAddress(t *testing.T) { - t.Run( - "should return balance of address", - func(t *testing.T) { - uassert.Equal(t, INITIAL_MINT_AMOUNT, BalanceOfAddress(consts.ADMIN)) - }, - ) - t.Run( - "should panic if address is not valid", - func(t *testing.T) { - uassert.PanicsWithMessage(t, "[GNOSWAP-COMMON-005] invalid address || 0xabcdefg", func() { - BalanceOfAddress("0xabcdefg") - }) - }, - ) -} - -func TestAllowanceOfAddress(t *testing.T) { - t.Run( - "should return allowance of address", - func(t *testing.T) { - uassert.Equal(t, uint64(0), AllowanceOfAddress(consts.ADMIN, alice)) - - std.TestSetOrigCaller(consts.ADMIN) - Approve(alice, uint64(123)) - uassert.Equal(t, uint64(123), AllowanceOfAddress(consts.ADMIN, alice)) - }, - ) - t.Run( - "should panic if address is not valid", - func(t *testing.T) { - uassert.PanicsWithMessage(t, "[GNOSWAP-COMMON-005] invalid address || 0xabcdefg", func() { - AllowanceOfAddress("0xabcdefg", alice) - }) - }, - ) - t.Run( - "should panic if spender is not valid", - func(t *testing.T) { - uassert.PanicsWithMessage(t, "[GNOSWAP-COMMON-005] invalid address || 0xabcdefg", func() { - AllowanceOfAddress(consts.ADMIN, "0xabcdefg") - }) - }, - ) +func TestTotalSupply(t *testing.T) { + uassert.Equal(t, INITIAL_MINT_AMOUNT, TotalSupply()) } func TestBalanceOf(t *testing.T) { uassert.Equal(t, INITIAL_MINT_AMOUNT, BalanceOf(consts.ADMIN)) } -func TestSpendAllowance(t *testing.T) { - t.Run( - "should spend allowance", - func(t *testing.T) { - std.TestSetOrigCaller(consts.ADMIN) - Approve(alice, uint64(123)) - - SpendAllowance(consts.ADMIN, alice, uint64(23)) - uassert.Equal(t, uint64(100), Allowance(consts.ADMIN, alice)) - }, - ) - t.Run( - "should panic if address is not valid", - func(t *testing.T) { - uassert.PanicsWithMessage(t, "invalid address", func() { - SpendAllowance("0xabcdefg", alice, uint64(123)) - }) - }, - ) - t.Run( - "should panic if spender is not valid", - func(t *testing.T) { - uassert.PanicsWithMessage(t, "invalid address", func() { - SpendAllowance(consts.ADMIN, "0xabcdefg", uint64(123)) - }) - }, - ) - t.Run( - "should panic if allowance is not enough", - func(t *testing.T) { - uassert.PanicsWithMessage(t, "insufficient allowance", func() { - SpendAllowance(consts.ADMIN, alice, uint64(123)) - }) - }, - ) -} - func TestAssertTooManyEmission(t *testing.T) { tests := []struct { name string