Skip to content

Commit

Permalink
fix subspace query tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rigelrozanski committed May 8, 2018
1 parent 1d82cdb commit 8dd3052
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions store/iavlstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,21 @@ func TestIAVLStoreQuery(t *testing.T) {
tree := iavl.NewVersionedTree(db, cacheSize)
iavlStore := newIAVLStore(tree, numHistory)

k1, v1 := []byte("aaa"), []byte("val1")
k2, v2 := []byte("bbb"), []byte("val2")
k1, v1 := []byte("key1"), []byte("val1")
k2, v2 := []byte("key2"), []byte("val2")
v3 := []byte("val3")

ksub = []byte("w")
KVs1, KVs2 := []KV{v1, v2}, []KV{v3, v2}
ksub := []byte("key")
KVs0 := []KV{}
KVs1 := []KV{
{k1, v1},
{k2, v2},
}
KVs2 := []KV{
{k1, v3},
{k2, v2},
}
valExpSubEmpty := cdc.MustMarshalBinary(KVs0)
valExpSub1 := cdc.MustMarshalBinary(KVs1)
valExpSub2 := cdc.MustMarshalBinary(KVs2)

Expand All @@ -277,12 +286,17 @@ func TestIAVLStoreQuery(t *testing.T) {
query := abci.RequestQuery{Path: "/key", Data: k1, Height: ver}
querySub := abci.RequestQuery{Path: "/subspace", Data: ksub, Height: ver}

// set data without commit, doesn't show up
iavlStore.Set(k1, v1)
qres := iavlStore.Query(query)
// query subspace before anything set
qres := iavlStore.Query(querySub)
assert.Equal(t, uint32(sdk.CodeOK), qres.Code)
assert.Nil(t, qres.Value)
qres = iavlStore.Query(querySub)
assert.Equal(t, valExpSubEmpty, qres.Value)

// set data
iavlStore.Set(k1, v1)
iavlStore.Set(k2, v2)

// set data without commit, doesn't show up
qres = iavlStore.Query(query)
assert.Equal(t, uint32(sdk.CodeOK), qres.Code)
assert.Nil(t, qres.Value)

Expand All @@ -291,9 +305,6 @@ func TestIAVLStoreQuery(t *testing.T) {
qres = iavlStore.Query(query)
assert.Equal(t, uint32(sdk.CodeOK), qres.Code)
assert.Nil(t, qres.Value)
qres = iavlStore.Query(querySub)
assert.Equal(t, uint32(sdk.CodeOK), qres.Code)
assert.Nil(t, qres.Value)

// but yes on the new version
query.Height = cid.Version
Expand All @@ -307,7 +318,6 @@ func TestIAVLStoreQuery(t *testing.T) {
assert.Equal(t, valExpSub1, qres.Value)

// modify
iavlStore.Set(k2, v2)
iavlStore.Set(k1, v3)
cid = iavlStore.Commit()

Expand All @@ -316,11 +326,6 @@ func TestIAVLStoreQuery(t *testing.T) {
assert.Equal(t, uint32(sdk.CodeOK), qres.Code)
assert.Equal(t, v1, qres.Value)

// and for the subspace
qres = iavlStore.Query(querySub)
assert.Equal(t, uint32(sdk.CodeOK), qres.Code)
assert.Equal(t, valExpSub1, qres.Value)

// update to latest in the query and we are happy
query.Height = cid.Version
qres = iavlStore.Query(query)
Expand Down

0 comments on commit 8dd3052

Please sign in to comment.