diff --git a/store/state/base.go b/store/state/base.go index f163c18b98a0..a6f429053248 100644 --- a/store/state/base.go +++ b/store/state/base.go @@ -15,13 +15,19 @@ type Base struct { } func EmptyBase() Base { - return NewBase(nil, nil) + return NewBase(nil, nil, nil) } -func NewBase(cdc *codec.Codec, key sdk.StoreKey) Base { +func NewBase(cdc *codec.Codec, key sdk.StoreKey, rootkey []byte) Base { + if len(rootkey) == 0 { + return Base{ + cdc: cdc, + storefn: func(ctx Context) KVStore { return ctx.KVStore(key) }, + } + } return Base{ cdc: cdc, - storefn: func(ctx Context) KVStore { return ctx.KVStore(key) }, + storefn: func(ctx Context) KVStore { return prefix.NewStore(ctx.KVStore(key), rootkey) }, } } diff --git a/store/state/value_test.go b/store/state/value_test.go index 24e4e708c458..e3c07e0e3968 100644 --- a/store/state/value_test.go +++ b/store/state/value_test.go @@ -14,7 +14,7 @@ type valuepair struct { func TestValue(t *testing.T) { key, ctx, cdc := defaultComponents() - base := NewBase(cdc, key) + base := NewBase(cdc, key, nil) cases := make([]valuepair, testsize) for i := range cases { diff --git a/x/ibc/02-client/manager.go b/x/ibc/02-client/manager.go index 5d52613be9df..e94d14702b72 100644 --- a/x/ibc/02-client/manager.go +++ b/x/ibc/02-client/manager.go @@ -2,7 +2,6 @@ package client import ( "errors" - "fmt" "strconv" "github.com/cosmos/cosmos-sdk/store/state" @@ -28,7 +27,6 @@ type Manager struct { } func NewManager(protocol, free state.Base, idgen IDGenerator) Manager { - fmt.Println(1234567890, protocol, free) return Manager{ protocol: state.NewMapping(protocol, []byte("/client")), idval: state.NewValue(free, []byte("/client/id")), diff --git a/x/ibc/03-connection/manager.go b/x/ibc/03-connection/manager.go index 7c0668bc0dbd..3c12fe5851d6 100644 --- a/x/ibc/03-connection/manager.go +++ b/x/ibc/03-connection/manager.go @@ -2,7 +2,6 @@ package connection import ( "errors" - "fmt" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/state" @@ -71,7 +70,6 @@ func (man CounterpartyManager) object(id string) CounterObject { } func (man Manager) Create(ctx sdk.Context, id string, connection Connection) (obj Object, err error) { - fmt.Println("create", id, connection) obj = man.object(id) if obj.exists(ctx) { err = errors.New("connection already exists for the provided id") @@ -202,24 +200,20 @@ func (obj Object) OpenTry(ctx sdk.Context, expheight uint64, timeoutHeight, next return errors.New("invalid state") } - fmt.Println(12345) err := assertTimeout(ctx, timeoutHeight) if err != nil { return err } - fmt.Println(67890) if !obj.counterparty.state.Is(ctx, Init) { return errors.New("counterparty state not init") } - fmt.Println(97) err = obj.assertSymmetric(ctx) if err != nil { return err } - fmt.Println(65) if !obj.counterparty.nextTimeout.Is(ctx, uint64(timeoutHeight)) { return errors.New("unexpected counterparty timeout value") } diff --git a/x/ibc/03-connection/tests/connection_test.go b/x/ibc/03-connection/tests/connection_test.go index 4ff890630135..338218542322 100644 --- a/x/ibc/03-connection/tests/connection_test.go +++ b/x/ibc/03-connection/tests/connection_test.go @@ -1,7 +1,6 @@ package connection import ( - "fmt" "testing" "github.com/cosmos/cosmos-sdk/codec" @@ -36,22 +35,31 @@ func TestHandshake(t *testing.T) { node.Advance(t) header := node.Commit() - fmt.Printf("ddd\n\n\n\n%+v\n", node.Root) - // counterparty.OpenTry node.Counterparty.UpdateClient(t, header) cliobj := node.CLIObject() _, pconn := node.Query(t, cliobj.ConnectionKey) - fmt.Printf("\n\n\n\n%s: %+v, %s\n", cliobj.ConnectionKey, pconn.(merkle.Proof).Proof, string(pconn.(merkle.Proof).Key)) _, pstate := node.Query(t, cliobj.StateKey) _, ptimeout := node.Query(t, cliobj.NextTimeoutKey) // TODO: implement consensus state checking // _, pclient := node.Query(t, cliobj.Client.ConsensusStateKey) - node.Advance(t, pconn, pstate, ptimeout) + node.Advance(t, pconn, pstate, ptimeout /*, pclient*/) + header = node.Counterparty.Commit() // self.OpenAck - node.Advance(t) + node.UpdateClient(t, header) + cliobj = node.Counterparty.CLIObject() + _, pconn = node.Counterparty.Query(t, cliobj.ConnectionKey) + _, pstate = node.Counterparty.Query(t, cliobj.StateKey) + _, ptimeout = node.Counterparty.Query(t, cliobj.NextTimeoutKey) + node.Advance(t, pconn, pstate, ptimeout) + header = node.Commit() // counterparty.OpenConfirm - node.Advance(t) + node.Counterparty.UpdateClient(t, header) + cliobj = node.CLIObject() + _, pconn = node.Query(t, cliobj.ConnectionKey) // TODO: check if it is needed + _, pstate = node.Query(t, cliobj.StateKey) + _, ptimeout = node.Query(t, cliobj.NextTimeoutKey) + node.Advance(t, pconn, pstate, ptimeout) } diff --git a/x/ibc/03-connection/tests/types.go b/x/ibc/03-connection/tests/types.go index 4a6d31a2f47e..18d941cad038 100644 --- a/x/ibc/03-connection/tests/types.go +++ b/x/ibc/03-connection/tests/types.go @@ -73,6 +73,11 @@ func (node *Node) UpdateClient(t *testing.T, header client.Header) { require.NoError(t, err) } +func (node *Node) SetState(state connection.State) { + node.State = state + node.Counterparty.State = state +} + func (node *Node) Object(t *testing.T, proofs []commitment.Proof) (sdk.Context, connection.Object) { ctx := node.Context() store, err := commitment.NewStore(node.Counterparty.Root, proofs) @@ -80,7 +85,7 @@ func (node *Node) Object(t *testing.T, proofs []commitment.Proof) (sdk.Context, ctx = commitment.WithStore(ctx, store) _, man := node.Manager() switch node.State { - case connection.Idle: + case connection.Idle, connection.Init: obj, err := man.Create(ctx, node.Name, node.Connection) require.NoError(t, err) return ctx, obj @@ -98,9 +103,8 @@ func (node *Node) CLIObject() connection.CLIObject { } func base(cdc *codec.Codec, key sdk.StoreKey) (state.Base, state.Base) { - base := state.NewBase(cdc, key) - protocol := base.Prefix([]byte("protocol")) - free := base.Prefix([]byte("free")) + protocol := state.NewBase(cdc, key, []byte("protocol")) + free := state.NewBase(cdc, key, []byte("free")) return protocol, free } @@ -112,6 +116,7 @@ func (node *Node) Manager() (client.Manager, connection.Manager) { func (node *Node) Advance(t *testing.T, proofs ...commitment.Proof) { switch node.State { + // TODO: use different enum type for node.State case connection.Idle: // self: Idle -> Init ctx, obj := node.Object(t, proofs) require.Equal(t, connection.Idle, obj.State(ctx)) @@ -119,7 +124,7 @@ func (node *Node) Advance(t *testing.T, proofs ...commitment.Proof) { require.NoError(t, err) require.Equal(t, connection.Init, obj.State(ctx)) require.Equal(t, node.Connection, obj.Connection(ctx)) - node.State = connection.Init + node.SetState(connection.Init) case connection.Init: // counter: Idle -> OpenTry ctx, obj := node.Counterparty.Object(t, proofs) require.Equal(t, connection.Idle, obj.State(ctx)) @@ -127,7 +132,7 @@ func (node *Node) Advance(t *testing.T, proofs ...commitment.Proof) { require.NoError(t, err) require.Equal(t, connection.OpenTry, obj.State(ctx)) require.Equal(t, node.Counterparty.Connection, obj.Connection(ctx)) - node.State = connection.OpenTry + node.SetState(connection.OpenTry) case connection.OpenTry: // self: Init -> Open ctx, obj := node.Object(t, proofs) require.Equal(t, connection.Init, obj.State(ctx)) @@ -135,7 +140,7 @@ func (node *Node) Advance(t *testing.T, proofs ...commitment.Proof) { require.NoError(t, err) require.Equal(t, connection.Open, obj.State(ctx)) require.Equal(t, node.Connection, obj.Connection(ctx)) - node.State = connection.Open + node.SetState(connection.Open) case connection.Open: // counter: OpenTry -> Open ctx, obj := node.Counterparty.Object(t, proofs) require.Equal(t, connection.OpenTry, obj.State(ctx)) @@ -143,8 +148,8 @@ func (node *Node) Advance(t *testing.T, proofs ...commitment.Proof) { require.NoError(t, err) require.Equal(t, connection.Open, obj.State(ctx)) require.Equal(t, node.Counterparty.Connection, obj.Connection(ctx)) - node.State = connection.CloseTry - // case connection.CloseTry // self: Open -> CloseTry + node.SetState(connection.CloseTry) + // case connection.CloseTry // self: Open -> CloseTry default: return } diff --git a/x/ibc/23-commitment/store.go b/x/ibc/23-commitment/store.go index 4a90426defcb..a5640db907c3 100644 --- a/x/ibc/23-commitment/store.go +++ b/x/ibc/23-commitment/store.go @@ -3,7 +3,6 @@ package commitment import ( "bytes" "errors" - "fmt" ) type Store interface { @@ -54,12 +53,9 @@ func NewStore(root Root, proofs []Proof) (res *store, err error) { err = errors.New("proof type not matching with root's") return } - fmt.Println("set key", string(proof.GetKey())) res.proofs[string(proof.GetKey())] = proof } - fmt.Printf("%+v\n", res) - return } @@ -75,13 +71,10 @@ func (store *store) Prove(key, value []byte) bool { } proof, ok := store.proofs[string(key)] if !ok { - fmt.Println("no proof") - fmt.Println("get key", string(key)) return false } err := proof.Verify(store.root, value) if err != nil { - fmt.Println("invalid proof") return false } store.verified[string(key)] = value