diff --git a/accounts/abi/bind/bind.go b/accounts/abi/bind/bind.go index 3ce73019f8..b9c1457225 100644 --- a/accounts/abi/bind/bind.go +++ b/accounts/abi/bind/bind.go @@ -421,7 +421,7 @@ func bind(types []string, abis []string, bytecodes []string, fsigs []map[string] var findDeps func(contract *tmplContract) map[string]struct{} findDeps = func(contract *tmplContract) map[string]struct{} { // 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 { panic(err) } diff --git a/accounts/abi/bind/source2.go.tpl b/accounts/abi/bind/source2.go.tpl index a77bc67657..a3d099b568 100644 --- a/accounts/abi/bind/source2.go.tpl +++ b/accounts/abi/bind/source2.go.tpl @@ -125,8 +125,6 @@ var ( } 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}}" if log.Topics[0] != _{{$contract.Type}}.abi.Events[event].ID { return nil, errors.New("event signature mismatch") @@ -183,6 +181,7 @@ var ( errName := "{{.Normalized.Name}}" out := new({{$contract.Type}}{{.Normalized.Name}}) if err := _{{$contract.Type}}.abi.UnpackIntoInterface(out, errName, raw); err != nil { + // TODO: output can be non-pointer type. return nil, err } return out, nil diff --git a/accounts/abi/bind/v2/backend.go b/accounts/abi/bind/v2/backend.go index ca4162efab..4f20c89e18 100644 --- a/accounts/abi/bind/v2/backend.go +++ b/accounts/abi/bind/v2/backend.go @@ -18,10 +18,11 @@ package v2 import ( "context" + "math/big" + "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "math/big" ) type BackendV2 interface { diff --git a/accounts/abi/bind/v2/contract_linking_test.go b/accounts/abi/bind/v2/contract_linking_test.go index 0091c2a88c..644e438bc7 100644 --- a/accounts/abi/bind/v2/contract_linking_test.go +++ b/accounts/abi/bind/v2/contract_linking_test.go @@ -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 . package v2 import ( "fmt" + "testing" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "golang.org/x/exp/rand" - "testing" ) type linkTestCase struct { diff --git a/accounts/abi/bind/v2/lib.go b/accounts/abi/bind/v2/lib.go index 434df783eb..e565eb5e80 100644 --- a/accounts/abi/bind/v2/lib.go +++ b/accounts/abi/bind/v2/lib.go @@ -17,14 +17,15 @@ package v2 import ( + "regexp" + "strings" + "github.com/ethereum/go-ethereum" "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" "github.com/ethereum/go-ethereum/event" - "regexp" - "strings" ) // ContractDeployParams represents state needed to deploy a contract: @@ -100,7 +101,7 @@ func (d *depTreeBuilder) buildDepTrees(pattern, contract string) { node.overrideAddr = &addr } // 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 { panic(err) } diff --git a/accounts/abi/bind/v2/lib_test.go b/accounts/abi/bind/v2/lib_test.go index 2d9f8378be..3c24bec514 100644 --- a/accounts/abi/bind/v2/lib_test.go +++ b/accounts/abi/bind/v2/lib_test.go @@ -19,7 +19,14 @@ package v2 import ( "context" "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/bind" "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/node" "github.com/ethereum/go-ethereum/params" - "io" - "math/big" - "os" - "path/filepath" - "strings" - "testing" - "time" ) 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) { signature, err := crypto.Sign(signer.Hash(tx).Bytes(), testKey) if err != nil { - panic(fmt.Sprintf("error signing tx: %v", err)) return nil, err } signedTx, err := tx.WithSignature(signer, signature) if err != nil { - panic(fmt.Sprintf("error creating tx with sig: %v", err)) return nil, err } return signedTx, nil @@ -304,7 +302,13 @@ func TestEvents(t *testing.T) { Context: context.Background(), } 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) + if err != nil { + t.Fatalf("WatchEvents returned error: %v", err) + } defer sub1.Unsubscribe() defer sub2.Unsubscribe() @@ -327,11 +331,11 @@ func TestEvents(t *testing.T) { e2Count := 0 for { select { - case _ = <-newCBasic1Ch: + case <-newCBasic1Ch: e1Count++ - case _ = <-newCBasic2Ch: + case <-newCBasic2Ch: e2Count++ - case _ = <-timeout.C: + case <-timeout.C: goto done } if e1Count == 2 && e2Count == 1 { @@ -478,6 +482,9 @@ func TestBindingGeneration(t *testing.T) { } existingBindings, err := os.ReadFile(filepath.Join(basePath, "bindings.go")) + if err != nil { + t.Fatalf("ReadFile returned error: %v", err) + } if code != string(existingBindings) { t.Fatalf("code mismatch for %s", dir) }