From 1e8be7972afaeff2d8d5e0ae0729a63ec499149e Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 23 Dec 2024 17:23:25 +0700 Subject: [PATCH] copy DeploymentParams overrides before creating tree deployer (prevent the backing-array provided by the API user from being mutated). re-enable deployment-with-overrides test --- accounts/abi/bind/dep_tree.go | 20 ++++++++++++++++++-- accounts/abi/bind/v2/lib_test.go | 11 +++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/accounts/abi/bind/dep_tree.go b/accounts/abi/bind/dep_tree.go index d7c3bdca7801..c7b813d0be1e 100644 --- a/accounts/abi/bind/dep_tree.go +++ b/accounts/abi/bind/dep_tree.go @@ -56,11 +56,20 @@ type depTreeDeployer struct { } func newDepTreeDeployer(deployParams *DeploymentParams, deployFn DeployFn) *depTreeDeployer { + deployedAddrs := maps.Clone(deployParams.overrides) + if deployedAddrs == nil { + deployedAddrs = make(map[string]common.Address) + } + inputs := deployParams.inputs + if inputs == nil { + inputs = make(map[string][]byte) + } + return &depTreeDeployer{ deployFn: deployFn, - deployedAddrs: maps.Clone(deployParams.overrides), + deployedAddrs: deployedAddrs, deployerTxs: make(map[string]*types.Transaction), - inputs: maps.Clone(deployParams.inputs), + inputs: inputs, } } @@ -97,6 +106,12 @@ func (d *depTreeDeployer) linkAndDeploy(metadata *MetaData) (common.Address, err // result returns a result for this deployment, or an error if it failed. func (d *depTreeDeployer) result() *DeploymentResult { + // remove the override addresses from the resulting deployedAddrs + for pattern, _ := range d.deployedAddrs { + if _, ok := d.deployerTxs[pattern]; !ok { + delete(d.deployedAddrs, pattern) + } + } return &DeploymentResult{ Txs: d.deployerTxs, Addrs: d.deployedAddrs, @@ -108,6 +123,7 @@ func (d *depTreeDeployer) result() *DeploymentResult { // deployed are returned in the result. func LinkAndDeploy(deployParams *DeploymentParams, deploy DeployFn) (res *DeploymentResult, err error) { deployer := newDepTreeDeployer(deployParams, deploy) + deployParams.inputs = make(map[string][]byte) for _, contract := range deployParams.contracts { if _, err := deployer.linkAndDeploy(contract); err != nil { return deployer.result(), err diff --git a/accounts/abi/bind/v2/lib_test.go b/accounts/abi/bind/v2/lib_test.go index 6c67bc932c62..1bd8104b144b 100644 --- a/accounts/abi/bind/v2/lib_test.go +++ b/accounts/abi/bind/v2/lib_test.go @@ -166,7 +166,6 @@ func TestDeploymentLibraries(t *testing.T) { } } -/* // Same as TestDeployment. However, stagger the deployments with overrides: // first deploy the library deps and then the contract. func TestDeploymentWithOverrides(t *testing.T) { @@ -176,8 +175,8 @@ func TestDeploymentWithOverrides(t *testing.T) { } defer bindBackend.Backend.Close() - // deploy some library deps - deploymentParams := bind.NewDeploymentParams(nested_libraries.C1LibraryDeps, nil, nil) + // deploy all the library dependencies of our target contract, but not the target contract itself. + deploymentParams := bind.NewDeploymentParams(nested_libraries.C1MetaData.Deps, nil, nil) res, err := bind.LinkAndDeploy(deploymentParams, makeTestDeployer(opts, bindBackend)) if err != nil { @@ -195,6 +194,7 @@ func TestDeploymentWithOverrides(t *testing.T) { } } + // TODO: constructor input packing should not return an error. ctrct, err := nested_libraries.NewC1() if err != nil { panic(err) @@ -254,7 +254,6 @@ func TestDeploymentWithOverrides(t *testing.T) { t.Fatalf("expected internal call count of 6. got %d.", internalCallCount.Uint64()) } } -*/ func TestEvents(t *testing.T) { // test watch/filter logs method on a contract that emits various kinds of events (struct-containing, etc.) @@ -412,7 +411,7 @@ func TestErrors(t *testing.T) { // TestBindingGeneration tests that re-running generation of bindings does not result in mutations to the binding code func TestBindingGeneration(t *testing.T) { - matches, _ := filepath.Glob("internal/*") + matches, _ := filepath.Glob("internal/contracts/*") var dirs []string for _, match := range matches { f, _ := os.Stat(match) @@ -429,7 +428,7 @@ func TestBindingGeneration(t *testing.T) { sigs []map[string]string libs = make(map[string]string) ) - basePath := filepath.Join("internal", dir) + basePath := filepath.Join("internal/contracts", dir) combinedJsonPath := filepath.Join(basePath, "combined-abi.json") abiBytes, err := os.ReadFile(combinedJsonPath) if err != nil {