mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-29 08:03:48 +00:00
make DeploymentParams fields private. instantiate it with a constructor method
This commit is contained in:
parent
484c723a0c
commit
f90a88e85a
3 changed files with 29 additions and 37 deletions
|
|
@ -11,13 +11,22 @@ import (
|
|||
// set of contracts. It takes an optional override
|
||||
// list to specify contracts/libraries that have already been deployed on-chain.
|
||||
type DeploymentParams struct {
|
||||
Contracts []*MetaData
|
||||
contracts []*MetaData
|
||||
// map of solidity library pattern to constructor input.
|
||||
Inputs map[string][]byte
|
||||
inputs map[string][]byte
|
||||
// Overrides is an optional map of pattern to deployment address.
|
||||
// Contracts/libraries that refer to dependencies in the override
|
||||
// set are linked to the provided address (an already-deployed contract).
|
||||
Overrides map[string]common.Address
|
||||
overrides map[string]common.Address
|
||||
}
|
||||
|
||||
// NewDeploymentParams instantiates a DeploymentParams instance.
|
||||
func NewDeploymentParams(contracts []*MetaData, inputs map[string][]byte, overrides map[string]common.Address) *DeploymentParams {
|
||||
return &DeploymentParams{
|
||||
contracts,
|
||||
inputs,
|
||||
overrides,
|
||||
}
|
||||
}
|
||||
|
||||
// DeploymentResult encapsulates information about the result of the deployment
|
||||
|
|
@ -203,22 +212,22 @@ func newDepTreeDeployer(deploy DeployFn) *depTreeDeployer {
|
|||
// LinkAndDeploy deploys a specified set of contracts and their dependent
|
||||
// libraries. If an error occurs, only contracts which were successfully
|
||||
// deployed are returned in the result.
|
||||
func LinkAndDeploy(deployParams DeploymentParams, deploy DeployFn) (res *DeploymentResult, err error) {
|
||||
func LinkAndDeploy(deployParams *DeploymentParams, deploy DeployFn) (res *DeploymentResult, err error) {
|
||||
unlinkedContracts := make(map[string]string)
|
||||
accumRes := &DeploymentResult{
|
||||
Txs: make(map[string]*types.Transaction),
|
||||
Addrs: make(map[string]common.Address),
|
||||
}
|
||||
for _, meta := range deployParams.Contracts {
|
||||
for _, meta := range deployParams.contracts {
|
||||
unlinkedContracts[meta.Pattern] = meta.Bin[2:]
|
||||
}
|
||||
treeBuilder := newDepTreeBuilder(deployParams.Overrides, unlinkedContracts)
|
||||
treeBuilder := newDepTreeBuilder(deployParams.overrides, unlinkedContracts)
|
||||
deps, _ := treeBuilder.BuildDepTrees()
|
||||
|
||||
for _, tr := range deps {
|
||||
deployer := newDepTreeDeployer(deploy)
|
||||
if deployParams.Inputs != nil {
|
||||
deployer.input = map[string][]byte{tr.pattern: deployParams.Inputs[tr.pattern]}
|
||||
if deployParams.inputs != nil {
|
||||
deployer.input = map[string][]byte{tr.pattern: deployParams.inputs[tr.pattern]}
|
||||
}
|
||||
err := deployer.linkAndDeploy(tr)
|
||||
res := deployer.result()
|
||||
|
|
|
|||
|
|
@ -138,25 +138,24 @@ func testLinkCase(t *testing.T, tcInput linkTestCaseInput) {
|
|||
return contractAddr, nil, nil
|
||||
}
|
||||
|
||||
var (
|
||||
deployParams DeploymentParams
|
||||
)
|
||||
var contracts []*MetaData
|
||||
overrides := make(map[string]common.Address)
|
||||
|
||||
for pattern, bin := range tc.contractCodes {
|
||||
deployParams.Contracts = append(deployParams.Contracts, &MetaData{Pattern: pattern, Bin: "0x" + bin})
|
||||
contracts = append(contracts, &MetaData{Pattern: pattern, Bin: "0x" + bin})
|
||||
}
|
||||
for pattern, bin := range tc.libCodes {
|
||||
deployParams.Contracts = append(deployParams.Contracts, &MetaData{
|
||||
contracts = append(contracts, &MetaData{
|
||||
Bin: "0x" + bin,
|
||||
Pattern: pattern,
|
||||
})
|
||||
}
|
||||
|
||||
overridePatterns := make(map[string]common.Address)
|
||||
for pattern, override := range tc.overrides {
|
||||
overridePatterns[pattern] = override
|
||||
overrides[pattern] = override
|
||||
}
|
||||
deployParams.Overrides = overridePatterns
|
||||
|
||||
deployParams := NewDeploymentParams(contracts, nil, overrides)
|
||||
res, err := LinkAndDeploy(deployParams, mockDeploy)
|
||||
if err != nil {
|
||||
t.Fatalf("got error from LinkAndDeploy: %v\n", err)
|
||||
|
|
|
|||
|
|
@ -121,11 +121,7 @@ func TestDeploymentLibraries(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("failed to pack constructor: %v", err)
|
||||
}
|
||||
deploymentParams := bind.DeploymentParams{
|
||||
Contracts: append(nested_libraries.C1LibraryDeps, nested_libraries.C1MetaData),
|
||||
Inputs: map[string][]byte{nested_libraries.C1MetaData.Pattern: constructorInput},
|
||||
Overrides: nil,
|
||||
}
|
||||
deploymentParams := bind.NewDeploymentParams(append(nested_libraries.C1LibraryDeps, nested_libraries.C1MetaData), map[string][]byte{nested_libraries.C1MetaData.Pattern: constructorInput}, nil)
|
||||
|
||||
res, err := bind.LinkAndDeploy(deploymentParams, makeTestDeployer(opts, bindBackend))
|
||||
if err != nil {
|
||||
|
|
@ -180,9 +176,7 @@ func TestDeploymentWithOverrides(t *testing.T) {
|
|||
defer bindBackend.Backend.Close()
|
||||
|
||||
// deploy some library deps
|
||||
deploymentParams := bind.DeploymentParams{
|
||||
Contracts: nested_libraries.C1LibraryDeps,
|
||||
}
|
||||
deploymentParams := bind.NewDeploymentParams(nested_libraries.C1LibraryDeps, nil, nil)
|
||||
|
||||
res, err := bind.LinkAndDeploy(deploymentParams, makeTestDeployer(opts, bindBackend))
|
||||
if err != nil {
|
||||
|
|
@ -210,11 +204,7 @@ func TestDeploymentWithOverrides(t *testing.T) {
|
|||
}
|
||||
overrides := res.Addrs
|
||||
// deploy the contract
|
||||
deploymentParams = bind.DeploymentParams{
|
||||
Contracts: []*bind.MetaData{nested_libraries.C1MetaData},
|
||||
Inputs: map[string][]byte{nested_libraries.C1MetaData.Pattern: constructorInput},
|
||||
Overrides: overrides,
|
||||
}
|
||||
deploymentParams = bind.NewDeploymentParams([]*bind.MetaData{nested_libraries.C1MetaData}, map[string][]byte{nested_libraries.C1MetaData.Pattern: constructorInput}, overrides)
|
||||
res, err = bind.LinkAndDeploy(deploymentParams, makeTestDeployer(opts, bindBackend))
|
||||
if err != nil {
|
||||
t.Fatalf("err: %+v\n", err)
|
||||
|
|
@ -271,10 +261,7 @@ func TestEvents(t *testing.T) {
|
|||
t.Fatalf("error setting up testing env: %v", err)
|
||||
}
|
||||
|
||||
deploymentParams := bind.DeploymentParams{
|
||||
Contracts: []*bind.MetaData{events.CMetaData},
|
||||
}
|
||||
|
||||
deploymentParams := bind.NewDeploymentParams([]*bind.MetaData{events.CMetaData}, nil, nil)
|
||||
res, err := bind.LinkAndDeploy(deploymentParams, makeTestDeployer(txAuth, backend))
|
||||
if err != nil {
|
||||
t.Fatalf("error deploying contract for testing: %v", err)
|
||||
|
|
@ -385,10 +372,7 @@ func TestErrors(t *testing.T) {
|
|||
t.Fatalf("error setting up testing env: %v", err)
|
||||
}
|
||||
|
||||
deploymentParams := bind.DeploymentParams{
|
||||
Contracts: []*bind.MetaData{solc_errors.CMetaData},
|
||||
}
|
||||
|
||||
deploymentParams := bind.NewDeploymentParams([]*bind.MetaData{solc_errors.CMetaData}, nil, nil)
|
||||
res, err := bind.LinkAndDeploy(deploymentParams, makeTestDeployer(txAuth, backend))
|
||||
if err != nil {
|
||||
t.Fatalf("error deploying contract for testing: %v", err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue