Skip to content

Commit

Permalink
Merge branch 'main' into carlos/fix-package-import
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Rodriguez authored Feb 28, 2022
2 parents 6fbc9a3 + 4545154 commit e522ad8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes

* (testing) [\#884](https://github.com/cosmos/ibc-go/pull/884) Add and use in simapp a custom ante handler that rejects redundant transactions
* (transfer) [\#978](https://github.com/cosmos/ibc-go/pull/978) Support base denoms with slashes in denom validation

## [v2.0.2](https://github.com/cosmos/ibc-go/releases/tag/v2.0.2) - 2021-12-15

Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (

coin = sdk.NewCoin("atom", sdk.NewInt(100))
ibcCoin = sdk.NewCoin("ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", sdk.NewInt(100))
invalidIBCCoin = sdk.NewCoin("notibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", sdk.NewInt(100))
invalidIBCCoin = sdk.NewCoin("ibc/7F1D3FCF4AE79E1554", sdk.NewInt(100))
invalidDenomCoin = sdk.Coin{Denom: "0atom", Amount: sdk.NewInt(100)}
zeroCoin = sdk.Coin{Denom: "atoms", Amount: sdk.NewInt(0)}

Expand Down
18 changes: 9 additions & 9 deletions modules/apps/transfer/types/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func ValidatePrefixedDenom(denom string) error {

// ValidateIBCDenom validates that the given denomination is either:
//
// - A valid base denomination (eg: 'uatom')
// - A valid base denomination (eg: 'uatom' or 'gamm/pool/1' as in https://github.com/cosmos/ibc-go/issues/894)
// - A valid fungible token representation (i.e 'ibc/{hash}') per ADR 001 https://github.com/cosmos/ibc-go/blob/main/docs/architecture/adr-001-coin-source-tracing.md
func ValidateIBCDenom(denom string) error {
if err := sdk.ValidateDenom(denom); err != nil {
Expand All @@ -172,17 +172,17 @@ func ValidateIBCDenom(denom string) error {
denomSplit := strings.SplitN(denom, "/", 2)

switch {
case strings.TrimSpace(denom) == "",
len(denomSplit) == 1 && denomSplit[0] == DenomPrefix,
len(denomSplit) == 2 && (denomSplit[0] != DenomPrefix || strings.TrimSpace(denomSplit[1]) == ""):
case denom == DenomPrefix:
return sdkerrors.Wrapf(ErrInvalidDenomForTransfer, "denomination should be prefixed with the format 'ibc/{hash(trace + \"/\" + %s)}'", denom)

case denomSplit[0] == denom && strings.TrimSpace(denom) != "":
return nil
}
case len(denomSplit) == 2 && denomSplit[0] == DenomPrefix:
if strings.TrimSpace(denomSplit[1]) == "" {
return sdkerrors.Wrapf(ErrInvalidDenomForTransfer, "denomination should be prefixed with the format 'ibc/{hash(trace + \"/\" + %s)}'", denom)
}

if _, err := ParseHexHash(denomSplit[1]); err != nil {
return sdkerrors.Wrapf(err, "invalid denom trace hash %s", denomSplit[1])
if _, err := ParseHexHash(denomSplit[1]); err != nil {
return sdkerrors.Wrapf(err, "invalid denom trace hash %s", denomSplit[1])
}
}

return nil
Expand Down
5 changes: 3 additions & 2 deletions modules/apps/transfer/types/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,12 @@ func TestValidateIBCDenom(t *testing.T) {
}{
{"denom with trace hash", "ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", false},
{"base denom", "uatom", false},
{"base denom with single '/'s", "gamm/pool/1", false},
{"base denom with double '/'s", "gamm//pool//1", false},
{"non-ibc prefix with hash", "notibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", false},
{"empty denom", "", true},
{"invalid prefixed denom", "transfer/channelToA/uatom", true},
{"denom 'ibc'", "ibc", true},
{"denom 'ibc/'", "ibc/", true},
{"invald prefix", "notibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", true},
{"invald hash", "ibc/!@#$!@#", true},
}

Expand Down

0 comments on commit e522ad8

Please sign in to comment.