Skip to content
51 changes: 51 additions & 0 deletions rpc/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
//
// This file is a derived work, based on the go-ethereum library whose original
// notices appear below.
//
// It is distributed under a license compatible with the licensing terms of the
// original code from which it is derived.
//
// Much love to the original authors for their work.
// **********
// Copyright 2016 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 rpc

import (
"os"
"testing"

"github.com/ava-labs/subnet-evm/plugin/evm/customtypes"
)

func TestMain(m *testing.M) {
customtypes.Register()

// Since there are so many flaky tests in the RPC package, we run the tests
// multiple times to try to get a passing run.
var code int
for range 5 {
code = m.Run()
if code == 0 {
break
}
}

os.Exit(code)
}
8 changes: 0 additions & 8 deletions rpc/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,14 @@ import (
"io"
"math/big"
"net"
"os"
"strings"
"testing"
"time"

"github.com/ava-labs/libevm/common"
"github.com/ava-labs/libevm/core/types"

"github.com/ava-labs/subnet-evm/plugin/evm/customtypes"
)

func TestMain(m *testing.M) {
customtypes.Register()
os.Exit(m.Run())
}

func TestNewID(t *testing.T) {
hexchars := "0123456789ABCDEFabcdef"
for i := 0; i < 100; i++ {
Expand Down
91 changes: 44 additions & 47 deletions rpc/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ func TestWebsocketOriginCheck(t *testing.T) {
}

// This test checks whether calls exceeding the request size limit are rejected.
/*
//
// This test times out occasionally due to context timeout differences with go-ethereum.
// These differences are not critical, so this test can simply be skipped.
func TestWebsocketLargeCall(t *testing.T) {
t.Parallel()
t.Skip("Flaky")

var (
srv = newTestServer()
Expand Down Expand Up @@ -124,66 +126,61 @@ func TestWebsocketLargeCall(t *testing.T) {
t.Fatal("no error for too large call")
}
}
*/

// This test checks whether the wsMessageSizeLimit option is obeyed.
//
// This test times out occasionally due to context timeout differences with go-ethereum.
// These differences are not critical, so this test can simply be skipped.
func TestWebsocketLargeRead(t *testing.T) {
t.Parallel()
t.Skip("Flaky")

var (
srv = newTestServer()
httpsrv = httptest.NewServer(srv.WebsocketHandler([]string{"*"}))
wsURL = "ws:" + strings.TrimPrefix(httpsrv.URL, "http:")
buffer = 64
)
defer srv.Stop()
defer httpsrv.Close()

testLimit := func(limit *int64) {
opts := []ClientOption{}
expLimit := int64(wsDefaultReadLimit)
if limit != nil && *limit >= 0 {
opts = append(opts, WithWebsocketMessageSizeLimit(*limit))
if *limit > 0 {
expLimit = *limit // 0 means infinite
for _, tt := range []struct {
size int
limit int
err bool
}{
{200, 200, false}, // Small, successful request and limit
{2048, 1024, true}, // Normal, failed request
{wsDefaultReadLimit + buffer, 0, false}, // Large, successful request, infinite limit
} {
func() {
if tt.limit != 0 {
// Some buffer is added to the limit to account for JSON encoding. It's
// skipped when the limit is zero since the intention is for the limit
// to be infinite.
tt.limit += buffer
}
}
client, err := DialOptions(context.Background(), wsURL, opts...)
if err != nil {
t.Fatalf("can't dial: %v", err)
}
defer client.Close()
// Remove some bytes for json encoding overhead.
underLimit := int(expLimit - 128)
overLimit := expLimit + 1
if expLimit == wsDefaultReadLimit {
// No point trying the full 32MB in tests. Just sanity-check that
// it's not obviously limited.
underLimit = 1024
overLimit = -1
}
var res string
// Check under limit
if err = client.Call(&res, "test_repeat", "A", underLimit); err != nil {
t.Fatalf("unexpected error with limit %d: %v", expLimit, err)
}
if len(res) != underLimit || strings.Count(res, "A") != underLimit {
t.Fatal("incorrect data")
}
// Check over limit
if overLimit > 0 {
err = client.Call(&res, "test_repeat", "A", expLimit+1)
if err == nil || err != websocket.ErrReadLimit {
t.Fatalf("wrong error with limit %d: %v expecting %v", expLimit, err, websocket.ErrReadLimit)
opts := []ClientOption{WithWebsocketMessageSizeLimit(int64(tt.limit))}
client, err := DialOptions(context.Background(), wsURL, opts...)
if err != nil {
t.Fatalf("failed to dial test server: %v", err)
}
}
}
ptr := func(v int64) *int64 { return &v }
defer client.Close()

testLimit(ptr(-1)) // Should be ignored (use default)
testLimit(ptr(0)) // Should be ignored (use default)
testLimit(nil) // Should be ignored (use default)
testLimit(ptr(200))
testLimit(ptr(wsDefaultReadLimit + 1024))
var res string
err = client.Call(&res, "test_repeat", "A", tt.size)
if tt.err && err == nil {
t.Fatalf("expected error, got none")
}
if !tt.err {
if err != nil {
t.Fatalf("unexpected error with limit %d: %v", tt.limit, err)
}
if strings.Count(res, "A") != tt.size {
t.Fatal("incorrect data")
}
}
}()
}
}

func TestWebsocketPeerInfo(t *testing.T) {
Expand Down
3 changes: 0 additions & 3 deletions scripts/known_flakes.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
TestChainIndexerWithChildren
TestClientCancelWebsocket
TestClientWebsocketLargeMessage
TestGolangBindings
TestMempoolEthTxsAppGossipHandling
TestResumeSyncAccountsTrieInterrupted
TestResyncNewRootAfterDeletes
TestTransactionSkipIndexing
TestVMShutdownWhileSyncing
TestWaitDeployedCornerCases
TestWebsocketLargeRead
Loading