Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove unnecessary functions from the gns realm #482

Merged
merged 4 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 7 additions & 22 deletions contract/r/gnoswap/gns/gns.gno
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func init() {
burnAmount = uint64(0)
}

func TotalSupply() uint64 {
return Token.TotalSupply()
}

func GetName() string {
return Token.GetName()
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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"
Expand Down
88 changes: 2 additions & 86 deletions contract/r/gnoswap/gns/gns_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading