Skip to content

Commit

Permalink
IOTEX-317 Error shouldn't been thrown when the failure receipt is ret…
Browse files Browse the repository at this point in the history
…urned (#706)
  • Loading branch information
zjshen14 committed Mar 14, 2019
1 parent 73b50fd commit 24abf03
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion action/protocol/execution/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func ExecuteContract(
stateDB.clear()
receipt.Logs = stateDB.Logs()
log.S().Debugf("Receipt: %+v, %v", receipt, err)
return receipt, err
return receipt, nil
}

func getChainConfig() *params.ChainConfig {
Expand Down
45 changes: 45 additions & 0 deletions action/protocol/execution/evm/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,24 @@
package evm

import (
"context"
"math/big"
"testing"

"github.com/iotexproject/iotex-core/state"

"github.com/iotexproject/iotex-core/test/identityset"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/iotexproject/iotex-core/action"
"github.com/iotexproject/iotex-core/action/protocol"
"github.com/iotexproject/iotex-core/db"
"github.com/iotexproject/iotex-core/pkg/hash"
"github.com/iotexproject/iotex-core/test/mock/mock_chainmanager"
"github.com/iotexproject/iotex-core/testutil"
)

func TestLogReceipt(t *testing.T) {
Expand Down Expand Up @@ -47,3 +59,36 @@ func TestLogReceipt(t *testing.T) {
require.Equal(len(receipt.Logs), len(actualReceipt.Logs))
require.Equal(receipt.ActHash, actualReceipt.ActHash)
}

func TestExecuteContractFailure(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

cm := mock_chainmanager.NewMockChainManager(ctrl)
sm := mock_chainmanager.NewMockStateManager(ctrl)
store := db.NewMemKVStore()
sm.EXPECT().GetDB().Return(store).AnyTimes()
cb := db.NewCachedBatch()
sm.EXPECT().GetCachedBatch().Return(cb).AnyTimes()
sm.EXPECT().State(gomock.Any(), gomock.Any()).Return(state.ErrStateNotExist).AnyTimes()

e, err := action.NewExecution(
"",
1,
big.NewInt(0),
testutil.TestGasLimit,
big.NewInt(0),
nil,
)
require.NoError(t, err)

ctx := protocol.WithRunActionsCtx(context.Background(), protocol.RunActionsCtx{
Caller: identityset.Address(0),
Producer: identityset.Address(1),
})

receipt, err := ExecuteContract(ctx, sm, e, cm)
require.NotNil(t, receipt)
assert.Equal(t, action.FailureReceiptStatus, receipt.Status)
require.NoError(t, err)
}

0 comments on commit 24abf03

Please sign in to comment.