gofmt files. add a TODO comment and remove another useless comment
This commit is contained in:
parent
645c844f4b
commit
709ff38bc1
|
@ -421,7 +421,7 @@ func bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
|
||||||
var findDeps func(contract *tmplContract) map[string]struct{}
|
var findDeps func(contract *tmplContract) map[string]struct{}
|
||||||
findDeps = func(contract *tmplContract) map[string]struct{} {
|
findDeps = func(contract *tmplContract) map[string]struct{} {
|
||||||
// 1) match all libraries that this contract depends on
|
// 1) match all libraries that this contract depends on
|
||||||
re, err := regexp.Compile("__\\$([a-f0-9]+)\\$__")
|
re, err := regexp.Compile(`__\\$([a-f0-9]+)\\$__`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,8 +125,6 @@ var (
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_{{$contract.Type}} *{{$contract.Type}}) Unpack{{.Normalized.Name}}Event(log *types.Log) (*{{$contract.Type}}{{.Normalized.Name}}, error) {
|
func (_{{$contract.Type}} *{{$contract.Type}}) Unpack{{.Normalized.Name}}Event(log *types.Log) (*{{$contract.Type}}{{.Normalized.Name}}, error) {
|
||||||
// TODO: okay to index by the original name here? I think so because we assume that the abi json is well-formed.
|
|
||||||
// and we only need normalized name when dealing with generated go symbols.
|
|
||||||
event := "{{.Original.Name}}"
|
event := "{{.Original.Name}}"
|
||||||
if log.Topics[0] != _{{$contract.Type}}.abi.Events[event].ID {
|
if log.Topics[0] != _{{$contract.Type}}.abi.Events[event].ID {
|
||||||
return nil, errors.New("event signature mismatch")
|
return nil, errors.New("event signature mismatch")
|
||||||
|
@ -183,6 +181,7 @@ var (
|
||||||
errName := "{{.Normalized.Name}}"
|
errName := "{{.Normalized.Name}}"
|
||||||
out := new({{$contract.Type}}{{.Normalized.Name}})
|
out := new({{$contract.Type}}{{.Normalized.Name}})
|
||||||
if err := _{{$contract.Type}}.abi.UnpackIntoInterface(out, errName, raw); err != nil {
|
if err := _{{$contract.Type}}.abi.UnpackIntoInterface(out, errName, raw); err != nil {
|
||||||
|
// TODO: output can be non-pointer type.
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
|
|
|
@ -18,10 +18,11 @@ package v2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum"
|
"github.com/ethereum/go-ethereum"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"math/big"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type BackendV2 interface {
|
type BackendV2 interface {
|
||||||
|
|
|
@ -1,13 +1,29 @@
|
||||||
|
// Copyright 2024 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
package v2
|
package v2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"golang.org/x/exp/rand"
|
"golang.org/x/exp/rand"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type linkTestCase struct {
|
type linkTestCase struct {
|
||||||
|
|
|
@ -17,14 +17,15 @@
|
||||||
package v2
|
package v2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum"
|
"github.com/ethereum/go-ethereum"
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContractDeployParams represents state needed to deploy a contract:
|
// ContractDeployParams represents state needed to deploy a contract:
|
||||||
|
@ -100,7 +101,7 @@ func (d *depTreeBuilder) buildDepTrees(pattern, contract string) {
|
||||||
node.overrideAddr = &addr
|
node.overrideAddr = &addr
|
||||||
}
|
}
|
||||||
// iterate each referenced library in the unlinked code, recurse and built its subtree.
|
// iterate each referenced library in the unlinked code, recurse and built its subtree.
|
||||||
reMatchSpecificPattern, err := regexp.Compile("__\\$([a-f0-9]+)\\$__")
|
reMatchSpecificPattern, err := regexp.Compile(`__\\$([a-f0-9]+)\\$__`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,14 @@ package v2
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"io"
|
||||||
|
"math/big"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
|
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
|
||||||
|
@ -36,13 +43,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/ethclient/simulated"
|
"github.com/ethereum/go-ethereum/ethclient/simulated"
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"io"
|
|
||||||
"math/big"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
var testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||||
|
@ -76,12 +76,10 @@ func testSetup() (*bind.TransactOpts, *backends.SimulatedBackend, error) {
|
||||||
Signer: func(address common.Address, tx *types.Transaction) (*types.Transaction, error) {
|
Signer: func(address common.Address, tx *types.Transaction) (*types.Transaction, error) {
|
||||||
signature, err := crypto.Sign(signer.Hash(tx).Bytes(), testKey)
|
signature, err := crypto.Sign(signer.Hash(tx).Bytes(), testKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("error signing tx: %v", err))
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
signedTx, err := tx.WithSignature(signer, signature)
|
signedTx, err := tx.WithSignature(signer, signature)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("error creating tx with sig: %v", err))
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return signedTx, nil
|
return signedTx, nil
|
||||||
|
@ -304,7 +302,13 @@ func TestEvents(t *testing.T) {
|
||||||
Context: context.Background(),
|
Context: context.Background(),
|
||||||
}
|
}
|
||||||
sub1, err := WatchEvents(&boundContract, watchOpts, events.CBasic1EventID(), ctrct.UnpackBasic1Event, newCBasic1Ch)
|
sub1, err := WatchEvents(&boundContract, watchOpts, events.CBasic1EventID(), ctrct.UnpackBasic1Event, newCBasic1Ch)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("WatchEvents returned error: %v", err)
|
||||||
|
}
|
||||||
sub2, err := WatchEvents(&boundContract, watchOpts, events.CBasic2EventID(), ctrct.UnpackBasic2Event, newCBasic2Ch)
|
sub2, err := WatchEvents(&boundContract, watchOpts, events.CBasic2EventID(), ctrct.UnpackBasic2Event, newCBasic2Ch)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("WatchEvents returned error: %v", err)
|
||||||
|
}
|
||||||
defer sub1.Unsubscribe()
|
defer sub1.Unsubscribe()
|
||||||
defer sub2.Unsubscribe()
|
defer sub2.Unsubscribe()
|
||||||
|
|
||||||
|
@ -327,11 +331,11 @@ func TestEvents(t *testing.T) {
|
||||||
e2Count := 0
|
e2Count := 0
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case _ = <-newCBasic1Ch:
|
case <-newCBasic1Ch:
|
||||||
e1Count++
|
e1Count++
|
||||||
case _ = <-newCBasic2Ch:
|
case <-newCBasic2Ch:
|
||||||
e2Count++
|
e2Count++
|
||||||
case _ = <-timeout.C:
|
case <-timeout.C:
|
||||||
goto done
|
goto done
|
||||||
}
|
}
|
||||||
if e1Count == 2 && e2Count == 1 {
|
if e1Count == 2 && e2Count == 1 {
|
||||||
|
@ -478,6 +482,9 @@ func TestBindingGeneration(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
existingBindings, err := os.ReadFile(filepath.Join(basePath, "bindings.go"))
|
existingBindings, err := os.ReadFile(filepath.Join(basePath, "bindings.go"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ReadFile returned error: %v", err)
|
||||||
|
}
|
||||||
if code != string(existingBindings) {
|
if code != string(existingBindings) {
|
||||||
t.Fatalf("code mismatch for %s", dir)
|
t.Fatalf("code mismatch for %s", dir)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue