Skip to content

Commit

Permalink
fix abci test for gas price multiplication
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Feb 8, 2024
1 parent 09c3d8c commit 54a4936
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 28 deletions.
4 changes: 2 additions & 2 deletions testutil/sample/crosschain.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ 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 {
r := newRandFromStringSeed(t, index)

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),
Expand Down
17 changes: 8 additions & 9 deletions x/crosschain/keeper/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions x/crosschain/keeper/grpc_query_cctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
})
Expand All @@ -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)
})
Expand All @@ -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)
})
Expand Down
12 changes: 6 additions & 6 deletions x/crosschain/keeper/msg_server_update_tss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand Down

0 comments on commit 54a4936

Please sign in to comment.