add missing files from testdata. refactor contract deployment API to be cleaner

This commit is contained in:
Jared Wasinger 2024-11-26 15:54:18 +07:00 committed by Felix Lange
parent 03a6ade16b
commit b2aec5af41
16 changed files with 990 additions and 84 deletions

View File

@ -89,11 +89,12 @@ type WatchOpts struct {
// MetaData collects all metadata for a bound contract.
type MetaData struct {
mu sync.Mutex
Sigs map[string]string
Bin string
ABI string
ab *abi.ABI
mu sync.Mutex
Sigs map[string]string
Bin string
ABI string
ab *abi.ABI
Pattern string
}
func (m *MetaData) GetAbi() (*abi.ABI, error) {

View File

@ -101,6 +101,7 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
func BindV2(types []string, abis []string, bytecodes []string, fsigs []map[string]string, pkg string, libs map[string]string, aliases map[string]string) (string, error) {
data, err := bind(types, abis, bytecodes, fsigs, pkg, libs, aliases)
if err != nil {
return "", err
}
@ -396,12 +397,21 @@ func bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
}
}
// map of contract name -> pattern
invertedLibs := make(map[string]string)
// assume that this is invertible/onto because I assume library names are unique now
// TODO: check that they've been sanitized at this point.
for pattern, name := range libs {
invertedLibs[name] = pattern
}
// Generate the contract template data content and render it
data := &tmplData{
Package: pkg,
Contracts: contracts,
Libraries: libs,
Structs: structs,
Package: pkg,
Contracts: contracts,
Libraries: libs,
InvertedLibs: invertedLibs,
Structs: structs,
}
return data, nil
}

View File

@ -24,10 +24,11 @@ import (
// tmplData is the data structure required to fill the binding template.
type tmplData struct {
Package string // Name of the package to place the generated file in
Contracts map[string]*tmplContract // List of contracts to generate into this file
Libraries map[string]string // Map the bytecode's link pattern to the library name
Structs map[string]*tmplStruct // Contract struct type definitions
Package string // Name of the package to place the generated file in
Contracts map[string]*tmplContract // List of contracts to generate into this file
Libraries map[string]string // Map the bytecode's link pattern to the library name
InvertedLibs map[string]string // map of the contract's name to the link pattern
Structs map[string]*tmplStruct // Contract struct type definitions
}
// tmplContract contains the data needed to generate an individual contract binding.

View File

@ -38,6 +38,7 @@ var (
{{end}}
{{range $contract := .Contracts}}
// TODO: turn this into a list, now that the pattern is embedded in each MetaData object
var {{$contract.Type}}LibraryDeps = map[string]*bind.MetaData{
{{range $name, $pattern := .AllLibraries -}}
"{{$pattern}}": {{$name}}MetaData,
@ -48,6 +49,7 @@ var (
// {{.Type}}MetaData contains all meta data concerning the {{.Type}} contract.
var {{.Type}}MetaData = &bind.MetaData{
ABI: "{{.InputABI}}",
Pattern: "{{index $.InvertedLibs .Type}}",
{{if $contract.FuncSigs -}}
Sigs: map[string]string{
{{range $strsig, $binsig := .FuncSigs}}"{{$binsig}}": "{{$strsig}}",

View File

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,501 @@
// Code generated via abigen V2 - DO NOT EDIT.
// This file is a generated binding and any manual changes will be lost.
package nested_libraries
import (
"errors"
"math/big"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
// Reference imports to suppress errors if they are not otherwise used.
var (
_ = errors.New
_ = big.NewInt
_ = bind.Bind
_ = common.Big1
_ = types.BloomLookup
_ = abi.ConvertType
)
// TODO: turn this into a list, now that the pattern is embedded in each MetaData object
var C1LibraryDeps = map[string]*bind.MetaData{
"ffc1393672b8ed81d0c8093ffcb0e7fbe8": L1MetaData,
"d03b97f5e1a564374023a72ac7d1806773": L3MetaData,
"d600bc30c225801bf5b413866ae334453d": L5MetaData,
}
// TODO: convert this type to value type after everything works.
// C1MetaData contains all meta data concerning the C1 contract.
var C1MetaData = &bind.MetaData{
ABI: "[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"v1\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"v2\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"val\",\"type\":\"uint256\"}],\"name\":\"Do\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"res\",\"type\":\"uint256\"}],\"stateMutability\":\"pure\",\"type\":\"function\"}]",
Pattern: "ae26158f1824f3918bd66724ee8b6eb7c9",
Bin: "0x6080604052348015600e575f80fd5b506040516103983803806103988339818101604052810190602e91906066565b5050609d565b5f80fd5b5f819050919050565b6048816038565b81146051575f80fd5b50565b5f815190506060816041565b92915050565b5f806040838503121560795760786034565b5b5f6084858286016054565b92505060206093858286016054565b9150509250929050565b6102ee806100aa5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c80632ad112721461002d575b5f80fd5b6100476004803603810190610042919061019e565b61005d565b60405161005491906101d8565b60405180910390f35b5f600173__$ffc1393672b8ed81d0c8093ffcb0e7fbe8$__632ad112725f6040518263ffffffff1660e01b81526004016100979190610200565b602060405180830381865af41580156100b2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906100d6919061022d565b73__$d600bc30c225801bf5b413866ae334453d$__632ad11272856040518263ffffffff1660e01b815260040161010d9190610200565b602060405180830381865af4158015610128573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061014c919061022d565b6101569190610285565b6101609190610285565b9050919050565b5f80fd5b5f819050919050565b61017d8161016b565b8114610187575f80fd5b50565b5f8135905061019881610174565b92915050565b5f602082840312156101b3576101b2610167565b5b5f6101c08482850161018a565b91505092915050565b6101d28161016b565b82525050565b5f6020820190506101eb5f8301846101c9565b92915050565b6101fa8161016b565b82525050565b5f6020820190506102135f8301846101f1565b92915050565b5f8151905061022781610174565b92915050565b5f6020828403121561024257610241610167565b5b5f61024f84828501610219565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f61028f8261016b565b915061029a8361016b565b92508282019050808211156102b2576102b1610258565b5b9291505056fea264697066735822122068ad2fa18c18d049dd707b5914a0aa9abd5c5f624e2f4886a07f9440f05fb91864736f6c634300081a0033",
}
// C1 is an auto generated Go binding around an Ethereum contract.
type C1 struct {
abi abi.ABI
}
// NewC1 creates a new instance of C1.
func NewC1() (*C1, error) {
parsed, err := C1MetaData.GetAbi()
if err != nil {
return nil, err
}
return &C1{abi: *parsed}, nil
}
// TODO: create custom exported types where unpack would generate a struct return.
// TODO: test constructor with inputs
func (_C1 *C1) PackConstructor(v1 *big.Int, v2 *big.Int) ([]byte, error) {
return _C1.abi.Pack("", v1, v2)
}
// Do is a free data retrieval call binding the contract method 0x2ad11272.
//
// Solidity: function Do(uint256 val) pure returns(uint256 res)
func (_C1 *C1) PackDo(val *big.Int) ([]byte, error) {
return _C1.abi.Pack("Do", val)
}
func (_C1 *C1) UnpackDo(data []byte) (*big.Int, error) {
out, err := _C1.abi.Unpack("Do", data)
if err != nil {
return *new(*big.Int), err
}
out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int)
return out0, err
}
// TODO: turn this into a list, now that the pattern is embedded in each MetaData object
var C2LibraryDeps = map[string]*bind.MetaData{
"ffc1393672b8ed81d0c8093ffcb0e7fbe8": L1MetaData,
"fd1474cf57f7ed48491e8bfdfd0d172adf": L2bMetaData,
"6070639404c39b5667691bb1f9177e1eac": L4bMetaData,
}
// TODO: convert this type to value type after everything works.
// C2MetaData contains all meta data concerning the C2 contract.
var C2MetaData = &bind.MetaData{
ABI: "[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"v1\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"v2\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"val\",\"type\":\"uint256\"}],\"name\":\"Do\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"res\",\"type\":\"uint256\"}],\"stateMutability\":\"pure\",\"type\":\"function\"}]",
Pattern: "78ef2840de5b706112ca2dbfa765501a89",
Bin: "0x6080604052348015600e575f80fd5b506040516103983803806103988339818101604052810190602e91906066565b5050609d565b5f80fd5b5f819050919050565b6048816038565b81146051575f80fd5b50565b5f815190506060816041565b92915050565b5f806040838503121560795760786034565b5b5f6084858286016054565b92505060206093858286016054565b9150509250929050565b6102ee806100aa5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c80632ad112721461002d575b5f80fd5b6100476004803603810190610042919061019e565b61005d565b60405161005491906101d8565b60405180910390f35b5f600173__$ffc1393672b8ed81d0c8093ffcb0e7fbe8$__632ad112725f6040518263ffffffff1660e01b81526004016100979190610200565b602060405180830381865af41580156100b2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906100d6919061022d565b73__$6070639404c39b5667691bb1f9177e1eac$__632ad11272856040518263ffffffff1660e01b815260040161010d9190610200565b602060405180830381865af4158015610128573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061014c919061022d565b6101569190610285565b6101609190610285565b9050919050565b5f80fd5b5f819050919050565b61017d8161016b565b8114610187575f80fd5b50565b5f8135905061019881610174565b92915050565b5f602082840312156101b3576101b2610167565b5b5f6101c08482850161018a565b91505092915050565b6101d28161016b565b82525050565b5f6020820190506101eb5f8301846101c9565b92915050565b6101fa8161016b565b82525050565b5f6020820190506102135f8301846101f1565b92915050565b5f8151905061022781610174565b92915050565b5f6020828403121561024257610241610167565b5b5f61024f84828501610219565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f61028f8261016b565b915061029a8361016b565b92508282019050808211156102b2576102b1610258565b5b9291505056fea2646970667358221220607a5019c269337b096c81ff7e87c99fc5415a2b6f40cc072d5e88396706090e64736f6c634300081a0033",
}
// C2 is an auto generated Go binding around an Ethereum contract.
type C2 struct {
abi abi.ABI
}
// NewC2 creates a new instance of C2.
func NewC2() (*C2, error) {
parsed, err := C2MetaData.GetAbi()
if err != nil {
return nil, err
}
return &C2{abi: *parsed}, nil
}
// TODO: create custom exported types where unpack would generate a struct return.
// TODO: test constructor with inputs
func (_C2 *C2) PackConstructor(v1 *big.Int, v2 *big.Int) ([]byte, error) {
return _C2.abi.Pack("", v1, v2)
}
// Do is a free data retrieval call binding the contract method 0x2ad11272.
//
// Solidity: function Do(uint256 val) pure returns(uint256 res)
func (_C2 *C2) PackDo(val *big.Int) ([]byte, error) {
return _C2.abi.Pack("Do", val)
}
func (_C2 *C2) UnpackDo(data []byte) (*big.Int, error) {
out, err := _C2.abi.Unpack("Do", data)
if err != nil {
return *new(*big.Int), err
}
out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int)
return out0, err
}
// TODO: turn this into a list, now that the pattern is embedded in each MetaData object
var L1LibraryDeps = map[string]*bind.MetaData{}
// TODO: convert this type to value type after everything works.
// L1MetaData contains all meta data concerning the L1 contract.
var L1MetaData = &bind.MetaData{
ABI: "[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"val\",\"type\":\"uint256\"}],\"name\":\"Do\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"pure\",\"type\":\"function\"}]",
Pattern: "ffc1393672b8ed81d0c8093ffcb0e7fbe8",
Bin: "0x61011c61004d600b8282823980515f1a6073146041577f4e487b71000000000000000000000000000000000000000000000000000000005f525f60045260245ffd5b305f52607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106032575f3560e01c80632ad11272146036575b5f80fd5b604c600480360381019060489190609c565b6060565b6040516057919060cf565b60405180910390f35b5f60019050919050565b5f80fd5b5f819050919050565b607e81606e565b81146087575f80fd5b50565b5f813590506096816077565b92915050565b5f6020828403121560ae5760ad606a565b5b5f60b984828501608a565b91505092915050565b60c981606e565b82525050565b5f60208201905060e05f83018460c2565b9291505056fea264697066735822122078914f7e9af117523b8392de05343b4af49014337eaffc86ff537b0ff54fd1ed64736f6c634300081a0033",
}
// L1 is an auto generated Go binding around an Ethereum contract.
type L1 struct {
abi abi.ABI
}
// NewL1 creates a new instance of L1.
func NewL1() (*L1, error) {
parsed, err := L1MetaData.GetAbi()
if err != nil {
return nil, err
}
return &L1{abi: *parsed}, nil
}
// TODO: create custom exported types where unpack would generate a struct return.
// TODO: test constructor with inputs
func (_L1 *L1) PackConstructor() ([]byte, error) {
return _L1.abi.Pack("")
}
// Do is a free data retrieval call binding the contract method 0x2ad11272.
//
// Solidity: function Do(uint256 val) pure returns(uint256)
func (_L1 *L1) PackDo(val *big.Int) ([]byte, error) {
return _L1.abi.Pack("Do", val)
}
func (_L1 *L1) UnpackDo(data []byte) (*big.Int, error) {
out, err := _L1.abi.Unpack("Do", data)
if err != nil {
return *new(*big.Int), err
}
out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int)
return out0, err
}
// TODO: turn this into a list, now that the pattern is embedded in each MetaData object
var L2LibraryDeps = map[string]*bind.MetaData{}
// TODO: convert this type to value type after everything works.
// L2MetaData contains all meta data concerning the L2 contract.
var L2MetaData = &bind.MetaData{
ABI: "[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"val\",\"type\":\"uint256\"}],\"name\":\"Do\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"pure\",\"type\":\"function\"}]",
Pattern: "2ce896a6dd38932d354f317286f90bc675",
Bin: "0x61011c61004d600b8282823980515f1a6073146041577f4e487b71000000000000000000000000000000000000000000000000000000005f525f60045260245ffd5b305f52607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106032575f3560e01c80632ad11272146036575b5f80fd5b604c600480360381019060489190609c565b6060565b6040516057919060cf565b60405180910390f35b5f60019050919050565b5f80fd5b5f819050919050565b607e81606e565b81146087575f80fd5b50565b5f813590506096816077565b92915050565b5f6020828403121560ae5760ad606a565b5b5f60b984828501608a565b91505092915050565b60c981606e565b82525050565b5f60208201905060e05f83018460c2565b9291505056fea26469706673582212205248bdbd4b939a2e899770a55b8b960ed9b95b22e949c50b4e0f94e27f1a764164736f6c634300081a0033",
}
// L2 is an auto generated Go binding around an Ethereum contract.
type L2 struct {
abi abi.ABI
}
// NewL2 creates a new instance of L2.
func NewL2() (*L2, error) {
parsed, err := L2MetaData.GetAbi()
if err != nil {
return nil, err
}
return &L2{abi: *parsed}, nil
}
// TODO: create custom exported types where unpack would generate a struct return.
// TODO: test constructor with inputs
func (_L2 *L2) PackConstructor() ([]byte, error) {
return _L2.abi.Pack("")
}
// Do is a free data retrieval call binding the contract method 0x2ad11272.
//
// Solidity: function Do(uint256 val) pure returns(uint256)
func (_L2 *L2) PackDo(val *big.Int) ([]byte, error) {
return _L2.abi.Pack("Do", val)
}
func (_L2 *L2) UnpackDo(data []byte) (*big.Int, error) {
out, err := _L2.abi.Unpack("Do", data)
if err != nil {
return *new(*big.Int), err
}
out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int)
return out0, err
}
// TODO: turn this into a list, now that the pattern is embedded in each MetaData object
var L2bLibraryDeps = map[string]*bind.MetaData{}
// TODO: convert this type to value type after everything works.
// L2bMetaData contains all meta data concerning the L2b contract.
var L2bMetaData = &bind.MetaData{
ABI: "[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"val\",\"type\":\"uint256\"}],\"name\":\"Do\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"pure\",\"type\":\"function\"}]",
Pattern: "fd1474cf57f7ed48491e8bfdfd0d172adf",
Bin: "0x61025161004d600b8282823980515f1a6073146041577f4e487b71000000000000000000000000000000000000000000000000000000005f525f60045260245ffd5b305f52607381538281f3fe7300000000000000000000000000000000000000003014608060405260043610610034575f3560e01c80632ad1127214610038575b5f80fd5b610052600480360381019061004d9190610129565b610068565b60405161005f9190610163565b60405180910390f35b5f600173__$ffc1393672b8ed81d0c8093ffcb0e7fbe8$__632ad11272846040518263ffffffff1660e01b81526004016100a29190610163565b602060405180830381865af41580156100bd573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906100e19190610190565b6100eb91906101e8565b9050919050565b5f80fd5b5f819050919050565b610108816100f6565b8114610112575f80fd5b50565b5f81359050610123816100ff565b92915050565b5f6020828403121561013e5761013d6100f2565b5b5f61014b84828501610115565b91505092915050565b61015d816100f6565b82525050565b5f6020820190506101765f830184610154565b92915050565b5f8151905061018a816100ff565b92915050565b5f602082840312156101a5576101a46100f2565b5b5f6101b28482850161017c565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f6101f2826100f6565b91506101fd836100f6565b9250828201905080821115610215576102146101bb565b5b9291505056fea2646970667358221220f2bec4e215b51a06ae5161d6a1fa3130877fb447fe26cf7cc5d1791ed58ec8ba64736f6c634300081a0033",
}
// L2b is an auto generated Go binding around an Ethereum contract.
type L2b struct {
abi abi.ABI
}
// NewL2b creates a new instance of L2b.
func NewL2b() (*L2b, error) {
parsed, err := L2bMetaData.GetAbi()
if err != nil {
return nil, err
}
return &L2b{abi: *parsed}, nil
}
// TODO: create custom exported types where unpack would generate a struct return.
// TODO: test constructor with inputs
func (_L2b *L2b) PackConstructor() ([]byte, error) {
return _L2b.abi.Pack("")
}
// Do is a free data retrieval call binding the contract method 0x2ad11272.
//
// Solidity: function Do(uint256 val) pure returns(uint256)
func (_L2b *L2b) PackDo(val *big.Int) ([]byte, error) {
return _L2b.abi.Pack("Do", val)
}
func (_L2b *L2b) UnpackDo(data []byte) (*big.Int, error) {
out, err := _L2b.abi.Unpack("Do", data)
if err != nil {
return *new(*big.Int), err
}
out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int)
return out0, err
}
// TODO: turn this into a list, now that the pattern is embedded in each MetaData object
var L3LibraryDeps = map[string]*bind.MetaData{}
// TODO: convert this type to value type after everything works.
// L3MetaData contains all meta data concerning the L3 contract.
var L3MetaData = &bind.MetaData{
ABI: "[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"val\",\"type\":\"uint256\"}],\"name\":\"Do\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"pure\",\"type\":\"function\"}]",
Pattern: "d03b97f5e1a564374023a72ac7d1806773",
Bin: "0x61025161004d600b8282823980515f1a6073146041577f4e487b71000000000000000000000000000000000000000000000000000000005f525f60045260245ffd5b305f52607381538281f3fe7300000000000000000000000000000000000000003014608060405260043610610034575f3560e01c80632ad1127214610038575b5f80fd5b610052600480360381019061004d9190610129565b610068565b60405161005f9190610163565b60405180910390f35b5f600173__$ffc1393672b8ed81d0c8093ffcb0e7fbe8$__632ad11272846040518263ffffffff1660e01b81526004016100a29190610163565b602060405180830381865af41580156100bd573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906100e19190610190565b6100eb91906101e8565b9050919050565b5f80fd5b5f819050919050565b610108816100f6565b8114610112575f80fd5b50565b5f81359050610123816100ff565b92915050565b5f6020828403121561013e5761013d6100f2565b5b5f61014b84828501610115565b91505092915050565b61015d816100f6565b82525050565b5f6020820190506101765f830184610154565b92915050565b5f8151905061018a816100ff565b92915050565b5f602082840312156101a5576101a46100f2565b5b5f6101b28482850161017c565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f6101f2826100f6565b91506101fd836100f6565b9250828201905080821115610215576102146101bb565b5b9291505056fea26469706673582212201a3e05a0b6b9da6c9f39bee5a339d955347a2c736f2a1e6350c33c2c3ba9764864736f6c634300081a0033",
}
// L3 is an auto generated Go binding around an Ethereum contract.
type L3 struct {
abi abi.ABI
}
// NewL3 creates a new instance of L3.
func NewL3() (*L3, error) {
parsed, err := L3MetaData.GetAbi()
if err != nil {
return nil, err
}
return &L3{abi: *parsed}, nil
}
// TODO: create custom exported types where unpack would generate a struct return.
// TODO: test constructor with inputs
func (_L3 *L3) PackConstructor() ([]byte, error) {
return _L3.abi.Pack("")
}
// Do is a free data retrieval call binding the contract method 0x2ad11272.
//
// Solidity: function Do(uint256 val) pure returns(uint256)
func (_L3 *L3) PackDo(val *big.Int) ([]byte, error) {
return _L3.abi.Pack("Do", val)
}
func (_L3 *L3) UnpackDo(data []byte) (*big.Int, error) {
out, err := _L3.abi.Unpack("Do", data)
if err != nil {
return *new(*big.Int), err
}
out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int)
return out0, err
}
// TODO: turn this into a list, now that the pattern is embedded in each MetaData object
var L4LibraryDeps = map[string]*bind.MetaData{}
// TODO: convert this type to value type after everything works.
// L4MetaData contains all meta data concerning the L4 contract.
var L4MetaData = &bind.MetaData{
ABI: "[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"val\",\"type\":\"uint256\"}],\"name\":\"Do\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"pure\",\"type\":\"function\"}]",
Pattern: "5f33a1fab8ea7d932b4bc8c5e7dcd90bc2",
Bin: "0x61011c61004d600b8282823980515f1a6073146041577f4e487b71000000000000000000000000000000000000000000000000000000005f525f60045260245ffd5b305f52607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106032575f3560e01c80632ad11272146036575b5f80fd5b604c600480360381019060489190609c565b6060565b6040516057919060cf565b60405180910390f35b5f60019050919050565b5f80fd5b5f819050919050565b607e81606e565b81146087575f80fd5b50565b5f813590506096816077565b92915050565b5f6020828403121560ae5760ad606a565b5b5f60b984828501608a565b91505092915050565b60c981606e565b82525050565b5f60208201905060e05f83018460c2565b9291505056fea2646970667358221220776962c71be9e15d17f5a247c2429fddd2e4b2a533e34d9c5e2e324ee6bd76af64736f6c634300081a0033",
}
// L4 is an auto generated Go binding around an Ethereum contract.
type L4 struct {
abi abi.ABI
}
// NewL4 creates a new instance of L4.
func NewL4() (*L4, error) {
parsed, err := L4MetaData.GetAbi()
if err != nil {
return nil, err
}
return &L4{abi: *parsed}, nil
}
// TODO: create custom exported types where unpack would generate a struct return.
// TODO: test constructor with inputs
func (_L4 *L4) PackConstructor() ([]byte, error) {
return _L4.abi.Pack("")
}
// Do is a free data retrieval call binding the contract method 0x2ad11272.
//
// Solidity: function Do(uint256 val) pure returns(uint256)
func (_L4 *L4) PackDo(val *big.Int) ([]byte, error) {
return _L4.abi.Pack("Do", val)
}
func (_L4 *L4) UnpackDo(data []byte) (*big.Int, error) {
out, err := _L4.abi.Unpack("Do", data)
if err != nil {
return *new(*big.Int), err
}
out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int)
return out0, err
}
// TODO: turn this into a list, now that the pattern is embedded in each MetaData object
var L4bLibraryDeps = map[string]*bind.MetaData{}
// TODO: convert this type to value type after everything works.
// L4bMetaData contains all meta data concerning the L4b contract.
var L4bMetaData = &bind.MetaData{
ABI: "[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"val\",\"type\":\"uint256\"}],\"name\":\"Do\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"pure\",\"type\":\"function\"}]",
Pattern: "6070639404c39b5667691bb1f9177e1eac",
Bin: "0x61025161004d600b8282823980515f1a6073146041577f4e487b71000000000000000000000000000000000000000000000000000000005f525f60045260245ffd5b305f52607381538281f3fe7300000000000000000000000000000000000000003014608060405260043610610034575f3560e01c80632ad1127214610038575b5f80fd5b610052600480360381019061004d9190610129565b610068565b60405161005f9190610163565b60405180910390f35b5f600173__$fd1474cf57f7ed48491e8bfdfd0d172adf$__632ad11272846040518263ffffffff1660e01b81526004016100a29190610163565b602060405180830381865af41580156100bd573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906100e19190610190565b6100eb91906101e8565b9050919050565b5f80fd5b5f819050919050565b610108816100f6565b8114610112575f80fd5b50565b5f81359050610123816100ff565b92915050565b5f6020828403121561013e5761013d6100f2565b5b5f61014b84828501610115565b91505092915050565b61015d816100f6565b82525050565b5f6020820190506101765f830184610154565b92915050565b5f8151905061018a816100ff565b92915050565b5f602082840312156101a5576101a46100f2565b5b5f6101b28482850161017c565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f6101f2826100f6565b91506101fd836100f6565b9250828201905080821115610215576102146101bb565b5b9291505056fea2646970667358221220efbb5a71ca406bdf7337c785a57fcc2211efa82182e9330541e41f7f3cbbfd6864736f6c634300081a0033",
}
// L4b is an auto generated Go binding around an Ethereum contract.
type L4b struct {
abi abi.ABI
}
// NewL4b creates a new instance of L4b.
func NewL4b() (*L4b, error) {
parsed, err := L4bMetaData.GetAbi()
if err != nil {
return nil, err
}
return &L4b{abi: *parsed}, nil
}
// TODO: create custom exported types where unpack would generate a struct return.
// TODO: test constructor with inputs
func (_L4b *L4b) PackConstructor() ([]byte, error) {
return _L4b.abi.Pack("")
}
// Do is a free data retrieval call binding the contract method 0x2ad11272.
//
// Solidity: function Do(uint256 val) pure returns(uint256)
func (_L4b *L4b) PackDo(val *big.Int) ([]byte, error) {
return _L4b.abi.Pack("Do", val)
}
func (_L4b *L4b) UnpackDo(data []byte) (*big.Int, error) {
out, err := _L4b.abi.Unpack("Do", data)
if err != nil {
return *new(*big.Int), err
}
out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int)
return out0, err
}
// TODO: turn this into a list, now that the pattern is embedded in each MetaData object
var L5LibraryDeps = map[string]*bind.MetaData{}
// TODO: convert this type to value type after everything works.
// L5MetaData contains all meta data concerning the L5 contract.
var L5MetaData = &bind.MetaData{
ABI: "[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"val\",\"type\":\"uint256\"}],\"name\":\"Do\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"pure\",\"type\":\"function\"}]",
Pattern: "d600bc30c225801bf5b413866ae334453d",
Bin: "0x61025161004d600b8282823980515f1a6073146041577f4e487b71000000000000000000000000000000000000000000000000000000005f525f60045260245ffd5b305f52607381538281f3fe7300000000000000000000000000000000000000003014608060405260043610610034575f3560e01c80632ad1127214610038575b5f80fd5b610052600480360381019061004d9190610129565b610068565b60405161005f9190610163565b60405180910390f35b5f600173__$d03b97f5e1a564374023a72ac7d1806773$__632ad11272846040518263ffffffff1660e01b81526004016100a29190610163565b602060405180830381865af41580156100bd573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906100e19190610190565b6100eb91906101e8565b9050919050565b5f80fd5b5f819050919050565b610108816100f6565b8114610112575f80fd5b50565b5f81359050610123816100ff565b92915050565b5f6020828403121561013e5761013d6100f2565b5b5f61014b84828501610115565b91505092915050565b61015d816100f6565b82525050565b5f6020820190506101765f830184610154565b92915050565b5f8151905061018a816100ff565b92915050565b5f602082840312156101a5576101a46100f2565b5b5f6101b28482850161017c565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f6101f2826100f6565b91506101fd836100f6565b9250828201905080821115610215576102146101bb565b5b9291505056fea26469706673582212209c255a72b1a53a20d1e2234d9692aba8973d3aa7271f120c00fe0fde8226532f64736f6c634300081a0033",
}
// L5 is an auto generated Go binding around an Ethereum contract.
type L5 struct {
abi abi.ABI
}
// NewL5 creates a new instance of L5.
func NewL5() (*L5, error) {
parsed, err := L5MetaData.GetAbi()
if err != nil {
return nil, err
}
return &L5{abi: *parsed}, nil
}
// TODO: create custom exported types where unpack would generate a struct return.
// TODO: test constructor with inputs
func (_L5 *L5) PackConstructor() ([]byte, error) {
return _L5.abi.Pack("")
}
// Do is a free data retrieval call binding the contract method 0x2ad11272.
//
// Solidity: function Do(uint256 val) pure returns(uint256)
func (_L5 *L5) PackDo(val *big.Int) ([]byte, error) {
return _L5.abi.Pack("Do", val)
}
func (_L5 *L5) UnpackDo(data []byte) (*big.Int, error) {
out, err := _L5.abi.Unpack("Do", data)
if err != nil {
return *new(*big.Int), err
}
out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int)
return out0, err
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,82 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
// L1
// \
// L2 L3 L1
// \ / /
// L4 /
// \ /
// C1
//
library L1 {
function Do(uint256 val) public pure returns (uint256) {
return uint256(1);
}
}
library L2 {
function Do(uint256 val) public pure returns (uint256) {
return uint256(1);
}
}
library L3 {
function Do(uint256 val) public pure returns (uint256) {
return L1.Do(uint256(val)) + uint256(1);
}
}
library L4 {
function Do(uint256 val) public pure returns (uint256) {
return uint256(1);
}
}
library L5 {
function Do(uint256 val) public pure returns (uint256) {
return L3.Do(uint256(val)) + uint256(1);
}
}
contract C1 {
function Do(uint256 val) public pure returns (uint256 res) {
return L5.Do(uint256(val)) + L1.Do(uint256(0)) + uint256(1);
}
constructor(uint256 v1, uint256 v2) {
// do something with these
}
}
// second contract+libraries: slightly different library deps than V1, but sharing several
// L1
// \
// L2b L3 L1
// \ / /
// L4b /
// \ /
// C2
//
library L4b {
function Do(uint256 val) public pure returns (uint256) {
return L2b.Do(uint256(val)) + uint256(1);
}
}
library L2b {
function Do(uint256 val) public pure returns (uint256) {
return L1.Do(uint256(val)) + uint256(1);
}
}
contract C2 {
function Do(uint256 val) public pure returns (uint256 res) {
return L4b.Do(uint256(val)) + L1.Do(uint256(0)) + uint256(1);
}
constructor(uint256 v1, uint256 v2) {
// do something with these
}
}

View File

@ -0,0 +1,2 @@
[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"firstArg","type":"uint256"},{"indexed":false,"internalType":"string","name":"secondArg","type":"string"}],"name":"Basic","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"firstArg","type":"uint256"},{"components":[{"internalType":"int256","name":"val1","type":"int256"},{"internalType":"int256","name":"val2","type":"int256"},{"internalType":"string","name":"val3","type":"string"}],"indexed":false,"internalType":"struct Example.exampleStruct","name":"secondArg","type":"tuple"}],"name":"Struct","type":"event"},{"inputs":[],"name":"emitEvent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"emitEventsDiffTypes","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"emitTwoEvents","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"num","type":"uint256"}],"name":"mutateStorageVal","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"retrieveStorageVal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]

View File

@ -0,0 +1 @@
6080604052348015600e575f80fd5b5061052b8061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610055575f3560e01c80636da1cd55146100595780637216c3331461007757806379da6d70146100815780637b0cb8391461008b578063bf54fad414610095575b5f80fd5b6100616100b1565b60405161006e9190610246565b60405180910390f35b61007f6100b9565b005b610089610129565b005b6100936101ec565b005b6100af60048036038101906100aa919061028d565b610225565b005b5f8054905090565b607b7f114f97f563bc13d79fae32f4746248fd563650659371fef0bc8a7011fdd7bc6a6040516100e890610312565b60405180910390a2607b7f114f97f563bc13d79fae32f4746248fd563650659371fef0bc8a7011fdd7bc6a60405161011f9061037a565b60405180910390a2565b607b7f114f97f563bc13d79fae32f4746248fd563650659371fef0bc8a7011fdd7bc6a60405161015890610312565b60405180910390a2607b7faa0aa64a4dab26dbe87da2dcff945b2197f80de1903db7334b8f496a94428d39604051806060016040528060018152602001600281526020016040518060400160405280600681526020017f737472696e6700000000000000000000000000000000000000000000000000008152508152506040516101e2919061046d565b60405180910390a2565b607b7f114f97f563bc13d79fae32f4746248fd563650659371fef0bc8a7011fdd7bc6a60405161021b906104d7565b60405180910390a2565b805f8190555050565b5f819050919050565b6102408161022e565b82525050565b5f6020820190506102595f830184610237565b92915050565b5f80fd5b61026c8161022e565b8114610276575f80fd5b50565b5f8135905061028781610263565b92915050565b5f602082840312156102a2576102a161025f565b5b5f6102af84828501610279565b91505092915050565b5f82825260208201905092915050565b7f6576656e743100000000000000000000000000000000000000000000000000005f82015250565b5f6102fc6006836102b8565b9150610307826102c8565b602082019050919050565b5f6020820190508181035f830152610329816102f0565b9050919050565b7f6576656e743200000000000000000000000000000000000000000000000000005f82015250565b5f6103646006836102b8565b915061036f82610330565b602082019050919050565b5f6020820190508181035f83015261039181610358565b9050919050565b5f819050919050565b6103aa81610398565b82525050565b5f81519050919050565b5f82825260208201905092915050565b8281835e5f83830152505050565b5f601f19601f8301169050919050565b5f6103f2826103b0565b6103fc81856103ba565b935061040c8185602086016103ca565b610415816103d8565b840191505092915050565b5f606083015f8301516104355f8601826103a1565b50602083015161044860208601826103a1565b506040830151848203604086015261046082826103e8565b9150508091505092915050565b5f6020820190508181035f8301526104858184610420565b905092915050565b7f6576656e740000000000000000000000000000000000000000000000000000005f82015250565b5f6104c16005836102b8565b91506104cc8261048d565b602082019050919050565b5f6020820190508181035f8301526104ee816104b5565b905091905056fea2646970667358221220946fc97c32ae98514551443303280f456cca960cbdcc95d1cec614233dec100764736f6c634300081a0033

View File

@ -0,0 +1,51 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.2 <0.9.0;
/**
* @title Storage
* @dev Store & retrieve value in a variable
* @custom:dev-run-script ./scripts/deploy_with_ethers.ts
*/
contract Example {
uint256 number;
struct exampleStruct {
int val1;
int val2;
string val3;
}
event Basic(uint indexed firstArg, string secondArg);
event Struct(uint indexed firstArg, exampleStruct secondArg);
/**
* @dev Store value in variable
* @param num value to store
*/
function mutateStorageVal(uint256 num) public {
number = num;
}
/**
* @dev Return value
* @return value of 'number'
*/
function retrieveStorageVal() public view returns (uint256){
return number;
}
function emitEvent() public {
emit Basic(123, "event");
}
function emitTwoEvents() public {
emit Basic(123, "event1");
emit Basic(123, "event2");
}
function emitEventsDiffTypes() public {
emit Basic(123, "event1");
emit Struct(123, exampleStruct({val1: 1, val2: 2, val3: "string"}));
}
}

View File

@ -0,0 +1,199 @@
// Code generated via abigen V2 - DO NOT EDIT.
// This file is a generated binding and any manual changes will be lost.
package v2_generated_testcase
import (
"errors"
"math/big"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
// Reference imports to suppress errors if they are not otherwise used.
var (
_ = errors.New
_ = big.NewInt
_ = bind.Bind
_ = common.Big1
_ = types.BloomLookup
_ = abi.ConvertType
)
// ExampleexampleStruct is an auto generated low-level Go binding around an user-defined struct.
type ExampleexampleStruct struct {
Val1 *big.Int
Val2 *big.Int
Val3 string
}
// V2GeneratedTestcaseMetaData contains all meta data concerning the V2GeneratedTestcase contract.
var V2GeneratedTestcaseMetaData = &bind.MetaData{
ABI: "[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"firstArg\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"secondArg\",\"type\":\"string\"}],\"name\":\"Basic\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"firstArg\",\"type\":\"uint256\"},{\"components\":[{\"internalType\":\"int256\",\"name\":\"val1\",\"type\":\"int256\"},{\"internalType\":\"int256\",\"name\":\"val2\",\"type\":\"int256\"},{\"internalType\":\"string\",\"name\":\"val3\",\"type\":\"string\"}],\"indexed\":false,\"internalType\":\"structExample.exampleStruct\",\"name\":\"secondArg\",\"type\":\"tuple\"}],\"name\":\"Struct\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"emitEvent\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"emitEventsDiffTypes\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"emitTwoEvents\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"num\",\"type\":\"uint256\"}],\"name\":\"mutateStorageVal\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"retrieveStorageVal\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]",
Bin: "0x6080604052348015600e575f80fd5b5061052b8061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610055575f3560e01c80636da1cd55146100595780637216c3331461007757806379da6d70146100815780637b0cb8391461008b578063bf54fad414610095575b5f80fd5b6100616100b1565b60405161006e9190610246565b60405180910390f35b61007f6100b9565b005b610089610129565b005b6100936101ec565b005b6100af60048036038101906100aa919061028d565b610225565b005b5f8054905090565b607b7f114f97f563bc13d79fae32f4746248fd563650659371fef0bc8a7011fdd7bc6a6040516100e890610312565b60405180910390a2607b7f114f97f563bc13d79fae32f4746248fd563650659371fef0bc8a7011fdd7bc6a60405161011f9061037a565b60405180910390a2565b607b7f114f97f563bc13d79fae32f4746248fd563650659371fef0bc8a7011fdd7bc6a60405161015890610312565b60405180910390a2607b7faa0aa64a4dab26dbe87da2dcff945b2197f80de1903db7334b8f496a94428d39604051806060016040528060018152602001600281526020016040518060400160405280600681526020017f737472696e6700000000000000000000000000000000000000000000000000008152508152506040516101e2919061046d565b60405180910390a2565b607b7f114f97f563bc13d79fae32f4746248fd563650659371fef0bc8a7011fdd7bc6a60405161021b906104d7565b60405180910390a2565b805f8190555050565b5f819050919050565b6102408161022e565b82525050565b5f6020820190506102595f830184610237565b92915050565b5f80fd5b61026c8161022e565b8114610276575f80fd5b50565b5f8135905061028781610263565b92915050565b5f602082840312156102a2576102a161025f565b5b5f6102af84828501610279565b91505092915050565b5f82825260208201905092915050565b7f6576656e743100000000000000000000000000000000000000000000000000005f82015250565b5f6102fc6006836102b8565b9150610307826102c8565b602082019050919050565b5f6020820190508181035f830152610329816102f0565b9050919050565b7f6576656e743200000000000000000000000000000000000000000000000000005f82015250565b5f6103646006836102b8565b915061036f82610330565b602082019050919050565b5f6020820190508181035f83015261039181610358565b9050919050565b5f819050919050565b6103aa81610398565b82525050565b5f81519050919050565b5f82825260208201905092915050565b8281835e5f83830152505050565b5f601f19601f8301169050919050565b5f6103f2826103b0565b6103fc81856103ba565b935061040c8185602086016103ca565b610415816103d8565b840191505092915050565b5f606083015f8301516104355f8601826103a1565b50602083015161044860208601826103a1565b506040830151848203604086015261046082826103e8565b9150508091505092915050565b5f6020820190508181035f8301526104858184610420565b905092915050565b7f6576656e740000000000000000000000000000000000000000000000000000005f82015250565b5f6104c16005836102b8565b91506104cc8261048d565b602082019050919050565b5f6020820190508181035f8301526104ee816104b5565b905091905056fea2646970667358221220946fc97c32ae98514551443303280f456cca960cbdcc95d1cec614233dec100764736f6c634300081a0033",
}
// V2GeneratedTestcaseInstance represents a deployed instance of the V2GeneratedTestcase contract.
type V2GeneratedTestcaseInstance struct {
V2GeneratedTestcase
address common.Address // consider removing this, not clear what it's used for now (and why did we need custom deploy method on previous abi?)
backend bind.ContractBackend
}
func NewV2GeneratedTestcaseInstance(c *V2GeneratedTestcase, address common.Address, backend bind.ContractBackend) *V2GeneratedTestcaseInstance {
return &V2GeneratedTestcaseInstance{V2GeneratedTestcase: *c, address: address}
}
func (i *V2GeneratedTestcaseInstance) Address() common.Address {
return i.address
}
func (i *V2GeneratedTestcaseInstance) Backend() bind.ContractBackend {
return i.backend
}
// V2GeneratedTestcase is an auto generated Go binding around an Ethereum contract.
type V2GeneratedTestcase struct {
abi abi.ABI
deployCode []byte
}
// NewV2GeneratedTestcase creates a new instance of V2GeneratedTestcase.
func NewV2GeneratedTestcase() (*V2GeneratedTestcase, error) {
parsed, err := V2GeneratedTestcaseMetaData.GetAbi()
if err != nil {
return nil, err
}
code := common.Hex2Bytes(V2GeneratedTestcaseMetaData.Bin)
return &V2GeneratedTestcase{abi: *parsed, deployCode: code}, nil
}
func (_V2GeneratedTestcase *V2GeneratedTestcase) DeployCode() []byte {
return _V2GeneratedTestcase.deployCode
}
func (_V2GeneratedTestcase *V2GeneratedTestcase) PackConstructor() ([]byte, error) {
return _V2GeneratedTestcase.abi.Pack("")
}
// EmitEvent is a free data retrieval call binding the contract method 0x7b0cb839.
//
// Solidity: function emitEvent() returns()
func (_V2GeneratedTestcase *V2GeneratedTestcase) PackEmitEvent() ([]byte, error) {
return _V2GeneratedTestcase.abi.Pack("emitEvent")
}
// EmitEventsDiffTypes is a free data retrieval call binding the contract method 0x79da6d70.
//
// Solidity: function emitEventsDiffTypes() returns()
func (_V2GeneratedTestcase *V2GeneratedTestcase) PackEmitEventsDiffTypes() ([]byte, error) {
return _V2GeneratedTestcase.abi.Pack("emitEventsDiffTypes")
}
// EmitTwoEvents is a free data retrieval call binding the contract method 0x7216c333.
//
// Solidity: function emitTwoEvents() returns()
func (_V2GeneratedTestcase *V2GeneratedTestcase) PackEmitTwoEvents() ([]byte, error) {
return _V2GeneratedTestcase.abi.Pack("emitTwoEvents")
}
// MutateStorageVal is a free data retrieval call binding the contract method 0xbf54fad4.
//
// Solidity: function mutateStorageVal(uint256 num) returns()
func (_V2GeneratedTestcase *V2GeneratedTestcase) PackMutateStorageVal(num *big.Int) ([]byte, error) {
return _V2GeneratedTestcase.abi.Pack("mutateStorageVal", num)
}
// RetrieveStorageVal is a free data retrieval call binding the contract method 0x6da1cd55.
//
// Solidity: function retrieveStorageVal() view returns(uint256)
func (_V2GeneratedTestcase *V2GeneratedTestcase) PackRetrieveStorageVal() ([]byte, error) {
return _V2GeneratedTestcase.abi.Pack("retrieveStorageVal")
}
func (_V2GeneratedTestcase *V2GeneratedTestcase) UnpackRetrieveStorageVal(data []byte) (*big.Int, error) {
out, err := _V2GeneratedTestcase.abi.Unpack("retrieveStorageVal", data)
if err != nil {
return *new(*big.Int), err
}
out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int)
return out0, err
}
// V2GeneratedTestcaseBasic represents a Basic event raised by the V2GeneratedTestcase contract.
type V2GeneratedTestcaseBasic struct {
FirstArg *big.Int
SecondArg string
Raw *types.Log // Blockchain specific contextual infos
}
func V2GeneratedTestcaseBasicEventID() common.Hash {
return common.HexToHash("0x114f97f563bc13d79fae32f4746248fd563650659371fef0bc8a7011fdd7bc6a")
}
func (_V2GeneratedTestcase *V2GeneratedTestcase) UnpackBasicEvent(log *types.Log) (*V2GeneratedTestcaseBasic, error) {
event := "Basic"
if log.Topics[0] != _V2GeneratedTestcase.abi.Events[event].ID {
return nil, errors.New("event signature mismatch")
}
out := new(V2GeneratedTestcaseBasic)
if len(log.Data) > 0 {
if err := _V2GeneratedTestcase.abi.UnpackIntoInterface(out, event, log.Data); err != nil {
return nil, err
}
}
var indexed abi.Arguments
for _, arg := range _V2GeneratedTestcase.abi.Events[event].Inputs {
if arg.Indexed {
indexed = append(indexed, arg)
}
}
if err := abi.ParseTopics(out, indexed, log.Topics[1:]); err != nil {
return nil, err
}
out.Raw = log
return out, nil
}
// V2GeneratedTestcaseStruct represents a Struct event raised by the V2GeneratedTestcase contract.
type V2GeneratedTestcaseStruct struct {
FirstArg *big.Int
SecondArg ExampleexampleStruct
Raw *types.Log // Blockchain specific contextual infos
}
func V2GeneratedTestcaseStructEventID() common.Hash {
return common.HexToHash("0xaa0aa64a4dab26dbe87da2dcff945b2197f80de1903db7334b8f496a94428d39")
}
func (_V2GeneratedTestcase *V2GeneratedTestcase) UnpackStructEvent(log *types.Log) (*V2GeneratedTestcaseStruct, error) {
event := "Struct"
if log.Topics[0] != _V2GeneratedTestcase.abi.Events[event].ID {
return nil, errors.New("event signature mismatch")
}
out := new(V2GeneratedTestcaseStruct)
if len(log.Data) > 0 {
if err := _V2GeneratedTestcase.abi.UnpackIntoInterface(out, event, log.Data); err != nil {
return nil, err
}
}
var indexed abi.Arguments
for _, arg := range _V2GeneratedTestcase.abi.Events[event].Inputs {
if arg.Indexed {
indexed = append(indexed, arg)
}
}
if err := abi.ParseTopics(out, indexed, log.Topics[1:]); err != nil {
return nil, err
}
out.Raw = log
return out, nil
}

View File

@ -1,45 +0,0 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
library RecursiveDep {
function AddOne(uint256 val) public pure returns (uint256 ret) {
return val + 1;
}
}
// Array function to delete element at index and re-organize the array
// so that there are no gaps between the elements.
library Array {
using RecursiveDep for uint256;
function remove(uint256[] storage arr, uint256 index) public {
// Move the last element into the place to delete
require(arr.length > 0, "Can't remove from empty array");
arr[index] = arr[arr.length - 1];
arr[index] = arr[index].AddOne();
arr.pop();
}
}
contract TestArray {
using Array for uint256[];
uint256[] public arr;
function testArrayRemove(uint256 value) public {
for (uint256 i = 0; i < 3; i++) {
arr.push(i);
}
arr.remove(1);
assert(arr.length == 2);
assert(arr[0] == 0);
assert(arr[1] == 2);
}
// a constructor with parameters
constructor(uint256 foo) {
}
}

View File

@ -77,7 +77,7 @@ func linkLibs(deps *map[string]string, linked *map[string]common.Address) (deplo
deployableDeps = make(map[string]string)
for pattern, dep := range *deps {
// attempt to replace references to every single linked dep
// link references to dependent libraries that have been deployed
for _, match := range reMatchSpecificPattern.FindAllStringSubmatch(dep, -1) {
matchingPattern := match[1]
addr, ok := (*linked)[matchingPattern]
@ -86,7 +86,7 @@ func linkLibs(deps *map[string]string, linked *map[string]common.Address) (deplo
}
(*deps)[pattern] = strings.ReplaceAll(dep, "__$"+matchingPattern+"$__", addr.String()[2:])
}
// if we linked something into this dep, see if it can be deployed
// if the library code became fully linked, deploy it
if !reMatchAnyPattern.MatchString((*deps)[pattern]) {
deployableDeps[pattern] = (*deps)[pattern]
delete(*deps, pattern)
@ -95,9 +95,37 @@ func linkLibs(deps *map[string]string, linked *map[string]common.Address) (deplo
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) {
allDeployAddrs = make(map[common.Address]struct{})
allDeployTxs = make(map[common.Address]*types.Transaction)
type ContractDeployParams struct {
Meta *bind.MetaData
Constructor []byte
}
type DeploymentParams struct {
Contracts []ContractDeployParams
// map of library pattern -> metadata
Libraries map[string]*bind.MetaData
// map of library pattern -> address
Overrides map[string]common.Address
}
type DeploymentResult struct {
// map of contract type name -> deploy transaction
Txs map[string]*types.Transaction
// map of contract type name -> deployed address
Addrs map[string]common.Address
}
// TODO: * pass single set of contracts (dont differentiate between contract/lib in parameters)
// - return map of pattern->address
// - in template, export a pattern for each contract (whether library/contract).
func LinkAndDeployContractWithOverrides(auth *bind.TransactOpts, backend bind.ContractBackend, deployParams DeploymentParams) (res *DeploymentResult, err error) {
libMetas := deployParams.Libraries
overrides := deployParams.Overrides
res = &DeploymentResult{
Txs: make(map[string]*types.Transaction),
Addrs: make(map[string]common.Address),
}
// re-express libraries as a map of pattern -> pre-link binary
libs := make(map[string]string)
@ -122,25 +150,31 @@ func LinkAndDeployContractWithOverrides(auth *bind.TransactOpts, backend bind.Co
}
deployTxs, deployAddrs, err := deployLibs(backend, auth, deployableDeps)
for pattern, addr := range deployAddrs {
allDeployAddrs[addr] = struct{}{}
linked[pattern] = addr
}
for addr, tx := range deployTxs {
allDeployTxs[addr] = tx
res.Addrs[pattern] = addr
res.Txs[pattern] = deployTxs[addr]
}
if err != nil {
return deployTxs, allDeployAddrs, err
return res, err
}
}
linkedContract, err := linkContract(contract.Bin, linked)
if err != nil {
return allDeployTxs, allDeployAddrs, err
for _, contractParams := range deployParams.Contracts {
linkedContract, err := linkContract(contractParams.Meta.Bin, linked)
if err != nil {
return res, err
}
// link and deploy the contracts
contractTx, contractAddr, err := deployContract(backend, auth, contractParams.Constructor, linkedContract)
if err != nil {
return res, err
}
res.Txs[contractParams.Meta.Pattern] = contractTx
res.Addrs[contractParams.Meta.Pattern] = contractAddr
}
// link and deploy the contracts
contractTx, contractAddr, err := deployContract(backend, auth, constructorInputs, linkedContract)
allDeployAddrs[contractAddr] = struct{}{}
allDeployTxs[contractAddr] = contractTx
return allDeployTxs, allDeployAddrs, err
return res, nil
}
func FilterLogs[T any](instance *ContractInstance, opts *bind.FilterOpts, eventID common.Hash, unpack func(*types.Log) (*T, error), topics ...[]any) (*EventIterator[T], error) {
@ -262,6 +296,7 @@ func Transact(instance bind.ContractInstance, opts *bind.TransactOpts, input []b
return c.RawTransact(opts, input)
}
// TODO: why do we need sepaarate transact/transfer methods?
func Transfer(instance bind.ContractInstance, opts *bind.TransactOpts) (*types.Transaction, error) {
backend := instance.Backend()
c := bind.NewBoundContract(instance.Address(), abi.ABI{}, backend, backend, backend)

View File

@ -3,9 +3,10 @@ package v2
import (
"context"
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/accounts/abi/bind/testdata/v2_generated_testcase"
"github.com/ethereum/go-ethereum/accounts/abi/bind/testdata/v2_testcase_library"
"github.com/ethereum/go-ethereum/accounts/abi/bind/testdata/v2/nested_libraries"
"github.com/ethereum/go-ethereum/accounts/abi/bind/testdata/v2/v2_generated_testcase"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
@ -165,30 +166,93 @@ func TestDeployment(t *testing.T) {
// TODO: allow for the flexibility of deploying only libraries.
// 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 {
for pattern, metadata := range nested_libraries.C1LibraryDeps {
libMetas[pattern] = metadata
}
ctrct, err := v2_testcase_library.NewTestArray()
ctrct, err := nested_libraries.NewC1()
if err != nil {
panic(err)
}
constructorInput, err := ctrct.PackConstructor(big.NewInt(42), false)
constructorInput, err := ctrct.PackConstructor(big.NewInt(42), big.NewInt(1))
if err != nil {
t.Fatalf("fack %v", err)
}
// TODO: test case with arguments-containing constructor
txs, _, err := LinkAndDeployContractWithOverrides(&opts, bindBackend, constructorInput, v2_testcase_library.TestArrayMetaData, v2_testcase_library.TestArrayLibraryDeps, nil)
deploymentParams := DeploymentParams{
Contracts: []ContractDeployParams{
{
Meta: nested_libraries.C1MetaData,
Constructor: constructorInput,
},
},
Libraries: nested_libraries.C1LibraryDeps,
Overrides: nil,
}
res, err := LinkAndDeployContractWithOverrides(&opts, bindBackend, deploymentParams)
if err != nil {
t.Fatalf("err: %+v\n", err)
}
bindBackend.Commit()
for _, tx := range txs {
// assert that only 4 txs were produced.
/*
if len(deployedLibs)+1 != 4 {
panic(fmt.Sprintf("whoops %d\n", len(deployedLibs)))
}
*/
for _, tx := range res.Txs {
_, err = bind.WaitDeployed(context.Background(), &bindBackend, tx)
if err != nil {
t.Fatalf("error deploying bound contract: %+v", err)
t.Fatalf("error deploying library: %+v", err)
}
}
c, err := nested_libraries.NewC1()
if err != nil {
t.Fatalf("err is %v", err)
}
doInput, err := c.PackDo(big.NewInt(1))
if err != nil {
t.Fatalf("pack function input err: %v\n", doInput)
}
cABI, err := nested_libraries.C1MetaData.GetAbi()
if err != nil {
t.Fatalf("error getting abi object: %v", err)
}
contractAddr := res.Addrs[nested_libraries.C1MetaData.Pattern]
boundC := bind.NewBoundContract(contractAddr, *cABI, &bindBackend, &bindBackend, &bindBackend)
callOpts := &bind.CallOpts{
From: common.Address{},
Context: context.Background(),
}
c1Code, err := bindBackend.PendingCodeAt(context.Background(), contractAddr)
if err != nil {
t.Fatalf("error getting pending code at %x: %v", contractAddr, err)
}
fmt.Printf("contract code:\n%x\n", c1Code)
fmt.Printf("contract input:\n%x\n", doInput)
callRes, err := boundC.CallRaw(callOpts, doInput)
if err != nil {
t.Fatalf("err calling contract: %v", err)
}
unpacked, err := c.UnpackDo(callRes)
if err != nil {
t.Fatalf("err unpacking result: %v", err)
}
// TODO: test transact
fmt.Println(unpacked.String())
}
func TestDeploymentWithOverrides(t *testing.T) {
// test that libs sharing deps, if overrides not specified we will deploy multiple versions of the dependent deps
// test that libs sharing deps, if overrides specified... overrides work.
}
func TestEvents(t *testing.T) {
// test watch/filter logs method on a contract that emits various kinds of events (struct-containing, etc.)
}
/* test-cases that should be extracted from v1 tests