mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
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 <wangpeculiar@gmail.com>
This commit is contained in:
parent
dd198e0371
commit
23acecf6d8
1 changed files with 25 additions and 0 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue