Skip to content

Commit

Permalink
refactor: add context timeout to integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrekucci committed Nov 13, 2024
1 parent 2d5c017 commit 813ce6f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion bridge/standard/pkg/transfer/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,15 @@ func NewTransferToL1(
}, nil
}

func (t *Transfer) Do(ctx context.Context) <-chan TransferStatus {
func (t *Transfer) Do(pctx context.Context) <-chan TransferStatus {
statusChan := make(chan TransferStatus)
go func() {
defer close(statusChan)

statusChan <- TransferStatus{Message: "Setting up initial transfer..."}

ctx, cancel := context.WithTimeout(pctx, 5*time.Minute)
defer cancel()
opts, err := t.signer.GetAuthWithCtx(ctx, t.srcChainID)
if err != nil {
statusChan <- TransferStatus{
Expand Down Expand Up @@ -194,6 +196,8 @@ func (t *Transfer) Do(ctx context.Context) <-chan TransferStatus {
Message: fmt.Sprintf("Transfer initiated with hash %s. Waiting for it to be mined...", tx.Hash().Hex()),
}

ctx, cancel = context.WithTimeout(pctx, 5*time.Minute)
defer cancel()
receipt, err := bind.WaitMined(ctx, t.srcClient, tx)
if err != nil {
statusChan <- TransferStatus{
Expand Down Expand Up @@ -235,6 +239,8 @@ func (t *Transfer) Do(ctx context.Context) <-chan TransferStatus {
Message: "Waiting for transfer to be finalized...",
}

ctx, cancel = context.WithTimeout(pctx, 5*time.Minute)
defer cancel()
switch err := t.destFilterer.WaitForTransferFinalized(ctx, t.destInitialBlock, transferIdx); {
case err == nil:
statusChan <- TransferStatus{Message: "Transfer finalized. Bridging complete."}
Expand Down

0 comments on commit 813ce6f

Please sign in to comment.