Skip to content

Commit

Permalink
renaming Test to keyValue
Browse files Browse the repository at this point in the history
  • Loading branch information
kishansagathiya committed Mar 18, 2022
1 parent 31d2b8e commit 5c7ec38
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
16 changes: 8 additions & 8 deletions lib/trie/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func newTestDB(t *testing.T) chaindb.Database {
}

func TestTrie_DatabaseStoreAndLoad(t *testing.T) {
cases := [][]Test{
cases := [][]keyValues{
{
{key: []byte{0x01, 0x35}, value: []byte("pen")},
{key: []byte{0x01, 0x35, 0x79}, value: []byte("penguin")},
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestTrie_DatabaseStoreAndLoad(t *testing.T) {
}

func TestTrie_WriteDirty_Put(t *testing.T) {
cases := [][]Test{
cases := [][]keyValues{
{
{key: []byte{0x01, 0x35}, value: []byte("pen")},
{key: []byte{0x01, 0x35, 0x79}, value: []byte("penguin")},
Expand Down Expand Up @@ -155,7 +155,7 @@ func TestTrie_WriteDirty_Put(t *testing.T) {
}

func TestTrie_WriteDirty_PutReplace(t *testing.T) {
cases := [][]Test{
cases := [][]keyValues{
{
{key: []byte{0x01, 0x35}, value: []byte("pen")},
{key: []byte{0x01, 0x35, 0x79}, value: []byte("penguin")},
Expand Down Expand Up @@ -218,7 +218,7 @@ func TestTrie_WriteDirty_PutReplace(t *testing.T) {
}

func TestTrie_WriteDirty_Delete(t *testing.T) {
cases := [][]Test{
cases := [][]keyValues{
{
{key: []byte{0x01, 0x35}, value: []byte("pen")},
{key: []byte{0x01, 0x35, 0x79}, value: []byte("penguin")},
Expand Down Expand Up @@ -285,7 +285,7 @@ func TestTrie_WriteDirty_Delete(t *testing.T) {
}

func TestTrie_WriteDirty_ClearPrefix(t *testing.T) {
cases := [][]Test{
cases := [][]keyValues{
{
{key: []byte{0x01, 0x35}, value: []byte("pen")},
{key: []byte{0x01, 0x35, 0x79}, value: []byte("penguin")},
Expand Down Expand Up @@ -338,7 +338,7 @@ func TestTrie_WriteDirty_ClearPrefix(t *testing.T) {
}

func TestTrie_GetFromDB(t *testing.T) {
cases := [][]Test{
cases := [][]keyValues{
{
{key: []byte{0x01, 0x35}, value: []byte("pen")},
{key: []byte{0x01, 0x35, 0x79}, value: []byte("penguin")},
Expand Down Expand Up @@ -390,7 +390,7 @@ func TestTrie_GetFromDB(t *testing.T) {
}

func TestStoreAndLoadWithChildTries(t *testing.T) {
testCase := []Test{
keyValue := []keyValues{
{key: []byte{0xf2, 0x3}, value: []byte("f")},
{key: []byte{0x09, 0xd3}, value: []byte("noot")},
{key: []byte{0x07}, value: []byte("ramen")},
Expand Down Expand Up @@ -420,7 +420,7 @@ func TestStoreAndLoadWithChildTries(t *testing.T) {
for _, keyToChild := range keysToTest {
trie := NewEmptyTrie()

for _, test := range testCase {
for _, test := range keyValue {
trie.Put(test.key, test.value)
}

Expand Down
2 changes: 1 addition & 1 deletion lib/trie/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type writeCall struct {

var errTest = errors.New("test error")

type Test struct {
type keyValues struct {
key []byte
value []byte
op int
Expand Down
42 changes: 21 additions & 21 deletions lib/trie/trie_endtoend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func writeFailedData(t *testing.T, kv map[string][]byte, path string) {
func buildSmallTrie() *Trie {
trie := NewEmptyTrie()

tests := []Test{
tests := []keyValues{
{key: []byte{0x01, 0x35}, value: []byte("pen")},
{key: []byte{0x01, 0x35, 0x79}, value: []byte("penguin")},
{key: []byte{0xf2}, value: []byte("feather")},
Expand All @@ -76,7 +76,7 @@ func buildSmallTrie() *Trie {
return trie
}

func runTests(t *testing.T, trie *Trie, tests []Test) {
func runTests(t *testing.T, trie *Trie, tests []keyValues) {
for _, test := range tests {
switch test.op {
case put:
Expand All @@ -96,7 +96,7 @@ func runTests(t *testing.T, trie *Trie, tests []Test) {
func TestPutAndGetBranch(t *testing.T) {
trie := NewEmptyTrie()

tests := []Test{
tests := []keyValues{
{key: []byte{0x01, 0x35}, value: []byte("spaghetti"), op: put},
{key: []byte{0x01, 0x35, 0x79}, value: []byte("gnocchi"), op: put},
{key: []byte{0x07}, value: []byte("ramen"), op: put},
Expand All @@ -115,7 +115,7 @@ func TestPutAndGetBranch(t *testing.T) {
func TestPutAndGetOddKeyLengths(t *testing.T) {
trie := NewEmptyTrie()

tests := []Test{
tests := []keyValues{
{key: []byte{0x43, 0xc1}, value: []byte("noot"), op: put},
{key: []byte{0x49, 0x29}, value: []byte("nootagain"), op: put},
{key: []byte{0x43, 0x0c}, value: []byte("odd"), op: put},
Expand Down Expand Up @@ -210,7 +210,7 @@ func Test_Trie_PutAndGet_FailedData(t *testing.T) {
func TestGetPartialKey(t *testing.T) {
trie := NewEmptyTrie()

tests := []Test{
tests := []keyValues{
{key: []byte{0x01, 0x35}, value: []byte("pen"), op: put},
{key: []byte{0x01, 0x35, 0x79}, value: []byte("penguin"), op: put},
{key: []byte{0x01, 0x35, 0x07}, value: []byte("odd"), op: put},
Expand All @@ -235,7 +235,7 @@ func TestGetPartialKey(t *testing.T) {
func TestDeleteSmall(t *testing.T) {
trie := buildSmallTrie()

tests := []Test{
tests := []keyValues{
{key: []byte{}, value: []byte("floof"), op: del},
{key: []byte{}, value: nil, op: get},
{key: []byte{}, value: []byte("floof"), op: put},
Expand Down Expand Up @@ -279,7 +279,7 @@ func TestDeleteSmall(t *testing.T) {
func TestDeleteCombineBranch(t *testing.T) {
trie := buildSmallTrie()

tests := []Test{
tests := []keyValues{
{key: []byte{0x01, 0x35, 0x46}, value: []byte("raccoon"), op: put},
{key: []byte{0x01, 0x35, 0x46, 0x77}, value: []byte("rat"), op: put},
{key: []byte{0x09, 0xd3}, value: []byte("noot"), op: del},
Expand All @@ -292,7 +292,7 @@ func TestDeleteCombineBranch(t *testing.T) {
func TestDeleteFromBranch(t *testing.T) {
trie := NewEmptyTrie()

tests := []Test{
tests := []keyValues{
{key: []byte{0x06, 0x15, 0xfc}, value: []byte("noot"), op: put},
{key: []byte{0x06, 0x2b, 0xa9}, value: []byte("nootagain"), op: put},
{key: []byte{0x06, 0xaf, 0xb1}, value: []byte("odd"), op: put},
Expand All @@ -317,7 +317,7 @@ func TestDeleteFromBranch(t *testing.T) {
func TestDeleteOddKeyLengths(t *testing.T) {
trie := NewEmptyTrie()

tests := []Test{
tests := []keyValues{
{key: []byte{0x43, 0xc1}, value: []byte("noot"), op: put},
{key: []byte{0x43, 0xc1}, value: []byte("noot"), op: get},
{key: []byte{0x49, 0x29}, value: []byte("nootagain"), op: put},
Expand Down Expand Up @@ -360,7 +360,7 @@ func TestTrieDiff(t *testing.T) {

var testKey = []byte("testKey")

tests := []Test{
tests := []keyValues{
{key: testKey, value: testKey},
{key: []byte("testKey1"), value: []byte("testKey1")},
{key: []byte("testKey2"), value: []byte("testKey2")},
Expand All @@ -374,7 +374,7 @@ func TestTrieDiff(t *testing.T) {
err = trie.Store(storageDB)
require.NoError(t, err)

tests = []Test{
tests = []keyValues{
{key: testKey, value: []byte("newTestKey2")},
{key: []byte("testKey2"), value: []byte("newKey")},
{key: []byte("testKey3"), value: []byte("testKey3")},
Expand Down Expand Up @@ -462,7 +462,7 @@ func TestDelete(t *testing.T) {
}

func TestClearPrefix(t *testing.T) {
tests := []Test{
tests := []keyValues{
{key: []byte{0x01, 0x35}, value: []byte("spaghetti"), op: put},
{key: []byte{0x01, 0x35, 0x79}, value: []byte("gnocchi"), op: put},
{key: []byte{0x01, 0x35, 0x79, 0xab}, value: []byte("spaghetti"), op: put},
Expand Down Expand Up @@ -627,7 +627,7 @@ func TestTrie_ClearPrefixVsDelete(t *testing.T) {
[]byte("a"),
}

cases := [][]Test{
cases := [][]keyValues{
{
{key: []byte{0x01, 0x35}, value: []byte("pen")},
{key: []byte{0x01, 0x35, 0x79}, value: []byte("penguin")},
Expand Down Expand Up @@ -681,7 +681,7 @@ func TestTrie_ClearPrefixVsDelete(t *testing.T) {
}

func TestSnapshot(t *testing.T) {
tests := []Test{
tests := []keyValues{
{key: []byte{0x01, 0x35}, value: []byte("spaghetti"), op: put},
{key: []byte{0x01, 0x35, 0x79}, value: []byte("gnocchi"), op: put},
{key: []byte{0x01, 0x35, 0x79, 0xab}, value: []byte("spaghetti"), op: put},
Expand Down Expand Up @@ -784,11 +784,11 @@ func TestTrie_ConcurrentSnapshotWrites(t *testing.T) {
const size = 1000
const workers = 4

testCases := make([][]Test, workers)
testCases := make([][]keyValues, workers)
expectedTries := make([]*Trie, workers)

for i := 0; i < workers; i++ {
testCases[i] = make([]Test, size)
testCases[i] = make([]keyValues, size)
expectedTries[i] = buildSmallTrie()
for j := 0; j < size; j++ {
k := make([]byte, 2)
Expand All @@ -805,7 +805,7 @@ func TestTrie_ConcurrentSnapshotWrites(t *testing.T) {
expectedTries[i].ClearPrefix(k)
}

testCases[i][j] = Test{
testCases[i][j] = keyValues{
key: k,
op: op,
}
Expand All @@ -821,7 +821,7 @@ func TestTrie_ConcurrentSnapshotWrites(t *testing.T) {
for i := 0; i < workers; i++ {
snapshotedTries[i] = buildSmallTrie().Snapshot()

go func(trie *Trie, operations []Test,
go func(trie *Trie, operations []keyValues,
startWg, finishWg *sync.WaitGroup) {
defer finishWg.Done()
startWg.Done()
Expand Down Expand Up @@ -864,7 +864,7 @@ func TestTrie_ClearPrefixLimit(t *testing.T) {
{0x09},
}

cases := [][]Test{
cases := [][]keyValues{
{
{key: []byte{0x01, 0x35}, value: []byte("pen")},
{key: []byte{0x01, 0x36}, value: []byte("pencil")},
Expand Down Expand Up @@ -900,7 +900,7 @@ func TestTrie_ClearPrefixLimit(t *testing.T) {
},
}

testFn := func(t *testing.T, testCase []Test, prefix []byte) {
testFn := func(t *testing.T, testCase []keyValues, prefix []byte) {
prefixNibbles := codec.KeyLEToNibbles(prefix)
if len(prefixNibbles) > 0 && prefixNibbles[len(prefixNibbles)-1] == 0 {
prefixNibbles = prefixNibbles[:len(prefixNibbles)-1]
Expand Down Expand Up @@ -965,7 +965,7 @@ func TestTrie_ClearPrefixLimitSnapshot(t *testing.T) {
{0x09},
}

cases := [][]Test{
cases := [][]keyValues{
{
{key: []byte{0x01}, value: []byte("feather")},
},
Expand Down

0 comments on commit 5c7ec38

Please sign in to comment.