Commit a09d4922 authored by liuyuhang's avatar liuyuhang

add test

parent 8a189752
...@@ -243,3 +243,7 @@ func (kvmMavls *KVMVCCMavlStore) Del(req *types.StoreDel) ([]byte, error) { ...@@ -243,3 +243,7 @@ func (kvmMavls *KVMVCCMavlStore) Del(req *types.StoreDel) ([]byte, error) {
} }
return hash, err return hash, err
} }
// TODO 数据库中mavl的清除
// 达到kvmvccMavlFork + 100000 后触发清除
// it := db.Iterator(nil, mvccPrefix, true)
\ No newline at end of file
...@@ -154,7 +154,7 @@ func TestKvmvccMavlCommit(t *testing.T) { ...@@ -154,7 +154,7 @@ func TestKvmvccMavlCommit(t *testing.T) {
req := &types.ReqHash{ req := &types.ReqHash{
Hash: hash, Hash: hash,
} }
if i + 1 == forkHeight { if i+1 == forkHeight {
frontHash = append(frontHash, hash...) frontHash = append(frontHash, hash...)
} }
_, err = store.Commit(req) _, err = store.Commit(req)
...@@ -244,7 +244,6 @@ func TestKvmvccMavlRollback(t *testing.T) { ...@@ -244,7 +244,6 @@ func TestKvmvccMavlRollback(t *testing.T) {
assert.Equal(t, types.ErrHashNotFound.Error(), err.Error()) assert.Equal(t, types.ErrHashNotFound.Error(), err.Error())
} }
/*
func TestKvmvccdbRollbackBatch(t *testing.T) { func TestKvmvccdbRollbackBatch(t *testing.T) {
dir, err := ioutil.TempDir("", "example") dir, err := ioutil.TempDir("", "example")
assert.Nil(t, err) assert.Nil(t, err)
...@@ -268,6 +267,11 @@ func TestKvmvccdbRollbackBatch(t *testing.T) { ...@@ -268,6 +267,11 @@ func TestKvmvccdbRollbackBatch(t *testing.T) {
hash1 := make([]byte, len(hash)) hash1 := make([]byte, len(hash))
copy(hash1, hash) copy(hash1, hash)
store.Commit(req) store.Commit(req)
// 设置分叉高度
kvmvccMavlFork = 50
defer func() {
kvmvccMavlFork = 200 * 10000
}()
for i := 1; i <= 202; i++ { for i := 1; i <= 202; i++ {
kvset = nil kvset = nil
datas1 := &types.StoreSet{StateHash: hash1, KV: datas.KV, Height: datas.Height + int64(i)} datas1 := &types.StoreSet{StateHash: hash1, KV: datas.KV, Height: datas.Height + int64(i)}
...@@ -335,7 +339,6 @@ func TestKvmvccdbRollbackBatch(t *testing.T) { ...@@ -335,7 +339,6 @@ func TestKvmvccdbRollbackBatch(t *testing.T) {
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
assert.Equal(t, int64(2), maxVersion) assert.Equal(t, int64(2), maxVersion)
} }
*/
func enableConfig() []byte { func enableConfig() []byte {
data, _ := json.Marshal(&subConfig{EnableMVCCIter: true}) data, _ := json.Marshal(&subConfig{EnableMVCCIter: true})
...@@ -414,7 +417,13 @@ func TestIterateRangeByStateHash(t *testing.T) { ...@@ -414,7 +417,13 @@ func TestIterateRangeByStateHash(t *testing.T) {
assert.Equal(t, int64(4), resp.Num) assert.Equal(t, int64(4), resp.Num)
assert.Equal(t, int64(340000000000), resp.Amount) assert.Equal(t, int64(340000000000), resp.Amount)
// 设置分叉高度
kvmvccMavlFork = 5
defer func() {
kvmvccMavlFork = 200 * 10000
}()
fmt.Println("---test case1-2 ---") fmt.Println("---test case1-2 ---")
firstForkHash := drivers.EmptyRoot[:]
for i := 1; i <= 10; i++ { for i := 1; i <= 10; i++ {
kvset = nil kvset = nil
...@@ -432,6 +441,9 @@ func TestIterateRangeByStateHash(t *testing.T) { ...@@ -432,6 +441,9 @@ func TestIterateRangeByStateHash(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
req := &types.ReqHash{Hash: hash1} req := &types.ReqHash{Hash: hash1}
store.Commit(req) store.Commit(req)
if int(kvmvccMavlFork) == i {
firstForkHash = hash1
}
} }
resp = &types.ReplyGetTotalCoins{} resp = &types.ReplyGetTotalCoins{}
...@@ -472,17 +484,15 @@ func TestIterateRangeByStateHash(t *testing.T) { ...@@ -472,17 +484,15 @@ func TestIterateRangeByStateHash(t *testing.T) {
assert.Equal(t, int64(2), resp.Num) assert.Equal(t, int64(2), resp.Num)
assert.Equal(t, int64(201900000000), resp.Amount) assert.Equal(t, int64(201900000000), resp.Amount)
if datas.Height >= kvmvccMavlFork {
fmt.Println("---test case1-6 ---") fmt.Println("---test case1-6 ---")
resp = &types.ReplyGetTotalCoins{} resp = &types.ReplyGetTotalCoins{}
resp.Count = 10000 resp.Count = 10000
store.IterateRangeByStateHash(hash, []byte("mavl-coins-bty-"), []byte("mavl-coins-bty-exec"), true, resp.IterateRangeByStateHash) store.IterateRangeByStateHash(firstForkHash, []byte("mavl-coins-bty-"), []byte("mavl-coins-bty-exec"), true, resp.IterateRangeByStateHash)
fmt.Println("resp.Num=", resp.Num) fmt.Println("resp.Num=", resp.Num)
fmt.Println("resp.Amount=", resp.Amount) fmt.Println("resp.Amount=", resp.Amount)
assert.Equal(t, int64(0), resp.Num) assert.Equal(t, int64(0), resp.Num)
assert.Equal(t, int64(0), resp.Amount) assert.Equal(t, int64(0), resp.Amount)
}
} }
func GetRandomString(length int) string { func GetRandomString(length int) string {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment