From 0df5b17df31b3b68948ba83cfa668d98b36964bc Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Wed, 5 Feb 2025 20:36:27 -0800 Subject: [PATCH] accounts/abi/bind/v2: simplify DefaultDeployer func signature --- accounts/abi/bind/v2/lib.go | 9 +-------- accounts/abi/bind/v2/lib_test.go | 19 ++++--------------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/accounts/abi/bind/v2/lib.go b/accounts/abi/bind/v2/lib.go index 919e277255..c7895b9141 100644 --- a/accounts/abi/bind/v2/lib.go +++ b/accounts/abi/bind/v2/lib.go @@ -17,7 +17,6 @@ package bind import ( - "context" "errors" "github.com/ethereum/go-ethereum" @@ -196,13 +195,7 @@ func DeployContract(opts *TransactOpts, bytecode []byte, backend ContractBackend // DefaultDeployer returns a DeployFn that signs and submits creation transactions // using the given signer. -func DefaultDeployer(ctx context.Context, from common.Address, backend ContractBackend, signer SignerFn) DeployFn { - opts := &TransactOpts{ - From: from, - Nonce: nil, - Signer: signer, - Context: ctx, - } +func DefaultDeployer(opts *TransactOpts, backend ContractBackend) DeployFn { return func(input []byte, deployer []byte) (common.Address, *types.Transaction, error) { addr, tx, err := DeployContract(opts, deployer, backend, input) if err != nil { diff --git a/accounts/abi/bind/v2/lib_test.go b/accounts/abi/bind/v2/lib_test.go index d89e8b5387..5cbc0374b5 100644 --- a/accounts/abi/bind/v2/lib_test.go +++ b/accounts/abi/bind/v2/lib_test.go @@ -60,20 +60,9 @@ func testSetup() (*backends.SimulatedBackend, error) { return &bindBackend, nil } -func makeTestDeployer(backend bind.ContractBackend) func(input, deployer []byte) (common.Address, *types.Transaction, error) { - signer := types.LatestSigner(params.AllDevChainProtocolChanges) - sign := func(sender common.Address, tx *types.Transaction) (*types.Transaction, error) { - signature, err := crypto.Sign(signer.Hash(tx).Bytes(), testKey) - if err != nil { - return nil, err - } - signedTx, err := tx.WithSignature(signer, signature) - if err != nil { - return nil, err - } - return signedTx, nil - } - return bind.DefaultDeployer(context.Background(), testAddr, backend, sign) +func makeTestDeployer(backend simulated.Client) func(input, deployer []byte) (common.Address, *types.Transaction, error) { + chainId, _ := backend.ChainID(context.Background()) + return bind.DefaultDeployer(bind.NewKeyedTransactor(testKey, chainId), backend) } // test that deploying a contract with library dependencies works, @@ -91,7 +80,7 @@ func TestDeploymentLibraries(t *testing.T) { Contracts: []*bind.MetaData{&nested_libraries.C1MetaData}, Inputs: map[string][]byte{nested_libraries.C1MetaData.ID: constructorInput}, } - res, err := bind.LinkAndDeploy(deploymentParams, makeTestDeployer(bindBackend)) + res, err := bind.LinkAndDeploy(deploymentParams, makeTestDeployer(bindBackend.Client)) if err != nil { t.Fatalf("err: %+v\n", err) }