Skip to content

Commit

Permalink
make changes based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Dec 17, 2024
1 parent 9f249f6 commit 456d59a
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 167 deletions.
20 changes: 10 additions & 10 deletions pkg/chains/chain_filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 3 additions & 1 deletion testutil/sample/crosschain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand Down
8 changes: 4 additions & 4 deletions x/crosschain/keeper/msg_server_vote_inbound_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}) {
Expand Down Expand Up @@ -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(
Expand All @@ -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{}) {
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/simulation/operation_abort_stuck_cctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/simulation/operation_add_outbound_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 4 additions & 11 deletions x/crosschain/simulation/operation_gas_price_voter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
}
Expand Down
123 changes: 0 additions & 123 deletions x/crosschain/simulation/operation_migrate_erc20_custody_funds.go

This file was deleted.

2 changes: 1 addition & 1 deletion x/crosschain/simulation/operation_vote_inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}) {
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/simulation/operation_vote_outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}) {
Expand Down
14 changes: 0 additions & 14 deletions x/crosschain/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -77,7 +74,6 @@ func WeightedOperations(
weightUpdateRateLimiterFlags int
weightRefundAbortedCCTX int
weightUpdateERC20CustodyPauseStatus int
weightMigrateERC20CustodyFunds int
)

appParams.GetOrGenerate(cdc, OpWeightMsgAddOutboundTracker, &weightAddOutboundTracker, nil,
Expand Down Expand Up @@ -158,12 +154,6 @@ func WeightedOperations(
},
)

appParams.GetOrGenerate(cdc, OpWeightMigrateERC20CustodyFunds, &weightMigrateERC20CustodyFunds, nil,
func(_ *rand.Rand) {
weightMigrateERC20CustodyFunds = DefaultWeightMigrateERC20CustodyFunds
},
)

return simulation.WeightedOperations{
simulation.NewWeightedOperation(
weightVoteGasPrice,
Expand Down Expand Up @@ -209,10 +199,6 @@ func WeightedOperations(
weightUpdateERC20CustodyPauseStatus,
SimulateUpdateERC20CustodyPauseStatus(k),
),
simulation.NewWeightedOperation(
weightMigrateERC20CustodyFunds,
SimulateMigrateERC20CustodyFunds(k),
),
simulation.NewWeightedOperation(
weightUpdateTssAddress,
SimulateMsgUpdateTssAddress(k),
Expand Down

0 comments on commit 456d59a

Please sign in to comment.