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