From 36daf8e290c4ad910d585da3e9d762e80c323624 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 2 Aug 2024 12:13:46 -0400 Subject: [PATCH] resolve comments --- cmd/zetae2e/local/local.go | 13 ++-------- e2e/runner/trackers.go | 17 ++++++++++++++ x/crosschain/types/cctx.go | 1 + x/observer/keeper/pending_nonces_test.go | 30 ++++++++++++------------ 4 files changed, 35 insertions(+), 26 deletions(-) create mode 100644 e2e/runner/trackers.go diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index f083f9c3a4..c57cd41c80 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -351,7 +351,8 @@ func localE2ETest(cmd *cobra.Command, _ []string) { if testTSSMigration { runTSSMigrationTest(deployerRunner, logger, verbose, conf) } - checkTrackers(deployerRunner) + // Verify that there are no trackers left over after tests complete + deployerRunner.EnsureNoTrackers() // print and validate report networkReport, err := deployerRunner.GenerateNetworkReport() if err != nil { @@ -366,16 +367,6 @@ func localE2ETest(cmd *cobra.Command, _ []string) { os.Exit(0) } -func checkTrackers(deployRunner *runner.E2ERunner) { - // get all trackers - res, err := deployRunner.CctxClient.OutTxTrackerAll( - deployRunner.Ctx, - &crosschaintypes.QueryAllOutboundTrackerRequest{}, - ) - require.NoError(deployRunner, err) - require.Empty(deployRunner, res.OutboundTracker, "there should be no trackers at the end of the test") -} - // waitKeygenHeight waits for keygen height func waitKeygenHeight( ctx context.Context, diff --git a/e2e/runner/trackers.go b/e2e/runner/trackers.go new file mode 100644 index 0000000000..0959086a3d --- /dev/null +++ b/e2e/runner/trackers.go @@ -0,0 +1,17 @@ +package runner + +import ( + "github.com/stretchr/testify/require" + crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" +) + +// EnsureNoTrackers ensures that there are no trackers left on zetacore +func (r *E2ERunner) EnsureNoTrackers() { + // get all trackers + res, err := r.CctxClient.OutTxTrackerAll( + r.Ctx, + &crosschaintypes.QueryAllOutboundTrackerRequest{}, + ) + require.NoError(r, err) + require.Empty(r, res.OutboundTracker, "there should be no trackers at the end of the test") +} diff --git a/x/crosschain/types/cctx.go b/x/crosschain/types/cctx.go index 88ab5c1b32..6952a5092f 100644 --- a/x/crosschain/types/cctx.go +++ b/x/crosschain/types/cctx.go @@ -164,6 +164,7 @@ func (m CrossChainTx) GetCCTXIndexBytes() ([32]byte, error) { return sendHash, nil } +// SetOutboundBallotIndex sets the outbound ballot index for the most recent outbound. func (m CrossChainTx) SetOutboundBallotIndex(index string) { m.GetCurrentOutboundParam().BallotIndex = index } diff --git a/x/observer/keeper/pending_nonces_test.go b/x/observer/keeper/pending_nonces_test.go index 22faf24fa7..a92155584c 100644 --- a/x/observer/keeper/pending_nonces_test.go +++ b/x/observer/keeper/pending_nonces_test.go @@ -144,47 +144,47 @@ func TestKeeper_RemoveFromPendingNonces(t *testing.T) { tss := sample.Tss() // make nonces and pubkey deterministic for test chainIDS := []int64{chains.GoerliLocalnet.ChainId, chains.BitcoinTestnet.ChainId, chains.BscTestnet.ChainId} - pn := make([]types.PendingNonces, len(chainIDS)) + pendingNonces := make([]types.PendingNonces, len(chainIDS)) for idx, chainID := range chainIDS { - pn[idx] = types.PendingNonces{ + pendingNonces[idx] = types.PendingNonces{ ChainId: chainID, NonceLow: 1, NonceHigh: 10, Tss: tss.TssPubkey, } } - for _, pendingNonce := range pn { + for _, pendingNonce := range pendingNonces { k.SetPendingNonces(ctx, pendingNonce) } // remove from pending nonces k.RemoveFromPendingNonces(ctx, tss.TssPubkey, chains.GoerliLocalnet.ChainId, 1) - pnGoerli, found := k.GetPendingNonces(ctx, tss.TssPubkey, chains.GoerliLocalnet.ChainId) + actualPendingNoncesGoerli, found := k.GetPendingNonces(ctx, tss.TssPubkey, chains.GoerliLocalnet.ChainId) require.True(t, found) - require.Equal(t, int64(2), pnGoerli.NonceLow) - require.Equal(t, int64(10), pnGoerli.NonceHigh) + require.Equal(t, int64(2), actualPendingNoncesGoerli.NonceLow) + require.Equal(t, int64(10), actualPendingNoncesGoerli.NonceHigh) // try removing lower than nonceLow, this might be triggered if we try to remove a previously removed nonce k.RemoveFromPendingNonces(ctx, tss.TssPubkey, chains.GoerliLocalnet.ChainId, 1) - pnGoerli, found = k.GetPendingNonces(ctx, tss.TssPubkey, chains.GoerliLocalnet.ChainId) + actualPendingNoncesGoerli, found = k.GetPendingNonces(ctx, tss.TssPubkey, chains.GoerliLocalnet.ChainId) require.True(t, found) - require.Equal(t, int64(2), pnGoerli.NonceLow) - require.Equal(t, int64(10), pnGoerli.NonceHigh) + require.Equal(t, int64(2), actualPendingNoncesGoerli.NonceLow) + require.Equal(t, int64(10), actualPendingNoncesGoerli.NonceHigh) // try removing higher than nonceHigh k.RemoveFromPendingNonces(ctx, tss.TssPubkey, chains.GoerliLocalnet.ChainId, 11) - pnGoerli, found = k.GetPendingNonces(ctx, tss.TssPubkey, chains.GoerliLocalnet.ChainId) + actualPendingNoncesGoerli, found = k.GetPendingNonces(ctx, tss.TssPubkey, chains.GoerliLocalnet.ChainId) require.True(t, found) - require.Equal(t, int64(2), pnGoerli.NonceLow) - require.Equal(t, int64(10), pnGoerli.NonceHigh) + require.Equal(t, int64(2), actualPendingNoncesGoerli.NonceLow) + require.Equal(t, int64(10), actualPendingNoncesGoerli.NonceHigh) //pending nonces for other chains should not be affected by removal for _, chainID := range chainIDS[1:] { - pn, found := k.GetPendingNonces(ctx, tss.TssPubkey, chainID) + pendingNonces, found := k.GetPendingNonces(ctx, tss.TssPubkey, chainID) require.True(t, found) - require.Equal(t, int64(1), pn.NonceLow) - require.Equal(t, int64(10), pn.NonceHigh) + require.Equal(t, int64(1), pendingNonces.NonceLow) + require.Equal(t, int64(10), pendingNonces.NonceHigh) } }) }