Browse Source

testing: use scoped logger for all public packages (#7504)

pull/7507/head
Sam Kleinman 3 years ago
committed by GitHub
parent
commit
5c0abb5367
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 265 additions and 122 deletions
  1. +1
    -1
      abci/client/socket_client_test.go
  2. +15
    -11
      abci/example/example_test.go
  3. +1
    -1
      abci/example/kvstore/kvstore_test.go
  4. +1
    -1
      abci/tests/client_server_test.go
  5. +2
    -1
      libs/events/event_cache_test.go
  6. +23
    -8
      libs/events/events_test.go
  7. +3
    -1
      libs/service/service_test.go
  8. +15
    -6
      light/client_benchmark_test.go
  9. +45
    -15
      light/client_test.go
  10. +22
    -8
      light/detector_test.go
  11. +4
    -1
      light/example_test.go
  12. +6
    -2
      light/light_test.go
  13. +37
    -25
      node/node_test.go
  14. +3
    -3
      privval/grpc/client_test.go
  15. +21
    -9
      privval/grpc/server_test.go
  16. +33
    -12
      privval/signer_client_test.go
  17. +6
    -4
      privval/signer_listener_endpoint_test.go
  18. +2
    -2
      rpc/client/rpc_test.go
  19. +1
    -1
      rpc/jsonrpc/client/ws_client_test.go
  20. +6
    -4
      rpc/jsonrpc/jsonrpc_test.go
  21. +7
    -2
      rpc/jsonrpc/server/http_server_test.go
  22. +11
    -4
      rpc/jsonrpc/server/ws_handler_test.go

+ 1
- 1
abci/client/socket_client_test.go View File

@ -23,7 +23,7 @@ func TestProperSyncCalls(t *testing.T) {
defer cancel() defer cancel()
app := slowApp{} app := slowApp{}
logger := log.TestingLogger()
logger := log.NewTestingLogger(t)
_, c := setupClientServer(ctx, t, logger, app) _, c := setupClientServer(ctx, t, logger, app)


+ 15
- 11
abci/example/example_test.go View File

@ -32,34 +32,38 @@ func init() {
func TestKVStore(t *testing.T) { func TestKVStore(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
logger := log.NewTestingLogger(t)
fmt.Println("### Testing KVStore")
testStream(ctx, t, kvstore.NewApplication())
logger.Info("### Testing KVStore")
testStream(ctx, t, logger, kvstore.NewApplication())
} }
func TestBaseApp(t *testing.T) { func TestBaseApp(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
fmt.Println("### Testing BaseApp")
testStream(ctx, t, types.NewBaseApplication())
logger := log.NewTestingLogger(t)
logger.Info("### Testing BaseApp")
testStream(ctx, t, logger, types.NewBaseApplication())
} }
func TestGRPC(t *testing.T) { func TestGRPC(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
fmt.Println("### Testing GRPC")
testGRPCSync(ctx, t, types.NewGRPCApplication(types.NewBaseApplication()))
logger := log.NewTestingLogger(t)
logger.Info("### Testing GRPC")
testGRPCSync(ctx, t, logger, types.NewGRPCApplication(types.NewBaseApplication()))
} }
func testStream(ctx context.Context, t *testing.T, app types.Application) {
func testStream(ctx context.Context, t *testing.T, logger log.Logger, app types.Application) {
t.Helper() t.Helper()
const numDeliverTxs = 20000 const numDeliverTxs = 20000
socketFile := fmt.Sprintf("test-%08x.sock", rand.Int31n(1<<30)) socketFile := fmt.Sprintf("test-%08x.sock", rand.Int31n(1<<30))
defer os.Remove(socketFile) defer os.Remove(socketFile)
socket := fmt.Sprintf("unix://%v", socketFile) socket := fmt.Sprintf("unix://%v", socketFile)
logger := log.TestingLogger()
// Start the listener // Start the listener
server := abciserver.NewSocketServer(logger.With("module", "abci-server"), socket, app) server := abciserver.NewSocketServer(logger.With("module", "abci-server"), socket, app)
t.Cleanup(server.Wait) t.Cleanup(server.Wait)
@ -67,7 +71,7 @@ func testStream(ctx context.Context, t *testing.T, app types.Application) {
require.NoError(t, err) require.NoError(t, err)
// Connect to the socket // Connect to the socket
client := abciclient.NewSocketClient(log.TestingLogger().With("module", "abci-client"), socket, false)
client := abciclient.NewSocketClient(logger.With("module", "abci-client"), socket, false)
t.Cleanup(client.Wait) t.Cleanup(client.Wait)
err = client.Start(ctx) err = client.Start(ctx)
@ -127,12 +131,12 @@ func dialerFunc(ctx context.Context, addr string) (net.Conn, error) {
return tmnet.Connect(addr) return tmnet.Connect(addr)
} }
func testGRPCSync(ctx context.Context, t *testing.T, app types.ABCIApplicationServer) {
func testGRPCSync(ctx context.Context, t *testing.T, logger log.Logger, app types.ABCIApplicationServer) {
numDeliverTxs := 2000 numDeliverTxs := 2000
socketFile := fmt.Sprintf("/tmp/test-%08x.sock", rand.Int31n(1<<30)) socketFile := fmt.Sprintf("/tmp/test-%08x.sock", rand.Int31n(1<<30))
defer os.Remove(socketFile) defer os.Remove(socketFile)
socket := fmt.Sprintf("unix://%v", socketFile) socket := fmt.Sprintf("unix://%v", socketFile)
logger := log.TestingLogger()
// Start the listener // Start the listener
server := abciserver.NewGRPCServer(logger.With("module", "abci-server"), socket, app) server := abciserver.NewGRPCServer(logger.With("module", "abci-server"), socket, app)


+ 1
- 1
abci/example/kvstore/kvstore_test.go View File

@ -289,7 +289,7 @@ func makeGRPCClientServer(
func TestClientServer(t *testing.T) { func TestClientServer(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
logger := log.TestingLogger()
logger := log.NewTestingLogger(t)
// set up socket app // set up socket app
kvstore := NewApplication() kvstore := NewApplication()


+ 1
- 1
abci/tests/client_server_test.go View File

@ -21,7 +21,7 @@ func TestClientServerNoAddrPrefix(t *testing.T) {
transport = "socket" transport = "socket"
) )
app := kvstore.NewApplication() app := kvstore.NewApplication()
logger := log.TestingLogger()
logger := log.NewTestingLogger(t)
server, err := abciserver.NewServer(logger, addr, transport, app) server, err := abciserver.NewServer(logger, addr, transport, app)
assert.NoError(t, err, "expected no error on NewServer") assert.NoError(t, err, "expected no error on NewServer")


+ 2
- 1
libs/events/event_cache_test.go View File

@ -13,7 +13,8 @@ func TestEventCache_Flush(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
evsw := NewEventSwitch(log.TestingLogger())
logger := log.NewTestingLogger(t)
evsw := NewEventSwitch(logger)
err := evsw.Start(ctx) err := evsw.Start(ctx)
require.NoError(t, err) require.NoError(t, err)


+ 23
- 8
libs/events/events_test.go View File

@ -19,7 +19,9 @@ func TestAddListenerForEventFireOnce(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
evsw := NewEventSwitch(log.TestingLogger())
logger := log.NewTestingLogger(t)
evsw := NewEventSwitch(logger)
require.NoError(t, evsw.Start(ctx)) require.NoError(t, evsw.Start(ctx))
t.Cleanup(evsw.Wait) t.Cleanup(evsw.Wait)
@ -48,7 +50,9 @@ func TestAddListenerForEventFireMany(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
evsw := NewEventSwitch(log.TestingLogger())
logger := log.NewTestingLogger(t)
evsw := NewEventSwitch(logger)
require.NoError(t, evsw.Start(ctx)) require.NoError(t, evsw.Start(ctx))
t.Cleanup(evsw.Wait) t.Cleanup(evsw.Wait)
@ -84,7 +88,9 @@ func TestAddListenerForDifferentEvents(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
evsw := NewEventSwitch(log.TestingLogger())
logger := log.NewTestingLogger(t)
evsw := NewEventSwitch(logger)
require.NoError(t, evsw.Start(ctx)) require.NoError(t, evsw.Start(ctx))
t.Cleanup(evsw.Wait) t.Cleanup(evsw.Wait)
@ -146,7 +152,8 @@ func TestAddDifferentListenerForDifferentEvents(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
evsw := NewEventSwitch(log.TestingLogger())
logger := log.NewTestingLogger(t)
evsw := NewEventSwitch(logger)
require.NoError(t, evsw.Start(ctx)) require.NoError(t, evsw.Start(ctx))
t.Cleanup(evsw.Wait) t.Cleanup(evsw.Wait)
@ -236,7 +243,9 @@ func TestAddAndRemoveListenerConcurrency(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
evsw := NewEventSwitch(log.TestingLogger())
logger := log.NewTestingLogger(t)
evsw := NewEventSwitch(logger)
require.NoError(t, evsw.Start(ctx)) require.NoError(t, evsw.Start(ctx))
t.Cleanup(evsw.Wait) t.Cleanup(evsw.Wait)
@ -285,7 +294,8 @@ func TestAddAndRemoveListener(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
evsw := NewEventSwitch(log.TestingLogger())
logger := log.NewTestingLogger(t)
evsw := NewEventSwitch(logger)
require.NoError(t, evsw.Start(ctx)) require.NoError(t, evsw.Start(ctx))
t.Cleanup(evsw.Wait) t.Cleanup(evsw.Wait)
@ -341,7 +351,10 @@ func TestAddAndRemoveListener(t *testing.T) {
func TestRemoveListener(t *testing.T) { func TestRemoveListener(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
evsw := NewEventSwitch(log.TestingLogger())
logger := log.NewTestingLogger(t)
evsw := NewEventSwitch(logger)
require.NoError(t, evsw.Start(ctx)) require.NoError(t, evsw.Start(ctx))
t.Cleanup(evsw.Wait) t.Cleanup(evsw.Wait)
@ -398,7 +411,9 @@ func TestRemoveListener(t *testing.T) {
func TestRemoveListenersAsync(t *testing.T) { func TestRemoveListenersAsync(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
evsw := NewEventSwitch(log.TestingLogger())
logger := log.NewTestingLogger(t)
evsw := NewEventSwitch(logger)
require.NoError(t, evsw.Start(ctx)) require.NoError(t, evsw.Start(ctx))
t.Cleanup(evsw.Wait) t.Cleanup(evsw.Wait)


+ 3
- 1
libs/service/service_test.go View File

@ -22,8 +22,10 @@ func TestBaseServiceWait(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
logger := log.NewTestingLogger(t)
ts := &testService{} ts := &testService{}
ts.BaseService = *NewBaseService(log.TestingLogger(), "TestService", ts)
ts.BaseService = *NewBaseService(logger, "TestService", ts)
err := ts.Start(ctx) err := ts.Start(ctx)
require.NoError(t, err) require.NoError(t, err)


+ 15
- 6
light/client_benchmark_test.go View File

@ -65,6 +65,8 @@ func BenchmarkSequence(b *testing.B) {
benchmarkFullNode := newProviderBenchmarkImpl(headers, vals) benchmarkFullNode := newProviderBenchmarkImpl(headers, vals)
genesisBlock, _ := benchmarkFullNode.LightBlock(context.Background(), 1) genesisBlock, _ := benchmarkFullNode.LightBlock(context.Background(), 1)
logger := log.NewTestingLogger(b)
c, err := light.NewClient( c, err := light.NewClient(
context.Background(), context.Background(),
chainID, chainID,
@ -76,7 +78,7 @@ func BenchmarkSequence(b *testing.B) {
benchmarkFullNode, benchmarkFullNode,
[]provider.Provider{benchmarkFullNode}, []provider.Provider{benchmarkFullNode},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
light.SequentialVerification(), light.SequentialVerification(),
) )
if err != nil { if err != nil {
@ -97,6 +99,8 @@ func BenchmarkBisection(b *testing.B) {
benchmarkFullNode := newProviderBenchmarkImpl(headers, vals) benchmarkFullNode := newProviderBenchmarkImpl(headers, vals)
genesisBlock, _ := benchmarkFullNode.LightBlock(context.Background(), 1) genesisBlock, _ := benchmarkFullNode.LightBlock(context.Background(), 1)
logger := log.NewTestingLogger(b)
c, err := light.NewClient( c, err := light.NewClient(
context.Background(), context.Background(),
chainID, chainID,
@ -108,7 +112,7 @@ func BenchmarkBisection(b *testing.B) {
benchmarkFullNode, benchmarkFullNode,
[]provider.Provider{benchmarkFullNode}, []provider.Provider{benchmarkFullNode},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
@ -124,12 +128,17 @@ func BenchmarkBisection(b *testing.B) {
} }
func BenchmarkBackwards(b *testing.B) { func BenchmarkBackwards(b *testing.B) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
headers, vals, _ := genLightBlocksWithKeys(chainID, 1000, 100, 1, bTime) headers, vals, _ := genLightBlocksWithKeys(chainID, 1000, 100, 1, bTime)
benchmarkFullNode := newProviderBenchmarkImpl(headers, vals) benchmarkFullNode := newProviderBenchmarkImpl(headers, vals)
trustedBlock, _ := benchmarkFullNode.LightBlock(context.Background(), 0)
trustedBlock, _ := benchmarkFullNode.LightBlock(ctx, 0)
logger := log.NewTestingLogger(b)
c, err := light.NewClient( c, err := light.NewClient(
context.Background(),
ctx,
chainID, chainID,
light.TrustOptions{ light.TrustOptions{
Period: 24 * time.Hour, Period: 24 * time.Hour,
@ -139,7 +148,7 @@ func BenchmarkBackwards(b *testing.B) {
benchmarkFullNode, benchmarkFullNode,
[]provider.Provider{benchmarkFullNode}, []provider.Provider{benchmarkFullNode},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
@ -147,7 +156,7 @@ func BenchmarkBackwards(b *testing.B) {
b.ResetTimer() b.ResetTimer()
for n := 0; n < b.N; n++ { for n := 0; n < b.N; n++ {
_, err = c.VerifyLightBlockAtHeight(context.Background(), 1, bTime)
_, err = c.VerifyLightBlockAtHeight(ctx, 1, bTime)
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }


+ 45
- 15
light/client_test.go View File

@ -209,6 +209,8 @@ func TestClient_SequentialVerification(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
testCase := tc testCase := tc
t.Run(testCase.name, func(t *testing.T) { t.Run(testCase.name, func(t *testing.T) {
logger := log.NewTestingLogger(t)
mockNode := mockNodeFromHeadersAndVals(testCase.otherHeaders, testCase.vals) mockNode := mockNodeFromHeadersAndVals(testCase.otherHeaders, testCase.vals)
mockNode.On("LightBlock", mock.Anything, mock.Anything).Return(nil, provider.ErrLightBlockNotFound) mockNode.On("LightBlock", mock.Anything, mock.Anything).Return(nil, provider.ErrLightBlockNotFound)
c, err := light.NewClient( c, err := light.NewClient(
@ -219,7 +221,7 @@ func TestClient_SequentialVerification(t *testing.T) {
[]provider.Provider{mockNode}, []provider.Provider{mockNode},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.SequentialVerification(), light.SequentialVerification(),
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
if testCase.initErr { if testCase.initErr {
@ -329,6 +331,8 @@ func TestClient_SkippingVerification(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
tc := tc tc := tc
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
logger := log.NewTestingLogger(t)
mockNode := mockNodeFromHeadersAndVals(tc.otherHeaders, tc.vals) mockNode := mockNodeFromHeadersAndVals(tc.otherHeaders, tc.vals)
mockNode.On("LightBlock", mock.Anything, mock.Anything).Return(nil, provider.ErrLightBlockNotFound) mockNode.On("LightBlock", mock.Anything, mock.Anything).Return(nil, provider.ErrLightBlockNotFound)
c, err := light.NewClient( c, err := light.NewClient(
@ -339,7 +343,7 @@ func TestClient_SkippingVerification(t *testing.T) {
[]provider.Provider{mockNode}, []provider.Provider{mockNode},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.SkippingVerification(light.DefaultTrustLevel), light.SkippingVerification(light.DefaultTrustLevel),
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
if tc.initErr { if tc.initErr {
require.Error(t, err) require.Error(t, err)
@ -436,6 +440,8 @@ func TestClientBisectionBetweenTrustedHeaders(t *testing.T) {
} }
func TestClient_Cleanup(t *testing.T) { func TestClient_Cleanup(t *testing.T) {
logger := log.NewTestingLogger(t)
mockFullNode := &provider_mocks.Provider{} mockFullNode := &provider_mocks.Provider{}
mockFullNode.On("LightBlock", mock.Anything, int64(1)).Return(l1, nil) mockFullNode.On("LightBlock", mock.Anything, int64(1)).Return(l1, nil)
c, err := light.NewClient( c, err := light.NewClient(
@ -445,7 +451,7 @@ func TestClient_Cleanup(t *testing.T) {
mockFullNode, mockFullNode,
[]provider.Provider{mockFullNode}, []provider.Provider{mockFullNode},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
require.NoError(t, err) require.NoError(t, err)
_, err = c.TrustedLightBlock(1) _, err = c.TrustedLightBlock(1)
@ -465,6 +471,8 @@ func TestClient_Cleanup(t *testing.T) {
func TestClientRestoresTrustedHeaderAfterStartup(t *testing.T) { func TestClientRestoresTrustedHeaderAfterStartup(t *testing.T) {
// 1. options.Hash == trustedHeader.Hash // 1. options.Hash == trustedHeader.Hash
t.Run("hashes should match", func(t *testing.T) { t.Run("hashes should match", func(t *testing.T) {
logger := log.NewTestingLogger(t)
mockNode := &provider_mocks.Provider{} mockNode := &provider_mocks.Provider{}
trustedStore := dbs.New(dbm.NewMemDB()) trustedStore := dbs.New(dbm.NewMemDB())
err := trustedStore.SaveLightBlock(l1) err := trustedStore.SaveLightBlock(l1)
@ -477,7 +485,7 @@ func TestClientRestoresTrustedHeaderAfterStartup(t *testing.T) {
mockNode, mockNode,
[]provider.Provider{mockNode}, []provider.Provider{mockNode},
trustedStore, trustedStore,
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
require.NoError(t, err) require.NoError(t, err)
@ -495,6 +503,8 @@ func TestClientRestoresTrustedHeaderAfterStartup(t *testing.T) {
err := trustedStore.SaveLightBlock(l1) err := trustedStore.SaveLightBlock(l1)
require.NoError(t, err) require.NoError(t, err)
logger := log.NewTestingLogger(t)
// header1 != h1 // header1 != h1
header1 := keys.GenSignedHeader(chainID, 1, bTime.Add(1*time.Hour), nil, vals, vals, header1 := keys.GenSignedHeader(chainID, 1, bTime.Add(1*time.Hour), nil, vals, vals,
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)) hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys))
@ -511,7 +521,7 @@ func TestClientRestoresTrustedHeaderAfterStartup(t *testing.T) {
mockNode, mockNode,
[]provider.Provider{mockNode}, []provider.Provider{mockNode},
trustedStore, trustedStore,
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
require.NoError(t, err) require.NoError(t, err)
@ -531,6 +541,9 @@ func TestClient_Update(t *testing.T) {
mockFullNode.On("LightBlock", mock.Anything, int64(0)).Return(l3, nil) mockFullNode.On("LightBlock", mock.Anything, int64(0)).Return(l3, nil)
mockFullNode.On("LightBlock", mock.Anything, int64(1)).Return(l1, nil) mockFullNode.On("LightBlock", mock.Anything, int64(1)).Return(l1, nil)
mockFullNode.On("LightBlock", mock.Anything, int64(3)).Return(l3, nil) mockFullNode.On("LightBlock", mock.Anything, int64(3)).Return(l3, nil)
logger := log.NewTestingLogger(t)
c, err := light.NewClient( c, err := light.NewClient(
ctx, ctx,
chainID, chainID,
@ -538,7 +551,7 @@ func TestClient_Update(t *testing.T) {
mockFullNode, mockFullNode,
[]provider.Provider{mockFullNode}, []provider.Provider{mockFullNode},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
require.NoError(t, err) require.NoError(t, err)
@ -553,6 +566,8 @@ func TestClient_Update(t *testing.T) {
} }
func TestClient_Concurrency(t *testing.T) { func TestClient_Concurrency(t *testing.T) {
logger := log.NewTestingLogger(t)
mockFullNode := &provider_mocks.Provider{} mockFullNode := &provider_mocks.Provider{}
mockFullNode.On("LightBlock", mock.Anything, int64(2)).Return(l2, nil) mockFullNode.On("LightBlock", mock.Anything, int64(2)).Return(l2, nil)
mockFullNode.On("LightBlock", mock.Anything, int64(1)).Return(l1, nil) mockFullNode.On("LightBlock", mock.Anything, int64(1)).Return(l1, nil)
@ -563,7 +578,7 @@ func TestClient_Concurrency(t *testing.T) {
mockFullNode, mockFullNode,
[]provider.Provider{mockFullNode}, []provider.Provider{mockFullNode},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
require.NoError(t, err) require.NoError(t, err)
@ -602,6 +617,8 @@ func TestClient_AddProviders(t *testing.T) {
1: h1, 1: h1,
2: h2, 2: h2,
}, valSet) }, valSet)
logger := log.NewTestingLogger(t)
c, err := light.NewClient( c, err := light.NewClient(
ctx, ctx,
chainID, chainID,
@ -609,7 +626,7 @@ func TestClient_AddProviders(t *testing.T) {
mockFullNode, mockFullNode,
[]provider.Provider{mockFullNode}, []provider.Provider{mockFullNode},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
require.NoError(t, err) require.NoError(t, err)
@ -638,6 +655,9 @@ func TestClientReplacesPrimaryWithWitnessIfPrimaryIsUnavailable(t *testing.T) {
mockDeadNode := &provider_mocks.Provider{} mockDeadNode := &provider_mocks.Provider{}
mockDeadNode.On("LightBlock", mock.Anything, mock.Anything).Return(nil, provider.ErrNoResponse) mockDeadNode.On("LightBlock", mock.Anything, mock.Anything).Return(nil, provider.ErrNoResponse)
logger := log.NewTestingLogger(t)
c, err := light.NewClient( c, err := light.NewClient(
ctx, ctx,
chainID, chainID,
@ -645,7 +665,7 @@ func TestClientReplacesPrimaryWithWitnessIfPrimaryIsUnavailable(t *testing.T) {
mockDeadNode, mockDeadNode,
[]provider.Provider{mockDeadNode, mockFullNode}, []provider.Provider{mockDeadNode, mockFullNode},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
require.NoError(t, err) require.NoError(t, err)
@ -666,6 +686,8 @@ func TestClientReplacesPrimaryWithWitnessIfPrimaryDoesntHaveBlock(t *testing.T)
mockFullNode := &provider_mocks.Provider{} mockFullNode := &provider_mocks.Provider{}
mockFullNode.On("LightBlock", mock.Anything, mock.Anything).Return(l1, nil) mockFullNode.On("LightBlock", mock.Anything, mock.Anything).Return(l1, nil)
logger := log.NewTestingLogger(t)
mockDeadNode := &provider_mocks.Provider{} mockDeadNode := &provider_mocks.Provider{}
mockDeadNode.On("LightBlock", mock.Anything, mock.Anything).Return(nil, provider.ErrLightBlockNotFound) mockDeadNode.On("LightBlock", mock.Anything, mock.Anything).Return(nil, provider.ErrLightBlockNotFound)
c, err := light.NewClient( c, err := light.NewClient(
@ -675,7 +697,7 @@ func TestClientReplacesPrimaryWithWitnessIfPrimaryDoesntHaveBlock(t *testing.T)
mockDeadNode, mockDeadNode,
[]provider.Provider{mockDeadNode, mockFullNode}, []provider.Provider{mockDeadNode, mockFullNode},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
require.NoError(t, err) require.NoError(t, err)
_, err = c.Update(ctx, bTime.Add(2*time.Hour)) _, err = c.Update(ctx, bTime.Add(2*time.Hour))
@ -689,6 +711,8 @@ func TestClientReplacesPrimaryWithWitnessIfPrimaryDoesntHaveBlock(t *testing.T)
} }
func TestClient_BackwardsVerification(t *testing.T) { func TestClient_BackwardsVerification(t *testing.T) {
logger := log.NewTestingLogger(t)
{ {
headers, vals, _ := genLightBlocksWithKeys(chainID, 9, 3, 0, bTime) headers, vals, _ := genLightBlocksWithKeys(chainID, 9, 3, 0, bTime)
delete(headers, 1) delete(headers, 1)
@ -709,7 +733,7 @@ func TestClient_BackwardsVerification(t *testing.T) {
mockLargeFullNode, mockLargeFullNode,
[]provider.Provider{mockLargeFullNode}, []provider.Provider{mockLargeFullNode},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
require.NoError(t, err) require.NoError(t, err)
@ -768,7 +792,7 @@ func TestClient_BackwardsVerification(t *testing.T) {
mockNode, mockNode,
[]provider.Provider{mockNode}, []provider.Provider{mockNode},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
require.NoError(t, err) require.NoError(t, err)
@ -802,6 +826,8 @@ func TestClient_NewClientFromTrustedStore(t *testing.T) {
} }
func TestClientRemovesWitnessIfItSendsUsIncorrectHeader(t *testing.T) { func TestClientRemovesWitnessIfItSendsUsIncorrectHeader(t *testing.T) {
logger := log.NewTestingLogger(t)
// different headers hash then primary plus less than 1/3 signed (no fork) // different headers hash then primary plus less than 1/3 signed (no fork)
headers1 := map[int64]*types.SignedHeader{ headers1 := map[int64]*types.SignedHeader{
1: h1, 1: h1,
@ -840,7 +866,7 @@ func TestClientRemovesWitnessIfItSendsUsIncorrectHeader(t *testing.T) {
mockFullNode, mockFullNode,
[]provider.Provider{mockBadNode1, mockBadNode2}, []provider.Provider{mockBadNode1, mockBadNode2},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
// witness should have behaved properly -> no error // witness should have behaved properly -> no error
require.NoError(t, err) require.NoError(t, err)
@ -865,6 +891,8 @@ func TestClientRemovesWitnessIfItSendsUsIncorrectHeader(t *testing.T) {
} }
func TestClient_TrustedValidatorSet(t *testing.T) { func TestClient_TrustedValidatorSet(t *testing.T) {
logger := log.NewTestingLogger(t)
differentVals, _ := factory.RandValidatorSet(10, 100) differentVals, _ := factory.RandValidatorSet(10, 100)
mockBadValSetNode := mockNodeFromHeadersAndVals( mockBadValSetNode := mockNodeFromHeadersAndVals(
map[int64]*types.SignedHeader{ map[int64]*types.SignedHeader{
@ -896,7 +924,7 @@ func TestClient_TrustedValidatorSet(t *testing.T) {
mockFullNode, mockFullNode,
[]provider.Provider{mockBadValSetNode, mockFullNode}, []provider.Provider{mockBadValSetNode, mockFullNode},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, 2, len(c.Witnesses())) assert.Equal(t, 2, len(c.Witnesses()))
@ -921,6 +949,8 @@ func TestClientPrunesHeadersAndValidatorSets(t *testing.T) {
0: vals, 0: vals,
}) })
logger := log.NewTestingLogger(t)
c, err := light.NewClient( c, err := light.NewClient(
ctx, ctx,
chainID, chainID,
@ -928,7 +958,7 @@ func TestClientPrunesHeadersAndValidatorSets(t *testing.T) {
mockFullNode, mockFullNode,
[]provider.Provider{mockFullNode}, []provider.Provider{mockFullNode},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
light.PruningSize(1), light.PruningSize(1),
) )
require.NoError(t, err) require.NoError(t, err)


+ 22
- 8
light/detector_test.go View File

@ -20,6 +20,8 @@ import (
) )
func TestLightClientAttackEvidence_Lunatic(t *testing.T) { func TestLightClientAttackEvidence_Lunatic(t *testing.T) {
logger := log.NewTestingLogger(t)
// primary performs a lunatic attack // primary performs a lunatic attack
var ( var (
latestHeight = int64(3) latestHeight = int64(3)
@ -88,7 +90,7 @@ func TestLightClientAttackEvidence_Lunatic(t *testing.T) {
mockPrimary, mockPrimary,
[]provider.Provider{mockWitness}, []provider.Provider{mockWitness},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
require.NoError(t, err) require.NoError(t, err)
@ -131,6 +133,8 @@ func TestLightClientAttackEvidence_Equivocation(t *testing.T) {
for _, tc := range cases { for _, tc := range cases {
testCase := tc testCase := tc
t.Run(testCase.name, func(t *testing.T) { t.Run(testCase.name, func(t *testing.T) {
logger := log.NewTestingLogger(t)
// primary performs an equivocation attack // primary performs an equivocation attack
var ( var (
valSize = 5 valSize = 5
@ -199,7 +203,7 @@ func TestLightClientAttackEvidence_Equivocation(t *testing.T) {
mockPrimary, mockPrimary,
[]provider.Provider{mockWitness}, []provider.Provider{mockWitness},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
testCase.lightOption, testCase.lightOption,
) )
require.NoError(t, err) require.NoError(t, err)
@ -228,6 +232,8 @@ func TestLightClientAttackEvidence_ForwardLunatic(t *testing.T) {
primaryValidators = make(map[int64]*types.ValidatorSet, forgedHeight) primaryValidators = make(map[int64]*types.ValidatorSet, forgedHeight)
) )
logger := log.NewTestingLogger(t)
witnessHeaders, witnessValidators, chainKeys := genLightBlocksWithKeys(chainID, latestHeight, valSize, 2, bTime) witnessHeaders, witnessValidators, chainKeys := genLightBlocksWithKeys(chainID, latestHeight, valSize, 2, bTime)
for _, unusedHeader := range []int64{3, 5, 6, 8} { for _, unusedHeader := range []int64{3, 5, 6, 8} {
delete(witnessHeaders, unusedHeader) delete(witnessHeaders, unusedHeader)
@ -298,7 +304,7 @@ func TestLightClientAttackEvidence_ForwardLunatic(t *testing.T) {
mockPrimary, mockPrimary,
[]provider.Provider{mockWitness, accomplice}, []provider.Provider{mockWitness, accomplice},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
light.MaxClockDrift(1*time.Second), light.MaxClockDrift(1*time.Second),
light.MaxBlockLag(1*time.Second), light.MaxBlockLag(1*time.Second),
) )
@ -358,7 +364,7 @@ func TestLightClientAttackEvidence_ForwardLunatic(t *testing.T) {
mockPrimary, mockPrimary,
[]provider.Provider{mockLaggingWitness, accomplice}, []provider.Provider{mockLaggingWitness, accomplice},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
light.MaxClockDrift(1*time.Second), light.MaxClockDrift(1*time.Second),
light.MaxBlockLag(1*time.Second), light.MaxBlockLag(1*time.Second),
) )
@ -381,6 +387,8 @@ func TestClientDivergentTraces1(t *testing.T) {
headers, vals, _ = genLightBlocksWithKeys(chainID, 1, 5, 2, bTime) headers, vals, _ = genLightBlocksWithKeys(chainID, 1, 5, 2, bTime)
mockWitness := mockNodeFromHeadersAndVals(headers, vals) mockWitness := mockNodeFromHeadersAndVals(headers, vals)
logger := log.NewTestingLogger(t)
_, err = light.NewClient( _, err = light.NewClient(
ctx, ctx,
chainID, chainID,
@ -392,7 +400,7 @@ func TestClientDivergentTraces1(t *testing.T) {
mockPrimary, mockPrimary,
[]provider.Provider{mockWitness}, []provider.Provider{mockWitness},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
require.Error(t, err) require.Error(t, err)
assert.Contains(t, err.Error(), "does not match primary") assert.Contains(t, err.Error(), "does not match primary")
@ -403,6 +411,8 @@ func TestClientDivergentTraces1(t *testing.T) {
// 2. Two out of three nodes don't respond but the third has a header that matches // 2. Two out of three nodes don't respond but the third has a header that matches
// => verification should be successful and all the witnesses should remain // => verification should be successful and all the witnesses should remain
func TestClientDivergentTraces2(t *testing.T) { func TestClientDivergentTraces2(t *testing.T) {
logger := log.NewTestingLogger(t)
headers, vals, _ := genLightBlocksWithKeys(chainID, 2, 5, 2, bTime) headers, vals, _ := genLightBlocksWithKeys(chainID, 2, 5, 2, bTime)
mockPrimaryNode := mockNodeFromHeadersAndVals(headers, vals) mockPrimaryNode := mockNodeFromHeadersAndVals(headers, vals)
mockDeadNode := &provider_mocks.Provider{} mockDeadNode := &provider_mocks.Provider{}
@ -420,7 +430,7 @@ func TestClientDivergentTraces2(t *testing.T) {
mockPrimaryNode, mockPrimaryNode,
[]provider.Provider{mockDeadNode, mockDeadNode, mockPrimaryNode}, []provider.Provider{mockDeadNode, mockDeadNode, mockPrimaryNode},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
require.NoError(t, err) require.NoError(t, err)
@ -435,6 +445,8 @@ func TestClientDivergentTraces2(t *testing.T) {
// => creation should succeed, but the verification should fail // => creation should succeed, but the verification should fail
//nolint: dupl //nolint: dupl
func TestClientDivergentTraces3(t *testing.T) { func TestClientDivergentTraces3(t *testing.T) {
logger := log.NewTestingLogger(t)
// //
primaryHeaders, primaryVals, _ := genLightBlocksWithKeys(chainID, 2, 5, 2, bTime) primaryHeaders, primaryVals, _ := genLightBlocksWithKeys(chainID, 2, 5, 2, bTime)
mockPrimary := mockNodeFromHeadersAndVals(primaryHeaders, primaryVals) mockPrimary := mockNodeFromHeadersAndVals(primaryHeaders, primaryVals)
@ -458,7 +470,7 @@ func TestClientDivergentTraces3(t *testing.T) {
mockPrimary, mockPrimary,
[]provider.Provider{mockWitness}, []provider.Provider{mockWitness},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
require.NoError(t, err) require.NoError(t, err)
@ -473,6 +485,8 @@ func TestClientDivergentTraces3(t *testing.T) {
// It should be ignored // It should be ignored
//nolint: dupl //nolint: dupl
func TestClientDivergentTraces4(t *testing.T) { func TestClientDivergentTraces4(t *testing.T) {
logger := log.NewTestingLogger(t)
// //
primaryHeaders, primaryVals, _ := genLightBlocksWithKeys(chainID, 2, 5, 2, bTime) primaryHeaders, primaryVals, _ := genLightBlocksWithKeys(chainID, 2, 5, 2, bTime)
mockPrimary := mockNodeFromHeadersAndVals(primaryHeaders, primaryVals) mockPrimary := mockNodeFromHeadersAndVals(primaryHeaders, primaryVals)
@ -496,7 +510,7 @@ func TestClientDivergentTraces4(t *testing.T) {
mockPrimary, mockPrimary,
[]provider.Provider{mockWitness}, []provider.Provider{mockWitness},
dbs.New(dbm.NewMemDB()), dbs.New(dbm.NewMemDB()),
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
require.NoError(t, err) require.NoError(t, err)


+ 4
- 1
light/example_test.go View File

@ -26,7 +26,10 @@ func ExampleClient() {
stdlog.Fatal(err) stdlog.Fatal(err)
} }
logger := log.TestingLogger()
logger, err := log.NewDefaultLogger(log.LogFormatPlain, log.LogLevelInfo, false)
if err != nil {
stdlog.Fatal(err)
}
// Start a test application // Start a test application
app := kvstore.NewApplication() app := kvstore.NewApplication()


+ 6
- 2
light/light_test.go View File

@ -31,6 +31,8 @@ func TestClientIntegration_Update(t *testing.T) {
conf, err := rpctest.CreateConfig(t.Name()) conf, err := rpctest.CreateConfig(t.Name())
require.NoError(t, err) require.NoError(t, err)
logger := log.NewTestingLogger(t)
// Start a test application // Start a test application
app := kvstore.NewApplication() app := kvstore.NewApplication()
_, closer, err := rpctest.StartTendermint(ctx, conf, app, rpctest.SuppressStdout) _, closer, err := rpctest.StartTendermint(ctx, conf, app, rpctest.SuppressStdout)
@ -67,7 +69,7 @@ func TestClientIntegration_Update(t *testing.T) {
primary, primary,
[]provider.Provider{primary}, // NOTE: primary should not be used here []provider.Provider{primary}, // NOTE: primary should not be used here
dbs.New(db), dbs.New(db),
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
require.NoError(t, err) require.NoError(t, err)
@ -92,6 +94,8 @@ func TestClientIntegration_VerifyLightBlockAtHeight(t *testing.T) {
conf, err := rpctest.CreateConfig(t.Name()) conf, err := rpctest.CreateConfig(t.Name())
require.NoError(t, err) require.NoError(t, err)
logger := log.NewTestingLogger(t)
// Start a test application // Start a test application
app := kvstore.NewApplication() app := kvstore.NewApplication()
@ -125,7 +129,7 @@ func TestClientIntegration_VerifyLightBlockAtHeight(t *testing.T) {
primary, primary,
[]provider.Provider{primary}, // NOTE: primary should not be used here []provider.Provider{primary}, // NOTE: primary should not be used here
dbs.New(db), dbs.New(db),
light.Logger(log.TestingLogger()),
light.Logger(logger),
) )
require.NoError(t, err) require.NoError(t, err)


+ 37
- 25
node/node_test.go View File

@ -46,8 +46,9 @@ func TestNodeStartStop(t *testing.T) {
ctx, bcancel := context.WithCancel(context.Background()) ctx, bcancel := context.WithCancel(context.Background())
defer bcancel() defer bcancel()
logger := log.NewTestingLogger(t)
// create & start node // create & start node
ns, err := newDefaultNode(ctx, cfg, log.TestingLogger())
ns, err := newDefaultNode(ctx, cfg, logger)
require.NoError(t, err) require.NoError(t, err)
n, ok := ns.(*nodeImpl) n, ok := ns.(*nodeImpl)
@ -110,8 +111,10 @@ func TestNodeDelayedStart(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
logger := log.NewTestingLogger(t)
// create & start node // create & start node
n := getTestNode(ctx, t, cfg, log.TestingLogger())
n := getTestNode(ctx, t, cfg, logger)
n.GenesisDoc().GenesisTime = now.Add(2 * time.Second) n.GenesisDoc().GenesisTime = now.Add(2 * time.Second)
require.NoError(t, n.Start(ctx)) require.NoError(t, n.Start(ctx))
@ -128,8 +131,10 @@ func TestNodeSetAppVersion(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
logger := log.NewTestingLogger(t)
// create node // create node
n := getTestNode(ctx, t, cfg, log.TestingLogger())
n := getTestNode(ctx, t, cfg, logger)
// default config uses the kvstore app // default config uses the kvstore app
appVersion := kvstore.ProtocolVersion appVersion := kvstore.ProtocolVersion
@ -149,16 +154,15 @@ func TestNodeSetPrivValTCP(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
logger := log.NewTestingLogger(t)
cfg, err := config.ResetTestRoot("node_priv_val_tcp_test") cfg, err := config.ResetTestRoot("node_priv_val_tcp_test")
require.NoError(t, err) require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir) defer os.RemoveAll(cfg.RootDir)
cfg.PrivValidator.ListenAddr = addr cfg.PrivValidator.ListenAddr = addr
dialer := privval.DialTCPFn(addr, 100*time.Millisecond, ed25519.GenPrivKey()) dialer := privval.DialTCPFn(addr, 100*time.Millisecond, ed25519.GenPrivKey())
dialerEndpoint := privval.NewSignerDialerEndpoint(
log.TestingLogger(),
dialer,
)
dialerEndpoint := privval.NewSignerDialerEndpoint(logger, dialer)
privval.SignerDialerEndpointTimeoutReadWrite(100 * time.Millisecond)(dialerEndpoint) privval.SignerDialerEndpointTimeoutReadWrite(100 * time.Millisecond)(dialerEndpoint)
signerServer := privval.NewSignerServer( signerServer := privval.NewSignerServer(
@ -175,7 +179,7 @@ func TestNodeSetPrivValTCP(t *testing.T) {
}() }()
defer signerServer.Stop() //nolint:errcheck // ignore for tests defer signerServer.Stop() //nolint:errcheck // ignore for tests
n := getTestNode(ctx, t, cfg, log.TestingLogger())
n := getTestNode(ctx, t, cfg, logger)
assert.IsType(t, &privval.RetrySignerClient{}, n.PrivValidator()) assert.IsType(t, &privval.RetrySignerClient{}, n.PrivValidator())
} }
@ -190,7 +194,10 @@ func TestPrivValidatorListenAddrNoProtocol(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir) defer os.RemoveAll(cfg.RootDir)
cfg.PrivValidator.ListenAddr = addrNoPrefix cfg.PrivValidator.ListenAddr = addrNoPrefix
n, err := newDefaultNode(ctx, cfg, log.TestingLogger())
logger := log.NewTestingLogger(t)
n, err := newDefaultNode(ctx, cfg, logger)
assert.Error(t, err) assert.Error(t, err)
@ -212,11 +219,11 @@ func TestNodeSetPrivValIPC(t *testing.T) {
defer os.RemoveAll(cfg.RootDir) defer os.RemoveAll(cfg.RootDir)
cfg.PrivValidator.ListenAddr = "unix://" + tmpfile cfg.PrivValidator.ListenAddr = "unix://" + tmpfile
logger := log.NewTestingLogger(t)
dialer := privval.DialUnixFn(tmpfile) dialer := privval.DialUnixFn(tmpfile)
dialerEndpoint := privval.NewSignerDialerEndpoint(
log.TestingLogger(),
dialer,
)
dialerEndpoint := privval.NewSignerDialerEndpoint(logger, dialer)
privval.SignerDialerEndpointTimeoutReadWrite(100 * time.Millisecond)(dialerEndpoint) privval.SignerDialerEndpointTimeoutReadWrite(100 * time.Millisecond)(dialerEndpoint)
pvsc := privval.NewSignerServer( pvsc := privval.NewSignerServer(
@ -230,7 +237,7 @@ func TestNodeSetPrivValIPC(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
}() }()
defer pvsc.Stop() //nolint:errcheck // ignore for tests defer pvsc.Stop() //nolint:errcheck // ignore for tests
n := getTestNode(ctx, t, cfg, log.TestingLogger())
n := getTestNode(ctx, t, cfg, logger)
assert.IsType(t, &privval.RetrySignerClient{}, n.PrivValidator()) assert.IsType(t, &privval.RetrySignerClient{}, n.PrivValidator())
} }
@ -253,13 +260,13 @@ func TestCreateProposalBlock(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir) defer os.RemoveAll(cfg.RootDir)
logger := log.NewTestingLogger(t)
cc := abciclient.NewLocalCreator(kvstore.NewApplication()) cc := abciclient.NewLocalCreator(kvstore.NewApplication())
proxyApp := proxy.NewAppConns(cc, log.TestingLogger(), proxy.NopMetrics())
proxyApp := proxy.NewAppConns(cc, logger, proxy.NopMetrics())
err = proxyApp.Start(ctx) err = proxyApp.Start(ctx)
require.Nil(t, err) require.Nil(t, err)
logger := log.TestingLogger()
const height int64 = 1 const height int64 = 1
state, stateDB, privVals := state(t, 1, height) state, stateDB, privVals := state(t, 1, height)
stateStore := sm.NewStore(stateDB) stateStore := sm.NewStore(stateDB)
@ -348,13 +355,14 @@ func TestMaxTxsProposalBlockSize(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir) defer os.RemoveAll(cfg.RootDir)
logger := log.NewTestingLogger(t)
cc := abciclient.NewLocalCreator(kvstore.NewApplication()) cc := abciclient.NewLocalCreator(kvstore.NewApplication())
proxyApp := proxy.NewAppConns(cc, log.TestingLogger(), proxy.NopMetrics())
proxyApp := proxy.NewAppConns(cc, logger, proxy.NopMetrics())
err = proxyApp.Start(ctx) err = proxyApp.Start(ctx)
require.Nil(t, err) require.Nil(t, err)
logger := log.TestingLogger()
const height int64 = 1 const height int64 = 1
state, stateDB, _ := state(t, 1, height) state, stateDB, _ := state(t, 1, height)
stateStore := sm.NewStore(stateDB) stateStore := sm.NewStore(stateDB)
@ -413,13 +421,14 @@ func TestMaxProposalBlockSize(t *testing.T) {
cfg, err := config.ResetTestRoot("node_create_proposal") cfg, err := config.ResetTestRoot("node_create_proposal")
require.NoError(t, err) require.NoError(t, err)
defer os.RemoveAll(cfg.RootDir) defer os.RemoveAll(cfg.RootDir)
logger := log.NewTestingLogger(t)
cc := abciclient.NewLocalCreator(kvstore.NewApplication()) cc := abciclient.NewLocalCreator(kvstore.NewApplication())
proxyApp := proxy.NewAppConns(cc, log.TestingLogger(), proxy.NopMetrics())
proxyApp := proxy.NewAppConns(cc, logger, proxy.NopMetrics())
err = proxyApp.Start(ctx) err = proxyApp.Start(ctx)
require.Nil(t, err) require.Nil(t, err)
logger := log.TestingLogger()
state, stateDB, _ := state(t, types.MaxVotesCount, int64(1)) state, stateDB, _ := state(t, types.MaxVotesCount, int64(1))
stateStore := sm.NewStore(stateDB) stateStore := sm.NewStore(stateDB)
blockStore := store.NewBlockStore(dbm.NewMemDB()) blockStore := store.NewBlockStore(dbm.NewMemDB())
@ -534,12 +543,14 @@ func TestNodeNewSeedNode(t *testing.T) {
nodeKey, err := types.LoadOrGenNodeKey(cfg.NodeKeyFile()) nodeKey, err := types.LoadOrGenNodeKey(cfg.NodeKeyFile())
require.NoError(t, err) require.NoError(t, err)
logger := log.NewTestingLogger(t)
ns, err := makeSeedNode(ctx, ns, err := makeSeedNode(ctx,
cfg, cfg,
config.DefaultDBProvider, config.DefaultDBProvider,
nodeKey, nodeKey,
defaultGenesisDocProviderFunc(cfg), defaultGenesisDocProviderFunc(cfg),
log.TestingLogger(),
logger,
) )
t.Cleanup(ns.Wait) t.Cleanup(ns.Wait)
@ -566,7 +577,8 @@ func TestNodeSetEventSink(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
logger := log.TestingLogger()
logger := log.NewTestingLogger(t)
setupTest := func(t *testing.T, conf *config.Config) []indexer.EventSink { setupTest := func(t *testing.T, conf *config.Config) []indexer.EventSink {
eventBus := eventbus.NewDefault(logger.With("module", "events")) eventBus := eventbus.NewDefault(logger.With("module", "events"))
require.NoError(t, eventBus.Start(ctx)) require.NoError(t, eventBus.Start(ctx))


+ 3
- 3
privval/grpc/client_test.go View File

@ -46,7 +46,7 @@ func TestSignerClient_GetPubKey(t *testing.T) {
defer cancel() defer cancel()
mockPV := types.NewMockPV() mockPV := types.NewMockPV()
logger := log.TestingLogger()
logger := log.NewTestingLogger(t)
srv, dialer := dialer(t, mockPV, logger) srv, dialer := dialer(t, mockPV, logger)
defer srv.Stop() defer srv.Stop()
@ -70,7 +70,7 @@ func TestSignerClient_SignVote(t *testing.T) {
defer cancel() defer cancel()
mockPV := types.NewMockPV() mockPV := types.NewMockPV()
logger := log.TestingLogger()
logger := log.NewTestingLogger(t)
srv, dialer := dialer(t, mockPV, logger) srv, dialer := dialer(t, mockPV, logger)
defer srv.Stop() defer srv.Stop()
@ -125,7 +125,7 @@ func TestSignerClient_SignProposal(t *testing.T) {
defer cancel() defer cancel()
mockPV := types.NewMockPV() mockPV := types.NewMockPV()
logger := log.TestingLogger()
logger := log.NewTestingLogger(t)
srv, dialer := dialer(t, mockPV, logger) srv, dialer := dialer(t, mockPV, logger)
defer srv.Stop() defer srv.Stop()


+ 21
- 9
privval/grpc/server_test.go View File

@ -34,14 +34,18 @@ func TestGetPubKey(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
tc := tc tc := tc
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
s := tmgrpc.NewSignerServer(ChainID, tc.pv, log.TestingLogger())
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger := log.NewTestingLogger(t)
s := tmgrpc.NewSignerServer(ChainID, tc.pv, logger)
req := &privvalproto.PubKeyRequest{ChainId: ChainID} req := &privvalproto.PubKeyRequest{ChainId: ChainID}
resp, err := s.GetPubKey(context.Background(), req)
resp, err := s.GetPubKey(ctx, req)
if tc.err { if tc.err {
require.Error(t, err) require.Error(t, err)
} else { } else {
pk, err := tc.pv.GetPubKey(context.Background())
pk, err := tc.pv.GetPubKey(ctx)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, resp.PubKey.GetEd25519(), pk.Bytes()) assert.Equal(t, resp.PubKey.GetEd25519(), pk.Bytes())
} }
@ -105,16 +109,20 @@ func TestSignVote(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
tc := tc tc := tc
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
s := tmgrpc.NewSignerServer(ChainID, tc.pv, log.TestingLogger())
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger := log.NewTestingLogger(t)
s := tmgrpc.NewSignerServer(ChainID, tc.pv, logger)
req := &privvalproto.SignVoteRequest{ChainId: ChainID, Vote: tc.have.ToProto()} req := &privvalproto.SignVoteRequest{ChainId: ChainID, Vote: tc.have.ToProto()}
resp, err := s.SignVote(context.Background(), req)
resp, err := s.SignVote(ctx, req)
if tc.err { if tc.err {
require.Error(t, err) require.Error(t, err)
} else { } else {
pbVote := tc.want.ToProto() pbVote := tc.want.ToProto()
require.NoError(t, tc.pv.SignVote(context.Background(), ChainID, pbVote))
require.NoError(t, tc.pv.SignVote(ctx, ChainID, pbVote))
assert.Equal(t, pbVote.Signature, resp.Vote.Signature) assert.Equal(t, pbVote.Signature, resp.Vote.Signature)
} }
@ -172,15 +180,19 @@ func TestSignProposal(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
tc := tc tc := tc
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
s := tmgrpc.NewSignerServer(ChainID, tc.pv, log.TestingLogger())
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger := log.NewTestingLogger(t)
s := tmgrpc.NewSignerServer(ChainID, tc.pv, logger)
req := &privvalproto.SignProposalRequest{ChainId: ChainID, Proposal: tc.have.ToProto()} req := &privvalproto.SignProposalRequest{ChainId: ChainID, Proposal: tc.have.ToProto()}
resp, err := s.SignProposal(context.Background(), req)
resp, err := s.SignProposal(ctx, req)
if tc.err { if tc.err {
require.Error(t, err) require.Error(t, err)
} else { } else {
pbProposal := tc.want.ToProto() pbProposal := tc.want.ToProto()
require.NoError(t, tc.pv.SignProposal(context.Background(), ChainID, pbProposal))
require.NoError(t, tc.pv.SignProposal(ctx, ChainID, pbProposal))
assert.Equal(t, pbProposal.Signature, resp.Proposal.Signature) assert.Equal(t, pbProposal.Signature, resp.Proposal.Signature)
} }
}) })


+ 33
- 12
privval/signer_client_test.go View File

@ -11,6 +11,7 @@ import (
"github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/tmhash" "github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/libs/log"
tmrand "github.com/tendermint/tendermint/libs/rand" tmrand "github.com/tendermint/tendermint/libs/rand"
cryptoproto "github.com/tendermint/tendermint/proto/tendermint/crypto" cryptoproto "github.com/tendermint/tendermint/proto/tendermint/crypto"
privvalproto "github.com/tendermint/tendermint/proto/tendermint/privval" privvalproto "github.com/tendermint/tendermint/proto/tendermint/privval"
@ -27,7 +28,7 @@ type signerTestCase struct {
closer context.CancelFunc closer context.CancelFunc
} }
func getSignerTestCases(ctx context.Context, t *testing.T) []signerTestCase {
func getSignerTestCases(ctx context.Context, t *testing.T, logger log.Logger) []signerTestCase {
t.Helper() t.Helper()
testCases := make([]signerTestCase, 0) testCases := make([]signerTestCase, 0)
@ -39,7 +40,7 @@ func getSignerTestCases(ctx context.Context, t *testing.T) []signerTestCase {
cctx, ccancel := context.WithCancel(ctx) cctx, ccancel := context.WithCancel(ctx)
// get a pair of signer listener, signer dialer endpoints // get a pair of signer listener, signer dialer endpoints
sl, sd := getMockEndpoints(cctx, t, dtc.addr, dtc.dialer)
sl, sd := getMockEndpoints(cctx, t, logger, dtc.addr, dtc.dialer)
sc, err := NewSignerClient(cctx, sl, chainID) sc, err := NewSignerClient(cctx, sl, chainID)
require.NoError(t, err) require.NoError(t, err)
ss := NewSignerServer(sd, chainID, mockPV) ss := NewSignerServer(sd, chainID, mockPV)
@ -63,7 +64,9 @@ func TestSignerClose(t *testing.T) {
bctx, bcancel := context.WithCancel(context.Background()) bctx, bcancel := context.WithCancel(context.Background())
defer bcancel() defer bcancel()
for _, tc := range getSignerTestCases(bctx, t) {
logger := log.NewTestingLogger(t)
for _, tc := range getSignerTestCases(bctx, t, logger) {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
defer tc.closer() defer tc.closer()
@ -77,7 +80,9 @@ func TestSignerPing(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
for _, tc := range getSignerTestCases(ctx, t) {
logger := log.NewTestingLogger(t)
for _, tc := range getSignerTestCases(ctx, t, logger) {
err := tc.signerClient.Ping() err := tc.signerClient.Ping()
assert.NoError(t, err) assert.NoError(t, err)
} }
@ -87,7 +92,9 @@ func TestSignerGetPubKey(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
for _, tc := range getSignerTestCases(ctx, t) {
logger := log.NewTestingLogger(t)
for _, tc := range getSignerTestCases(ctx, t, logger) {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
defer tc.closer() defer tc.closer()
@ -113,7 +120,9 @@ func TestSignerProposal(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
for _, tc := range getSignerTestCases(ctx, t) {
logger := log.NewTestingLogger(t)
for _, tc := range getSignerTestCases(ctx, t, logger) {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
defer tc.closer() defer tc.closer()
@ -149,7 +158,9 @@ func TestSignerVote(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
for _, tc := range getSignerTestCases(ctx, t) {
logger := log.NewTestingLogger(t)
for _, tc := range getSignerTestCases(ctx, t, logger) {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
defer tc.closer() defer tc.closer()
@ -188,7 +199,9 @@ func TestSignerVoteResetDeadline(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
for _, tc := range getSignerTestCases(ctx, t) {
logger := log.NewTestingLogger(t)
for _, tc := range getSignerTestCases(ctx, t, logger) {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
ts := time.Now() ts := time.Now()
hash := tmrand.Bytes(tmhash.Size) hash := tmrand.Bytes(tmhash.Size)
@ -235,7 +248,9 @@ func TestSignerVoteKeepAlive(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
for _, tc := range getSignerTestCases(ctx, t) {
logger := log.NewTestingLogger(t)
for _, tc := range getSignerTestCases(ctx, t, logger) {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
defer tc.closer() defer tc.closer()
@ -283,7 +298,9 @@ func TestSignerSignProposalErrors(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
for _, tc := range getSignerTestCases(ctx, t) {
logger := log.NewTestingLogger(t)
for _, tc := range getSignerTestCases(ctx, t, logger) {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
defer tc.closer() defer tc.closer()
// Replace service with a mock that always fails // Replace service with a mock that always fails
@ -320,7 +337,9 @@ func TestSignerSignVoteErrors(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
for _, tc := range getSignerTestCases(ctx, t) {
logger := log.NewTestingLogger(t)
for _, tc := range getSignerTestCases(ctx, t, logger) {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
defer tc.closer() defer tc.closer()
@ -382,7 +401,9 @@ func TestSignerUnexpectedResponse(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
for _, tc := range getSignerTestCases(ctx, t) {
logger := log.NewTestingLogger(t)
for _, tc := range getSignerTestCases(ctx, t, logger) {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
defer tc.closer() defer tc.closer()


+ 6
- 4
privval/signer_listener_endpoint_test.go View File

@ -42,6 +42,8 @@ func TestSignerRemoteRetryTCPOnly(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
logger := log.NewTestingLogger(t)
ln, err := net.Listen("tcp", "127.0.0.1:0") ln, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err) require.NoError(t, err)
@ -64,8 +66,7 @@ func TestSignerRemoteRetryTCPOnly(t *testing.T) {
} }
}(ln, attemptCh) }(ln, attemptCh)
dialerEndpoint := NewSignerDialerEndpoint(
log.TestingLogger(),
dialerEndpoint := NewSignerDialerEndpoint(logger,
DialTCPFn(ln.Addr().String(), testTimeoutReadWrite, ed25519.GenPrivKey()), DialTCPFn(ln.Addr().String(), testTimeoutReadWrite, ed25519.GenPrivKey()),
) )
SignerDialerEndpointTimeoutReadWrite(time.Millisecond)(dialerEndpoint) SignerDialerEndpointTimeoutReadWrite(time.Millisecond)(dialerEndpoint)
@ -91,9 +92,10 @@ func TestRetryConnToRemoteSigner(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
logger := log.NewTestingLogger(t)
for _, tc := range getDialerTestCases(t) { for _, tc := range getDialerTestCases(t) {
var ( var (
logger = log.TestingLogger()
chainID = tmrand.Str(12) chainID = tmrand.Str(12)
mockPV = types.NewMockPV() mockPV = types.NewMockPV()
endpointIsOpenCh = make(chan struct{}) endpointIsOpenCh = make(chan struct{})
@ -184,12 +186,12 @@ func startListenerEndpointAsync(
func getMockEndpoints( func getMockEndpoints(
ctx context.Context, ctx context.Context,
t *testing.T, t *testing.T,
logger log.Logger,
addr string, addr string,
socketDialer SocketDialer, socketDialer SocketDialer,
) (*SignerListenerEndpoint, *SignerDialerEndpoint) { ) (*SignerListenerEndpoint, *SignerDialerEndpoint) {
var ( var (
logger = log.TestingLogger()
endpointIsOpenCh = make(chan struct{}) endpointIsOpenCh = make(chan struct{})
dialerEndpoint = NewSignerDialerEndpoint( dialerEndpoint = NewSignerDialerEndpoint(


+ 2
- 2
rpc/client/rpc_test.go View File

@ -40,7 +40,7 @@ func getHTTPClient(t *testing.T, conf *config.Config) *rpchttp.HTTP {
c, err := rpchttp.NewWithClient(rpcAddr, http.DefaultClient) c, err := rpchttp.NewWithClient(rpcAddr, http.DefaultClient)
require.NoError(t, err) require.NoError(t, err)
c.Logger = log.TestingLogger()
c.Logger = log.NewTestingLogger(t)
t.Cleanup(func() { t.Cleanup(func() {
if c.IsRunning() { if c.IsRunning() {
require.NoError(t, c.Stop()) require.NoError(t, c.Stop())
@ -59,7 +59,7 @@ func getHTTPClientWithTimeout(t *testing.T, conf *config.Config, timeout time.Du
c, err := rpchttp.NewWithClient(rpcAddr, http.DefaultClient) c, err := rpchttp.NewWithClient(rpcAddr, http.DefaultClient)
require.NoError(t, err) require.NoError(t, err)
c.Logger = log.TestingLogger()
c.Logger = log.NewTestingLogger(t)
t.Cleanup(func() { t.Cleanup(func() {
http.DefaultClient.Timeout = 0 http.DefaultClient.Timeout = 0
if c.IsRunning() { if c.IsRunning() {


+ 1
- 1
rpc/jsonrpc/client/ws_client_test.go View File

@ -228,7 +228,7 @@ func startClient(ctx context.Context, t *testing.T, addr string) *WSClient {
require.Nil(t, err) require.Nil(t, err)
err = c.Start(ctx) err = c.Start(ctx)
require.Nil(t, err) require.Nil(t, err)
c.Logger = log.TestingLogger()
c.Logger = log.NewTestingLogger(t)
return c return c
} }


+ 6
- 4
rpc/jsonrpc/jsonrpc_test.go View File

@ -273,6 +273,8 @@ func TestServersAndClientsBasic(t *testing.T) {
ctx, cancel := context.WithCancel(bctx) ctx, cancel := context.WithCancel(bctx)
defer cancel() defer cancel()
logger := log.NewTestingLogger(t)
cl2, err := client.New(addr) cl2, err := client.New(addr)
require.Nil(t, err) require.Nil(t, err)
fmt.Printf("=== testing server on %s using JSONRPC client", addr) fmt.Printf("=== testing server on %s using JSONRPC client", addr)
@ -280,7 +282,7 @@ func TestServersAndClientsBasic(t *testing.T) {
cl3, err := client.NewWS(addr, websocketEndpoint) cl3, err := client.NewWS(addr, websocketEndpoint)
require.Nil(t, err) require.Nil(t, err)
cl3.Logger = log.TestingLogger()
cl3.Logger = logger
err = cl3.Start(ctx) err = cl3.Start(ctx)
require.Nil(t, err) require.Nil(t, err)
fmt.Printf("=== testing server on %s using WS client", addr) fmt.Printf("=== testing server on %s using WS client", addr)
@ -296,7 +298,7 @@ func TestWSNewWSRPCFunc(t *testing.T) {
cl, err := client.NewWS(tcpAddr, websocketEndpoint) cl, err := client.NewWS(tcpAddr, websocketEndpoint)
require.Nil(t, err) require.Nil(t, err)
cl.Logger = log.TestingLogger()
cl.Logger = log.NewTestingLogger(t)
err = cl.Start(ctx) err = cl.Start(ctx)
require.Nil(t, err) require.Nil(t, err)
t.Cleanup(func() { t.Cleanup(func() {
@ -330,7 +332,7 @@ func TestWSHandlesArrayParams(t *testing.T) {
cl, err := client.NewWS(tcpAddr, websocketEndpoint) cl, err := client.NewWS(tcpAddr, websocketEndpoint)
require.Nil(t, err) require.Nil(t, err)
cl.Logger = log.TestingLogger()
cl.Logger = log.NewTestingLogger(t)
require.Nil(t, cl.Start(ctx)) require.Nil(t, cl.Start(ctx))
t.Cleanup(func() { t.Cleanup(func() {
if err := cl.Stop(); err != nil { if err := cl.Stop(); err != nil {
@ -362,7 +364,7 @@ func TestWSClientPingPong(t *testing.T) {
cl, err := client.NewWS(tcpAddr, websocketEndpoint) cl, err := client.NewWS(tcpAddr, websocketEndpoint)
require.Nil(t, err) require.Nil(t, err)
cl.Logger = log.TestingLogger()
cl.Logger = log.NewTestingLogger(t)
err = cl.Start(ctx) err = cl.Start(ctx)
require.Nil(t, err) require.Nil(t, err)
t.Cleanup(func() { t.Cleanup(func() {


+ 7
- 2
rpc/jsonrpc/server/http_server_test.go View File

@ -31,6 +31,8 @@ func TestMaxOpenConnections(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
logger := log.NewTestingLogger(t)
// Start the server. // Start the server.
var open int32 var open int32
mux := http.NewServeMux() mux := http.NewServeMux()
@ -46,7 +48,8 @@ func TestMaxOpenConnections(t *testing.T) {
l, err := Listen("tcp://127.0.0.1:0", max) l, err := Listen("tcp://127.0.0.1:0", max)
require.NoError(t, err) require.NoError(t, err)
defer l.Close() defer l.Close()
go Serve(ctx, l, mux, log.TestingLogger(), config) //nolint:errcheck // ignore for tests
go Serve(ctx, l, mux, logger, config) //nolint:errcheck // ignore for tests
// Make N GET calls to the server. // Make N GET calls to the server.
attempts := max * 2 attempts := max * 2
@ -87,9 +90,11 @@ func TestServeTLS(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
logger := log.NewTestingLogger(t)
chErr := make(chan error, 1) chErr := make(chan error, 1)
go func() { go func() {
chErr <- ServeTLS(ctx, ln, mux, "test.crt", "test.key", log.TestingLogger(), DefaultConfig())
chErr <- ServeTLS(ctx, ln, mux, "test.crt", "test.key", logger, DefaultConfig())
}() }()
select { select {


+ 11
- 4
rpc/jsonrpc/server/ws_handler_test.go View File

@ -13,7 +13,9 @@ import (
) )
func TestWebsocketManagerHandler(t *testing.T) { func TestWebsocketManagerHandler(t *testing.T) {
s := newWSServer()
logger := log.NewTestingLogger(t)
s := newWSServer(t, logger)
defer s.Close() defer s.Close()
// check upgrader works // check upgrader works
@ -42,15 +44,20 @@ func TestWebsocketManagerHandler(t *testing.T) {
dialResp.Body.Close() dialResp.Body.Close()
} }
func newWSServer() *httptest.Server {
func newWSServer(t *testing.T, logger log.Logger) *httptest.Server {
funcMap := map[string]*RPCFunc{ funcMap := map[string]*RPCFunc{
"c": NewWSRPCFunc(func(ctx *rpctypes.Context, s string, i int) (string, error) { return "foo", nil }, "s,i"), "c": NewWSRPCFunc(func(ctx *rpctypes.Context, s string, i int) (string, error) { return "foo", nil }, "s,i"),
} }
wm := NewWebsocketManager(funcMap) wm := NewWebsocketManager(funcMap)
wm.SetLogger(log.TestingLogger())
wm.SetLogger(logger)
mux := http.NewServeMux() mux := http.NewServeMux()
mux.HandleFunc("/websocket", wm.WebsocketHandler) mux.HandleFunc("/websocket", wm.WebsocketHandler)
return httptest.NewServer(mux)
srv := httptest.NewServer(mux)
t.Cleanup(srv.Close)
return srv
} }

Loading…
Cancel
Save