From f2f0d6cb2880123d221ce4e9ba365df2628b9939 Mon Sep 17 00:00:00 2001 From: Nick DeLuca Date: Tue, 30 Jul 2024 16:12:15 +0000 Subject: [PATCH] refactor: ExpectFunc default should be nil When defining a test fixture with no expectations, the test fixture should use a nil function for expectFunc, instead of an empty function which serves no purpose. This also ensures we check for nil before calling the set function in order to prevent panics. --- x/evm/genesis_test.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/x/evm/genesis_test.go b/x/evm/genesis_test.go index a6443f1cf3..40f8ffc132 100644 --- a/x/evm/genesis_test.go +++ b/x/evm/genesis_test.go @@ -60,7 +60,7 @@ func TestInitGenesis(t *testing.T) { ctx: ctx, state: state, precompiles: nil, - expectFunc: func() {}, + expectFunc: nil, expectPanic: nil, } }, @@ -97,7 +97,7 @@ func TestInitGenesis(t *testing.T) { ctx: ctx, state: types.DefaultGenesisState(), precompiles: nil, - expectFunc: func() {}, + expectFunc: nil, expectPanic: err, } }, @@ -137,7 +137,7 @@ func TestInitGenesis(t *testing.T) { ctx: ctx, state: state, precompiles: nil, - expectFunc: func() {}, + expectFunc: nil, expectPanic: errors.New("error setting params invalid denom: "), } }, @@ -156,7 +156,7 @@ func TestInitGenesis(t *testing.T) { ctx: ctx, state: types.DefaultGenesisState(), precompiles: nil, - expectFunc: func() {}, + expectFunc: nil, expectPanic: "the EVM module account has not been set", } }, @@ -176,7 +176,7 @@ func TestInitGenesis(t *testing.T) { ctx: ctx, state: state, precompiles: nil, - expectFunc: func() {}, + expectFunc: nil, expectPanic: fmt.Errorf("account not found for address %s", address), } }, @@ -200,7 +200,7 @@ func TestInitGenesis(t *testing.T) { ctx: ctx, state: state, precompiles: nil, - expectFunc: func() {}, + expectFunc: nil, expectPanic: fmt.Errorf("account %s must be an EthAccount interface, got %T", address, acc), } }, @@ -236,7 +236,7 @@ func TestInitGenesis(t *testing.T) { ctx: ctx, state: state, precompiles: nil, - expectFunc: func() {}, + expectFunc: nil, expectPanic: expectedPanic, } }, @@ -265,7 +265,7 @@ func TestInitGenesis(t *testing.T) { ctx: ctx, state: state, precompiles: nil, - expectFunc: func() {}, + expectFunc: nil, expectPanic: nil, } }, @@ -299,7 +299,7 @@ func TestInitGenesis(t *testing.T) { ctx: ctx, state: state, precompiles: nil, - expectFunc: func() {}, + expectFunc: nil, expectPanic: expectedPanic, } }, @@ -530,7 +530,9 @@ func TestInitGenesis(t *testing.T) { } // Run test specific assertions - tf.expectFunc() + if tf.expectFunc != nil { + tf.expectFunc() + } }) } }