Skip to content

Commit

Permalink
Add more unit tests for ExtractDenomFromFullPath (#6431)
Browse files Browse the repository at this point in the history
* chore: adding additional unit tests for ExtractDenomFromFullPath

* chore: adding additial tests based on PR feedback
  • Loading branch information
chatton authored May 30, 2024
1 parent 2a555af commit 45c7eea
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions modules/apps/transfer/types/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,30 @@ func TestValidateIBCDenom(t *testing.T) {
require.NoError(t, err, tc.name)
}
}

func TestExtractDenomFromFullPath(t *testing.T) {
testCases := []struct {
name string
fullPath string
expDenom types.Denom
}{
{"base denom no slashes", "atom", types.Denom{Base: "atom"}},
{"base denom with trailing slash", "atom/", types.Denom{Base: "atom/"}},
{"base denom multiple trailing slash", "foo///bar//baz/atom/", types.Denom{Base: "foo///bar//baz/atom/"}},
{"ibc denom one hop", "transfer/channel-0/atom", types.Denom{Base: "atom", Trace: []string{"transfer/channel-0"}}},
{"ibc denom one hop trailing slash", "transfer/channel-0/atom/", types.Denom{Base: "atom/", Trace: []string{"transfer/channel-0"}}},
{"ibc denom two hops", "transfer/channel-0/transfer/channel-60/atom", types.Denom{Base: "atom", Trace: []string{"transfer/channel-0", "transfer/channel-60"}}},
{"ibc denom two hops trailing slash", "transfer/channel-0/transfer/channel-60/atom/", types.Denom{Base: "atom/", Trace: []string{"transfer/channel-0", "transfer/channel-60"}}},
{"empty prefix", "/uatom", types.Denom{Base: "/uatom"}},
{"empty identifiers", "//uatom", types.Denom{Base: "//uatom"}},
{"base denom with single '/'", "erc20/0x85bcBCd7e79Ec36f4fBBDc54F90C643d921151AA", types.Denom{Base: "erc20/0x85bcBCd7e79Ec36f4fBBDc54F90C643d921151AA"}},
{"single trace identifier", "transfer/", types.Denom{Base: "transfer/"}},
}

for _, tc := range testCases {
tc := tc

denom := types.ExtractDenomFromFullPath(tc.fullPath)
require.Equal(t, tc.expDenom, denom, tc.name)
}
}

0 comments on commit 45c7eea

Please sign in to comment.