Skip to content

Commit

Permalink
add root and storekey to tests/node, add codec
Browse files Browse the repository at this point in the history
  • Loading branch information
mossid committed Jun 26, 2019
1 parent 994ac60 commit 25a503d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
10 changes: 10 additions & 0 deletions x/ibc/02-client/codec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package client

import (
"github.com/cosmos/cosmos-sdk/codec"
)

func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterInterface((*ConsensusState)(nil), nil)
cdc.RegisterInterface((*Header)(nil), nil)
}
11 changes: 11 additions & 0 deletions x/ibc/02-client/tendermint/codec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package tendermint

import (
"github.com/cosmos/cosmos-sdk/codec"
)

func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterConcrete(ConsensusState{}, "ibc/client/tendermint/ConsensusState", nil)
cdc.RegisterConcrete(Header{}, "ibc/client/tendermint/Header", nil)

}
8 changes: 6 additions & 2 deletions x/ibc/02-client/tendermint/tests/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func (node *Node) LastStateVerifier(root merkle.Root) *Verifier {
return NewVerifier(node.Last(), node.Valset, root)
}

func (node *Node) Context() sdk.Context {
return sdk.NewContext(node.Cms, abci.Header{}, false, log.NewNopLogger())
}

type Verifier struct {
client.ConsensusState
}
Expand Down Expand Up @@ -139,7 +143,7 @@ func (node *Node) Query(t *testing.T, root merkle.Root, k []byte) ([]byte, commi
}

func (node *Node) Set(k, value []byte) {
node.Store.Set(newRoot().Key(k), value)
node.Store.Set(node.Root.Key(k), value)
}

func testProof(t *testing.T) {
Expand All @@ -159,7 +163,7 @@ func testProof(t *testing.T) {
}
header := node.Commit()
proofs := []commitment.Proof{}
root := newRoot().Update(header.AppHash)
root := node.Root.Update(header.AppHash)
for _, kvp := range kvps {
v, p := node.Query(t, root.(merkle.Root), []byte(kvp.Key))
require.Equal(t, kvp.Value, v)
Expand Down
1 change: 1 addition & 0 deletions x/ibc/02-client/tendermint/tests/valset.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type MockValidators []MockValidator

var _ sort.Interface = MockValidators{}

// TODO: differenciate power between the vals
func NewMockValidators(num int, power int64) MockValidators {
res := make(MockValidators, num)
for i := range res {
Expand Down

0 comments on commit 25a503d

Please sign in to comment.