Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Commit

Permalink
Add unit test for checkFraudulentStateTransition
Browse files Browse the repository at this point in the history
  • Loading branch information
Manav-Aggarwal committed Oct 20, 2022
1 parent 91be0fe commit 7f82c06
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions baseapp/fraudproof_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package baseapp

import (
"testing"

"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/abci/types"
)

// Tests the checkFraudulentStateTransition for all possible cases.
func TestCheckFraudulentStateTransition(t *testing.T) {

//Case when only BeginBlock is set
fraudProof := FraudProof{}
fraudProof.fraudulentBeginBlock = &types.RequestBeginBlock{}
result := fraudProof.checkFraudulentStateTransition()
require.True(t, result)

//Case when only DeliverTx is set
fraudProof = FraudProof{}
fraudProof.fraudulentDeliverTx = &types.RequestDeliverTx{}
result = fraudProof.checkFraudulentStateTransition()
require.True(t, result)

//Case when only EndBlock is set
fraudProof = FraudProof{}
fraudProof.fraudulentEndBlock = &types.RequestEndBlock{}
result = fraudProof.checkFraudulentStateTransition()
require.True(t, result)

//Case when both BeginBlock and DeliverTx are set
fraudProof = FraudProof{}
fraudProof.fraudulentBeginBlock = &types.RequestBeginBlock{}
fraudProof.fraudulentDeliverTx = &types.RequestDeliverTx{}
result = fraudProof.checkFraudulentStateTransition()
require.False(t, result)

//Case when both BeginBlock and EndBlock are set
fraudProof = FraudProof{}
fraudProof.fraudulentBeginBlock = &types.RequestBeginBlock{}
fraudProof.fraudulentEndBlock = &types.RequestEndBlock{}
result = fraudProof.checkFraudulentStateTransition()
require.False(t, result)

//Case when both DeliverTx and EndBlock are set
fraudProof = FraudProof{}
fraudProof.fraudulentDeliverTx = &types.RequestDeliverTx{}
fraudProof.fraudulentEndBlock = &types.RequestEndBlock{}
result = fraudProof.checkFraudulentStateTransition()
require.False(t, result)

//Case when both DeliverTx and EndBlock are set
fraudProof = FraudProof{}
fraudProof.fraudulentBeginBlock = &types.RequestBeginBlock{}
fraudProof.fraudulentDeliverTx = &types.RequestDeliverTx{}
fraudProof.fraudulentEndBlock = &types.RequestEndBlock{}
result = fraudProof.checkFraudulentStateTransition()
require.False(t, result)

}

0 comments on commit 7f82c06

Please sign in to comment.