Add test for DoCall ApplyMessage nil return

This commit is contained in:
Olexandr88 2025-12-19 12:17:19 +02:00
parent c1b705392e
commit ebe1ab2b54
No known key found for this signature in database
2 changed files with 25 additions and 1 deletions

View file

@ -1002,6 +1002,9 @@ func DoCall(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash
// Execute the message.
gp := new(core.GasPool).AddGas(math.MaxUint64)
result, err := core.ApplyMessage(evm, msg, gp)
if result == nil && err == nil {
return nil, errors.New("EVM ApplyMessage returned nil result without error")
}
if err := vmError(); err != nil {
return nil, err
}

View file

@ -157,3 +157,24 @@ func allTransactionTypes(addr common.Address, config *params.ChainConfig) []type
},
}
}
type mockBackend struct {
evmResult *ExecutionResult
evmError error
}
func (m *mockBackend) StateAndHeaderByNumberOrHash(_ context.Context, _ rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error) {
return &state.StateDB{}, &types.Header{}, nil
}
func (m *mockBackend) Apply(_ *state.StateDB) error {
return nil
}
func (m *mockBackend) EVM(ctx context.Context, msg Message, state *state.StateDB, header *types.Header, cfg vm.Config) (*ExecutionResult, error) {
return m.evmResult, m.evmError
}
func TestDoCall_ApplyMessageReturnsNil(t *testing.T) {
backend := &mockBackend{
evmResult: nil,
evmError: