fix flaky test TestDeploymentWithOverrides

This commit is contained in:
steven 2025-07-14 19:17:15 +08:00
parent 90a098904f
commit afdbefebe4
No known key found for this signature in database

View file

@ -27,7 +27,10 @@
package bind package bind
import ( import (
"context"
"errors" "errors"
"fmt"
"time"
"github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi"
@ -224,7 +227,28 @@ func DeployContract(opts *TransactOpts, bytecode []byte, backend ContractBackend
if err != nil { if err != nil {
return common.Address{}, nil, err return common.Address{}, nil, err
} }
return crypto.CreateAddress(opts.From, tx.Nonce()), tx, nil
addr := crypto.CreateAddress(opts.From, tx.Nonce())
ctx, cancel := context.WithTimeout(opts.Context, 5*time.Second)
defer cancel()
ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return common.Address{}, nil, fmt.Errorf("contract deployment timeout at %s", addr.Hex())
case <-ticker.C:
code, err := c.transactor.PendingCodeAt(ensureContext(ctx), addr)
if err != nil {
return common.Address{}, nil, err
}
if len(code) != 0 {
return addr, tx, nil
}
}
}
} }
// DefaultDeployer returns a DeployFn that signs and submits creation transactions // DefaultDeployer returns a DeployFn that signs and submits creation transactions