Skip to content

Commit

Permalink
add unit test for invalid chain
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Aug 30, 2024
1 parent 564d747 commit b0c2455
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
6 changes: 6 additions & 0 deletions pkg/address/validate_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import (
"github.com/zeta-chain/zetacore/pkg/chains"
)

// ValidateAddressForChain validates the address for the chain
// NOTE: since these checks are currently not used, we don't provide additional chains for simplicity
// https://github.com/zeta-chain/node/issues/2234
// https://github.com/zeta-chain/node/issues/2385
// NOTE: We should eventually not using these hard-coded checks at all for same reasons as above

// TODO : Use this function to validate Sender and Receiver address for CCTX
// https://github.com/zeta-chain/node/issues/2697
func ValidateAddressForChain(address string, chainID int64, additionalChains []chains.Chain) error {
Expand Down
4 changes: 3 additions & 1 deletion pkg/address/validate_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func TestValidateAddressForChain(t *testing.T) {
allChains := appendChains(evmChains, zetaChains, baseChains, solanaChains, opChains, bitcoinChains)
require.ElementsMatch(t, allChains, chains.DefaultChainsList())

//test for invalid chain
require.ErrorContains(t, address.ValidateAddressForChain("0x123", 123, additionalChains), "chain id 123 not supported")

// test for evm chain chains
for _, chain := range evmChains {
require.Error(t, address.ValidateAddressForChain("0x123", chain.ChainId, additionalChains))
Expand Down Expand Up @@ -113,7 +116,6 @@ func TestValidateAddressForChain(t *testing.T) {
}

// test for btc chain

require.NoError(
t,
address.ValidateAddressForChain(
Expand Down
7 changes: 0 additions & 7 deletions x/crosschain/types/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,3 @@ func ValidateHashForChain(hash string, chainID int64) error {
}
return fmt.Errorf("invalid chain id %d", chainID)
}

// ValidateAddressForChain validates the address for the chain
// NOTE: since these checks are currently not used, we don't provide additional chains for simplicity
// TODO: use authorityKeeper.GetChainInfo to provide additional chains
// https://github.com/zeta-chain/node/issues/2234
// https://github.com/zeta-chain/node/issues/2385
// NOTE: We should eventually not using these hard-coded checks at all for same reasons as above

0 comments on commit b0c2455

Please sign in to comment.