From d68263f2d709cea2040c2a45676ea5342afb1ae5 Mon Sep 17 00:00:00 2001 From: lumtis Date: Fri, 30 Aug 2024 14:33:04 +0200 Subject: [PATCH 1/2] refactor is EVM chain --- pkg/chains/chain.go | 10 +++++++--- pkg/chains/chain_test.go | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/chains/chain.go b/pkg/chains/chain.go index 221da26a32..bfd7398625 100644 --- a/pkg/chains/chain.go +++ b/pkg/chains/chain.go @@ -86,7 +86,7 @@ func (chain Chain) EncodeAddress(b []byte) (string, error) { } func (chain Chain) IsEVMChain() bool { - return chain.Consensus == Consensus_ethereum + return chain.Vm == Vm_evm } func (chain Chain) IsBitcoinChain() bool { @@ -109,11 +109,15 @@ func DecodeAddressFromChainID(chainID int64, addr string, additionalChains []Cha } } -// IsEVMChain returns true if the chain is an EVM chain or uses the ethereum consensus mechanism for block finality +// IsEVMChain returns true if the chain is an EVM chain // additionalChains is a list of additional chains to search from // in practice, it is used in the protocol to dynamically support new chains without doing an upgrade func IsEVMChain(chainID int64, additionalChains []Chain) bool { - return ChainIDInChainList(chainID, ChainListByConsensus(Consensus_ethereum, additionalChains)) + chain, found := GetChainFromChainID(chainID, additionalChains) + if !found { + return false + } + return chain.IsEVMChain() } // IsBitcoinChain returns true if the chain is a Bitcoin-based chain or uses the bitcoin consensus mechanism for block finality diff --git a/pkg/chains/chain_test.go b/pkg/chains/chain_test.go index d097d3946c..af53ac1be2 100644 --- a/pkg/chains/chain_test.go +++ b/pkg/chains/chain_test.go @@ -222,7 +222,7 @@ func TestChain_IsEVMChain(t *testing.T) { {"Goerli Testnet", chains.Goerli, true}, {"Sepolia Testnet", chains.Sepolia, true}, {"Non-EVM", chains.BitcoinMainnet, false}, - {"Zeta Mainnet", chains.ZetaChainMainnet, false}, + {"Zeta Mainnet", chains.ZetaChainMainnet, true}, } for _, tt := range tests { @@ -331,7 +331,7 @@ func TestIsEVMChain(t *testing.T) { {"Goerli Testnet", chains.Goerli.ChainId, true}, {"Sepolia Testnet", chains.Sepolia.ChainId, true}, {"Non-EVM", chains.BitcoinMainnet.ChainId, false}, - {"Zeta Mainnet", chains.ZetaChainMainnet.ChainId, false}, + {"Zeta Mainnet", chains.ZetaChainMainnet.ChainId, true}, } for _, tt := range tests { From d857bc75c383f864a82602c22657641a0409c804 Mon Sep 17 00:00:00 2001 From: lumtis Date: Fri, 30 Aug 2024 14:33:14 +0200 Subject: [PATCH 2/2] fix unit test --- x/crosschain/keeper/refund_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/crosschain/keeper/refund_test.go b/x/crosschain/keeper/refund_test.go index 1b1a22e100..415716bb54 100644 --- a/x/crosschain/keeper/refund_test.go +++ b/x/crosschain/keeper/refund_test.go @@ -216,11 +216,12 @@ func TestKeeper_RefundAmountOnZetaChainZeta(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) sender := sample.EthAddress() + chainID := getValidBtcChainID() err := k.RefundAmountOnZetaChainZeta(ctx, types.CrossChainTx{ InboundParams: &types.InboundParams{ CoinType: coin.CoinType_Gas, - SenderChainId: 101, + SenderChainId: chainID, Sender: sender.String(), TxOrigin: sender.String(), Amount: math.NewUint(20),