mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-04 02:53:45 +00:00
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
This commit is contained in:
parent
f4acb0ce04
commit
708dc59223
2 changed files with 23 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue