Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add wait for block to tss migration test #2931

Merged
merged 5 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions e2e/e2etests/test_migrate_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func TestMigrateTSS(r *runner.E2ERunner, _ []string) {
btcBalance = btcBalance - 0.01
btcChain := chains.BitcoinRegtest.ChainId

r.WaitForTSSGeneration(2)

//migrate btc funds
// #nosec G701 e2eTest - always in range
migrationAmountBTC := sdkmath.NewUint(uint64(btcBalance * 1e8))
Expand Down
29 changes: 29 additions & 0 deletions e2e/runner/zeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ import (
"github.com/zeta-chain/node/e2e/utils"
"github.com/zeta-chain/node/pkg/retry"
"github.com/zeta-chain/node/x/crosschain/types"
observertypes "github.com/zeta-chain/node/x/observer/types"
)

// WaitForBlocks waits for a specific number of blocks to be generated
// The parameter n is the number of blocks to wait for
func (r *E2ERunner) WaitForBlocks(n int64) {
height, err := r.CctxClient.LastZetaHeight(r.Ctx, &types.QueryLastZetaHeightRequest{})
if err != nil {
Expand All @@ -31,6 +34,32 @@ func (r *E2ERunner) WaitForBlocks(n int64) {
err = retry.DoWithBackoff(call, boWithMaxRetries)
require.NoError(r, err, "failed to wait for %d blocks", n)
}

// WaitForTSSGeneration waits for a specific number of TSS to be generated
// The parameter n is the number of TSS to wait for
func (r *E2ERunner) WaitForTSSGeneration(tssNumber int64) {
call := func() error {
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
return retry.Retry(r.checkNumberOfTSSGenerated(tssNumber))
}
bo := backoff.NewConstantBackOff(time.Second * 5)
boWithMaxRetries := backoff.WithMaxRetries(bo, 10)
err := retry.DoWithBackoff(call, boWithMaxRetries)
require.NoError(r, err, "failed to wait for %d tss generation", tssNumber)
}

// checkNumberOfTSSGenerated checks the number of TSS generated
// if the number of tss is less that the `tssNumber` provided we return an error
func (r *E2ERunner) checkNumberOfTSSGenerated(tssNumber int64) error {
tssList, err := r.ObserverClient.TssHistory(r.Ctx, &observertypes.QueryTssHistoryRequest{})
if err != nil {
return err
}
if int64(len(tssList.TssList)) < tssNumber {
return fmt.Errorf("waiting for %d tss generation, number of TSS :%d", tssNumber, len(tssList.TssList))
}
return nil
}

func (r *E2ERunner) waitForBlock(n int64) error {
height, err := r.CctxClient.LastZetaHeight(r.Ctx, &types.QueryLastZetaHeightRequest{})
if err != nil {
Expand Down
Loading