Skip to content

Commit ef8d561

Browse files
Darioush Jalaliceyonuraaronbuchwald
authored
[AV-1644] bump coreth dependency to v1.10.18 (ava-labs#822)
* go deps * core/rawdb * accounts * tracers * rpc * ethdb (NewBatchWithSize only) * trie * plugin/evm (interface update) * misc. * eth/filters * eth/tracers: fix * core/vm * core/types * cmd/abigen eth/ethconfig eth/gasprice ethclient * core/types: regenerate rlp files + update commands * trie: use ptr to generate account rlp * internal/flags: license text update * core/rawdb * core * snapshot * go.mod version workaround * go.mod try 2 * gen_header_json fix * remove snapshot journaling * snapshot: minimize diff * snapshot: unused code (dangling.go) * remove unused const * snpashot: unused structs * core/genesis: cleanup unused code * remove unused method from Snapshot interface * eth/tracers: minor test improvement * add coreth header * use coreth imports * nit * add GetRawReceipts to PublicDebugApi * trie/node_enc.go: add coreth header * Fix imports (ava-labs#823) * fix imports from geth to coreth * run go mod tidy with -compat=1.17 * Revert "run go mod tidy with -compat=1.17" This reverts commit c66470010d8e9e1b541709742238685909e8231e. * run goimports * eth/traces: restore unneeded changes * core/types: revert coinbase to required * core/state/snapshot: revert range based snapshot * fix typo * Geth v1.10.18 nits (ava-labs#826) * Update pending name to accepted * Remove lock from Parent call * Update errors * Add finalized as an optional string that results in AcceptedBlockNumber * Add back lock when grabbing parent Co-authored-by: Ceyhun Onur <[email protected]> Co-authored-by: aaronbuchwald <[email protected]>
1 parent 8be8349 commit ef8d561

File tree

130 files changed

+2295
-947
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+2295
-947
lines changed

accounts/abi/argument.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (arguments Arguments) isTuple() bool {
8888
// Unpack performs the operation hexdata -> Go format.
8989
func (arguments Arguments) Unpack(data []byte) ([]interface{}, error) {
9090
if len(data) == 0 {
91-
if len(arguments) != 0 {
91+
if len(arguments.NonIndexed()) != 0 {
9292
return nil, fmt.Errorf("abi: attempting to unmarshall an empty string while arguments are expected")
9393
}
9494
return make([]interface{}, 0), nil
@@ -103,7 +103,7 @@ func (arguments Arguments) UnpackIntoMap(v map[string]interface{}, data []byte)
103103
return fmt.Errorf("abi: cannot unpack into a nil map")
104104
}
105105
if len(data) == 0 {
106-
if len(arguments) != 0 {
106+
if len(arguments.NonIndexed()) != 0 {
107107
return fmt.Errorf("abi: attempting to unmarshall an empty string while arguments are expected")
108108
}
109109
return nil // Nothing to unmarshal, return
@@ -125,8 +125,8 @@ func (arguments Arguments) Copy(v interface{}, values []interface{}) error {
125125
return fmt.Errorf("abi: Unpack(non-pointer %T)", v)
126126
}
127127
if len(values) == 0 {
128-
if len(arguments) != 0 {
129-
return fmt.Errorf("abi: attempting to copy no values while %d arguments are expected", len(arguments))
128+
if len(arguments.NonIndexed()) != 0 {
129+
return fmt.Errorf("abi: attempting to copy no values while arguments are expected")
130130
}
131131
return nil // Nothing to copy, return
132132
}

accounts/abi/bind/auth.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"crypto/ecdsa"
3232
"errors"
3333
"io"
34-
"io/ioutil"
3534
"math/big"
3635

3736
"github.com/ava-labs/coreth/accounts"
@@ -55,7 +54,7 @@ var ErrNotAuthorized = errors.New("not authorized to sign this account")
5554
// Deprecated: Use NewTransactorWithChainID instead.
5655
func NewTransactor(keyin io.Reader, passphrase string) (*TransactOpts, error) {
5756
log.Warn("WARNING: NewTransactor has been deprecated in favour of NewTransactorWithChainID")
58-
json, err := ioutil.ReadAll(keyin)
57+
json, err := io.ReadAll(keyin)
5958
if err != nil {
6059
return nil, err
6160
}
@@ -116,7 +115,7 @@ func NewKeyedTransactor(key *ecdsa.PrivateKey) *TransactOpts {
116115
// NewTransactorWithChainID is a utility method to easily create a transaction signer from
117116
// an encrypted json key stream and the associated passphrase.
118117
func NewTransactorWithChainID(keyin io.Reader, passphrase string, chainID *big.Int) (*TransactOpts, error) {
119-
json, err := ioutil.ReadAll(keyin)
118+
json, err := io.ReadAll(keyin)
120119
if err != nil {
121120
return nil, err
122121
}

accounts/abi/bind/base.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,10 @@ func (c *BoundContract) Call(opts *CallOpts, results *[]interface{}, method stri
201201
return ErrNoAcceptedState
202202
}
203203
output, err = pb.AcceptedCallContract(ctx, msg)
204-
if err == nil && len(output) == 0 {
204+
if err != nil {
205+
return err
206+
}
207+
if len(output) == 0 {
205208
// Make sure we have a contract to operate on, and bail out otherwise.
206209
if code, err = pb.AcceptedCodeAt(ctx, c.address); err != nil {
207210
return err

accounts/abi/bind/base_test.go

Lines changed: 165 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ package bind_test
2828

2929
import (
3030
"context"
31+
"errors"
3132
"fmt"
3233
"math/big"
3334
"reflect"
@@ -87,34 +88,50 @@ func (mt *mockTransactor) SendTransaction(ctx context.Context, tx *types.Transac
8788
}
8889

8990
type mockCaller struct {
90-
codeAtBlockNumber *big.Int
91-
callContractBlockNumber *big.Int
92-
acceptedCodeAtCalled bool
93-
acceptedCallContractCalled bool
91+
codeAtBlockNumber *big.Int
92+
callContractBlockNumber *big.Int
93+
callContractBytes []byte
94+
callContractErr error
95+
codeAtBytes []byte
96+
codeAtErr error
9497
}
9598

9699
func (mc *mockCaller) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error) {
97100
mc.codeAtBlockNumber = blockNumber
98-
return []byte{1, 2, 3}, nil
101+
return mc.codeAtBytes, mc.codeAtErr
99102
}
100103

101104
func (mc *mockCaller) CallContract(ctx context.Context, call interfaces.CallMsg, blockNumber *big.Int) ([]byte, error) {
102105
mc.callContractBlockNumber = blockNumber
103-
return nil, nil
106+
return mc.callContractBytes, mc.callContractErr
107+
}
108+
109+
type mockAcceptedCaller struct {
110+
*mockCaller
111+
acceptedCodeAtBytes []byte
112+
acceptedCodeAtErr error
113+
acceptedCodeAtCalled bool
114+
acceptedCallContractCalled bool
115+
acceptedCallContractBytes []byte
116+
acceptedCallContractErr error
104117
}
105118

106-
func (mc *mockCaller) AcceptedCodeAt(ctx context.Context, contract common.Address) ([]byte, error) {
119+
func (mc *mockAcceptedCaller) AcceptedCodeAt(ctx context.Context, contract common.Address) ([]byte, error) {
107120
mc.acceptedCodeAtCalled = true
108-
return nil, nil
121+
return mc.acceptedCodeAtBytes, mc.acceptedCodeAtErr
109122
}
110123

111-
func (mc *mockCaller) AcceptedCallContract(ctx context.Context, call interfaces.CallMsg) ([]byte, error) {
124+
func (mc *mockAcceptedCaller) AcceptedCallContract(ctx context.Context, call interfaces.CallMsg) ([]byte, error) {
112125
mc.acceptedCallContractCalled = true
113-
return nil, nil
126+
return mc.acceptedCallContractBytes, mc.acceptedCallContractErr
114127
}
115128
func TestPassingBlockNumber(t *testing.T) {
116129

117-
mc := &mockCaller{}
130+
mc := &mockAcceptedCaller{
131+
mockCaller: &mockCaller{
132+
codeAtBytes: []byte{1, 2, 3},
133+
},
134+
}
118135

119136
bc := bind.NewBoundContract(common.HexToAddress("0x0"), abi.ABI{
120137
Methods: map[string]abi.Method{
@@ -427,3 +444,140 @@ func newMockLog(topics []common.Hash, txHash common.Hash) types.Log {
427444
Removed: false,
428445
}
429446
}
447+
448+
func TestCall(t *testing.T) {
449+
var method, methodWithArg = "something", "somethingArrrrg"
450+
tests := []struct {
451+
name, method string
452+
opts *bind.CallOpts
453+
mc bind.ContractCaller
454+
results *[]interface{}
455+
wantErr bool
456+
wantErrExact error
457+
}{{
458+
name: "ok not accepted",
459+
mc: &mockCaller{
460+
codeAtBytes: []byte{0},
461+
},
462+
method: method,
463+
}, {
464+
name: "ok accepted",
465+
mc: &mockAcceptedCaller{
466+
acceptedCodeAtBytes: []byte{0},
467+
},
468+
opts: &bind.CallOpts{
469+
Accepted: true,
470+
},
471+
method: method,
472+
}, {
473+
name: "pack error, no method",
474+
mc: new(mockCaller),
475+
method: "else",
476+
wantErr: true,
477+
}, {
478+
name: "interface error, accepted but not a AcceptedContractCaller",
479+
mc: new(mockCaller),
480+
opts: &bind.CallOpts{
481+
Accepted: true,
482+
},
483+
method: method,
484+
wantErrExact: bind.ErrNoAcceptedState,
485+
}, {
486+
name: "accepted call canceled",
487+
mc: &mockAcceptedCaller{
488+
acceptedCallContractErr: context.DeadlineExceeded,
489+
},
490+
opts: &bind.CallOpts{
491+
Accepted: true,
492+
},
493+
method: method,
494+
wantErrExact: context.DeadlineExceeded,
495+
}, {
496+
name: "accepted code at error",
497+
mc: &mockAcceptedCaller{
498+
acceptedCodeAtErr: errors.New(""),
499+
},
500+
opts: &bind.CallOpts{
501+
Accepted: true,
502+
},
503+
method: method,
504+
wantErr: true,
505+
}, {
506+
name: "no accepted code at",
507+
mc: new(mockAcceptedCaller),
508+
opts: &bind.CallOpts{
509+
Accepted: true,
510+
},
511+
method: method,
512+
wantErrExact: bind.ErrNoCode,
513+
}, {
514+
name: "call contract error",
515+
mc: &mockCaller{
516+
callContractErr: context.DeadlineExceeded,
517+
},
518+
method: method,
519+
wantErrExact: context.DeadlineExceeded,
520+
}, {
521+
name: "code at error",
522+
mc: &mockCaller{
523+
codeAtErr: errors.New(""),
524+
},
525+
method: method,
526+
wantErr: true,
527+
}, {
528+
name: "no code at",
529+
mc: new(mockCaller),
530+
method: method,
531+
wantErrExact: bind.ErrNoCode,
532+
}, {
533+
name: "unpack error missing arg",
534+
mc: &mockCaller{
535+
codeAtBytes: []byte{0},
536+
},
537+
method: methodWithArg,
538+
wantErr: true,
539+
}, {
540+
name: "interface unpack error",
541+
mc: &mockCaller{
542+
codeAtBytes: []byte{0},
543+
},
544+
method: method,
545+
results: &[]interface{}{0},
546+
wantErr: true,
547+
}}
548+
for _, test := range tests {
549+
bc := bind.NewBoundContract(common.HexToAddress("0x0"), abi.ABI{
550+
Methods: map[string]abi.Method{
551+
method: {
552+
Name: method,
553+
Outputs: abi.Arguments{},
554+
},
555+
methodWithArg: {
556+
Name: methodWithArg,
557+
Outputs: abi.Arguments{abi.Argument{}},
558+
},
559+
},
560+
}, test.mc, nil, nil)
561+
err := bc.Call(test.opts, test.results, test.method)
562+
if test.wantErr || test.wantErrExact != nil {
563+
if err == nil {
564+
t.Fatalf("%q expected error", test.name)
565+
}
566+
if test.wantErrExact != nil && !errors.Is(err, test.wantErrExact) {
567+
t.Fatalf("%q expected error %q but got %q", test.name, test.wantErrExact, err)
568+
}
569+
continue
570+
}
571+
if err != nil {
572+
t.Fatalf("%q unexpected error: %v", test.name, err)
573+
}
574+
}
575+
}
576+
577+
// TestCrashers contains some strings which previously caused the abi codec to crash.
578+
func TestCrashers(t *testing.T) {
579+
abi.JSON(strings.NewReader(`[{"inputs":[{"type":"tuple[]","components":[{"type":"bool","name":"_1"}]}]}]`))
580+
abi.JSON(strings.NewReader(`[{"inputs":[{"type":"tuple[]","components":[{"type":"bool","name":"&"}]}]}]`))
581+
abi.JSON(strings.NewReader(`[{"inputs":[{"type":"tuple[]","components":[{"type":"bool","name":"----"}]}]}]`))
582+
abi.JSON(strings.NewReader(`[{"inputs":[{"type":"tuple[]","components":[{"type":"bool","name":"foo.Bar"}]}]}]`))
583+
}

accounts/abi/bind/bind.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
189189

190190
contracts[types[i]] = &tmplContract{
191191
Type: capitalise(types[i]),
192-
InputABI: strings.Replace(strippedABI, "\"", "\\\"", -1),
192+
InputABI: strings.ReplaceAll(strippedABI, "\"", "\\\""),
193193
InputBin: strings.TrimPrefix(strings.TrimSpace(bytecodes[i]), "0x"),
194194
Constructor: evmABI.Constructor,
195195
Calls: calls,

accounts/abi/bind/bind_test.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ package bind
2828

2929
import (
3030
"fmt"
31-
"io/ioutil"
3231
"os"
3332
"os/exec"
3433
"path/filepath"
@@ -2006,14 +2005,10 @@ func golangBindings(t *testing.T, overload bool) {
20062005
t.Skip("go sdk not found for testing")
20072006
}
20082007
// Create a temporary workspace for the test suite
2009-
ws, err := ioutil.TempDir("", "binding-test")
2010-
if err != nil {
2011-
t.Fatalf("failed to create temporary workspace: %v", err)
2012-
}
2013-
//defer os.RemoveAll(ws)
2008+
ws := t.TempDir()
20142009

20152010
pkg := filepath.Join(ws, "bindtest")
2016-
if err = os.MkdirAll(pkg, 0700); err != nil {
2011+
if err := os.MkdirAll(pkg, 0700); err != nil {
20172012
t.Fatalf("failed to create package: %v", err)
20182013
}
20192014
// Generate the test suite for all the contracts
@@ -2038,7 +2033,7 @@ func golangBindings(t *testing.T, overload bool) {
20382033
if err != nil {
20392034
t.Fatalf("test %d: failed to generate binding: %v", i, err)
20402035
}
2041-
if err = ioutil.WriteFile(filepath.Join(pkg, strings.ToLower(tt.name)+".go"), []byte(bind), 0600); err != nil {
2036+
if err = os.WriteFile(filepath.Join(pkg, strings.ToLower(tt.name)+".go"), []byte(bind), 0600); err != nil {
20422037
t.Fatalf("test %d: failed to write binding: %v", i, err)
20432038
}
20442039
// Generate the test file with the injected test code
@@ -2054,7 +2049,7 @@ func golangBindings(t *testing.T, overload bool) {
20542049
%s
20552050
}
20562051
`, tt.imports, tt.name, tt.tester)
2057-
if err := ioutil.WriteFile(filepath.Join(pkg, strings.ToLower(tt.name)+"_test.go"), []byte(code), 0600); err != nil {
2052+
if err := os.WriteFile(filepath.Join(pkg, strings.ToLower(tt.name)+"_test.go"), []byte(code), 0600); err != nil {
20582053
t.Fatalf("test %d: failed to write tests: %v", i, err)
20592054
}
20602055
})

accounts/abi/bind/template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ var (
171171
}
172172
{{range $pattern, $name := .Libraries}}
173173
{{decapitalise $name}}Addr, _, _, _ := Deploy{{capitalise $name}}(auth, backend)
174-
{{$contract.Type}}Bin = strings.Replace({{$contract.Type}}Bin, "__${{$pattern}}$__", {{decapitalise $name}}Addr.String()[2:], -1)
174+
{{$contract.Type}}Bin = strings.ReplaceAll({{$contract.Type}}Bin, "__${{$pattern}}$__", {{decapitalise $name}}Addr.String()[2:])
175175
{{end}}
176176
address, tx, contract, err := bind.DeployContract(auth, *parsed, common.FromHex({{.Type}}Bin), backend {{range .Constructor.Inputs}}, {{.Name}}{{end}})
177177
if err != nil {

accounts/abi/error.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//
99
// Much love to the original authors for their work.
1010
// **********
11-
// Copyright 2021 The go-ethereum Authors
11+
// Copyright 2016 The go-ethereum Authors
1212
// This file is part of the go-ethereum library.
1313
//
1414
// The go-ethereum library is free software: you can redistribute it and/or modify

accounts/abi/topics_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//
99
// Much love to the original authors for their work.
1010
// **********
11-
// Copyright 2019 The go-ethereum Authors
11+
// Copyright 2020 The go-ethereum Authors
1212
// This file is part of the go-ethereum library.
1313
//
1414
// The go-ethereum library is free software: you can redistribute it and/or modify

0 commit comments

Comments
 (0)