From c57595e6f8d2efd6507033af7b202e0fad76b348 Mon Sep 17 00:00:00 2001 From: PrathyushaLakkireddy Date: Wed, 28 Feb 2024 11:22:15 +0530 Subject: [PATCH 1/2] use isType in tests --- node/full_node_test.go | 4 +++- node/light_client_test.go | 2 ++ node/node_test.go | 6 ++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/node/full_node_test.go b/node/full_node_test.go index 79ae58a494..7ca294eb0e 100644 --- a/node/full_node_test.go +++ b/node/full_node_test.go @@ -27,13 +27,15 @@ import ( // simply check that node is starting and stopping without panicking func TestStartup(t *testing.T) { ctx := context.Background() - _ = initAndStartNodeWithCleanup(ctx, t, "full").(*FullNode) + node := initAndStartNodeWithCleanup(ctx, t, "full").(*FullNode) + require.IsType(t, new(FullNode), node) } func TestMempoolDirectly(t *testing.T) { ctx := context.Background() node := initAndStartNodeWithCleanup(ctx, t, "full").(*FullNode) + require.IsType(t, new(FullNode), node) assert := assert.New(t) peerID := getPeerID(assert) diff --git a/node/light_client_test.go b/node/light_client_test.go index 4d731a5a1a..9fd46a0170 100644 --- a/node/light_client_test.go +++ b/node/light_client_test.go @@ -6,6 +6,7 @@ import ( rpcclient "github.com/cometbft/cometbft/rpc/client" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) // TestLightClient_Panics tests that all methods of LightClient and ensures that @@ -17,6 +18,7 @@ func TestLightClient_Panics(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() ln := initAndStartNodeWithCleanup(ctx, t, "light").(*LightNode) + require.IsType(t, new(LightNode), ln) tests := []struct { name string diff --git a/node/node_test.go b/node/node_test.go index 0f5d08e3e9..a1925672ba 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -81,6 +81,8 @@ func newTestNode(ctx context.Context, t *testing.T, nodeType string) (Node, ed25 func TestNewNode(t *testing.T) { ctx := context.Background() - _ = initAndStartNodeWithCleanup(ctx, t, "light").(*LightNode) - _ = initAndStartNodeWithCleanup(ctx, t, "full").(*FullNode) + ln := initAndStartNodeWithCleanup(ctx, t, "light").(*LightNode) + require.IsType(t, new(LightNode), ln) + fn := initAndStartNodeWithCleanup(ctx, t, "full").(*FullNode) + require.IsType(t, new(FullNode), fn) } From 610d6179b7db1a1674821a04fad0261cd1219e14 Mon Sep 17 00:00:00 2001 From: PrathyushaLakkireddy Date: Wed, 28 Feb 2024 14:59:17 +0530 Subject: [PATCH 2/2] remove type assertions --- node/full_node_test.go | 7 ++++--- node/light_client_test.go | 2 +- node/node_test.go | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/node/full_node_test.go b/node/full_node_test.go index 7ca294eb0e..54abe8c52c 100644 --- a/node/full_node_test.go +++ b/node/full_node_test.go @@ -27,16 +27,17 @@ import ( // simply check that node is starting and stopping without panicking func TestStartup(t *testing.T) { ctx := context.Background() - node := initAndStartNodeWithCleanup(ctx, t, "full").(*FullNode) + node := initAndStartNodeWithCleanup(ctx, t, "full") require.IsType(t, new(FullNode), node) } func TestMempoolDirectly(t *testing.T) { ctx := context.Background() - node := initAndStartNodeWithCleanup(ctx, t, "full").(*FullNode) - require.IsType(t, new(FullNode), node) + fn := initAndStartNodeWithCleanup(ctx, t, "full") + require.IsType(t, new(FullNode), fn) + node := fn.(*FullNode) assert := assert.New(t) peerID := getPeerID(assert) verifyTransactions(node, peerID, assert) diff --git a/node/light_client_test.go b/node/light_client_test.go index 9fd46a0170..5f4c9a8ffe 100644 --- a/node/light_client_test.go +++ b/node/light_client_test.go @@ -17,7 +17,7 @@ import ( func TestLightClient_Panics(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - ln := initAndStartNodeWithCleanup(ctx, t, "light").(*LightNode) + ln := initAndStartNodeWithCleanup(ctx, t, "light") require.IsType(t, new(LightNode), ln) tests := []struct { diff --git a/node/node_test.go b/node/node_test.go index a1925672ba..8576a15256 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -81,8 +81,8 @@ func newTestNode(ctx context.Context, t *testing.T, nodeType string) (Node, ed25 func TestNewNode(t *testing.T) { ctx := context.Background() - ln := initAndStartNodeWithCleanup(ctx, t, "light").(*LightNode) + ln := initAndStartNodeWithCleanup(ctx, t, "light") require.IsType(t, new(LightNode), ln) - fn := initAndStartNodeWithCleanup(ctx, t, "full").(*FullNode) + fn := initAndStartNodeWithCleanup(ctx, t, "full") require.IsType(t, new(FullNode), fn) }