Skip to content

Commit 80ccca4

Browse files
authored
refactor: remove unnecessary functions from the gns realm (#482)
1 parent 08777bc commit 80ccca4

File tree

2 files changed

+9
-108
lines changed

2 files changed

+9
-108
lines changed

contract/r/gnoswap/gns/gns.gno

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ func init() {
4949
burnAmount = uint64(0)
5050
}
5151

52+
func TotalSupply() uint64 {
53+
return Token.TotalSupply()
54+
}
55+
5256
func GetName() string {
5357
return Token.GetName()
5458
}
@@ -61,35 +65,16 @@ func GetDecimals() uint {
6165
return Token.GetDecimals()
6266
}
6367

64-
func TotalSupply() uint64 {
65-
return Token.TotalSupply()
66-
}
67-
6868
func KnownAccounts() int {
6969
return Token.KnownAccounts()
7070
}
7171

72-
func BalanceOfAddress(owner std.Address) uint64 {
73-
common.AssertValidAddr(owner)
74-
return Token.BalanceOf(owner)
75-
}
76-
77-
func AllowanceOfAddress(owner, spender std.Address) uint64 {
78-
common.AssertValidAddr(owner)
79-
common.AssertValidAddr(spender)
80-
return Token.Allowance(owner, spender)
81-
}
82-
8372
func BalanceOf(owner std.Address) uint64 {
84-
return UserTeller.BalanceOf(owner)
73+
return Token.BalanceOf(owner)
8574
}
8675

8776
func Allowance(owner, spender std.Address) uint64 {
88-
return UserTeller.Allowance(owner, spender)
89-
}
90-
91-
func SpendAllowance(owner, spender std.Address, amount uint64) {
92-
checkErr(privateLedger.SpendAllowance(owner, spender, amount))
77+
return Token.Allowance(owner, spender)
9378
}
9479

9580
func MintGns(address std.Address) uint64 {
@@ -173,7 +158,7 @@ func Render(path string) string {
173158
return Token.RenderHome()
174159
case c == 2 && parts[0] == "balance":
175160
owner := std.Address(parts[1])
176-
balance := UserTeller.BalanceOf(owner)
161+
balance := Token.BalanceOf(owner)
177162
return ufmt.Sprintf("%d\n", balance)
178163
default:
179164
return "404\n"

contract/r/gnoswap/gns/gns_test.gno

Lines changed: 2 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -39,102 +39,18 @@ func TestGetDecimals(t *testing.T) {
3939
uassert.Equal(t, uint(6), GetDecimals())
4040
}
4141

42-
func TestTotalSupply(t *testing.T) {
43-
44-
uassert.Equal(t, INITIAL_MINT_AMOUNT, TotalSupply())
45-
}
46-
4742
func TestKnownAccounts(t *testing.T) {
4843
uassert.Equal(t, int(1), KnownAccounts())
4944
}
5045

51-
func TestBalanceOfAddress(t *testing.T) {
52-
t.Run(
53-
"should return balance of address",
54-
func(t *testing.T) {
55-
uassert.Equal(t, INITIAL_MINT_AMOUNT, BalanceOfAddress(consts.ADMIN))
56-
},
57-
)
58-
t.Run(
59-
"should panic if address is not valid",
60-
func(t *testing.T) {
61-
uassert.PanicsWithMessage(t, "[GNOSWAP-COMMON-005] invalid address || 0xabcdefg", func() {
62-
BalanceOfAddress("0xabcdefg")
63-
})
64-
},
65-
)
66-
}
67-
68-
func TestAllowanceOfAddress(t *testing.T) {
69-
t.Run(
70-
"should return allowance of address",
71-
func(t *testing.T) {
72-
uassert.Equal(t, uint64(0), AllowanceOfAddress(consts.ADMIN, alice))
73-
74-
std.TestSetOrigCaller(consts.ADMIN)
75-
Approve(alice, uint64(123))
76-
uassert.Equal(t, uint64(123), AllowanceOfAddress(consts.ADMIN, alice))
77-
},
78-
)
79-
t.Run(
80-
"should panic if address is not valid",
81-
func(t *testing.T) {
82-
uassert.PanicsWithMessage(t, "[GNOSWAP-COMMON-005] invalid address || 0xabcdefg", func() {
83-
AllowanceOfAddress("0xabcdefg", alice)
84-
})
85-
},
86-
)
87-
t.Run(
88-
"should panic if spender is not valid",
89-
func(t *testing.T) {
90-
uassert.PanicsWithMessage(t, "[GNOSWAP-COMMON-005] invalid address || 0xabcdefg", func() {
91-
AllowanceOfAddress(consts.ADMIN, "0xabcdefg")
92-
})
93-
},
94-
)
46+
func TestTotalSupply(t *testing.T) {
47+
uassert.Equal(t, INITIAL_MINT_AMOUNT, TotalSupply())
9548
}
9649

9750
func TestBalanceOf(t *testing.T) {
9851
uassert.Equal(t, INITIAL_MINT_AMOUNT, BalanceOf(consts.ADMIN))
9952
}
10053

101-
func TestSpendAllowance(t *testing.T) {
102-
t.Run(
103-
"should spend allowance",
104-
func(t *testing.T) {
105-
std.TestSetOrigCaller(consts.ADMIN)
106-
Approve(alice, uint64(123))
107-
108-
SpendAllowance(consts.ADMIN, alice, uint64(23))
109-
uassert.Equal(t, uint64(100), Allowance(consts.ADMIN, alice))
110-
},
111-
)
112-
t.Run(
113-
"should panic if address is not valid",
114-
func(t *testing.T) {
115-
uassert.PanicsWithMessage(t, "invalid address", func() {
116-
SpendAllowance("0xabcdefg", alice, uint64(123))
117-
})
118-
},
119-
)
120-
t.Run(
121-
"should panic if spender is not valid",
122-
func(t *testing.T) {
123-
uassert.PanicsWithMessage(t, "invalid address", func() {
124-
SpendAllowance(consts.ADMIN, "0xabcdefg", uint64(123))
125-
})
126-
},
127-
)
128-
t.Run(
129-
"should panic if allowance is not enough",
130-
func(t *testing.T) {
131-
uassert.PanicsWithMessage(t, "insufficient allowance", func() {
132-
SpendAllowance(consts.ADMIN, alice, uint64(123))
133-
})
134-
},
135-
)
136-
}
137-
13854
func TestAssertTooManyEmission(t *testing.T) {
13955
tests := []struct {
14056
name string

0 commit comments

Comments
 (0)