Skip to content

Commit

Permalink
refactor: ExpectFunc default should be nil
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nddeluca committed Jul 30, 2024
1 parent b4db5f9 commit f2f0d6c
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions x/evm/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestInitGenesis(t *testing.T) {
ctx: ctx,
state: state,
precompiles: nil,
expectFunc: func() {},
expectFunc: nil,
expectPanic: nil,
}
},
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestInitGenesis(t *testing.T) {
ctx: ctx,
state: types.DefaultGenesisState(),
precompiles: nil,
expectFunc: func() {},
expectFunc: nil,
expectPanic: err,
}
},
Expand Down Expand Up @@ -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: "),
}
},
Expand All @@ -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",
}
},
Expand All @@ -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),
}
},
Expand All @@ -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),
}
},
Expand Down Expand Up @@ -236,7 +236,7 @@ func TestInitGenesis(t *testing.T) {
ctx: ctx,
state: state,
precompiles: nil,
expectFunc: func() {},
expectFunc: nil,
expectPanic: expectedPanic,
}
},
Expand Down Expand Up @@ -265,7 +265,7 @@ func TestInitGenesis(t *testing.T) {
ctx: ctx,
state: state,
precompiles: nil,
expectFunc: func() {},
expectFunc: nil,
expectPanic: nil,
}
},
Expand Down Expand Up @@ -299,7 +299,7 @@ func TestInitGenesis(t *testing.T) {
ctx: ctx,
state: state,
precompiles: nil,
expectFunc: func() {},
expectFunc: nil,
expectPanic: expectedPanic,
}
},
Expand Down Expand Up @@ -530,7 +530,9 @@ func TestInitGenesis(t *testing.T) {
}

// Run test specific assertions
tf.expectFunc()
if tf.expectFunc != nil {
tf.expectFunc()
}
})
}
}
Expand Down

0 comments on commit f2f0d6c

Please sign in to comment.