Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Aug 2, 2024
1 parent 22f14ac commit 36daf8e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 26 deletions.
13 changes: 2 additions & 11 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions e2e/runner/trackers.go
Original file line number Diff line number Diff line change
@@ -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")
}
1 change: 1 addition & 0 deletions x/crosschain/types/cctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
30 changes: 15 additions & 15 deletions x/observer/keeper/pending_nonces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}

0 comments on commit 36daf8e

Please sign in to comment.