Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Oct 26, 2022
1 parent 7c658d8 commit 1677bfc
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 45 deletions.
2 changes: 1 addition & 1 deletion client/file/decoder.go → client/decoder.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package file
package client

import (
"github.com/cosmos/cosmos-sdk/store/types"
Expand Down
83 changes: 41 additions & 42 deletions versiondb/backend_test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,39 @@ import (
var (
key1 = []byte("key1")
key2 = []byte("key2")
value1 = []byte("value1")
value2 = []byte("value2")
value3 = []byte("value3")
value1 = []byte("1")
value2 = []byte("2")
key1_subkey = []byte("key1/subkey")
)

func MockStoreKVPairs(v int64) []types.StoreKVPair {
switch v {
case 0:
return []types.StoreKVPair{
{StoreKey: "evm", Key: []byte("delete-in-block2"), Value: []byte("1")},
{StoreKey: "evm", Key: []byte("re-add-in-block3"), Value: []byte("1")},
{StoreKey: "evm", Key: []byte("z-genesis-only"), Value: []byte("2")},
{StoreKey: "evm", Key: []byte("modify-in-block2"), Value: []byte("1")},
{StoreKey: "staking", Key: []byte("key1"), Value: []byte("value1")},
{StoreKey: "staking", Key: []byte("key1/subkey"), Value: []byte("value1")},
{StoreKey: "evm", Key: []byte("delete-in-block2"), Value: value1},
{StoreKey: "evm", Key: []byte("re-add-in-block3"), Value: value1},
{StoreKey: "evm", Key: []byte("z-genesis-only"), Value: value2},
{StoreKey: "evm", Key: []byte("modify-in-block2"), Value: value1},
{StoreKey: "staking", Key: key1, Value: value1},
{StoreKey: "staking", Key: key1_subkey, Value: value1},
}
case 1:
return []types.StoreKVPair{
{StoreKey: "evm", Key: []byte("re-add-in-block3"), Delete: true},
{StoreKey: "evm", Key: []byte("add-in-block1"), Value: []byte("1")},
{StoreKey: "staking", Key: []byte("key1"), Delete: true},
{StoreKey: "evm", Key: []byte("add-in-block1"), Value: value1},
{StoreKey: "staking", Key: key1, Delete: true},
}
case 2:
return []types.StoreKVPair{
{StoreKey: "evm", Key: []byte("add-in-block2"), Value: []byte("1")},
{StoreKey: "evm", Key: []byte("add-in-block2"), Value: value1},
{StoreKey: "evm", Key: []byte("delete-in-block2"), Delete: true},
{StoreKey: "evm", Key: []byte("modify-in-block2"), Value: []byte("2")},
{StoreKey: "evm", Key: []byte("key2"), Delete: true},
{StoreKey: "staking", Key: []byte("key1"), Value: []byte("value2")},
{StoreKey: "evm", Key: []byte("modify-in-block2"), Value: value2},
{StoreKey: "evm", Key: key2, Delete: true},
{StoreKey: "staking", Key: key1, Value: value2},
}
case 3:
return []types.StoreKVPair{
{StoreKey: "evm", Key: []byte("re-add-in-block3"), Value: []byte("2")},
{StoreKey: "evm", Key: []byte("re-add-in-block3"), Value: value2},
}
case 4:
return []types.StoreKVPair{
Expand Down Expand Up @@ -82,15 +81,15 @@ func testBasics(t *testing.T, store VersionStore) {

value, err := store.GetAtVersion("evm", []byte("z-genesis-only"), nil)
require.NoError(t, err)
require.Equal(t, value, []byte("2"))
require.Equal(t, value, value2)

v = 4
ok, err := store.HasAtVersion("evm", []byte("z-genesis-only"), &v)
require.NoError(t, err)
require.True(t, ok)
value, err = store.GetAtVersion("evm", []byte("z-genesis-only"), &v)
require.NoError(t, err)
require.Equal(t, value, []byte("2"))
require.Equal(t, value, value2)

value, err = store.GetAtVersion("evm", []byte("re-add-in-block3"), nil)
require.NoError(t, err)
Expand All @@ -102,12 +101,12 @@ func testBasics(t *testing.T, store VersionStore) {

value, err = store.GetAtVersion("staking", key1, nil)
require.NoError(t, err)
require.Equal(t, value, []byte("value2"))
require.Equal(t, value, value2)

v = 2
value, err = store.GetAtVersion("staking", key1, &v)
require.NoError(t, err)
require.Equal(t, value, []byte("value2"))
require.Equal(t, value, value2)

ok, err = store.HasAtVersion("staking", key1, &v)
require.NoError(t, err)
Expand All @@ -116,7 +115,7 @@ func testBasics(t *testing.T, store VersionStore) {
v = 0
value, err = store.GetAtVersion("staking", key1, &v)
require.NoError(t, err)
require.Equal(t, value, []byte("value1"))
require.Equal(t, value, value1)

v = 1
value, err = store.GetAtVersion("staking", key1, &v)
Expand Down Expand Up @@ -146,35 +145,35 @@ func testIterator(t *testing.T, store VersionStore) {

expItems := [][]KVPair{
{
KVPair{[]byte("delete-in-block2"), []byte("1")},
KVPair{[]byte("modify-in-block2"), []byte("1")},
KVPair{[]byte("re-add-in-block3"), []byte("1")},
KVPair{[]byte("z-genesis-only"), []byte("2")},
KVPair{[]byte("delete-in-block2"), value1},
KVPair{[]byte("modify-in-block2"), value1},
KVPair{[]byte("re-add-in-block3"), value1},
KVPair{[]byte("z-genesis-only"), value2},
},
{
KVPair{[]byte("add-in-block1"), []byte("1")},
KVPair{[]byte("delete-in-block2"), []byte("1")},
KVPair{[]byte("modify-in-block2"), []byte("1")},
KVPair{[]byte("z-genesis-only"), []byte("2")},
KVPair{[]byte("add-in-block1"), value1},
KVPair{[]byte("delete-in-block2"), value1},
KVPair{[]byte("modify-in-block2"), value1},
KVPair{[]byte("z-genesis-only"), value2},
},
{
KVPair{[]byte("add-in-block1"), []byte("1")},
KVPair{[]byte("add-in-block2"), []byte("1")},
KVPair{[]byte("modify-in-block2"), []byte("2")},
KVPair{[]byte("z-genesis-only"), []byte("2")},
KVPair{[]byte("add-in-block1"), value1},
KVPair{[]byte("add-in-block2"), value1},
KVPair{[]byte("modify-in-block2"), value2},
KVPair{[]byte("z-genesis-only"), value2},
},
{
KVPair{[]byte("add-in-block1"), []byte("1")},
KVPair{[]byte("add-in-block2"), []byte("1")},
KVPair{[]byte("modify-in-block2"), []byte("2")},
KVPair{[]byte("re-add-in-block3"), []byte("2")},
KVPair{[]byte("z-genesis-only"), []byte("2")},
KVPair{[]byte("add-in-block1"), value1},
KVPair{[]byte("add-in-block2"), value1},
KVPair{[]byte("modify-in-block2"), value2},
KVPair{[]byte("re-add-in-block3"), value2},
KVPair{[]byte("z-genesis-only"), value2},
},
{
KVPair{[]byte("add-in-block1"), []byte("1")},
KVPair{[]byte("add-in-block2"), []byte("1")},
KVPair{[]byte("modify-in-block2"), []byte("2")},
KVPair{[]byte("z-genesis-only"), []byte("2")},
KVPair{[]byte("add-in-block1"), value1},
KVPair{[]byte("add-in-block2"), value1},
KVPair{[]byte("modify-in-block2"), value2},
KVPair{[]byte("z-genesis-only"), value2},
},
}
for i, exp := range expItems {
Expand Down
4 changes: 2 additions & 2 deletions versiondb/tmdb/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/crypto-org-chain/cronos/client/file"
"github.com/crypto-org-chain/cronos/client"
"github.com/crypto-org-chain/cronos/versiondb"
"github.com/crypto-org-chain/cronos/x/cronos/types"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -35,7 +35,7 @@ func TestFeed(t *testing.T) {
_, err = buf.Write(bz)
require.NoError(t, err)
}
pairs, err := file.DecodeData(buf.Bytes())
pairs, err := client.DecodeData(buf.Bytes())
require.NoError(t, err)
require.NotEmpty(t, pairs)
store := storeCreator()
Expand Down

0 comments on commit 1677bfc

Please sign in to comment.