From afdbefebe418f31d24fb6d29f2a39b6547ee9c95 Mon Sep 17 00:00:00 2001 From: steven Date: Mon, 14 Jul 2025 19:17:15 +0800 Subject: [PATCH] fix flaky test TestDeploymentWithOverrides --- accounts/abi/bind/v2/lib.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/accounts/abi/bind/v2/lib.go b/accounts/abi/bind/v2/lib.go index 3831161341..56b6d999a3 100644 --- a/accounts/abi/bind/v2/lib.go +++ b/accounts/abi/bind/v2/lib.go @@ -27,7 +27,10 @@ package bind import ( + "context" "errors" + "fmt" + "time" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi" @@ -224,7 +227,28 @@ func DeployContract(opts *TransactOpts, bytecode []byte, backend ContractBackend if err != nil { 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