-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove unused CoinFromRequestKey method; add tests for DenomFromReque…
…stKey; handle case where key is invalid and contains no denom
- Loading branch information
Joe Bowman
committed
Mar 10, 2023
1 parent
6707f34
commit a0fc86f
Showing
3 changed files
with
79 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package utils_test | ||
|
||
import ( | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
"github.com/stretchr/testify/require" | ||
|
||
utils "github.com/ingenuity-build/quicksilver/utils" | ||
) | ||
|
||
func TestDenomFromRequestKey(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
fn func() (sdk.AccAddress, string, []byte) | ||
err string | ||
}{ | ||
{ | ||
"valid", | ||
func() (sdk.AccAddress, string, []byte) { | ||
accAddr := utils.GenerateAccAddressForTest() | ||
prefix := banktypes.CreateAccountBalancesPrefix(accAddr.Bytes()) | ||
key := append(prefix, []byte("denom")...) | ||
return accAddr, "denom", key | ||
}, | ||
"", | ||
}, | ||
{ | ||
"invalid - address mismatch", | ||
func() (sdk.AccAddress, string, []byte) { | ||
keyAddr, err := utils.AccAddressFromBech32("cosmos135rd8ft0dyq8fv3w3hhmaa55qu3pe668j99qh67mg747ew4ad03qsgq8vh", "cosmos") | ||
require.NoError(t, err) | ||
checkAddr, err := utils.AccAddressFromBech32("cosmos1ent5eg0xn3pskf3fhdw8mky88ry7t4kx628ru3pzp4nqjp6eufusphlldy", "cosmos") | ||
require.NoError(t, err) | ||
prefix := banktypes.CreateAccountBalancesPrefix(keyAddr.Bytes()) | ||
key := append(prefix, []byte("denom")...) | ||
return checkAddr, "denom", key | ||
}, | ||
"account mismatch; expected cosmos135rd8ft0dyq8fv3w3hhmaa55qu3pe668j99qh67mg747ew4ad03qsgq8vh, got cosmos1ent5eg0xn3pskf3fhdw8mky88ry7t4kx628ru3pzp4nqjp6eufusphlldy", | ||
}, | ||
{ | ||
"invalid - empty address", | ||
func() (sdk.AccAddress, string, []byte) { | ||
accAddr := sdk.AccAddress{} | ||
prefix := banktypes.CreateAccountBalancesPrefix(accAddr.Bytes()) | ||
key := append(prefix, []byte("denom")...) | ||
return accAddr, "denom", key | ||
}, | ||
"invalid key", | ||
}, | ||
{ | ||
"invalid - empty denom", | ||
func() (sdk.AccAddress, string, []byte) { | ||
accAddr := utils.GenerateAccAddressForTest() | ||
prefix := banktypes.CreateAccountBalancesPrefix(accAddr.Bytes()) | ||
key := append(prefix, []byte("")...) | ||
return accAddr, "", key | ||
}, | ||
"key contained no denom", | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
address, expectedDenom, key := c.fn() | ||
actualDenom, error := utils.DenomFromRequestKey(key, address) | ||
if len(c.err) == 0 { | ||
require.NoError(t, error) | ||
require.Equal(t, expectedDenom, actualDenom) | ||
} else { | ||
require.Errorf(t, error, c.err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters