[WIP] tests

This commit is contained in:
Roy Crihfield 2020-09-14 17:59:47 -05:00
parent 7188c73032
commit 22c85cfc4a
3 changed files with 36 additions and 2 deletions

View File

@ -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
// this also mutates the passed in createKeys and deleteKeys, removing the intersection keys
// 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
// as directed by the keys found as the intersection of the two

View File

@ -38,7 +38,7 @@ func sortKeys(data AccountMap) []string {
// findIntersection finds the set of strings from both arrays that are equivalent
// 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
func findIntersection(a, b []string) []string {
func FindIntersection(a, b []string) []string {
lenA := len(a)
lenB := len(b)
iOfA, iOfB := 0, 0

34
pkg/helpers_test.go Normal file
View 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)
}
}
}