From 54a4936f2aef7e5b54ebab1a28d7086f2f2392de Mon Sep 17 00:00:00 2001 From: Tanmay Date: Thu, 8 Feb 2024 14:07:33 -0500 Subject: [PATCH] fix abci test for gas price multiplication --- testutil/sample/crosschain.go | 4 ++-- x/crosschain/keeper/abci_test.go | 17 ++++++++--------- x/crosschain/keeper/grpc_query_cctx_test.go | 4 ++-- .../keeper/msg_server_abort_stuck_cctx_test.go | 18 +++++++++--------- .../keeper/msg_server_update_tss_test.go | 12 ++++++------ 5 files changed, 27 insertions(+), 28 deletions(-) diff --git a/testutil/sample/crosschain.go b/testutil/sample/crosschain.go index f31da030f6..87bb3e7245 100644 --- a/testutil/sample/crosschain.go +++ b/testutil/sample/crosschain.go @@ -75,7 +75,7 @@ func Status(t *testing.T, index string) *types.Status { LastUpdateTimestamp: r.Int63(), } } -func GetCctxHash(index string) string { +func GetCctxIndexFromString(index string) string { return crypto.Keccak256Hash([]byte(index)).String() } func CrossChainTx(t *testing.T, index string) *types.CrossChainTx { @@ -83,7 +83,7 @@ func CrossChainTx(t *testing.T, index string) *types.CrossChainTx { return &types.CrossChainTx{ Creator: AccAddress(), - Index: GetCctxHash(index), + Index: GetCctxIndexFromString(index), ZetaFees: math.NewUint(uint64(r.Int63())), RelayedMessage: StringRandom(r, 32), CctxStatus: Status(t, index), diff --git a/x/crosschain/keeper/abci_test.go b/x/crosschain/keeper/abci_test.go index ea46e70dc4..4487d7dcec 100644 --- a/x/crosschain/keeper/abci_test.go +++ b/x/crosschain/keeper/abci_test.go @@ -58,7 +58,7 @@ func TestKeeper_IterateAndUpdateCctxGasPrice(t *testing.T) { createCctxWithNonceRange(t, ctx, *k, 40, 45, common.ZetaChainMainnet().ChainId, tss, zk) // set a cctx where the update function should fail to test that the next cctx are not updated but the next chains are - failMap["1-12"] = struct{}{} + failMap[sample.GetCctxIndexFromString("1-12")] = struct{}{} // test that the default crosschain flags are used when not set and the epoch length is not reached ctx = ctx.WithBlockHeight(observertypes.DefaultCrosschainFlags().GasPriceIncreaseFlags.EpochLength + 1) @@ -84,7 +84,6 @@ func TestKeeper_IterateAndUpdateCctxGasPrice(t *testing.T) { require.Equal(t, customFlags, flags) // test that cctx are iterated and updated when the epoch length is reached - ctx = ctx.WithBlockHeight(observertypes.DefaultCrosschainFlags().GasPriceIncreaseFlags.EpochLength * 2) cctxCount, flags = k.IterateAndUpdateCctxGasPrice(ctx, supportedChains, updateFunc) @@ -94,14 +93,14 @@ func TestKeeper_IterateAndUpdateCctxGasPrice(t *testing.T) { // check that the update function was called with the cctx index require.Equal(t, 7, len(updateFuncMap)) - require.Contains(t, updateFuncMap, "1-10") - require.Contains(t, updateFuncMap, "1-11") + require.Contains(t, updateFuncMap, sample.GetCctxIndexFromString("1-10")) + require.Contains(t, updateFuncMap, sample.GetCctxIndexFromString("1-11")) - require.Contains(t, updateFuncMap, "56-30") - require.Contains(t, updateFuncMap, "56-31") - require.Contains(t, updateFuncMap, "56-32") - require.Contains(t, updateFuncMap, "56-33") - require.Contains(t, updateFuncMap, "56-34") + require.Contains(t, updateFuncMap, sample.GetCctxIndexFromString("56-30")) + require.Contains(t, updateFuncMap, sample.GetCctxIndexFromString("56-31")) + require.Contains(t, updateFuncMap, sample.GetCctxIndexFromString("56-32")) + require.Contains(t, updateFuncMap, sample.GetCctxIndexFromString("56-33")) + require.Contains(t, updateFuncMap, sample.GetCctxIndexFromString("56-34")) } func TestCheckAndUpdateCctxGasPrice(t *testing.T) { diff --git a/x/crosschain/keeper/grpc_query_cctx_test.go b/x/crosschain/keeper/grpc_query_cctx_test.go index bf8579990b..6865d6d51e 100644 --- a/x/crosschain/keeper/grpc_query_cctx_test.go +++ b/x/crosschain/keeper/grpc_query_cctx_test.go @@ -135,12 +135,12 @@ func TestKeeper_CctxListPending(t *testing.T) { cctxs := createCctxWithNonceRange(t, ctx, *k, 1000, 2000, chainID, tss, zk) // set some cctxs as pending below nonce - cctx1, found := k.GetCrossChainTx(ctx, sample.GetCctxHash("1337-940")) + cctx1, found := k.GetCrossChainTx(ctx, sample.GetCctxIndexFromString("1337-940")) require.True(t, found) cctx1.CctxStatus.Status = types.CctxStatus_PendingOutbound k.SetCrossChainTx(ctx, cctx1) - cctx2, found := k.GetCrossChainTx(ctx, sample.GetCctxHash("1337-955")) + cctx2, found := k.GetCrossChainTx(ctx, sample.GetCctxIndexFromString("1337-955")) require.True(t, found) cctx2.CctxStatus.Status = types.CctxStatus_PendingOutbound k.SetCrossChainTx(ctx, cctx2) diff --git a/x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go b/x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go index 0ee02ff129..fadda6b74f 100644 --- a/x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go +++ b/x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go @@ -29,11 +29,11 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { // abort the cctx _, err := msgServer.AbortStuckCCTX(ctx, &crosschaintypes.MsgAbortStuckCCTX{ Creator: admin, - CctxIndex: sample.GetCctxHash("cctx_index"), + CctxIndex: sample.GetCctxIndexFromString("cctx_index"), }) require.NoError(t, err) - cctxFound, found := k.GetCrossChainTx(ctx, sample.GetCctxHash("cctx_index")) + cctxFound, found := k.GetCrossChainTx(ctx, sample.GetCctxIndexFromString("cctx_index")) require.True(t, found) require.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status) require.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage) @@ -56,11 +56,11 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { // abort the cctx _, err := msgServer.AbortStuckCCTX(ctx, &crosschaintypes.MsgAbortStuckCCTX{ Creator: admin, - CctxIndex: sample.GetCctxHash("cctx_index"), + CctxIndex: sample.GetCctxIndexFromString("cctx_index"), }) require.NoError(t, err) - cctxFound, found := k.GetCrossChainTx(ctx, sample.GetCctxHash("cctx_index")) + cctxFound, found := k.GetCrossChainTx(ctx, sample.GetCctxIndexFromString("cctx_index")) require.True(t, found) require.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status) require.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage) @@ -83,11 +83,11 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { // abort the cctx _, err := msgServer.AbortStuckCCTX(ctx, &crosschaintypes.MsgAbortStuckCCTX{ Creator: admin, - CctxIndex: sample.GetCctxHash("cctx_index"), + CctxIndex: sample.GetCctxIndexFromString("cctx_index"), }) require.NoError(t, err) - cctxFound, found := k.GetCrossChainTx(ctx, sample.GetCctxHash("cctx_index")) + cctxFound, found := k.GetCrossChainTx(ctx, sample.GetCctxIndexFromString("cctx_index")) require.True(t, found) require.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status) require.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage) @@ -108,7 +108,7 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { // abort the cctx _, err := msgServer.AbortStuckCCTX(ctx, &crosschaintypes.MsgAbortStuckCCTX{ Creator: sample.AccAddress(), - CctxIndex: sample.GetCctxHash("cctx_index"), + CctxIndex: sample.GetCctxIndexFromString("cctx_index"), }) require.ErrorIs(t, err, observertypes.ErrNotAuthorized) }) @@ -122,7 +122,7 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { // abort the cctx _, err := msgServer.AbortStuckCCTX(ctx, &crosschaintypes.MsgAbortStuckCCTX{ Creator: admin, - CctxIndex: sample.GetCctxHash("cctx_index"), + CctxIndex: sample.GetCctxIndexFromString("cctx_index"), }) require.ErrorIs(t, err, crosschaintypes.ErrCannotFindCctx) }) @@ -144,7 +144,7 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { // abort the cctx _, err := msgServer.AbortStuckCCTX(ctx, &crosschaintypes.MsgAbortStuckCCTX{ Creator: admin, - CctxIndex: sample.GetCctxHash("cctx_index"), + CctxIndex: sample.GetCctxIndexFromString("cctx_index"), }) require.ErrorIs(t, err, crosschaintypes.ErrStatusNotPending) }) diff --git a/x/crosschain/keeper/msg_server_update_tss_test.go b/x/crosschain/keeper/msg_server_update_tss_test.go index 5ed175dd88..fbc8567d5f 100644 --- a/x/crosschain/keeper/msg_server_update_tss_test.go +++ b/x/crosschain/keeper/msg_server_update_tss_test.go @@ -28,7 +28,7 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { index := chain.ChainName.String() + "_migration_tx_index" k.GetObserverKeeper().SetFundMigrator(ctx, types.TssFundMigratorInfo{ ChainId: chain.ChainId, - MigrationCctxIndex: sample.GetCctxHash(index), + MigrationCctxIndex: sample.GetCctxIndexFromString(index), }) cctx := sample.CrossChainTx(t, index) cctx.CctxStatus.Status = crosschaintypes.CctxStatus_OutboundMined @@ -60,7 +60,7 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { index := chain.ChainName.String() + "_migration_tx_index" k.GetObserverKeeper().SetFundMigrator(ctx, types.TssFundMigratorInfo{ ChainId: chain.ChainId, - MigrationCctxIndex: sample.GetCctxHash(index), + MigrationCctxIndex: sample.GetCctxIndexFromString(index), }) cctx := sample.CrossChainTx(t, index) cctx.CctxStatus.Status = crosschaintypes.CctxStatus_OutboundMined @@ -91,7 +91,7 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { index := chain.ChainName.String() + "_migration_tx_index" k.GetObserverKeeper().SetFundMigrator(ctx, types.TssFundMigratorInfo{ ChainId: chain.ChainId, - MigrationCctxIndex: sample.GetCctxHash(index), + MigrationCctxIndex: sample.GetCctxIndexFromString(index), }) cctx := sample.CrossChainTx(t, index) cctx.CctxStatus.Status = crosschaintypes.CctxStatus_OutboundMined @@ -128,7 +128,7 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { index := chain.ChainName.String() + "_migration_tx_index" k.GetObserverKeeper().SetFundMigrator(ctx, types.TssFundMigratorInfo{ ChainId: chain.ChainId, - MigrationCctxIndex: sample.GetCctxHash(index), + MigrationCctxIndex: sample.GetCctxIndexFromString(index), }) cctx := sample.CrossChainTx(t, index) cctx.CctxStatus.Status = crosschaintypes.CctxStatus_OutboundMined @@ -165,7 +165,7 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { index := chain.ChainName.String() + "_migration_tx_index" k.GetObserverKeeper().SetFundMigrator(ctx, types.TssFundMigratorInfo{ ChainId: chain.ChainId, - MigrationCctxIndex: sample.GetCctxHash(index), + MigrationCctxIndex: sample.GetCctxIndexFromString(index), }) cctx := sample.CrossChainTx(t, index) cctx.CctxStatus.Status = crosschaintypes.CctxStatus_PendingOutbound @@ -202,7 +202,7 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { index := chain.ChainName.String() + "_migration_tx_index" k.GetObserverKeeper().SetFundMigrator(ctx, types.TssFundMigratorInfo{ ChainId: chain.ChainId, - MigrationCctxIndex: sample.GetCctxHash(index), + MigrationCctxIndex: sample.GetCctxIndexFromString(index), }) } assert.Equal(t, len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), len(k.GetObserverKeeper().GetSupportedChains(ctx)))