update library test contract to have constructor with inputs. remove some debug print statements
This commit is contained in:
parent
42d159fb9a
commit
41b77f9d9c
|
@ -76,7 +76,7 @@ var (
|
|||
// TODO: create custom exported types where unpack would generate a struct return.
|
||||
|
||||
// TODO: test constructor with inputs
|
||||
func (_{{$contract.Type}} *{{$contract.Type}}) PackConstructor({{range .Constructor.Inputs}} {{.Name}} {{bindtype .Type $structs}} {{end}}) ([]byte, error) {
|
||||
func (_{{$contract.Type}} *{{$contract.Type}}) PackConstructor({{range .Constructor.Inputs}} {{.Name}} {{bindtype .Type $structs}}, {{end}}) ([]byte, error) {
|
||||
return _{{$contract.Type}}.abi.Pack("" {{range .Constructor.Inputs}}, {{.Name}}{{end}})
|
||||
}
|
||||
|
||||
|
|
|
@ -37,4 +37,9 @@ contract TestArray {
|
|||
assert(arr[0] == 0);
|
||||
assert(arr[1] == 2);
|
||||
}
|
||||
|
||||
// a constructor with parameters
|
||||
constructor(uint256 foo) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ func deployContract(backend bind.ContractBackend, auth *bind.TransactOpts, const
|
|||
if err != nil {
|
||||
return nil, common.Address{}, fmt.Errorf("contract bytecode is not a hex string: %s", contractBinBytes[2:])
|
||||
}
|
||||
fmt.Println("before DeployContractRaw")
|
||||
addr, tx, _, err := bind.DeployContractRaw(auth, contractBinBytes, backend, constructor)
|
||||
if err != nil {
|
||||
return nil, common.Address{}, fmt.Errorf("failed to deploy contract: %v", err)
|
||||
|
@ -79,42 +78,35 @@ func linkLibs(deps *map[string]string, linked *map[string]common.Address) (deplo
|
|||
deployableDeps = make(map[string]string)
|
||||
|
||||
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
|
||||
for _, match := range reMatchSpecificPattern.FindAllStringSubmatch(dep, -1) {
|
||||
matchingPattern := match[1]
|
||||
fmt.Printf("has matching pattern %s\n", matchingPattern)
|
||||
addr, ok := (*linked)[matchingPattern]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
(*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 !reMatchAnyPattern.MatchString((*deps)[pattern]) {
|
||||
fmt.Printf("is deployable %s\n", pattern)
|
||||
deployableDeps[pattern] = (*deps)[pattern]
|
||||
delete(*deps, pattern)
|
||||
}
|
||||
}
|
||||
|
||||
return deployableDeps
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
allDeployAddrs = make(map[common.Address]struct{})
|
||||
allDeployTxs = make(map[common.Address]*types.Transaction)
|
||||
|
||||
// re-express libraries as a map of pattern -> pre-linking binary
|
||||
// re-express libraries as a map of pattern -> pre-link binary
|
||||
libs := make(map[string]string)
|
||||
for pattern, meta := range libMetas {
|
||||
libs[pattern] = meta.Bin
|
||||
}
|
||||
|
||||
// initialize the set of already-deployed contracts with given override addresses
|
||||
linked := make(map[string]common.Address)
|
||||
for pattern, deployAddr := range overrides {
|
||||
linked[pattern] = deployAddr
|
||||
|
@ -133,7 +125,6 @@ func LinkAndDeployContractWithOverrides(auth *bind.TransactOpts, backend bind.Co
|
|||
for pattern, addr := range deployAddrs {
|
||||
allDeployAddrs[addr] = struct{}{}
|
||||
linked[pattern] = addr
|
||||
fmt.Printf("we've linked %s\n", pattern)
|
||||
}
|
||||
for addr, tx := range deployTxs {
|
||||
allDeployTxs[addr] = tx
|
||||
|
|
|
@ -169,8 +169,16 @@ func TestDeployment(t *testing.T) {
|
|||
libMetas[pattern] = metadata
|
||||
}
|
||||
|
||||
ctrct, err := v2_testcase_library.NewTestArray()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
constructorInput, err := ctrct.PackConstructor(big.NewInt(42), false)
|
||||
if err != nil {
|
||||
t.Fatalf("fack %v", err)
|
||||
}
|
||||
// TODO: test case with arguments-containing constructor
|
||||
txs, _, err := LinkAndDeployContractWithOverrides(&opts, bindBackend, []byte{}, v2_testcase_library.TestArrayMetaData, v2_testcase_library.TestArrayLibraryDeps, nil)
|
||||
txs, _, err := LinkAndDeployContractWithOverrides(&opts, bindBackend, constructorInput, v2_testcase_library.TestArrayMetaData, v2_testcase_library.TestArrayLibraryDeps, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %+v\n", err)
|
||||
}
|
||||
|
|
|
@ -243,7 +243,6 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
|
|||
// Get the operation from the jump table and validate the stack to ensure there are
|
||||
// enough stack items available to perform the operation.
|
||||
op = contract.GetOp(pc)
|
||||
fmt.Printf("op name is: %s\n", op.String())
|
||||
operation := in.table[op]
|
||||
cost = operation.constantGas // For tracing
|
||||
// Validate stack
|
||||
|
|
Loading…
Reference in New Issue