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

chore: add r/demo/tests/test20 + add grc20.TokenGetter to reduce boilerplate when using grc20reg #3397

Merged
merged 1 commit into from
Dec 28, 2024
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
8 changes: 8 additions & 0 deletions examples/gno.land/p/demo/grc/grc20/token.gno
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ func (tok *Token) RenderHome() string {
return str
}

// Getter returns a TokenGetter function that returns this token. This allows
// storing indirect pointers to a token in a remote realm.
func (tok *Token) Getter() TokenGetter {
return func() *Token {
return tok
}
}

// SpendAllowance decreases the allowance of the specified owner and spender.
func (led *PrivateLedger) SpendAllowance(owner, spender std.Address, amount uint64) error {
if !owner.IsValid() {
Expand Down
3 changes: 1 addition & 2 deletions examples/gno.land/r/demo/bar20/bar20.gno
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ var (
)

func init() {
getter := func() *grc20.Token { return Token }
grc20reg.Register(getter, "")
grc20reg.Register(Token.Getter(), "")
}

func Faucet() string {
Expand Down
3 changes: 1 addition & 2 deletions examples/gno.land/r/demo/foo20/foo20.gno
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ var (

func init() {
privateLedger.Mint(Ownable.Owner(), 1_000_000*10_000) // @privateLedgeristrator (1M)
getter := func() *grc20.Token { return Token }
grc20reg.Register(getter, "")
grc20reg.Register(Token.Getter(), "")
}

func TotalSupply() uint64 {
Expand Down
3 changes: 1 addition & 2 deletions examples/gno.land/r/demo/grc20factory/grc20factory.gno
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ func NewWithAdmin(name, symbol string, decimals uint, initialMint, faucet uint64
faucet: faucet,
}
instances.Set(symbol, &inst)
getter := func() *grc20.Token { return token }
grc20reg.Register(getter, symbol)
grc20reg.Register(token.Getter(), symbol)
}

func (inst instance) Token() *grc20.Token {
Expand Down
1 change: 1 addition & 0 deletions examples/gno.land/r/demo/tests/test20/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/demo/tests/test20
20 changes: 20 additions & 0 deletions examples/gno.land/r/demo/tests/test20/test20.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Package test20 implements a deliberately insecure ERC20 token for testing purposes.
// The Test20 token allows anyone to mint any amount of tokens to any address, making
// it unsuitable for production use. The primary goal of this package is to facilitate
// testing and experimentation without any security measures or restrictions.
//
// WARNING: This token is highly insecure and should not be used in any
// production environment. It is intended solely for testing and
// educational purposes.
package test20

import (
"gno.land/p/demo/grc/grc20"
"gno.land/r/demo/grc20reg"
)

var Token, PrivateLedger = grc20.NewToken("Test20", "TST", 4)

func init() {
grc20reg.Register(Token.Getter(), "")
}
3 changes: 1 addition & 2 deletions examples/gno.land/r/demo/wugnot/wugnot.gno
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ const (
)

func init() {
getter := func() *grc20.Token { return Token }
grc20reg.Register(getter, "")
grc20reg.Register(Token.Getter(), "")
}

func Deposit() {
Expand Down
Loading