Skip to content

Commit

Permalink
copy DeploymentParams overrides before creating tree deployer (preven…
Browse files Browse the repository at this point in the history
…t the backing-array provided by the API user from being mutated). re-enable deployment-with-overrides test
  • Loading branch information
jwasinger committed Dec 23, 2024
1 parent c802765 commit 1e8be79
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
20 changes: 18 additions & 2 deletions accounts/abi/bind/dep_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
11 changes: 5 additions & 6 deletions accounts/abi/bind/v2/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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.)
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit 1e8be79

Please sign in to comment.