Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
remove accounts.db testdata from git, test distinctNetSet with >1 ip (#4
Browse files Browse the repository at this point in the history
)

* Apply source code formating provided by `go` tool

* solution: remove not-to-be versioned accounts.db testdata

* problem: should test distinctNetSet with >1 address

solution: create test for dynamic number of ips

problem: test fails

* Fix for p2p table
Node managment inside buckets

* solution: remove coverage.tmp

* Updated findnode mechanism to filter out local IPs

* problem: test fails

because that's not how distinctNetSet is supposed to work

solution: use EF test for EF code
  • Loading branch information
whilei authored and r8d8 committed Mar 21, 2018
1 parent e57ea2f commit 8356820
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -31,3 +31,5 @@ coverage.txt

# VSCode
.vscode

accounts/testdata/keystore/accounts.db
59 changes: 32 additions & 27 deletions p2p/distip/net_test.go
@@ -1,6 +1,7 @@
package distip

import (
"fmt"
"net"
"testing"
)
Expand All @@ -26,36 +27,40 @@ func checkContains(t *testing.T, fn func(net.IP) bool, inc, exc []string) {
}
}

func makeTestDistinctNetSet() *DistinctNetSet {
return &DistinctNetSet{
Subnet: 24,
Limit: 1,
}
}

func TestDistinctNetSet(t *testing.T) {
set := makeTestDistinctNetSet()
testip := net.ParseIP("24.207.212.9")

key := set.key(testip)
t.Logf("key: %v", key)

if ok := set.Add(testip); !ok {
t.Errorf("got: %v, want: %v", ok, true)
}
if contains := set.Contains(testip); !contains {
t.Errorf("got: %v, want: %v", contains, true)
}
if len := set.Len(); len != 1 {
t.Errorf("got: %v, want: %v", len, 1)
ops := []struct {
add, remove string
fails bool
}{
{add: "127.0.0.1"},
{add: "127.0.0.2"},
{add: "127.0.0.3", fails: true},
{add: "127.32.0.1"},
{add: "127.32.0.2"},
{add: "127.32.0.3", fails: true},
{add: "127.33.0.1", fails: true},
{add: "127.34.0.1"},
{add: "127.34.0.2"},
{add: "127.34.0.3", fails: true},
// Make room for an address, then add again.
{remove: "127.0.0.1"},
{add: "127.0.0.3"},
{add: "127.0.0.3", fails: true},
}

set.Remove(testip)
if contains := set.Contains(testip); contains {
t.Errorf("got: %v, want: %v", contains, false)
}
if len := set.Len(); len != 0 {
t.Errorf("got: %v, want: %v", len, 0)
set := DistinctNetSet{Subnet: 15, Limit: 2}
for _, op := range ops {
var desc string
if op.add != "" {
desc = fmt.Sprintf("Add(%s)", op.add)
if ok := set.Add(parseIP(op.add)); ok != !op.fails {
t.Errorf("%s == %t, want %t", desc, ok, !op.fails)
}
} else {
desc = fmt.Sprintf("Remove(%s)", op.remove)
set.Remove(parseIP(op.remove))
}
t.Logf("%s: %v", desc, set)
}
}

Expand Down

0 comments on commit 8356820

Please sign in to comment.