diff --git a/pkg/chains/chain_filters_test.go b/pkg/chains/chain_filters_test.go index fe936e5110..d1fc057572 100644 --- a/pkg/chains/chain_filters_test.go +++ b/pkg/chains/chain_filters_test.go @@ -14,42 +14,42 @@ func TestFilterChains(t *testing.T) { expected func() []chains.Chain }{ { - name: "Filter external chains", + name: "filter external chains", filters: []chains.ChainFilter{chains.FilterExternalChains}, expected: func() []chains.Chain { return chains.ExternalChainList([]chains.Chain{}) }, }, { - name: "Filter gateway observer chains", + name: "filter gateway observer chains", filters: []chains.ChainFilter{chains.FilterByGateway(chains.CCTXGateway_observers)}, expected: func() []chains.Chain { return chains.ChainListByGateway(chains.CCTXGateway_observers, []chains.Chain{}) }, }, { - name: "Filter consensus ethereum chains", + name: "filter consensus ethereum chains", filters: []chains.ChainFilter{chains.FilterByConsensus(chains.Consensus_ethereum)}, expected: func() []chains.Chain { return chains.ChainListByConsensus(chains.Consensus_ethereum, []chains.Chain{}) }, }, { - name: "Filter consensus bitcoin chains", + name: "filter consensus bitcoin chains", filters: []chains.ChainFilter{chains.FilterByConsensus(chains.Consensus_bitcoin)}, expected: func() []chains.Chain { return chains.ChainListByConsensus(chains.Consensus_bitcoin, []chains.Chain{}) }, }, { - name: "Filter consensus solana chains", + name: "filter consensus solana chains", filters: []chains.ChainFilter{chains.FilterByConsensus(chains.Consensus_solana_consensus)}, expected: func() []chains.Chain { return chains.ChainListByConsensus(chains.Consensus_solana_consensus, []chains.Chain{}) }, }, { - name: "Filter vm evm chains", + name: "filter evm chains", filters: []chains.ChainFilter{ chains.FilterByVM(chains.Vm_evm), }, @@ -64,7 +64,7 @@ func TestFilterChains(t *testing.T) { }, }, { - name: "Apply multiple filters external chains and gateway observer", + name: "apply multiple filters external chains and gateway observer", filters: []chains.ChainFilter{ chains.FilterExternalChains, chains.FilterByGateway(chains.CCTXGateway_observers), @@ -81,7 +81,7 @@ func TestFilterChains(t *testing.T) { }, }, { - name: "Apply multiple filters external chains with gateway observer and consensus ethereum", + name: "apply multiple filters external chains with gateway observer and consensus ethereum", filters: []chains.ChainFilter{ chains.FilterExternalChains, chains.FilterByGateway(chains.CCTXGateway_observers), @@ -100,7 +100,7 @@ func TestFilterChains(t *testing.T) { }, }, { - name: "Apply multiple filters external chains with gateway observer and consensus bitcoin", + name: "apply multiple filters external chains with gateway observer and consensus bitcoin", filters: []chains.ChainFilter{ chains.FilterExternalChains, chains.FilterByGateway(chains.CCTXGateway_observers), @@ -131,7 +131,7 @@ func TestFilterChains(t *testing.T) { }, }, { - name: "Test multiple filters in random order", + name: "test multiple filters in random order", filters: []chains.ChainFilter{ chains.FilterByGateway(chains.CCTXGateway_observers), chains.FilterByConsensus(chains.Consensus_ethereum), diff --git a/testutil/sample/crosschain.go b/testutil/sample/crosschain.go index ffe2afeee2..f201602155 100644 --- a/testutil/sample/crosschain.go +++ b/testutil/sample/crosschain.go @@ -151,8 +151,10 @@ func GasPriceWithChainID(t *testing.T, chainID int64) types.GasPrice { func GasPriceFromRand(r *rand.Rand, chainID int64) *types.GasPrice { var price uint64 for price == 0 { - price = r.Uint64() + maxGasPrice := uint64(1000 * 1e9) // 1000 Gwei + price = uint64(1e9) + r.Uint64()%maxGasPrice } + // Select priority fee between 0 and price priorityFee := r.Uint64() % price return &types.GasPrice{ Creator: "", 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 7fc5c9be99..57e73a72ae 100644 --- a/x/crosschain/keeper/msg_server_vote_inbound_tx_test.go +++ b/x/crosschain/keeper/msg_server_vote_inbound_tx_test.go @@ -52,7 +52,7 @@ func TestKeeper_VoteInbound(t *testing.T) { msgServer := keeper.NewMsgServerImpl(*k) validatorList := setObservers(t, k, ctx, zk) - to, from := int64(1337), int64(101) + to, from := chains.GoerliLocalnet.ChainId, chains.ZetaChainPrivnet.ChainId supportedChains := zk.ObserverKeeper.GetSupportedChains(ctx) for _, chain := range supportedChains { if chains.IsEthereumChain(chain.ChainId, []chains.Chain{}) { @@ -185,7 +185,7 @@ func TestKeeper_VoteInbound(t *testing.T) { observerMock.On("VoteOnInboundBallot", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(true, false, errors.New("err")) msgServer := keeper.NewMsgServerImpl(*k) - to, from := int64(1337), int64(101) + to, from := chains.GoerliLocalnet.ChainId, chains.ZetaChainPrivnet.ChainId msg := sample.InboundVote(0, from, to) res, err := msgServer.VoteInbound( @@ -208,7 +208,7 @@ func TestKeeper_VoteInbound(t *testing.T) { zk.ObserverKeeper.SetObserverSet(ctx, observertypes.ObserverSet{ ObserverList: observerSet, }) - to, from := int64(1337), int64(101) + to, from := chains.GoerliLocalnet.ChainId, chains.ZetaChainPrivnet.ChainId supportedChains := zk.ObserverKeeper.GetSupportedChains(ctx) for _, chain := range supportedChains { if chains.IsEthereumChain(chain.ChainId, []chains.Chain{}) { @@ -255,7 +255,7 @@ func TestKeeper_VoteInbound(t *testing.T) { Return(true, false, nil) observerMock.On("GetTSS", mock.Anything).Return(observertypes.TSS{}, false) msgServer := keeper.NewMsgServerImpl(*k) - to, from := int64(1337), int64(101) + to, from := chains.GoerliLocalnet.ChainId, chains.ZetaChainPrivnet.ChainId msg := sample.InboundVote(0, from, to) res, err := msgServer.VoteInbound( diff --git a/x/crosschain/simulation/operation_abort_stuck_cctx.go b/x/crosschain/simulation/operation_abort_stuck_cctx.go index 40b4f21b53..55d0a1cd60 100644 --- a/x/crosschain/simulation/operation_abort_stuck_cctx.go +++ b/x/crosschain/simulation/operation_abort_stuck_cctx.go @@ -19,7 +19,7 @@ func SimulateMsgAbortStuckCCTX(k keeper.Keeper) simtypes.Operation { return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simtypes.Account, _ string, ) (OperationMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) { // Pick a ethereum chain to abort a stuck cctx - chainID := int64(1337) + chainID := chains.GoerliLocalnet.ChainId supportedChains := k.GetObserverKeeper().GetSupportedChains(ctx) if len(supportedChains) == 0 { return simtypes.NoOpMsg( diff --git a/x/crosschain/simulation/operation_add_outbound_tracker.go b/x/crosschain/simulation/operation_add_outbound_tracker.go index c4134745a2..8441a6aba0 100644 --- a/x/crosschain/simulation/operation_add_outbound_tracker.go +++ b/x/crosschain/simulation/operation_add_outbound_tracker.go @@ -19,7 +19,7 @@ import ( func SimulateMsgAddOutboundTracker(k keeper.Keeper) simtypes.Operation { return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simtypes.Account, _ string, ) (OperationMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) { - chainID := int64(1337) + chainID := chains.GoerliLocalnet.ChainId supportedChains := k.GetObserverKeeper().GetSupportedChains(ctx) if len(supportedChains) == 0 { return simtypes.NoOpMsg( diff --git a/x/crosschain/simulation/operation_gas_price_voter.go b/x/crosschain/simulation/operation_gas_price_voter.go index b4e1f5f903..701ce1051c 100644 --- a/x/crosschain/simulation/operation_gas_price_voter.go +++ b/x/crosschain/simulation/operation_gas_price_voter.go @@ -8,6 +8,7 @@ import ( moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" + "github.com/zeta-chain/node/testutil/sample" "github.com/zeta-chain/node/pkg/authz" "github.com/zeta-chain/node/x/crosschain/keeper" @@ -36,21 +37,13 @@ func SimulateMsgVoteGasPrice(k keeper.Keeper) simtypes.Operation { ), nil, nil } randomChainID := GetRandomChainID(r, supportedChains) - // Vote for random gas price. Gas prices do not use a ballot system, so we can vote directly without having to schedule future operations. - - var price uint64 - for price == 0 { - maxGasPrice := uint64(1000 * 1e9) // 1000 Gwei - price = uint64(1e9) + r.Uint64()%maxGasPrice - } - // Select priority fee between 0 and price - priorityFee := r.Uint64() % price + gasPrice := sample.GasPriceFromRand(r, randomChainID) msg := types.MsgVoteGasPrice{ Creator: randomObserver, ChainId: randomChainID, - Price: price, - PriorityFee: priorityFee, + Price: gasPrice.Prices[0], + PriorityFee: gasPrice.PriorityFees[0], BlockNumber: uint64(ctx.BlockHeight()) + r.Uint64()%1000, // #nosec G115 - overflow is not a issue here Supply: sdk.NewInt(r.Int63n(1e18)).String(), } diff --git a/x/crosschain/simulation/operation_migrate_erc20_custody_funds.go b/x/crosschain/simulation/operation_migrate_erc20_custody_funds.go deleted file mode 100644 index ff486b27e7..0000000000 --- a/x/crosschain/simulation/operation_migrate_erc20_custody_funds.go +++ /dev/null @@ -1,123 +0,0 @@ -package simulation - -import ( - "math/rand" - - "github.com/cosmos/cosmos-sdk/baseapp" - sdk "github.com/cosmos/cosmos-sdk/types" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/x/simulation" - - "github.com/zeta-chain/node/pkg/chains" - "github.com/zeta-chain/node/testutil/sample" - "github.com/zeta-chain/node/x/crosschain/keeper" - "github.com/zeta-chain/node/x/crosschain/types" -) - -// SimulateMigrateERC20CustodyFunds generates a MsgMigrateERC20CustodyFunds with random values and delivers it -func SimulateMigrateERC20CustodyFunds(k keeper.Keeper) simtypes.Operation { - return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simtypes.Account, _ string, - ) (OperationMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) { - policyAccount, err := GetPolicyAccount(ctx, k.GetAuthorityKeeper(), accounts) - if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgMigrateERC20CustodyFunds, err.Error()), nil, nil - } - - authAccount := k.GetAuthKeeper().GetAccount(ctx, policyAccount.Address) - spendable := k.GetBankKeeper().SpendableCoins(ctx, authAccount.GetAddress()) - - supportedChains := k.GetObserverKeeper().GetSupportedChains(ctx) - if len(supportedChains) == 0 { - return simtypes.NoOpMsg( - types.ModuleName, - types.TypeMsgMigrateERC20CustodyFunds, - "no supported chains found", - ), nil, nil - } - - filteredChains := chains.FilterChains(supportedChains, chains.FilterExternalChains) - - //pick a random chain - randomChain := filteredChains[r.Intn(len(filteredChains))] - - _, found := k.GetObserverKeeper().GetChainNonces(ctx, randomChain.ChainId) - if !found { - return simtypes.NoOpMsg( - types.ModuleName, - types.TypeMsgMigrateERC20CustodyFunds, - "no chain nonces found", - ), nil, nil - } - - _, found = k.GetObserverKeeper().GetTSS(ctx) - if !found { - return simtypes.NoOpMsg( - types.ModuleName, - types.TypeMsgMigrateERC20CustodyFunds, - "no TSS found", - ), nil, nil - } - - _, found = k.GetObserverKeeper().GetChainParamsByChainID(ctx, randomChain.ChainId) - if !found { - return simtypes.NoOpMsg( - types.ModuleName, - types.TypeMsgMigrateERC20CustodyFunds, - "no chain params found", - ), nil, nil - } - medianGasPrice, priorityFee, found := k.GetMedianGasValues(ctx, randomChain.ChainId) - if !found { - return simtypes.NoOpMsg( - types.ModuleName, - types.TypeMsgMigrateERC20CustodyFunds, - "no median gas values found", - ), nil, nil - } - medianGasPrice = medianGasPrice.MulUint64(types.ERC20CustodyPausingGasMultiplierEVM) - priorityFee = priorityFee.MulUint64(types.ERC20CustodyPausingGasMultiplierEVM) - - if priorityFee.GT(medianGasPrice) { - return simtypes.NoOpMsg( - types.ModuleName, - types.TypeMsgMigrateERC20CustodyFunds, - "priorityFee is greater than median gasPrice", - ), nil, nil - } - - msg := types.MsgMigrateERC20CustodyFunds{ - Creator: policyAccount.Address.String(), - ChainId: randomChain.ChainId, - NewCustodyAddress: sample.EthAddressFromRand(r).String(), - Erc20Address: sample.EthAddressFromRand(r).String(), - Amount: sdk.NewUint(r.Uint64()), - } - - err = msg.ValidateBasic() - if err != nil { - return simtypes.NoOpMsg( - types.ModuleName, - msg.Type(), - "unable to validate MsgMigrateERC20CustodyFunds", - ), nil, err - } - - txCtx := simulation.OperationInput{ - R: r, - App: app, - TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, - Cdc: nil, - Msg: &msg, - MsgType: msg.Type(), - Context: ctx, - SimAccount: policyAccount, - AccountKeeper: k.GetAuthKeeper(), - Bankkeeper: k.GetBankKeeper(), - ModuleName: types.ModuleName, - CoinsSpentInMsg: spendable, - } - - return simulation.GenAndDeliverTxWithRandFees(txCtx) - } -} diff --git a/x/crosschain/simulation/operation_vote_inbound.go b/x/crosschain/simulation/operation_vote_inbound.go index d4833adb73..714d649aaa 100644 --- a/x/crosschain/simulation/operation_vote_inbound.go +++ b/x/crosschain/simulation/operation_vote_inbound.go @@ -64,7 +64,7 @@ func SimulateVoteInbound(k keeper.Keeper) simtypes.Operation { accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { - to, from := int64(1337), int64(101) + to, from := chains.GoerliLocalnet.ChainId, chains.ZetaChainPrivnet.ChainId supportedChains := k.GetObserverKeeper().GetSupportedChains(ctx) for _, chain := range supportedChains { if chains.IsEthereumChain(chain.ChainId, []chains.Chain{}) { diff --git a/x/crosschain/simulation/operation_vote_outbound.go b/x/crosschain/simulation/operation_vote_outbound.go index 51f7113c2c..bf4dbaf5dd 100644 --- a/x/crosschain/simulation/operation_vote_outbound.go +++ b/x/crosschain/simulation/operation_vote_outbound.go @@ -71,7 +71,7 @@ func SimulateVoteOutbound(k keeper.Keeper) simtypes.Operation { accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { - to, from := int64(1337), int64(101) + to, from := chains.GoerliLocalnet.ChainId, chains.ZetaChainPrivnet.ChainId supportedChains := k.GetObserverKeeper().GetSupportedChains(ctx) for _, chain := range supportedChains { if chains.IsEthereumChain(chain.ChainId, []chains.Chain{}) { diff --git a/x/crosschain/simulation/operations.go b/x/crosschain/simulation/operations.go index f4590986bd..5d2403a64f 100644 --- a/x/crosschain/simulation/operations.go +++ b/x/crosschain/simulation/operations.go @@ -42,7 +42,6 @@ const ( DefaultWeightUpdateRateLimiterFlags = 10 DefaultWeightRefundAbortedCCTX = 10 DefaultWeightUpdateERC20CustodyPauseStatus = 10 - DefaultWeightMigrateERC20CustodyFunds = 10 OpWeightMsgAddOutboundTracker = "op_weight_msg_add_outbound_tracker" // #nosec G101 not a hardcoded credential OpWeightAddInboundTracker = "op_weight_msg_add_inbound_tracker" // #nosec G101 not a hardcoded credential @@ -57,8 +56,6 @@ const ( OpWeightUpdateRateLimiterFlags = "op_weight_msg_update_rate_limiter_flags" // #nosec G101 not a hardcoded credential OpWeightRefundAbortedCCTX = "op_weight_msg_refund_aborted_cctx" // #nosec G101 not a hardcoded credential OpWeightUpdateERC20CustodyPauseStatus = "op_weight_msg_update_erc20_custody_pause_status" // #nosec G101 not a hardcoded credential - OpWeightMigrateERC20CustodyFunds = "op_weight_msg_migrate_erc20_custody_funds" // #nosec G101 not a hardcoded credential - ) func WeightedOperations( @@ -77,7 +74,6 @@ func WeightedOperations( weightUpdateRateLimiterFlags int weightRefundAbortedCCTX int weightUpdateERC20CustodyPauseStatus int - weightMigrateERC20CustodyFunds int ) appParams.GetOrGenerate(cdc, OpWeightMsgAddOutboundTracker, &weightAddOutboundTracker, nil, @@ -158,12 +154,6 @@ func WeightedOperations( }, ) - appParams.GetOrGenerate(cdc, OpWeightMigrateERC20CustodyFunds, &weightMigrateERC20CustodyFunds, nil, - func(_ *rand.Rand) { - weightMigrateERC20CustodyFunds = DefaultWeightMigrateERC20CustodyFunds - }, - ) - return simulation.WeightedOperations{ simulation.NewWeightedOperation( weightVoteGasPrice, @@ -209,10 +199,6 @@ func WeightedOperations( weightUpdateERC20CustodyPauseStatus, SimulateUpdateERC20CustodyPauseStatus(k), ), - simulation.NewWeightedOperation( - weightMigrateERC20CustodyFunds, - SimulateMigrateERC20CustodyFunds(k), - ), simulation.NewWeightedOperation( weightUpdateTssAddress, SimulateMsgUpdateTssAddress(k),