Skip to content

Commit

Permalink
fix: std.Address validation
Browse files Browse the repository at this point in the history
  • Loading branch information
r3v4s committed Mar 20, 2024
1 parent 5c5d9ef commit db58dad
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
12 changes: 12 additions & 0 deletions gno.land/cmd/gnoland/testdata/pr-1799.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Test for https://github.com/gnolang/gno/pull/xxxx
loadpkg gno.land/r/demo/foo20

gnoland start

# execute Faucet
gnokey maketx call -pkgpath gno.land/r/demo/foo20 -func Faucet -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1
stdout 'OK!'

# execute Transfer for invalid address
! gnokey maketx call -pkgpath gno.land/r/demo/foo20 -func Transfer -args g1ubwj0apf60hd90txhnh855fkac34rxlsvua0aa -args 1 -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1
stderr '"gnokey" error: --= Error =--\nData: invalid address'
5 changes: 3 additions & 2 deletions gnovm/stdlibs/std/crypto.gno
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ func (a Address) String() string {
return string(a)
}

// IsValid checks if the address is of specific length. Doesn't check prefix or checksum for the address
// IsValid checks if the address is valid bech32 encoded string
func (a Address) IsValid() bool {
return len(a) == RawAddressSize*2 // hex length
_, _, ok := decodeBech32(a.String())
return ok
}

const RawAddressSize = 20
Expand Down
5 changes: 3 additions & 2 deletions gnovm/stdlibs/stdshim/crypto.gno
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ func (a Address) String() string {
return string(a)
}

// IsValid checks if the address is of specific length. Doesn't check prefix or checksum for the address
// IsValid checks if the address is valid bech32 encoded string
func (a Address) IsValid() bool {
return len(a) == RawAddressSize*2 // hex length
_, _, ok := decodeBech32(a.String())
return ok
}

const RawAddressSize = 20
Expand Down

0 comments on commit db58dad

Please sign in to comment.