wormchain: tokenbridge: Parse chain id as an unsigned integer

A chain id cannot be negative so parse it using `strconv.ParseUint` to
avoid issues with negative values.
This commit is contained in:
Chirantan Ekbote 2022-08-22 15:52:47 +09:00 committed by Chirantan Ekbote
parent 62edb5b5b1
commit a66b3ac28c
2 changed files with 8 additions and 1 deletions

View File

@ -111,7 +111,7 @@ func GetWrappedCoinMeta(identifier string) (tokenChain uint16, tokenAddress [32]
return 0, [32]byte{}, false
}
tokenChain64, err := strconv.ParseInt(parts[1], 10, 16)
tokenChain64, err := strconv.ParseUint(parts[1], 10, 16)
if err != nil {
return 0, [32]byte{}, false
}

View File

@ -80,6 +80,13 @@ func TestGetWrappedCoinMeta(t *testing.T) {
tokenAddress: [32]byte{},
wrapped: false,
},
{
name: "negative chain id",
identifier: "wh/-0222/165809739240a0ac03b98440fe8985548e3aa683cd0d4d9df5b5659669faa300",
tokenChain: 0,
tokenAddress: [32]byte{},
wrapped: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {