[WIP] tests
This commit is contained in:
parent
7188c73032
commit
22c85cfc4a
@ -250,7 +250,7 @@ func (sdb *builder) buildStateDiff(args []iterPair, params Params) ([]StateNode,
|
|||||||
// these are the leafkeys for the accounts which exist at both A and B but are different
|
// these are the leafkeys for the accounts which exist at both A and B but are different
|
||||||
// this also mutates the passed in createKeys and deleteKeys, removing the intersection keys
|
// this also mutates the passed in createKeys and deleteKeys, removing the intersection keys
|
||||||
// and leaving the truly created or deleted keys in place
|
// and leaving the truly created or deleted keys in place
|
||||||
updatedKeys := findIntersection(createKeys, deleteKeys)
|
updatedKeys := FindIntersection(createKeys, deleteKeys)
|
||||||
|
|
||||||
// build the diff nodes for the updated accounts using the mappings at both A and B
|
// build the diff nodes for the updated accounts using the mappings at both A and B
|
||||||
// as directed by the keys found as the intersection of the two
|
// as directed by the keys found as the intersection of the two
|
||||||
|
@ -38,7 +38,7 @@ func sortKeys(data AccountMap) []string {
|
|||||||
// findIntersection finds the set of strings from both arrays that are equivalent
|
// findIntersection finds the set of strings from both arrays that are equivalent
|
||||||
// a and b must first be sorted
|
// a and b must first be sorted
|
||||||
// this is used to find which keys have been both "deleted" and "created" i.e. they were updated
|
// this is used to find which keys have been both "deleted" and "created" i.e. they were updated
|
||||||
func findIntersection(a, b []string) []string {
|
func FindIntersection(a, b []string) []string {
|
||||||
lenA := len(a)
|
lenA := len(a)
|
||||||
lenB := len(b)
|
lenB := len(b)
|
||||||
iOfA, iOfB := 0, 0
|
iOfA, iOfB := 0, 0
|
||||||
|
34
pkg/helpers_test.go
Normal file
34
pkg/helpers_test.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package statediff_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
sd "github.com/vulcanize/eth-statediff-service/pkg"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFindIntersection(t *testing.T) {
|
||||||
|
// precond: a, b are sorted w/ no duplicates
|
||||||
|
testCases := []struct {
|
||||||
|
a, b, expected []string
|
||||||
|
}{
|
||||||
|
{[]string{}, []string{}, []string{}},
|
||||||
|
{[]string{""}, []string{""}, []string{""}},
|
||||||
|
{
|
||||||
|
[]string{"a", "b"},
|
||||||
|
[]string{"a", "c"},
|
||||||
|
[]string{"a"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
[]string{"a", "b", "c"},
|
||||||
|
[]string{"a", "b"},
|
||||||
|
[]string{"a", "b"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
intersection := sd.FindIntersection(test.a, test.b)
|
||||||
|
if !reflect.DeepEqual(test.expected, intersection) {
|
||||||
|
t.Errorf("failed: TestFindIntersection\nexpected: %v\nactual %v\n", test.expected, intersection)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user