Skip to content

Commit a4f4590

Browse files
Merge branch 'master' into JonathanOppenheimer/remove-customlogs
2 parents 3f62f7c + 9465469 commit a4f4590

File tree

5 files changed

+112
-65
lines changed

5 files changed

+112
-65
lines changed

accounts/abi/bind/bind_test.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,20 +2157,10 @@ func golangBindings(t *testing.T, overload bool) {
21572157
import (
21582158
"testing"
21592159
2160-
"github.com/ava-labs/coreth/params"
2161-
"github.com/ava-labs/coreth/plugin/evm/customtypes"
2162-
libevmparams "github.com/ava-labs/libevm/params"
2163-
libevmtypes "github.com/ava-labs/libevm/core/types"
2164-
21652160
%s
21662161
)
21672162
21682163
func Test%s(t *testing.T) {
2169-
customtypes.Register()
2170-
t.Cleanup(libevmtypes.TestOnlyClearRegisteredExtras)
2171-
params.RegisterExtras()
2172-
t.Cleanup(libevmparams.TestOnlyClearRegisteredExtras)
2173-
21742164
%s
21752165
}
21762166
`, tt.imports, tt.name, tt.tester)
@@ -2179,6 +2169,30 @@ func golangBindings(t *testing.T, overload bool) {
21792169
}
21802170
})
21812171
}
2172+
2173+
// We must also write a main_test.go file for libevm registrations.
2174+
mainTest := `
2175+
package bindtest
2176+
2177+
import (
2178+
"os"
2179+
"testing"
2180+
2181+
"github.com/ava-labs/coreth/params"
2182+
"github.com/ava-labs/coreth/plugin/evm/customtypes"
2183+
)
2184+
2185+
func TestMain(m *testing.M) {
2186+
customtypes.Register()
2187+
params.RegisterExtras()
2188+
os.Exit(m.Run())
2189+
}
2190+
`
2191+
mainPath := filepath.Join(pkg, "main_test.go")
2192+
if err := os.WriteFile(mainPath, []byte(mainTest), 0600); err != nil {
2193+
t.Fatalf("os.WriteFile(%q, 0600): %v", mainPath, err)
2194+
}
2195+
21822196
// Convert the package to go modules and use the current source for go-ethereum
21832197
moder := exec.Command(gocmd, "mod", "init", "bindtest")
21842198
moder.Dir = pkg
@@ -2197,7 +2211,7 @@ func golangBindings(t *testing.T, overload bool) {
21972211
t.Fatalf("failed to tidy Go module file: %v\n%s", err, out)
21982212
}
21992213
// Test the entire package and report any failures
2200-
cmd := exec.Command(gocmd, "test", "-v", "-count", "1")
2214+
cmd := exec.Command(gocmd, "test", "-v", "-count", "1", "-race")
22012215
cmd.Dir = pkg
22022216
if out, err := cmd.CombinedOutput(); err != nil {
22032217
t.Fatalf("failed to run binding test: %v\n%s", err, out)

rpc/main_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
//
4+
// This file is a derived work, based on the go-ethereum library whose original
5+
// notices appear below.
6+
//
7+
// It is distributed under a license compatible with the licensing terms of the
8+
// original code from which it is derived.
9+
//
10+
// Much love to the original authors for their work.
11+
// **********
12+
// Copyright 2016 The go-ethereum Authors
13+
// This file is part of the go-ethereum library.
14+
//
15+
// The go-ethereum library is free software: you can redistribute it and/or modify
16+
// it under the terms of the GNU Lesser General Public License as published by
17+
// the Free Software Foundation, either version 3 of the License, or
18+
// (at your option) any later version.
19+
//
20+
// The go-ethereum library is distributed in the hope that it will be useful,
21+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
22+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23+
// GNU Lesser General Public License for more details.
24+
//
25+
// You should have received a copy of the GNU Lesser General Public License
26+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
27+
28+
package rpc
29+
30+
import (
31+
"os"
32+
"testing"
33+
34+
"github.com/ava-labs/coreth/plugin/evm/customtypes"
35+
)
36+
37+
func TestMain(m *testing.M) {
38+
customtypes.Register()
39+
40+
// Since there are so many flaky tests in the RPC package, we run the tests
41+
// multiple times to try to get a passing run.
42+
var code int
43+
for range 5 {
44+
code = m.Run()
45+
if code == 0 {
46+
break
47+
}
48+
}
49+
50+
os.Exit(code)
51+
}

rpc/subscription_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,14 @@ import (
3535
"io"
3636
"math/big"
3737
"net"
38-
"os"
3938
"strings"
4039
"testing"
4140
"time"
4241

43-
"github.com/ava-labs/coreth/plugin/evm/customtypes"
4442
"github.com/ava-labs/libevm/common"
4543
"github.com/ava-labs/libevm/core/types"
4644
)
4745

48-
func TestMain(m *testing.M) {
49-
customtypes.Register()
50-
os.Exit(m.Run())
51-
}
52-
5346
func TestNewID(t *testing.T) {
5447
hexchars := "0123456789ABCDEFabcdef"
5548
for i := 0; i < 100; i++ {

rpc/websocket_test.go

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -134,56 +134,49 @@ func TestWebsocketLargeRead(t *testing.T) {
134134
srv = newTestServer()
135135
httpsrv = httptest.NewServer(srv.WebsocketHandler([]string{"*"}))
136136
wsURL = "ws:" + strings.TrimPrefix(httpsrv.URL, "http:")
137+
buffer = 64
137138
)
138139
defer srv.Stop()
139140
defer httpsrv.Close()
140141

141-
testLimit := func(limit *int64) {
142-
opts := []ClientOption{}
143-
expLimit := int64(wsDefaultReadLimit)
144-
if limit != nil && *limit >= 0 {
145-
opts = append(opts, WithWebsocketMessageSizeLimit(*limit))
146-
if *limit > 0 {
147-
expLimit = *limit // 0 means infinite
142+
for _, tt := range []struct {
143+
size int
144+
limit int
145+
err bool
146+
}{
147+
{200, 200, false}, // Small, successful request and limit
148+
{2048, 1024, true}, // Normal, failed request
149+
{wsDefaultReadLimit + buffer, 0, false}, // Large, successful request, infinite limit
150+
} {
151+
func() {
152+
if tt.limit != 0 {
153+
// Some buffer is added to the limit to account for JSON encoding. It's
154+
// skipped when the limit is zero since the intention is for the limit
155+
// to be infinite.
156+
tt.limit += buffer
148157
}
149-
}
150-
client, err := DialOptions(context.Background(), wsURL, opts...)
151-
if err != nil {
152-
t.Fatalf("can't dial: %v", err)
153-
}
154-
defer client.Close()
155-
// Remove some bytes for json encoding overhead.
156-
underLimit := int(expLimit - 128)
157-
overLimit := expLimit + 1
158-
if expLimit == wsDefaultReadLimit {
159-
// No point trying the full 32MB in tests. Just sanity-check that
160-
// it's not obviously limited.
161-
underLimit = 1024
162-
overLimit = -1
163-
}
164-
var res string
165-
// Check under limit
166-
if err = client.Call(&res, "test_repeat", "A", underLimit); err != nil {
167-
t.Fatalf("unexpected error with limit %d: %v", expLimit, err)
168-
}
169-
if len(res) != underLimit || strings.Count(res, "A") != underLimit {
170-
t.Fatal("incorrect data")
171-
}
172-
// Check over limit
173-
if overLimit > 0 {
174-
err = client.Call(&res, "test_repeat", "A", expLimit+1)
175-
if err == nil || err != websocket.ErrReadLimit {
176-
t.Fatalf("wrong error with limit %d: %v expecting %v", expLimit, err, websocket.ErrReadLimit)
158+
opts := []ClientOption{WithWebsocketMessageSizeLimit(int64(tt.limit))}
159+
client, err := DialOptions(context.Background(), wsURL, opts...)
160+
if err != nil {
161+
t.Fatalf("failed to dial test server: %v", err)
177162
}
178-
}
179-
}
180-
ptr := func(v int64) *int64 { return &v }
163+
defer client.Close()
181164

182-
testLimit(ptr(-1)) // Should be ignored (use default)
183-
testLimit(ptr(0)) // Should be ignored (use default)
184-
testLimit(nil) // Should be ignored (use default)
185-
testLimit(ptr(200))
186-
testLimit(ptr(wsDefaultReadLimit + 1024))
165+
var res string
166+
err = client.Call(&res, "test_repeat", "A", tt.size)
167+
if tt.err && err == nil {
168+
t.Fatalf("expected error, got none")
169+
}
170+
if !tt.err {
171+
if err != nil {
172+
t.Fatalf("unexpected error with limit %d: %v", tt.limit, err)
173+
}
174+
if strings.Count(res, "A") != tt.size {
175+
t.Fatal("incorrect data")
176+
}
177+
}
178+
}()
179+
}
187180
}
188181

189182
func TestWebsocketPeerInfo(t *testing.T) {

scripts/known_flakes.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
TestClientCancelWebsocket
2-
TestClientWebsocketLargeMessage
3-
TestGolangBindings
41
TestMempoolAtmTxsAppGossipHandlingDiscardedTx
52
TestMempoolEthTxsAppGossipHandling
63
TestResumeSyncAccountsTrieInterrupted
74
TestResyncNewRootAfterDeletes
85
TestTransactionSkipIndexing
96
TestUpdatedKeyfileContents
10-
TestWebsocketLargeRead

0 commit comments

Comments
 (0)