diff --git a/testutil/sample/fungible.go b/testutil/sample/fungible.go index 73fdc2b2e3..3be91d06a3 100644 --- a/testutil/sample/fungible.go +++ b/testutil/sample/fungible.go @@ -3,6 +3,7 @@ package sample import ( "testing" + "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/coin" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -22,6 +23,35 @@ func ForeignCoins(t *testing.T, address string) types.ForeignCoins { } } +func ForeignCoinList(t *testing.T, zrc20ETH, zrc20BTC, zrc20ERC20, erc20Asset string) []types.ForeignCoins { + // eth and btc chain id + ethChainID := chains.GoerliLocalnetChain().ChainId + btcChainID := chains.BtcRegtestChain().ChainId + + // add zrc20 ETH + fcGas := ForeignCoins(t, zrc20ETH) + fcGas.Asset = "" + fcGas.ForeignChainId = ethChainID + fcGas.Decimals = 18 + fcGas.CoinType = coin.CoinType_Gas + + // add zrc20 BTC + fcBTC := ForeignCoins(t, zrc20BTC) + fcBTC.Asset = "" + fcBTC.ForeignChainId = btcChainID + fcBTC.Decimals = 8 + fcBTC.CoinType = coin.CoinType_Gas + + // add zrc20 ERC20 + fcERC20 := ForeignCoins(t, zrc20ERC20) + fcERC20.Asset = erc20Asset + fcERC20.ForeignChainId = ethChainID + fcERC20.Decimals = 6 + fcERC20.CoinType = coin.CoinType_ERC20 + + return []types.ForeignCoins{fcGas, fcBTC, fcERC20} +} + func SystemContract() *types.SystemContract { return &types.SystemContract{ SystemContract: EthAddress().String(), diff --git a/x/crosschain/keeper/cctx_utils_test.go b/x/crosschain/keeper/cctx_utils_test.go index e0dedbb41d..af6445744c 100644 --- a/x/crosschain/keeper/cctx_utils_test.go +++ b/x/crosschain/keeper/cctx_utils_test.go @@ -42,7 +42,7 @@ func TestGetRevertGasLimit(t *testing.T) { k, ctx, sdkk, zk := keepertest.CrosschainKeeper(t) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) gas := setupGasCoin(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper, chainID, "foo", "FOO") @@ -63,7 +63,7 @@ func TestGetRevertGasLimit(t *testing.T) { k, ctx, sdkk, zk := keepertest.CrosschainKeeper(t) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) asset := sample.EthAddress().String() zrc20Addr := deployZRC20( @@ -107,7 +107,7 @@ func TestGetRevertGasLimit(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() zk.FungibleKeeper.SetForeignCoins(ctx, fungibletypes.ForeignCoins{ Zrc20ContractAddress: sample.EthAddress().String(), @@ -141,7 +141,7 @@ func TestGetRevertGasLimit(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() asset := sample.EthAddress().String() zk.FungibleKeeper.SetForeignCoins(ctx, fungibletypes.ForeignCoins{ diff --git a/x/crosschain/keeper/evm_deposit_test.go b/x/crosschain/keeper/evm_deposit_test.go index 1f6cd4fad4..d30424697c 100644 --- a/x/crosschain/keeper/evm_deposit_test.go +++ b/x/crosschain/keeper/evm_deposit_test.go @@ -84,7 +84,7 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { UseFungibleMock: true, }) - senderChain := getValidEthChainID(t) + senderChain := getValidEthChainID() fungibleMock := keepertest.GetCrosschainFungibleMock(t, k) receiver := sample.EthAddress() @@ -127,7 +127,7 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { UseFungibleMock: true, }) - senderChain := getValidEthChainID(t) + senderChain := getValidEthChainID() fungibleMock := keepertest.GetCrosschainFungibleMock(t, k) receiver := sample.EthAddress() @@ -186,7 +186,7 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { UseFungibleMock: true, }) - senderChain := getValidEthChainID(t) + senderChain := getValidEthChainID() fungibleMock := keepertest.GetCrosschainFungibleMock(t, k) receiver := sample.EthAddress() @@ -273,7 +273,7 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { UseFungibleMock: true, }) - senderChain := getValidEthChainID(t) + senderChain := getValidEthChainID() fungibleMock := keepertest.GetCrosschainFungibleMock(t, k) receiver := sample.EthAddress() @@ -317,7 +317,7 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { UseFungibleMock: true, }) - senderChain := getValidEthChainID(t) + senderChain := getValidEthChainID() fungibleMock := keepertest.GetCrosschainFungibleMock(t, k) receiver := sample.EthAddress() @@ -361,7 +361,7 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { UseFungibleMock: true, }) - senderChain := getValidEthChainID(t) + senderChain := getValidEthChainID() fungibleMock := keepertest.GetCrosschainFungibleMock(t, k) receiver := sample.EthAddress() @@ -404,7 +404,7 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { UseFungibleMock: true, }) - senderChain := getValidEthChainID(t) + senderChain := getValidEthChainID() fungibleMock := keepertest.GetCrosschainFungibleMock(t, k) receiver := sample.EthAddress() @@ -447,7 +447,7 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { UseFungibleMock: true, }) - senderChain := getValidEthChainID(t) + senderChain := getValidEthChainID() fungibleMock := keepertest.GetCrosschainFungibleMock(t, k) receiver := sample.EthAddress() @@ -487,7 +487,7 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseFungibleMock: true, }) - senderChain := getValidEthChainID(t) + senderChain := getValidEthChainID() cctx := sample.CrossChainTx(t, "foo") cctx.GetCurrentOutTxParam().Receiver = sample.EthAddress().String() @@ -509,7 +509,7 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { UseFungibleMock: true, }) - senderChain := getValidEthChainID(t) + senderChain := getValidEthChainID() fungibleMock := keepertest.GetCrosschainFungibleMock(t, k) receiver := sample.EthAddress() @@ -555,7 +555,7 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { UseFungibleMock: true, }) - senderChain := getValidEthChainID(t) + senderChain := getValidEthChainID() fungibleMock := keepertest.GetCrosschainFungibleMock(t, k) receiver := sample.EthAddress() diff --git a/x/crosschain/keeper/gas_payment_test.go b/x/crosschain/keeper/gas_payment_test.go index 569a360327..8079c3c67a 100644 --- a/x/crosschain/keeper/gas_payment_test.go +++ b/x/crosschain/keeper/gas_payment_test.go @@ -30,7 +30,7 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) // deploy gas coin and set fee params - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() setSupportedChain(ctx, zk, chainID) deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) @@ -72,7 +72,7 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) { t.Run("should fail if not coin type gas", func(t *testing.T) { k, ctx, _, _ := testkeeper.CrosschainKeeper(t) - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() cctx := types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ CoinType: coin.CoinType_Zeta, @@ -98,7 +98,7 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) // deploy gas coin and set fee params - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() setSupportedChain(ctx, zk, chainID) deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) setupGasCoin(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper, chainID, "foobar", "foobar") @@ -127,7 +127,7 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) // deploy gas coin and set fee params - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() setSupportedChain(ctx, zk, chainID) deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) zrc20 := setupGasCoin(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper, chainID, "foobar", "foobar") @@ -170,7 +170,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) // deploy gas coin, erc20 and set fee params - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() setSupportedChain(ctx, zk, chainID) assetAddress := sample.EthAddress().String() deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) @@ -236,7 +236,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { t.Run("should fail if not coin type erc20", func(t *testing.T) { k, ctx, _, _ := testkeeper.CrosschainKeeper(t) - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() cctx := types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ CoinType: coin.CoinType_Gas, @@ -262,7 +262,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) // deploy gas coin and set fee params - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() setSupportedChain(ctx, zk, chainID) deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) setupGasCoin(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper, chainID, "foobar", "foobar") @@ -291,7 +291,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) // deploy gas coin, erc20 and set fee params - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() setSupportedChain(ctx, zk, chainID) assetAddress := sample.EthAddress().String() deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) @@ -333,7 +333,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) // deploy gas coin, erc20 and set fee params - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() setSupportedChain(ctx, zk, chainID) assetAddress := sample.EthAddress().String() deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) @@ -385,7 +385,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) // deploy gas coin, erc20 and set fee params - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() setSupportedChain(ctx, zk, chainID) assetAddress := sample.EthAddress().String() deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) @@ -453,7 +453,7 @@ func TestKeeper_PayGasInZetaAndUpdateCctx(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) // deploy gas coin and set fee params - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() setSupportedChain(ctx, zk, chainID) deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) zrc20 := setupGasCoin(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper, chainID, "foobar", "foobar") @@ -514,7 +514,7 @@ func TestKeeper_PayGasInZetaAndUpdateCctx(t *testing.T) { t.Run("should fail if pay gas in zeta with coin type other than zeta", func(t *testing.T) { k, ctx, _, _ := testkeeper.CrosschainKeeper(t) - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() cctx := types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ CoinType: coin.CoinType_Gas, @@ -540,7 +540,7 @@ func TestKeeper_PayGasInZetaAndUpdateCctx(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) // deploy gas coin and set fee params - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() setSupportedChain(ctx, zk, chainID) deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) setupGasCoin(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper, chainID, "foobar", "foobar") @@ -571,7 +571,7 @@ func TestKeeper_PayGasInZetaAndUpdateCctx(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) // deploy gas coin and set fee params - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() setSupportedChain(ctx, zk, chainID) deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) zrc20 := setupGasCoin(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper, chainID, "foobar", "foobar") diff --git a/x/crosschain/keeper/grpc_query_cctx_rate_limit_test.go b/x/crosschain/keeper/grpc_query_cctx_rate_limit_test.go index 5c2eee4066..31939862b5 100644 --- a/x/crosschain/keeper/grpc_query_cctx_rate_limit_test.go +++ b/x/crosschain/keeper/grpc_query_cctx_rate_limit_test.go @@ -1,16 +1,182 @@ package keeper_test import ( + "fmt" + "sort" "testing" + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + "github.com/zeta-chain/zetacore/pkg/coin" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + "github.com/zeta-chain/zetacore/testutil/sample" + "github.com/zeta-chain/zetacore/x/crosschain/keeper" + "github.com/zeta-chain/zetacore/x/crosschain/types" + observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) -func TestKeeper_CctxListPendingWithRateLimit(t *testing.T) { +// createTestRateLimiterFlags creates a custom rate limiter flags +func createTestRateLimiterFlags( + zrc20ETH string, + zrc20BTC string, + zrc20USDT string, + ethRate string, + btcRate string, + usdtRate string, +) types.RateLimiterFlags { + var rateLimiterFlags = types.RateLimiterFlags{ + Enabled: true, + Window: 100, // 100 zeta blocks, 10 minutes + Rate: math.NewUint(1000), // 1000 ZETA + Conversions: []types.Conversion{ + // ETH + { + Zrc20: zrc20ETH, + Rate: sdk.MustNewDecFromStr(ethRate), + }, + // BTC + { + Zrc20: zrc20BTC, + Rate: sdk.MustNewDecFromStr(btcRate), + }, + // USDT + { + Zrc20: zrc20USDT, + Rate: sdk.MustNewDecFromStr(usdtRate), + }, + }, + } + return rateLimiterFlags +} + +// createCctxWithCopyTypeAndBlockRange +// - create 1 cctx per block from lowBlock to highBlock (inclusive) +// +// return created cctxs +func createCctxWithCopyTypeAndHeightRange( + t *testing.T, + ctx sdk.Context, + k keeper.Keeper, + zk keepertest.ZetaKeepers, + tss observertypes.TSS, + lowBlock uint64, + highBlock uint64, + chainID int64, + coinType coin.CoinType, + asset string, + amount uint64, + status types.CctxStatus, +) (cctxs []*types.CrossChainTx) { + // create 1 pending cctxs per block + for i := lowBlock; i <= highBlock; i++ { + nonce := i - 1 + cctx := sample.CrossChainTx(t, fmt.Sprintf("%d-%d", chainID, nonce)) + cctx.CctxStatus.Status = status + cctx.InboundTxParams.SenderChainId = chainID + cctx.InboundTxParams.CoinType = coinType + cctx.InboundTxParams.Asset = asset + cctx.InboundTxParams.InboundTxObservedExternalHeight = i + cctx.GetCurrentOutTxParam().Amount = sdk.NewUint(amount) + cctx.GetCurrentOutTxParam().OutboundTxTssNonce = nonce + k.SetCrossChainTx(ctx, *cctx) + zk.ObserverKeeper.SetNonceToCctx(ctx, observertypes.NonceToCctx{ + ChainId: chainID, + // #nosec G701 always in range for tests + Nonce: int64(nonce), + CctxIndex: cctx.Index, + Tss: tss.TssPubkey, + }) + cctxs = append(cctxs, cctx) + } + return cctxs +} + +// setPendingNonces sets the pending nonces for the given chainID +func setPendingNonces( + ctx sdk.Context, + zk keepertest.ZetaKeepers, + chainID int64, + nonceLow int64, + nonceHigh int64, + tssPubKey string, +) { + zk.ObserverKeeper.SetPendingNonces(ctx, observertypes.PendingNonces{ + ChainId: chainID, + NonceLow: nonceLow, + NonceHigh: nonceHigh, + Tss: tssPubKey, + }) +} + +// setupForeignCoins adds ETH, BTC, USDT to the foreign coins store +func setupForeignCoins( + t *testing.T, + ctx sdk.Context, + zk keepertest.ZetaKeepers, + zrc20ETH, zrc20BTC, zrc20USDT, assetUSDT string, +) { + // set foreign coins + fCoins := sample.ForeignCoinList(t, zrc20ETH, zrc20BTC, zrc20USDT, assetUSDT) + for _, fc := range fCoins { + zk.FungibleKeeper.SetForeignCoins(ctx, fc) + } +} + +func TestKeeper_ListPendingCctxWithinRateLimit(t *testing.T) { + // chain IDs + ethChainID := getValidEthChainID() + + // define cctx status + statusPending := types.CctxStatus_PendingOutbound + statusMined := types.CctxStatus_OutboundMined + t.Run("should fail for empty req", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) _, err := k.ListPendingCctxWithinRateLimit(ctx, nil) require.ErrorContains(t, err, "invalid request") }) + t.Run("should use fallback query", func(t *testing.T) { + k, ctx, _, zk := keepertest.CrosschainKeeper(t) + + // Set TSS + tss := sample.Tss() + zk.ObserverKeeper.SetTSS(ctx, tss) + + // Set rate limiter flags as disabled + rateLimiterFlags := sample.RateLimiterFlags() + rateLimiterFlags.Enabled = false + k.SetRateLimiterFlags(ctx, rateLimiterFlags) + + // Create cctxs [0~999] and [1000~1199] for Eth chain, 0.001 ETH per cctx + _ = createCctxWithCopyTypeAndHeightRange(t, ctx, *k, zk, tss, 1, 1000, ethChainID, coin.CoinType_Gas, "", uint64(1e15), statusMined) + cctxETH := createCctxWithCopyTypeAndHeightRange(t, ctx, *k, zk, tss, 1001, 1200, ethChainID, coin.CoinType_Gas, "", uint64(1e15), statusPending) + + // Set Eth chain pending nonces which contains 100 missing cctxs + setPendingNonces(ctx, zk, ethChainID, 1100, 1200, tss.TssPubkey) + + // Query pending cctxs use small limit + res, err := k.ListPendingCctxWithinRateLimit(ctx, &types.QueryListPendingCctxWithinRateLimitRequest{Limit: 100}) + require.NoError(t, err) + require.Equal(t, 100, len(res.CrossChainTx)) + + // sort res.CrossChainTx by outbound nonce ascending so that we can compare with cctxETH + sort.Slice(res.CrossChainTx, func(i, j int) bool { + return res.CrossChainTx[i].GetCurrentOutTxParam().OutboundTxTssNonce < res.CrossChainTx[j].GetCurrentOutTxParam().OutboundTxTssNonce + }) + require.EqualValues(t, cctxETH[:100], res.CrossChainTx) + require.EqualValues(t, uint64(200), res.TotalPending) + + // Query pending cctxs use max limit + res, err = k.ListPendingCctxWithinRateLimit(ctx, &types.QueryListPendingCctxWithinRateLimitRequest{Limit: keeper.MaxPendingCctxs}) + require.NoError(t, err) + require.Equal(t, 200, len(res.CrossChainTx)) + + // sort res.CrossChainTx by outbound nonce ascending so that we can compare with cctxETH + sort.Slice(res.CrossChainTx, func(i, j int) bool { + return res.CrossChainTx[i].GetCurrentOutTxParam().OutboundTxTssNonce < res.CrossChainTx[j].GetCurrentOutTxParam().OutboundTxTssNonce + }) + require.EqualValues(t, cctxETH, res.CrossChainTx) + require.EqualValues(t, uint64(200), res.TotalPending) + }) } diff --git a/x/crosschain/keeper/grpc_query_cctx_test.go b/x/crosschain/keeper/grpc_query_cctx_test.go index 240d0bfe92..f530ef305b 100644 --- a/x/crosschain/keeper/grpc_query_cctx_test.go +++ b/x/crosschain/keeper/grpc_query_cctx_test.go @@ -94,7 +94,7 @@ func TestKeeper_CctxListPending(t *testing.T) { t.Run("can retrieve pending cctx in range", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() tss := sample.Tss() zk.ObserverKeeper.SetTSS(ctx, tss) cctxs := createCctxWithNonceRange(t, ctx, *k, 1000, 2000, chainID, tss, zk) @@ -114,7 +114,7 @@ func TestKeeper_CctxListPending(t *testing.T) { t.Run("can retrieve pending cctx with range smaller than max", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() tss := sample.Tss() zk.ObserverKeeper.SetTSS(ctx, tss) cctxs := createCctxWithNonceRange(t, ctx, *k, 1000, 1100, chainID, tss, zk) @@ -128,7 +128,7 @@ func TestKeeper_CctxListPending(t *testing.T) { t.Run("can retrieve pending cctx with pending cctx below nonce low", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() tss := sample.Tss() zk.ObserverKeeper.SetTSS(ctx, tss) cctxs := createCctxWithNonceRange(t, ctx, *k, 1000, 2000, chainID, tss, zk) @@ -157,7 +157,7 @@ func TestKeeper_CctxListPending(t *testing.T) { t.Run("error if some before low nonce are missing", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() tss := sample.Tss() zk.ObserverKeeper.SetTSS(ctx, tss) cctxs := createCctxWithNonceRange(t, ctx, *k, 1000, 2000, chainID, tss, zk) @@ -226,7 +226,7 @@ func TestKeeper_CctxByNonce(t *testing.T) { t.Run("should error if nonce to cctx not found", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() tss := sample.Tss() zk.ObserverKeeper.SetTSS(ctx, tss) @@ -239,7 +239,7 @@ func TestKeeper_CctxByNonce(t *testing.T) { t.Run("should error if crosschain tx not found", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() tss := sample.Tss() zk.ObserverKeeper.SetTSS(ctx, tss) nonce := 1000 @@ -262,7 +262,7 @@ func TestKeeper_CctxByNonce(t *testing.T) { t.Run("should return if crosschain tx found", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() tss := sample.Tss() zk.ObserverKeeper.SetTSS(ctx, tss) nonce := 1000 diff --git a/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go b/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go index a18d7e737a..9c0547e9fb 100644 --- a/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go +++ b/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go @@ -36,7 +36,7 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) txHash := "string" - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ Creator: nonAdmin, @@ -63,7 +63,7 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(nil) txHash := "string" - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ Creator: sample.AccAddress(), @@ -95,7 +95,7 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) txHash := "string" - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() setSupportedChain(ctx, zk, chainID) _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ @@ -128,7 +128,7 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(true) txHash := "string" - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ Creator: admin, @@ -163,7 +163,7 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.New("error")) txHash := "string" - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ Creator: admin, @@ -197,7 +197,7 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(nil, false) txHash := "string" - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ Creator: admin, @@ -232,7 +232,7 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { observerMock.On("GetTssAddress", mock.Anything, mock.Anything).Return(nil, errors.New("error")) txHash := "string" - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() setSupportedChain(ctx, zk, chainID) _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ @@ -272,7 +272,7 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]byte("invalid"), nil) txHash := "string" - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() setSupportedChain(ctx, zk, chainID) _, err := msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ diff --git a/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go b/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go index f13a0065ae..5865c6ccca 100644 --- a/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go +++ b/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go @@ -89,7 +89,7 @@ func TestKeeper_MigrateTSSFundsForChain(t *testing.T) { keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupAdmin, true) msgServer := keeper.NewMsgServerImpl(*k) - chain := getValidEthChain(t) + chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") indexString, _ := setupTssMigrationParams(zk, k, ctx, *chain, amount, true, true) gp, found := k.GetMedianGasPriceInUint(ctx, chain.ChainId) @@ -149,7 +149,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupAdmin, false) msgServer := keeper.NewMsgServerImpl(*k) - chain := getValidEthChain(t) + chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") _, err := msgServer.MigrateTssFunds(ctx, &crosschaintypes.MsgMigrateTssFunds{ Creator: admin, @@ -172,7 +172,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) observerMock.On("IsInboundEnabled", mock.Anything).Return(true) msgServer := keeper.NewMsgServerImpl(*k) - chain := getValidEthChain(t) + chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") _, err := msgServer.MigrateTssFunds(ctx, &crosschaintypes.MsgMigrateTssFunds{ Creator: admin, @@ -197,7 +197,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { observerMock.On("GetTSS", mock.Anything).Return(observertypes.TSS{}, false) msgServer := keeper.NewMsgServerImpl(*k) - chain := getValidEthChain(t) + chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") _, err := msgServer.MigrateTssFunds(ctx, &crosschaintypes.MsgMigrateTssFunds{ Creator: admin, @@ -223,7 +223,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { observerMock.On("GetAllTSS", mock.Anything).Return([]observertypes.TSS{}) msgServer := keeper.NewMsgServerImpl(*k) - chain := getValidEthChain(t) + chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") _, err := msgServer.MigrateTssFunds(ctx, &crosschaintypes.MsgMigrateTssFunds{ Creator: admin, @@ -250,7 +250,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { observerMock.On("GetAllTSS", mock.Anything).Return([]observertypes.TSS{tss}) msgServer := keeper.NewMsgServerImpl(*k) - chain := getValidEthChain(t) + chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") _, err := msgServer.MigrateTssFunds(ctx, &crosschaintypes.MsgMigrateTssFunds{ Creator: admin, @@ -280,7 +280,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { observerMock.On("GetAllTSS", mock.Anything).Return([]observertypes.TSS{tss2}) msgServer := keeper.NewMsgServerImpl(*k) - chain := getValidEthChain(t) + chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") _, err := msgServer.MigrateTssFunds(ctx, &crosschaintypes.MsgMigrateTssFunds{ Creator: admin, @@ -311,7 +311,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { observerMock.On("GetPendingNonces", mock.Anything, mock.Anything, mock.Anything).Return(observertypes.PendingNonces{}, false) msgServer := keeper.NewMsgServerImpl(*k) - chain := getValidEthChain(t) + chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") _, err := msgServer.MigrateTssFunds(ctx, &crosschaintypes.MsgMigrateTssFunds{ Creator: admin, @@ -331,7 +331,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupAdmin, true) msgServer := keeper.NewMsgServerImpl(*k) - chain := getValidEthChain(t) + chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") indexString, _ := setupTssMigrationParams(zk, k, ctx, *chain, amount, true, true) _, err := msgServer.MigrateTssFunds(ctx, &crosschaintypes.MsgMigrateTssFunds{ @@ -359,7 +359,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupAdmin, true) msgServer := keeper.NewMsgServerImpl(*k) - chain := getValidEthChain(t) + chain := getValidEthChain() amount := sdkmath.NewUintFromString("100") indexString, _ := setupTssMigrationParams(zk, k, ctx, *chain, amount, true, true) _, err := msgServer.MigrateTssFunds(ctx, &crosschaintypes.MsgMigrateTssFunds{ @@ -384,7 +384,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupAdmin, true) msgServer := keeper.NewMsgServerImpl(*k) - chain := getValidEthChain(t) + chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") indexString, _ := setupTssMigrationParams(zk, k, ctx, *chain, amount, false, true) _, err := msgServer.MigrateTssFunds(ctx, &crosschaintypes.MsgMigrateTssFunds{ @@ -409,7 +409,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupAdmin, true) msgServer := keeper.NewMsgServerImpl(*k) - chain := getValidEthChain(t) + chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") indexString, tssPubkey := setupTssMigrationParams(zk, k, ctx, *chain, amount, true, true) k.GetObserverKeeper().SetPendingNonces(ctx, observertypes.PendingNonces{ @@ -441,7 +441,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupAdmin, true) msgServer := keeper.NewMsgServerImpl(*k) - chain := getValidEthChain(t) + chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") indexString, tssPubkey := setupTssMigrationParams(zk, k, ctx, *chain, amount, true, true) k.GetObserverKeeper().SetPendingNonces(ctx, observertypes.PendingNonces{ @@ -482,7 +482,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupAdmin, true) msgServer := keeper.NewMsgServerImpl(*k) - chain := getValidEthChain(t) + chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") indexString, _ := setupTssMigrationParams(zk, k, ctx, *chain, amount, false, false) currentTss, found := k.GetObserverKeeper().GetTSS(ctx) diff --git a/x/crosschain/keeper/msg_server_refund_aborted_tx_test.go b/x/crosschain/keeper/msg_server_refund_aborted_tx_test.go index f5615c8963..0b54a93c69 100644 --- a/x/crosschain/keeper/msg_server_refund_aborted_tx_test.go +++ b/x/crosschain/keeper/msg_server_refund_aborted_tx_test.go @@ -42,7 +42,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { }) admin := sample.AccAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) @@ -81,7 +81,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { }) admin := sample.AccAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) @@ -120,7 +120,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { }) admin := sample.AccAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) @@ -160,7 +160,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { }) admin := sample.AccAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) @@ -192,7 +192,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { }) admin := sample.AccAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) @@ -224,7 +224,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { }) admin := sample.AccAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) @@ -263,7 +263,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { }) admin := sample.AccAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() asset := sample.EthAddress().String() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) @@ -352,7 +352,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { }) admin := sample.AccAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) @@ -383,7 +383,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { }) admin := sample.AccAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) @@ -414,7 +414,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { }) admin := sample.AccAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) @@ -447,7 +447,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { }) admin := sample.AccAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) @@ -507,7 +507,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { }) admin := sample.AccAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) @@ -537,7 +537,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { }) admin := sample.AccAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, false) diff --git a/x/crosschain/keeper/msg_server_vote_inbound_tx_test.go b/x/crosschain/keeper/msg_server_vote_inbound_tx_test.go index f8d6a4bcb8..379f24741b 100644 --- a/x/crosschain/keeper/msg_server_vote_inbound_tx_test.go +++ b/x/crosschain/keeper/msg_server_vote_inbound_tx_test.go @@ -312,7 +312,7 @@ func TestKeeper_SaveInbound(t *testing.T) { zk.ObserverKeeper.SetTSS(ctx, sample.Tss()) receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() cctx := GetERC20Cctx(t, receiver, *senderChain, "", amount) eventIndex := sample.Uint64InRange(1, 100) k.SaveInbound(ctx, cctx, eventIndex) @@ -326,7 +326,7 @@ func TestKeeper_SaveInbound(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() cctx := GetERC20Cctx(t, receiver, *senderChain, "", amount) hash := sample.Hash() cctx.InboundTxParams.InboundTxObservedHash = hash.String() diff --git a/x/crosschain/keeper/msg_server_vote_outbound_tx_test.go b/x/crosschain/keeper/msg_server_vote_outbound_tx_test.go index fa9884f25a..11ea50a514 100644 --- a/x/crosschain/keeper/msg_server_vote_outbound_tx_test.go +++ b/x/crosschain/keeper/msg_server_vote_outbound_tx_test.go @@ -129,7 +129,7 @@ func TestKeeper_VoteOnObservedOutboundTx(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() asset := "" observer := sample.AccAddress() tss := sample.Tss() @@ -180,7 +180,7 @@ func TestKeeper_VoteOnObservedOutboundTx(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() asset := "" observer := sample.AccAddress() tss := sample.Tss() @@ -239,7 +239,7 @@ func TestKeeper_VoteOnObservedOutboundTx(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() asset := "" observer := sample.AccAddress() tss := sample.Tss() @@ -302,7 +302,7 @@ func TestKeeper_VoteOnObservedOutboundTx(t *testing.T) { fungibleMock := keepertest.GetCrosschainFungibleMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() asset := "" observer := sample.AccAddress() tss := sample.Tss() @@ -354,7 +354,7 @@ func TestKeeper_VoteOnObservedOutboundTx(t *testing.T) { // Setup mock data receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() asset := "" r := rand.New(rand.NewSource(42)) validator := sample.Validator(t, r) @@ -401,7 +401,7 @@ func TestKeeper_VoteOnObservedOutboundTx(t *testing.T) { // Setup mock data receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() asset := "" r := rand.New(rand.NewSource(42)) validator := sample.Validator(t, r) diff --git a/x/crosschain/keeper/msg_server_whitelist_erc20_test.go b/x/crosschain/keeper/msg_server_whitelist_erc20_test.go index 2d193e8f5b..6db8243405 100644 --- a/x/crosschain/keeper/msg_server_whitelist_erc20_test.go +++ b/x/crosschain/keeper/msg_server_whitelist_erc20_test.go @@ -26,7 +26,7 @@ func TestKeeper_WhitelistERC20(t *testing.T) { msgServer := crosschainkeeper.NewMsgServerImpl(*k) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() setSupportedChain(ctx, zk, chainID) admin := sample.AccAddress() @@ -104,7 +104,7 @@ func TestKeeper_WhitelistERC20(t *testing.T) { _, err := msgServer.WhitelistERC20(ctx, &types.MsgWhitelistERC20{ Creator: admin, Erc20Address: sample.EthAddress().Hex(), - ChainId: getValidEthChainID(t), + ChainId: getValidEthChainID(), Name: "foo", Symbol: "FOO", Decimals: 18, @@ -128,7 +128,7 @@ func TestKeeper_WhitelistERC20(t *testing.T) { _, err := msgServer.WhitelistERC20(ctx, &types.MsgWhitelistERC20{ Creator: admin, Erc20Address: "invalid", - ChainId: getValidEthChainID(t), + ChainId: getValidEthChainID(), Name: "foo", Symbol: "FOO", Decimals: 18, @@ -149,7 +149,7 @@ func TestKeeper_WhitelistERC20(t *testing.T) { authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() asset := sample.EthAddress().Hex() fc := sample.ForeignCoins(t, sample.EthAddress().Hex()) fc.Asset = asset @@ -176,7 +176,7 @@ func TestKeeper_WhitelistERC20(t *testing.T) { msgServer := crosschainkeeper.NewMsgServerImpl(*k) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() admin := sample.AccAddress() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupOperational, true) diff --git a/x/crosschain/keeper/process_inbound_test.go b/x/crosschain/keeper/process_inbound_test.go index ec3bcaea94..3e86cd68c5 100644 --- a/x/crosschain/keeper/process_inbound_test.go +++ b/x/crosschain/keeper/process_inbound_test.go @@ -83,7 +83,7 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() errDeposit := fmt.Errorf("deposit failed") // Setup expected calls @@ -113,7 +113,7 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() asset := "" errDeposit := fmt.Errorf("deposit failed") @@ -145,7 +145,7 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { fungibleMock := keepertest.GetCrosschainFungibleMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() asset := "" // Setup expected calls @@ -182,7 +182,7 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { fungibleMock := keepertest.GetCrosschainFungibleMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() asset := "" // Setup expected calls @@ -220,7 +220,7 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() asset := "" errDeposit := fmt.Errorf("deposit failed") @@ -260,7 +260,7 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() asset := "" errDeposit := fmt.Errorf("deposit failed") @@ -299,7 +299,7 @@ func TestKeeper_ProcessInboundZEVMDeposit(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() asset := "" errDeposit := fmt.Errorf("deposit failed") @@ -335,7 +335,7 @@ func TestKeeper_ProcessInboundProcessCrosschainMsgPassing(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - receiverChain := getValidEthChain(t) + receiverChain := getValidEthChain() // mock successful PayGasAndUpdateCctx keepertest.MockPayGasAndUpdateCCTX(fungibleMock, observerMock, ctx, *k, *receiverChain, "") @@ -360,7 +360,7 @@ func TestKeeper_ProcessInboundProcessCrosschainMsgPassing(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - receiverChain := getValidEthChain(t) + receiverChain := getValidEthChain() // mock unsuccessful PayGasAndUpdateCctx observerMock.On("GetSupportedChainFromChainID", mock.Anything, receiverChain.ChainId). @@ -384,7 +384,7 @@ func TestKeeper_ProcessInboundProcessCrosschainMsgPassing(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - receiverChain := getValidEthChain(t) + receiverChain := getValidEthChain() // mock successful PayGasAndUpdateCctx keepertest.MockPayGasAndUpdateCCTX(fungibleMock, observerMock, ctx, *k, *receiverChain, "") diff --git a/x/crosschain/keeper/process_outbound_test.go b/x/crosschain/keeper/process_outbound_test.go index 2bd17818c6..b4dbbef200 100644 --- a/x/crosschain/keeper/process_outbound_test.go +++ b/x/crosschain/keeper/process_outbound_test.go @@ -137,7 +137,7 @@ func TestKeeper_ProcessFailedOutbound(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() asset := "" // mock successful GetRevertGasLimit for ERC20 @@ -169,7 +169,7 @@ func TestKeeper_ProcessFailedOutbound(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() asset := "" // mock successful GetRevertGasLimit for ERC20 @@ -201,7 +201,7 @@ func TestKeeper_ProcessFailedOutbound(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() asset := "" // mock successful GetRevertGasLimit for ERC20 @@ -232,7 +232,7 @@ func TestKeeper_ProcessFailedOutbound(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() asset := "" // mock successful GetRevertGasLimit for ERC20 @@ -258,7 +258,7 @@ func TestKeeper_ProcessFailedOutbound(t *testing.T) { fungibleMock := keepertest.GetCrosschainFungibleMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() asset := "" // mock failed GetRevertGasLimit for ERC20 @@ -324,7 +324,7 @@ func TestKeeper_ProcessOutbound(t *testing.T) { fungibleMock := keepertest.GetCrosschainFungibleMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() asset := "" cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) @@ -353,7 +353,7 @@ func TestKeeper_ProcessOutbound(t *testing.T) { fungibleMock := keepertest.GetCrosschainFungibleMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() asset := "" cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) @@ -381,7 +381,7 @@ func TestKeeper_ProcessOutbound(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) receiver := sample.EthAddress() amount := big.NewInt(42) - senderChain := getValidEthChain(t) + senderChain := getValidEthChain() asset := "" cctx := GetERC20Cctx(t, receiver, *senderChain, asset, amount) diff --git a/x/crosschain/keeper/refund_test.go b/x/crosschain/keeper/refund_test.go index 09732bd23a..5f00310be3 100644 --- a/x/crosschain/keeper/refund_test.go +++ b/x/crosschain/keeper/refund_test.go @@ -23,7 +23,7 @@ func TestKeeper_RefundAmountOnZetaChainGas(t *testing.T) { k, ctx, sdkk, zk := keepertest.CrosschainKeeper(t) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) sender := sample.EthAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) zrc20 := setupGasCoin(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper, chainID, "foobar", "foobar") @@ -54,7 +54,7 @@ func TestKeeper_RefundAmountOnZetaChainGas(t *testing.T) { fungibleMock := keepertest.GetCrosschainFungibleMock(t, k) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) sender := sample.EthAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() fungibleMock.On("GetGasCoinForForeignCoin", mock.Anything, mock.Anything).Return(fungibletypes.ForeignCoins{ Zrc20ContractAddress: "0x", @@ -84,7 +84,7 @@ func TestKeeper_RefundAmountOnZetaChainGas(t *testing.T) { fungibleMock := keepertest.GetCrosschainFungibleMock(t, k) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) sender := sample.EthAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() fungibleMock.On("GetGasCoinForForeignCoin", mock.Anything, mock.Anything).Return(fungibletypes.ForeignCoins{ Zrc20ContractAddress: sample.EthAddress().Hex(), @@ -113,7 +113,7 @@ func TestKeeper_RefundAmountOnZetaChainGas(t *testing.T) { k, ctx, sdkk, zk := keepertest.CrosschainKeeper(t) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) sender := sample.EthAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) zrc20 := setupGasCoin(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper, chainID, "foobar", "foobar") @@ -137,7 +137,7 @@ func TestKeeper_RefundAmountOnZetaChainGas(t *testing.T) { k, ctx, sdkk, zk := keepertest.CrosschainKeeper(t) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) sender := sample.EthAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) err := k.RefundAmountOnZetaChainGas(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ @@ -160,7 +160,7 @@ func TestKeeper_RefundAmountOnZetaChainGas(t *testing.T) { k, ctx, sdkk, zk := keepertest.CrosschainKeeper(t) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) sender := sample.EthAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) _ = setupGasCoin(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper, chainID, "foobar", "foobar") @@ -188,7 +188,7 @@ func TestKeeper_RefundAmountOnZetaChainZeta(t *testing.T) { k, ctx, sdkk, _ := keepertest.CrosschainKeeper(t) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) sender := sample.EthAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() err := k.RefundAmountOnZetaChainZeta(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ @@ -240,7 +240,7 @@ func TestKeeper_RefundAmountOnZetaChainZeta(t *testing.T) { fungibleMock.On("DepositCoinZeta", mock.Anything, mock.Anything, mock.Anything).Return(errors.New("err")) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) sender := sample.EthAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() err := k.RefundAmountOnZetaChainZeta(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ @@ -263,7 +263,7 @@ func TestKeeper_RefundAmountOnZetaChainZeta(t *testing.T) { k, ctx, sdkk, _ := keepertest.CrosschainKeeper(t) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) sender := sample.EthAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() err := k.RefundAmountOnZetaChainZeta(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ @@ -284,7 +284,7 @@ func TestKeeper_RefundAmountOnZetaChainZeta(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) sender := sample.EthAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() err := k.RefundAmountOnZetaChainZeta(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ @@ -310,7 +310,7 @@ func TestKeeper_RefundAmountOnZetaChainERC20(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) asset := sample.EthAddress().String() sender := sample.EthAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() // deploy zrc20 deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) @@ -376,7 +376,7 @@ func TestKeeper_RefundAmountOnZetaChainERC20(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) asset := sample.EthAddress().String() sender := sample.EthAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() err := k.RefundAmountOnZetaChainERC20(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ @@ -403,7 +403,7 @@ func TestKeeper_RefundAmountOnZetaChainERC20(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) asset := sample.EthAddress().String() sender := sample.EthAddress() - chainID := getValidEthChainID(t) + chainID := getValidEthChainID() fungibleMock.On("GetForeignCoinFromAsset", mock.Anything, mock.Anything, mock.Anything).Return(fungibletypes.ForeignCoins{ Zrc20ContractAddress: sample.EthAddress().Hex(), @@ -462,7 +462,7 @@ func TestKeeper_RefundAmountOnZetaChainERC20(t *testing.T) { err = k.RefundAmountOnZetaChainERC20(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ CoinType: coin.CoinType_ERC20, - SenderChainId: getValidEthChainID(t), + SenderChainId: getValidEthChainID(), Sender: sample.EthAddress().String(), Amount: math.Uint{}, }}, @@ -473,7 +473,7 @@ func TestKeeper_RefundAmountOnZetaChainERC20(t *testing.T) { err = k.RefundAmountOnZetaChainERC20(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ CoinType: coin.CoinType_ERC20, - SenderChainId: getValidEthChainID(t), + SenderChainId: getValidEthChainID(), Sender: sample.EthAddress().String(), Amount: math.ZeroUint(), }}, @@ -485,7 +485,7 @@ func TestKeeper_RefundAmountOnZetaChainERC20(t *testing.T) { err = k.RefundAmountOnZetaChainERC20(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ CoinType: coin.CoinType_ERC20, - SenderChainId: getValidEthChainID(t), + SenderChainId: getValidEthChainID(), Sender: sample.EthAddress().String(), Asset: sample.EthAddress().String(), Amount: math.NewUint(42), diff --git a/x/crosschain/keeper/utils_test.go b/x/crosschain/keeper/utils_test.go index 732ec5d0bd..3b3ab6967c 100644 --- a/x/crosschain/keeper/utils_test.go +++ b/x/crosschain/keeper/utils_test.go @@ -22,12 +22,12 @@ import ( ) // getValidEthChainID get a valid eth chain id -func getValidEthChainID(t *testing.T) int64 { - return getValidEthChain(t).ChainId +func getValidEthChainID() int64 { + return getValidEthChain().ChainId } // getValidEthChain get a valid eth chain -func getValidEthChain(_ *testing.T) *chains.Chain { +func getValidEthChain() *chains.Chain { goerli := chains.GoerliLocalnetChain() return &goerli }