mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-16 08:53:46 +00:00
closer to test passing now...
This commit is contained in:
parent
5ba939f50c
commit
7c95aa1411
3 changed files with 36 additions and 9 deletions
|
|
@ -38,12 +38,13 @@ var (
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{range $contract := .Contracts}}
|
{{range $contract := .Contracts}}
|
||||||
var {{$contract.Type}}LibraryDeps = map[string]string{
|
var {{$contract.Type}}LibraryDeps = map[string]*bind.MetaData{
|
||||||
{{range $name, $pattern := .AllLibraries -}}
|
{{range $name, $pattern := .AllLibraries -}}
|
||||||
"{{$name}}": "{{$pattern}}",
|
"{{$pattern}}": {{$name}}MetaData,
|
||||||
{{ end}}
|
{{ end}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: convert this type to value type after everything works.
|
||||||
// {{.Type}}MetaData contains all meta data concerning the {{.Type}} contract.
|
// {{.Type}}MetaData contains all meta data concerning the {{.Type}} contract.
|
||||||
var {{.Type}}MetaData = &bind.MetaData{
|
var {{.Type}}MetaData = &bind.MetaData{
|
||||||
ABI: "{{.InputABI}}",
|
ABI: "{{.InputABI}}",
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,11 @@ func deployContract(backend bind.ContractBackend, auth *bind.TransactOpts, const
|
||||||
return tx, addr, nil
|
return tx, addr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func deployLibs(backend bind.ContractBackend, auth *bind.TransactOpts, contracts map[string]string) (deploymentTxs map[common.Address]*types.Transaction, deployAddrs map[common.Address]struct{}, err error) {
|
func deployLibs(backend bind.ContractBackend, auth *bind.TransactOpts, contracts map[string]string) (deploymentTxs map[common.Address]*types.Transaction, deployAddrs map[string]common.Address, err error) {
|
||||||
for _, contractBin := range contracts {
|
deploymentTxs = make(map[common.Address]*types.Transaction)
|
||||||
|
deployAddrs = make(map[string]common.Address)
|
||||||
|
|
||||||
|
for pattern, contractBin := range contracts {
|
||||||
contractBinBytes, err := hex.DecodeString(contractBin[2:])
|
contractBinBytes, err := hex.DecodeString(contractBin[2:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return deploymentTxs, deployAddrs, fmt.Errorf("contract bytecode is not a hex string: %s", contractBin[2:])
|
return deploymentTxs, deployAddrs, fmt.Errorf("contract bytecode is not a hex string: %s", contractBin[2:])
|
||||||
|
|
@ -42,7 +45,7 @@ func deployLibs(backend bind.ContractBackend, auth *bind.TransactOpts, contracts
|
||||||
return deploymentTxs, deployAddrs, fmt.Errorf("failed to deploy contract: %v", err)
|
return deploymentTxs, deployAddrs, fmt.Errorf("failed to deploy contract: %v", err)
|
||||||
}
|
}
|
||||||
deploymentTxs[addr] = tx
|
deploymentTxs[addr] = tx
|
||||||
deployAddrs[addr] = struct{}{}
|
deployAddrs[pattern] = addr
|
||||||
}
|
}
|
||||||
|
|
||||||
return deploymentTxs, deployAddrs, nil
|
return deploymentTxs, deployAddrs, nil
|
||||||
|
|
@ -58,7 +61,7 @@ func linkContract(contract string, linkedLibs map[string]common.Address) (deploy
|
||||||
for _, match := range reMatchSpecificPattern.FindAllStringSubmatch(contract, -1) {
|
for _, match := range reMatchSpecificPattern.FindAllStringSubmatch(contract, -1) {
|
||||||
matchingPattern := match[1]
|
matchingPattern := match[1]
|
||||||
addr := linkedLibs[matchingPattern]
|
addr := linkedLibs[matchingPattern]
|
||||||
contract = strings.ReplaceAll(contract, matchingPattern, addr.String())
|
contract = strings.ReplaceAll(contract, "__$"+matchingPattern+"$__", addr.String()[2:])
|
||||||
}
|
}
|
||||||
return contract, nil
|
return contract, nil
|
||||||
}
|
}
|
||||||
|
|
@ -75,17 +78,22 @@ func linkLibs(deps *map[string]string, linked *map[string]common.Address) (deplo
|
||||||
deployableDeps = make(map[string]string)
|
deployableDeps = make(map[string]string)
|
||||||
|
|
||||||
for pattern, dep := range *deps {
|
for pattern, dep := range *deps {
|
||||||
|
fmt.Printf("dep is:\n%s\n", dep)
|
||||||
|
fmt.Println(pattern)
|
||||||
// attempt to replace references to every single linked dep
|
// attempt to replace references to every single linked dep
|
||||||
for _, match := range reMatchSpecificPattern.FindAllStringSubmatch(dep, -1) {
|
for _, match := range reMatchSpecificPattern.FindAllStringSubmatch(dep, -1) {
|
||||||
matchingPattern := match[1]
|
matchingPattern := match[1]
|
||||||
|
fmt.Printf("has matching pattern %s\n", matchingPattern)
|
||||||
addr, ok := (*linked)[matchingPattern]
|
addr, ok := (*linked)[matchingPattern]
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
(*deps)[pattern] = strings.ReplaceAll(dep, matchingPattern, addr.String())
|
(*deps)[pattern] = strings.ReplaceAll(dep, "__$"+matchingPattern+"$__", addr.String()[2:])
|
||||||
|
fmt.Printf("lib after linking:\n%s\n", (*deps)[pattern])
|
||||||
}
|
}
|
||||||
// if we linked something into this dep, see if it can be deployed
|
// if we linked something into this dep, see if it can be deployed
|
||||||
if !reMatchAnyPattern.MatchString((*deps)[pattern]) {
|
if !reMatchAnyPattern.MatchString((*deps)[pattern]) {
|
||||||
|
fmt.Printf("is deployable %s\n", pattern)
|
||||||
deployableDeps[pattern] = (*deps)[pattern]
|
deployableDeps[pattern] = (*deps)[pattern]
|
||||||
delete(*deps, pattern)
|
delete(*deps, pattern)
|
||||||
}
|
}
|
||||||
|
|
@ -94,8 +102,18 @@ func linkLibs(deps *map[string]string, linked *map[string]common.Address) (deplo
|
||||||
return deployableDeps
|
return deployableDeps
|
||||||
}
|
}
|
||||||
|
|
||||||
func LinkAndDeployContractWithOverrides(auth *bind.TransactOpts, backend bind.ContractBackend, constructorInputs []byte, contract *bind.MetaData, libs map[string]string, overrides map[string]common.Address) (allDeployTxs map[common.Address]*types.Transaction, allDeployAddrs map[common.Address]struct{}, err error) {
|
func LinkAndDeployContractWithOverrides(auth *bind.TransactOpts, backend bind.ContractBackend, constructorInputs []byte, contract *bind.MetaData, libMetas map[string]*bind.MetaData, overrides map[string]common.Address) (allDeployTxs map[common.Address]*types.Transaction, allDeployAddrs map[common.Address]struct{}, err error) {
|
||||||
// initialize the set of already-deployed contracts with given override addresses
|
// initialize the set of already-deployed contracts with given override addresses
|
||||||
|
|
||||||
|
allDeployAddrs = make(map[common.Address]struct{})
|
||||||
|
allDeployTxs = make(map[common.Address]*types.Transaction)
|
||||||
|
|
||||||
|
// re-express libraries as a map of pattern -> pre-linking binary
|
||||||
|
libs := make(map[string]string)
|
||||||
|
for pattern, meta := range libMetas {
|
||||||
|
libs[pattern] = meta.Bin
|
||||||
|
}
|
||||||
|
|
||||||
linked := make(map[string]common.Address)
|
linked := make(map[string]common.Address)
|
||||||
for pattern, deployAddr := range overrides {
|
for pattern, deployAddr := range overrides {
|
||||||
linked[pattern] = deployAddr
|
linked[pattern] = deployAddr
|
||||||
|
|
@ -111,8 +129,10 @@ func LinkAndDeployContractWithOverrides(auth *bind.TransactOpts, backend bind.Co
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
deployTxs, deployAddrs, err := deployLibs(backend, auth, deployableDeps)
|
deployTxs, deployAddrs, err := deployLibs(backend, auth, deployableDeps)
|
||||||
for addr, _ := range deployAddrs {
|
for pattern, addr := range deployAddrs {
|
||||||
allDeployAddrs[addr] = struct{}{}
|
allDeployAddrs[addr] = struct{}{}
|
||||||
|
linked[pattern] = addr
|
||||||
|
fmt.Printf("we've linked %s\n", pattern)
|
||||||
}
|
}
|
||||||
for addr, tx := range deployTxs {
|
for addr, tx := range deployTxs {
|
||||||
allDeployTxs[addr] = tx
|
allDeployTxs[addr] = tx
|
||||||
|
|
|
||||||
|
|
@ -165,6 +165,12 @@ func TestDeployment(t *testing.T) {
|
||||||
|
|
||||||
// TODO: add public interface for deploy library, deploy contract (or make them same method?)
|
// TODO: add public interface for deploy library, deploy contract (or make them same method?)
|
||||||
// want to allow more flexibility.
|
// want to allow more flexibility.
|
||||||
|
|
||||||
|
// also, i kind of hate this conversion. But the API of LinkAndDeployContractWithOverrides feels cleaner this way... idk.
|
||||||
|
libMetas := make(map[string]*bind.MetaData)
|
||||||
|
for pattern, metadata := range v2_testcase_library.TestArrayLibraryDeps {
|
||||||
|
libMetas[pattern] = metadata
|
||||||
|
}
|
||||||
txs, _, err := LinkAndDeployContractWithOverrides(&opts, bindBackend, []byte{}, v2_testcase_library.TestArrayMetaData, v2_testcase_library.TestArrayLibraryDeps, nil)
|
txs, _, err := LinkAndDeployContractWithOverrides(&opts, bindBackend, []byte{}, v2_testcase_library.TestArrayMetaData, v2_testcase_library.TestArrayLibraryDeps, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %+v\n", err)
|
t.Fatalf("err: %+v\n", err)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue