From 23acecf6d89763ba1ea1d851065e8c09b8e56df5 Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Sat, 13 Sep 2025 09:50:19 +0800 Subject: [PATCH] account/abi/bind/v2: fix TestDeploymentWithOverrides #32212 (#1426) The root cause of the flaky test was a nonce conflict caused by async contract deployments. This solution defines a custom deployer with automatic nonce management. Co-authored-by: steven --- accounts/abi/bind/v2/lib.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/accounts/abi/bind/v2/lib.go b/accounts/abi/bind/v2/lib.go index 16e2bcbde1..36252cbc6d 100644 --- a/accounts/abi/bind/v2/lib.go +++ b/accounts/abi/bind/v2/lib.go @@ -28,6 +28,7 @@ package bind import ( "errors" + "math/big" ethereum "github.com/XinFinOrg/XDPoSChain" "github.com/XinFinOrg/XDPoSChain/accounts/abi" @@ -241,3 +242,27 @@ func DefaultDeployer(opts *TransactOpts, backend ContractBackend) DeployFn { return addr, tx, nil } } + +// DeployerWithNonceAssignment is basically identical to DefaultDeployer, +// but it additionally tracks the nonce to enable automatic assignment. +// +// This is especially useful when deploying multiple contracts +// from the same address — whether they are independent contracts +// or part of a dependency chain that must be deployed in order. +func DeployerWithNonceAssignment(opts *TransactOpts, backend ContractBackend) DeployFn { + var pendingNonce int64 + if opts.Nonce != nil { + pendingNonce = opts.Nonce.Int64() + } + return func(input []byte, deployer []byte) (common.Address, *types.Transaction, error) { + if pendingNonce != 0 { + opts.Nonce = big.NewInt(pendingNonce) + } + addr, tx, err := DeployContract(opts, deployer, backend, input) + if err != nil { + return common.Address{}, nil, err + } + pendingNonce = int64(tx.Nonce() + 1) + return addr, tx, nil + } +}