Some checks failed
CodeQL / Analyze (push) Waiting to run
Docker Build & Push Simapp (main) / docker-build (push) Waiting to run
golangci-lint / lint (push) Waiting to run
Tests / Code Coverage / build (amd64) (push) Waiting to run
Tests / Code Coverage / build (arm64) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[additional-args:-tags="test_e2e" name:e2e path:./e2e]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:08-wasm path:./modules/light-clients/08-wasm]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:ibc-go path:.]) (push) Waiting to run
Deploy to GitHub Pages / Deploy to GitHub Pages (push) Has been cancelled
Buf-Push / push (push) Has been cancelled
88 lines
2.2 KiB
Go
88 lines
2.2 KiB
Go
package tendermint_test
|
|
|
|
import (
|
|
"time"
|
|
|
|
commitmenttypes "github.com/cosmos/ibc-go/v10/modules/core/23-commitment/types"
|
|
"github.com/cosmos/ibc-go/v10/modules/core/exported"
|
|
ibctm "github.com/cosmos/ibc-go/v10/modules/light-clients/07-tendermint"
|
|
)
|
|
|
|
func (suite *TendermintTestSuite) TestConsensusStateValidateBasic() {
|
|
testCases := []struct {
|
|
msg string
|
|
consensusState *ibctm.ConsensusState
|
|
expectPass bool
|
|
}{
|
|
{
|
|
"success",
|
|
&ibctm.ConsensusState{
|
|
Timestamp: suite.now,
|
|
Root: commitmenttypes.NewMerkleRoot([]byte("app_hash")),
|
|
NextValidatorsHash: suite.valsHash,
|
|
},
|
|
true,
|
|
},
|
|
{
|
|
"success with sentinel",
|
|
&ibctm.ConsensusState{
|
|
Timestamp: suite.now,
|
|
Root: commitmenttypes.NewMerkleRoot([]byte(ibctm.SentinelRoot)),
|
|
NextValidatorsHash: suite.valsHash,
|
|
},
|
|
true,
|
|
},
|
|
{
|
|
"root is nil",
|
|
&ibctm.ConsensusState{
|
|
Timestamp: suite.now,
|
|
Root: commitmenttypes.MerkleRoot{},
|
|
NextValidatorsHash: suite.valsHash,
|
|
},
|
|
false,
|
|
},
|
|
{
|
|
"root is empty",
|
|
&ibctm.ConsensusState{
|
|
Timestamp: suite.now,
|
|
Root: commitmenttypes.MerkleRoot{},
|
|
NextValidatorsHash: suite.valsHash,
|
|
},
|
|
false,
|
|
},
|
|
{
|
|
"nextvalshash is invalid",
|
|
&ibctm.ConsensusState{
|
|
Timestamp: suite.now,
|
|
Root: commitmenttypes.NewMerkleRoot([]byte("app_hash")),
|
|
NextValidatorsHash: []byte("hi"),
|
|
},
|
|
false,
|
|
},
|
|
|
|
{
|
|
"timestamp is zero",
|
|
&ibctm.ConsensusState{
|
|
Timestamp: time.Time{},
|
|
Root: commitmenttypes.NewMerkleRoot([]byte("app_hash")),
|
|
NextValidatorsHash: suite.valsHash,
|
|
},
|
|
false,
|
|
},
|
|
}
|
|
|
|
for i, tc := range testCases {
|
|
suite.Run(tc.msg, func() {
|
|
// check just to increase coverage
|
|
suite.Require().Equal(exported.Tendermint, tc.consensusState.ClientType())
|
|
suite.Require().Equal(tc.consensusState.GetRoot(), tc.consensusState.Root)
|
|
|
|
err := tc.consensusState.ValidateBasic()
|
|
if tc.expectPass {
|
|
suite.Require().NoError(err, "valid test case %d failed: %s", i, tc.msg)
|
|
} else {
|
|
suite.Require().Error(err, "invalid test case %d passed: %s", i, tc.msg)
|
|
}
|
|
})
|
|
}
|
|
}
|