Test update with bad commit

This commit is contained in:
Jae Kwon 2017-01-29 21:16:51 -08:00
parent 28667a9a9f
commit 0e94253d43
2 changed files with 24 additions and 8 deletions

View File

@ -66,7 +66,8 @@ const (
IBCCodeChainAlreadyExists = abci.CodeType(1002)
IBCCodePacketAlreadyExists = abci.CodeType(1003)
IBCCodeUnknownHeight = abci.CodeType(1004)
IBCCodeInvalidProof = abci.CodeType(1005)
IBCCodeInvalidCommit = abci.CodeType(1005)
IBCCodeInvalidProof = abci.CodeType(1006)
)
var _ = wire.RegisterInterface(
@ -154,7 +155,7 @@ func (ibc *IBCPlugin) RunTx(store types.KVStore, ctx types.CallContext, txBytes
var tx IBCTx
err := wire.ReadBinaryBytes(txBytes, &tx)
if err != nil {
return abci.ErrBaseEncodingError.AppendLog("Error decoding tx: " + err.Error()).PrependLog("IBCTx Error: ")
return abci.ErrBaseEncodingError.AppendLog("Error decoding tx: " + err.Error())
}
// Validate tx
@ -265,7 +266,8 @@ func (sm *IBCStateMachine) runUpdateChainTx(tx IBCUpdateChainTx) {
// Check commit against last known state & validators
err = verifyCommit(chainState, &tx.Header, &tx.Commit)
if err != nil {
sm.res = abci.ErrInternalError.AppendLog(cmn.Fmt("Invalid Commit: %v", err.Error()))
sm.res.Code = IBCCodeInvalidCommit
sm.res.Log = cmn.Fmt("Invalid Commit: %v", err.Error())
return
}

View File

@ -11,6 +11,7 @@ import (
"github.com/tendermint/basecoin/testutils"
"github.com/tendermint/basecoin/types"
cmn "github.com/tendermint/go-common"
crypto "github.com/tendermint/go-crypto"
"github.com/tendermint/go-wire"
eyes "github.com/tendermint/merkleeyes/client"
tm "github.com/tendermint/tendermint/types"
@ -87,7 +88,7 @@ func TestIBCPlugin(t *testing.T) {
Genesis: "<THIS IS NOT JSON>",
},
}}))
assert.Equal(t, res.Code, IBCCodeEncodingError)
assert.Equal(t, IBCCodeEncodingError, res.Code)
t.Log(">>", strings.Join(store.GetLogLines(), "\n"))
store.ClearLogLines()
@ -109,7 +110,7 @@ func TestIBCPlugin(t *testing.T) {
Genesis: string(genDocJSON_1),
},
}}))
assert.Equal(t, res.Code, IBCCodeChainAlreadyExists, res.Log)
assert.Equal(t, IBCCodeChainAlreadyExists, res.Code, res.Log)
t.Log(">>", strings.Join(store.GetLogLines(), "\n"))
store.ClearLogLines()
@ -123,7 +124,7 @@ func TestIBCPlugin(t *testing.T) {
Payload: []byte("hello world"),
},
}}))
assert.Equal(t, res.Code, abci.CodeType(0), res.Log)
assert.Equal(t, abci.CodeType_OK, res.Code, res.Log)
t.Log(">>", strings.Join(store.GetLogLines(), "\n"))
store.ClearLogLines()
@ -137,7 +138,7 @@ func TestIBCPlugin(t *testing.T) {
Payload: []byte("hello world"),
},
}}))
assert.Equal(t, res.Code, IBCCodePacketAlreadyExists, res.Log)
assert.Equal(t, IBCCodePacketAlreadyExists, res.Code, res.Log)
t.Log(">>", strings.Join(store.GetLogLines(), "\n"))
store.ClearLogLines()
@ -179,7 +180,20 @@ func TestIBCPlugin(t *testing.T) {
Header: header,
Commit: commit,
}}))
assert.Equal(t, res.Code, abci.CodeType(0), res.Log)
assert.Equal(t, abci.CodeType_OK, res.Code, res.Log)
t.Log(">>", strings.Join(store.GetLogLines(), "\n"))
store.ClearLogLines()
// Update a chain with a broken commit
// Modify the first byte of the first signature
sig := commit.Precommits[0].Signature.(crypto.SignatureEd25519)
sig[0] += 1
commit.Precommits[0].Signature = sig
res = ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCUpdateChainTx{
Header: header,
Commit: commit,
}}))
assert.Equal(t, IBCCodeInvalidCommit, res.Code, res.Log)
t.Log(">>", strings.Join(store.GetLogLines(), "\n"))
store.ClearLogLines()
}