mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 02:40:45 +00:00
replace comment out tests with t.Skip()
This commit is contained in:
parent
7f581be3be
commit
d17f1fdd75
11 changed files with 837 additions and 772 deletions
|
|
@ -245,6 +245,15 @@ func loadKeyStoreTestV1(file string, t *testing.T) map[string]KeyStoreTestV1 {
|
||||||
return tests
|
return tests
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestKeyForDirectICAP(t *testing.T) {
|
||||||
|
t.Skip("Test unresponsive")
|
||||||
|
t.Parallel()
|
||||||
|
key := NewKeyForDirectICAP(rand.Reader)
|
||||||
|
if !strings.HasPrefix(key.Address.Hex(), "0x00") {
|
||||||
|
t.Errorf("Expected first address byte to be zero, have: %s", key.Address.Hex())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestV3_31_Byte_Key(t *testing.T) {
|
func TestV3_31_Byte_Key(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
tests := loadKeyStoreTestV3("testdata/v3_test_vector.json", t)
|
tests := loadKeyStoreTestV3("testdata/v3_test_vector.json", t)
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,15 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
|
"github.com/ethereum/go-ethereum/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testFile struct {
|
type testFile struct {
|
||||||
|
|
@ -53,197 +61,198 @@ func TestCLISwarmFsDefaultIPCPath(t *testing.T) {
|
||||||
// and without any log messages in the log:
|
// and without any log messages in the log:
|
||||||
// /Library/Filesystems/osxfuse.fs/Contents/Resources/load_osxfuse.
|
// /Library/Filesystems/osxfuse.fs/Contents/Resources/load_osxfuse.
|
||||||
// This is the reason for this file not being built on darwin architecture.
|
// This is the reason for this file not being built on darwin architecture.
|
||||||
// func TestCLISwarmFs(t *testing.T) {
|
func TestCLISwarmFs(t *testing.T) {
|
||||||
// cluster := newTestCluster(t, 3)
|
t.Skip("Test fail on travis")
|
||||||
// defer cluster.Shutdown()
|
cluster := newTestCluster(t, 3)
|
||||||
|
defer cluster.Shutdown()
|
||||||
|
|
||||||
// // create a tmp dir
|
// create a tmp dir
|
||||||
// mountPoint, err := ioutil.TempDir("", "swarm-test")
|
mountPoint, err := ioutil.TempDir("", "swarm-test")
|
||||||
// log.Debug("swarmfs cli test", "1st mount", mountPoint)
|
log.Debug("swarmfs cli test", "1st mount", mountPoint)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// t.Fatal(err)
|
t.Fatal(err)
|
||||||
// }
|
}
|
||||||
// defer os.RemoveAll(mountPoint)
|
defer os.RemoveAll(mountPoint)
|
||||||
|
|
||||||
// handlingNode := cluster.Nodes[0]
|
handlingNode := cluster.Nodes[0]
|
||||||
// mhash := doUploadEmptyDir(t, handlingNode)
|
mhash := doUploadEmptyDir(t, handlingNode)
|
||||||
// log.Debug("swarmfs cli test: mounting first run", "ipc path", filepath.Join(handlingNode.Dir, handlingNode.IpcPath))
|
log.Debug("swarmfs cli test: mounting first run", "ipc path", filepath.Join(handlingNode.Dir, handlingNode.IpcPath))
|
||||||
|
|
||||||
// mount := runSwarm(t, []string{
|
mount := runSwarm(t, []string{
|
||||||
// fmt.Sprintf("--%s", utils.IPCPathFlag.Name), filepath.Join(handlingNode.Dir, handlingNode.IpcPath),
|
fmt.Sprintf("--%s", utils.IPCPathFlag.Name), filepath.Join(handlingNode.Dir, handlingNode.IpcPath),
|
||||||
// "fs",
|
"fs",
|
||||||
// "mount",
|
"mount",
|
||||||
// mhash,
|
mhash,
|
||||||
// mountPoint,
|
mountPoint,
|
||||||
// }...)
|
}...)
|
||||||
// mount.ExpectExit()
|
mount.ExpectExit()
|
||||||
|
|
||||||
// filesToAssert := []*testFile{}
|
filesToAssert := []*testFile{}
|
||||||
|
|
||||||
// dirPath, err := createDirInDir(mountPoint, "testSubDir")
|
dirPath, err := createDirInDir(mountPoint, "testSubDir")
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// t.Fatal(err)
|
t.Fatal(err)
|
||||||
// }
|
}
|
||||||
// dirPath2, err := createDirInDir(dirPath, "AnotherTestSubDir")
|
dirPath2, err := createDirInDir(dirPath, "AnotherTestSubDir")
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// t.Fatal(err)
|
t.Fatal(err)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// dummyContent := "somerandomtestcontentthatshouldbeasserted"
|
dummyContent := "somerandomtestcontentthatshouldbeasserted"
|
||||||
// dirs := []string{
|
dirs := []string{
|
||||||
// mountPoint,
|
mountPoint,
|
||||||
// dirPath,
|
dirPath,
|
||||||
// dirPath2,
|
dirPath2,
|
||||||
// }
|
}
|
||||||
// files := []string{"f1.tmp", "f2.tmp"}
|
files := []string{"f1.tmp", "f2.tmp"}
|
||||||
// for _, d := range dirs {
|
for _, d := range dirs {
|
||||||
// for _, entry := range files {
|
for _, entry := range files {
|
||||||
// tFile, err := createTestFileInPath(d, entry, dummyContent)
|
tFile, err := createTestFileInPath(d, entry, dummyContent)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// t.Fatal(err)
|
t.Fatal(err)
|
||||||
// }
|
}
|
||||||
// filesToAssert = append(filesToAssert, tFile)
|
filesToAssert = append(filesToAssert, tFile)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// if len(filesToAssert) != len(dirs)*len(files) {
|
if len(filesToAssert) != len(dirs)*len(files) {
|
||||||
// t.Fatalf("should have %d files to assert now, got %d", len(dirs)*len(files), len(filesToAssert))
|
t.Fatalf("should have %d files to assert now, got %d", len(dirs)*len(files), len(filesToAssert))
|
||||||
// }
|
}
|
||||||
// //hashRegexp := `[a-f\d]{64}`
|
//hashRegexp := `[a-f\d]{64}`
|
||||||
// //log.Debug("swarmfs cli test: unmounting first run...", "ipc path", filepath.Join(handlingNode.Dir, handlingNode.IpcPath))
|
//log.Debug("swarmfs cli test: unmounting first run...", "ipc path", filepath.Join(handlingNode.Dir, handlingNode.IpcPath))
|
||||||
|
|
||||||
// // unmount := runSwarm(t, []string{
|
// unmount := runSwarm(t, []string{
|
||||||
// // fmt.Sprintf("--%s", utils.IPCPathFlag.Name), filepath.Join(handlingNode.Dir, handlingNode.IpcPath),
|
// fmt.Sprintf("--%s", utils.IPCPathFlag.Name), filepath.Join(handlingNode.Dir, handlingNode.IpcPath),
|
||||||
// // "fs",
|
// "fs",
|
||||||
// // "unmount",
|
// "unmount",
|
||||||
// // mountPoint,
|
// mountPoint,
|
||||||
// // }...)
|
// }...)
|
||||||
// // _, matches := unmount.ExpectRegexp(hashRegexp)
|
// _, matches := unmount.ExpectRegexp(hashRegexp)
|
||||||
// // unmount.ExpectExit()
|
// unmount.ExpectExit()
|
||||||
// //
|
//
|
||||||
// // hash := matches[0]
|
// hash := matches[0]
|
||||||
// // if hash == mhash {
|
// if hash == mhash {
|
||||||
// // t.Fatal("this should not be equal")
|
// t.Fatal("this should not be equal")
|
||||||
// // }
|
// }
|
||||||
// // log.Debug("swarmfs cli test: asserting no files in mount point")
|
// log.Debug("swarmfs cli test: asserting no files in mount point")
|
||||||
// //
|
//
|
||||||
// // //check that there's nothing in the mount folder
|
// //check that there's nothing in the mount folder
|
||||||
// // filesInDir, err := ioutil.ReadDir(mountPoint)
|
// filesInDir, err := ioutil.ReadDir(mountPoint)
|
||||||
// // if err != nil {
|
// if err != nil {
|
||||||
// // t.Fatalf("had an error reading the directory: %v", err)
|
// t.Fatalf("had an error reading the directory: %v", err)
|
||||||
// // }
|
// }
|
||||||
// //
|
//
|
||||||
// // if len(filesInDir) != 0 {
|
// if len(filesInDir) != 0 {
|
||||||
// // t.Fatal("there shouldn't be anything here")
|
// t.Fatal("there shouldn't be anything here")
|
||||||
// // }
|
// }
|
||||||
// //
|
//
|
||||||
// // secondMountPoint, err := ioutil.TempDir("", "swarm-test")
|
// secondMountPoint, err := ioutil.TempDir("", "swarm-test")
|
||||||
// // log.Debug("swarmfs cli test", "2nd mount point at", secondMountPoint)
|
// log.Debug("swarmfs cli test", "2nd mount point at", secondMountPoint)
|
||||||
// // if err != nil {
|
// if err != nil {
|
||||||
// // t.Fatal(err)
|
// t.Fatal(err)
|
||||||
// // }
|
// }
|
||||||
// // defer os.RemoveAll(secondMountPoint)
|
// defer os.RemoveAll(secondMountPoint)
|
||||||
// //
|
//
|
||||||
// // log.Debug("swarmfs cli test: remounting at second mount point", "ipc path", filepath.Join(handlingNode.Dir, handlingNode.IpcPath))
|
// log.Debug("swarmfs cli test: remounting at second mount point", "ipc path", filepath.Join(handlingNode.Dir, handlingNode.IpcPath))
|
||||||
// //
|
//
|
||||||
// // //remount, check files
|
// //remount, check files
|
||||||
// // newMount := runSwarm(t, []string{
|
// newMount := runSwarm(t, []string{
|
||||||
// // fmt.Sprintf("--%s", utils.IPCPathFlag.Name), filepath.Join(handlingNode.Dir, handlingNode.IpcPath),
|
// fmt.Sprintf("--%s", utils.IPCPathFlag.Name), filepath.Join(handlingNode.Dir, handlingNode.IpcPath),
|
||||||
// // "fs",
|
// "fs",
|
||||||
// // "mount",
|
// "mount",
|
||||||
// // hash, // the latest hash
|
// hash, // the latest hash
|
||||||
// // secondMountPoint,
|
// secondMountPoint,
|
||||||
// // }...)
|
// }...)
|
||||||
// //
|
//
|
||||||
// // newMount.ExpectExit()
|
// newMount.ExpectExit()
|
||||||
// // time.Sleep(1 * time.Second)
|
// time.Sleep(1 * time.Second)
|
||||||
// //
|
//
|
||||||
// // filesInDir, err = ioutil.ReadDir(secondMountPoint)
|
// filesInDir, err = ioutil.ReadDir(secondMountPoint)
|
||||||
// // if err != nil {
|
// if err != nil {
|
||||||
// // t.Fatal(err)
|
// t.Fatal(err)
|
||||||
// // }
|
// }
|
||||||
// //
|
//
|
||||||
// // if len(filesInDir) == 0 {
|
// if len(filesInDir) == 0 {
|
||||||
// // t.Fatal("there should be something here")
|
// t.Fatal("there should be something here")
|
||||||
// // }
|
// }
|
||||||
// //
|
//
|
||||||
// // log.Debug("swarmfs cli test: traversing file tree to see it matches previous mount")
|
// log.Debug("swarmfs cli test: traversing file tree to see it matches previous mount")
|
||||||
// //
|
//
|
||||||
// // for _, file := range filesToAssert {
|
// for _, file := range filesToAssert {
|
||||||
// // file.filePath = strings.Replace(file.filePath, mountPoint, secondMountPoint, -1)
|
// file.filePath = strings.Replace(file.filePath, mountPoint, secondMountPoint, -1)
|
||||||
// // fileBytes, err := ioutil.ReadFile(file.filePath)
|
// fileBytes, err := ioutil.ReadFile(file.filePath)
|
||||||
// //
|
//
|
||||||
// // if err != nil {
|
// if err != nil {
|
||||||
// // t.Fatal(err)
|
// t.Fatal(err)
|
||||||
// // }
|
// }
|
||||||
// // if !bytes.Equal(fileBytes, bytes.NewBufferString(file.content).Bytes()) {
|
// if !bytes.Equal(fileBytes, bytes.NewBufferString(file.content).Bytes()) {
|
||||||
// // t.Fatal("this should be equal")
|
// t.Fatal("this should be equal")
|
||||||
// // }
|
// }
|
||||||
// // }
|
// }
|
||||||
// //
|
//
|
||||||
// // log.Debug("swarmfs cli test: unmounting second run", "ipc path", filepath.Join(handlingNode.Dir, handlingNode.IpcPath))
|
// log.Debug("swarmfs cli test: unmounting second run", "ipc path", filepath.Join(handlingNode.Dir, handlingNode.IpcPath))
|
||||||
// //
|
//
|
||||||
// // unmountSec := runSwarm(t, []string{
|
// unmountSec := runSwarm(t, []string{
|
||||||
// // fmt.Sprintf("--%s", utils.IPCPathFlag.Name), filepath.Join(handlingNode.Dir, handlingNode.IpcPath),
|
// fmt.Sprintf("--%s", utils.IPCPathFlag.Name), filepath.Join(handlingNode.Dir, handlingNode.IpcPath),
|
||||||
// // "fs",
|
// "fs",
|
||||||
// // "unmount",
|
// "unmount",
|
||||||
// // secondMountPoint,
|
// secondMountPoint,
|
||||||
// // }...)
|
// }...)
|
||||||
// //
|
//
|
||||||
// // _, matches = unmountSec.ExpectRegexp(hashRegexp)
|
// _, matches = unmountSec.ExpectRegexp(hashRegexp)
|
||||||
// // unmountSec.ExpectExit()
|
// unmountSec.ExpectExit()
|
||||||
// //
|
//
|
||||||
// // if matches[0] != hash {
|
// if matches[0] != hash {
|
||||||
// // t.Fatal("these should be equal - no changes made")
|
// t.Fatal("these should be equal - no changes made")
|
||||||
// // }
|
// }
|
||||||
// }
|
}
|
||||||
|
|
||||||
// func doUploadEmptyDir(t *testing.T, node *testNode) string {
|
func doUploadEmptyDir(t *testing.T, node *testNode) string {
|
||||||
// // create a tmp dir
|
// create a tmp dir
|
||||||
// tmpDir, err := ioutil.TempDir("", "swarm-test")
|
tmpDir, err := ioutil.TempDir("", "swarm-test")
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// t.Fatal(err)
|
t.Fatal(err)
|
||||||
// }
|
}
|
||||||
// defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
// hashRegexp := `[a-f\d]{64}`
|
hashRegexp := `[a-f\d]{64}`
|
||||||
|
|
||||||
// flags := []string{
|
flags := []string{
|
||||||
// "--bzzapi", node.URL,
|
"--bzzapi", node.URL,
|
||||||
// "--recursive",
|
"--recursive",
|
||||||
// "up",
|
"up",
|
||||||
// tmpDir}
|
tmpDir}
|
||||||
|
|
||||||
// log.Info("swarmfs cli test: uploading dir with 'swarm up'")
|
log.Info("swarmfs cli test: uploading dir with 'swarm up'")
|
||||||
// up := runSwarm(t, flags...)
|
up := runSwarm(t, flags...)
|
||||||
// _, matches := up.ExpectRegexp(hashRegexp)
|
_, matches := up.ExpectRegexp(hashRegexp)
|
||||||
// up.ExpectExit()
|
up.ExpectExit()
|
||||||
// hash := matches[0]
|
hash := matches[0]
|
||||||
// log.Info("swarmfs cli test: dir uploaded", "hash", hash)
|
log.Info("swarmfs cli test: dir uploaded", "hash", hash)
|
||||||
// return hash
|
return hash
|
||||||
// }
|
}
|
||||||
|
|
||||||
// func createDirInDir(createInDir string, dirToCreate string) (string, error) {
|
func createDirInDir(createInDir string, dirToCreate string) (string, error) {
|
||||||
// fullpath := filepath.Join(createInDir, dirToCreate)
|
fullpath := filepath.Join(createInDir, dirToCreate)
|
||||||
// err := os.MkdirAll(fullpath, 0777)
|
err := os.MkdirAll(fullpath, 0777)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return "", err
|
return "", err
|
||||||
// }
|
}
|
||||||
// return fullpath, nil
|
return fullpath, nil
|
||||||
// }
|
}
|
||||||
|
|
||||||
// func createTestFileInPath(dir, filename, content string) (*testFile, error) {
|
func createTestFileInPath(dir, filename, content string) (*testFile, error) {
|
||||||
// tFile := &testFile{}
|
tFile := &testFile{}
|
||||||
// filePath := filepath.Join(dir, filename)
|
filePath := filepath.Join(dir, filename)
|
||||||
// if file, err := os.Create(filePath); err == nil {
|
if file, err := os.Create(filePath); err == nil {
|
||||||
// tFile.content = content
|
tFile.content = content
|
||||||
// tFile.filePath = filePath
|
tFile.filePath = filePath
|
||||||
|
|
||||||
// _, err = io.WriteString(file, content)
|
_, err = io.WriteString(file, content)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return nil, err
|
return nil, err
|
||||||
// }
|
}
|
||||||
// file.Close()
|
file.Close()
|
||||||
// }
|
}
|
||||||
|
|
||||||
// return tFile, nil
|
return tFile, nil
|
||||||
// }
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,305 +16,306 @@
|
||||||
|
|
||||||
package protocols
|
package protocols
|
||||||
|
|
||||||
// import (
|
import (
|
||||||
// "context"
|
"context"
|
||||||
// "flag"
|
"flag"
|
||||||
// "fmt"
|
"fmt"
|
||||||
// "io/ioutil"
|
"io/ioutil"
|
||||||
// "math/rand"
|
"math/rand"
|
||||||
// "os"
|
"os"
|
||||||
// "path/filepath"
|
"path/filepath"
|
||||||
// "reflect"
|
"reflect"
|
||||||
// "sync"
|
"sync"
|
||||||
// "testing"
|
"testing"
|
||||||
// "time"
|
"time"
|
||||||
|
|
||||||
// "github.com/mattn/go-colorable"
|
"github.com/mattn/go-colorable"
|
||||||
|
|
||||||
// "github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
// "github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
|
|
||||||
// "github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
// "github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
// "github.com/ethereum/go-ethereum/p2p/enode"
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||||
// "github.com/ethereum/go-ethereum/p2p/simulations"
|
"github.com/ethereum/go-ethereum/p2p/simulations"
|
||||||
// "github.com/ethereum/go-ethereum/p2p/simulations/adapters"
|
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
|
||||||
// )
|
)
|
||||||
|
|
||||||
// const (
|
const (
|
||||||
// content = "123456789"
|
content = "123456789"
|
||||||
// )
|
)
|
||||||
|
|
||||||
// var (
|
var (
|
||||||
// nodes = flag.Int("nodes", 30, "number of nodes to create (default 30)")
|
nodes = flag.Int("nodes", 30, "number of nodes to create (default 30)")
|
||||||
// msgs = flag.Int("msgs", 100, "number of messages sent by node (default 100)")
|
msgs = flag.Int("msgs", 100, "number of messages sent by node (default 100)")
|
||||||
// loglevel = flag.Int("loglevel", 0, "verbosity of logs")
|
loglevel = flag.Int("loglevel", 0, "verbosity of logs")
|
||||||
// rawlog = flag.Bool("rawlog", false, "remove terminal formatting from logs")
|
rawlog = flag.Bool("rawlog", false, "remove terminal formatting from logs")
|
||||||
// )
|
)
|
||||||
|
|
||||||
// func init() {
|
func init() {
|
||||||
// flag.Parse()
|
// flag.Parse()
|
||||||
// log.PrintOrigins(true)
|
log.PrintOrigins(true)
|
||||||
// log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(*loglevel), log.StreamHandler(colorable.NewColorableStderr(), log.TerminalFormat(!*rawlog))))
|
log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(*loglevel), log.StreamHandler(colorable.NewColorableStderr(), log.TerminalFormat(!*rawlog))))
|
||||||
// }
|
}
|
||||||
|
|
||||||
// //TestAccountingSimulation runs a p2p/simulations simulation
|
//TestAccountingSimulation runs a p2p/simulations simulation
|
||||||
// //It creates a *nodes number of nodes, connects each one with each other,
|
//It creates a *nodes number of nodes, connects each one with each other,
|
||||||
// //then sends out a random selection of messages up to *msgs amount of messages
|
//then sends out a random selection of messages up to *msgs amount of messages
|
||||||
// //from the test protocol spec.
|
//from the test protocol spec.
|
||||||
// //The spec has some accounted messages defined through the Prices interface.
|
//The spec has some accounted messages defined through the Prices interface.
|
||||||
// //The test does accounting for all the message exchanged, and then checks
|
//The test does accounting for all the message exchanged, and then checks
|
||||||
// //that every node has the same balance with a peer, but with opposite signs.
|
//that every node has the same balance with a peer, but with opposite signs.
|
||||||
// //Balance(AwithB) = 0 - Balance(BwithA) or Abs|Balance(AwithB)| == Abs|Balance(BwithA)|
|
//Balance(AwithB) = 0 - Balance(BwithA) or Abs|Balance(AwithB)| == Abs|Balance(BwithA)|
|
||||||
// func TestAccountingSimulation(t *testing.T) {
|
func TestAccountingSimulation(t *testing.T) {
|
||||||
// //setup the balances objects for every node
|
t.Skip("Test no longer works")
|
||||||
// bal := newBalances(*nodes)
|
//setup the balances objects for every node
|
||||||
// //setup the metrics system or tests will fail trying to write metrics
|
bal := newBalances(*nodes)
|
||||||
// dir, err := ioutil.TempDir("", "account-sim")
|
//setup the metrics system or tests will fail trying to write metrics
|
||||||
// if err != nil {
|
dir, err := ioutil.TempDir("", "account-sim")
|
||||||
// t.Fatal(err)
|
if err != nil {
|
||||||
// }
|
t.Fatal(err)
|
||||||
// defer os.RemoveAll(dir)
|
}
|
||||||
// SetupAccountingMetrics(1*time.Second, filepath.Join(dir, "metrics.db"))
|
defer os.RemoveAll(dir)
|
||||||
// //define the node.Service for this test
|
SetupAccountingMetrics(1*time.Second, filepath.Join(dir, "metrics.db"))
|
||||||
// services := adapters.Services{
|
//define the node.Service for this test
|
||||||
// "accounting": func(ctx *adapters.ServiceContext) (node.Service, error) {
|
services := adapters.Services{
|
||||||
// return bal.newNode(), nil
|
"accounting": func(ctx *adapters.ServiceContext) (node.Service, error) {
|
||||||
// },
|
return bal.newNode(), nil
|
||||||
// }
|
},
|
||||||
// //setup the simulation
|
}
|
||||||
// adapter := adapters.NewSimAdapter(services)
|
//setup the simulation
|
||||||
// net := simulations.NewNetwork(adapter, &simulations.NetworkConfig{DefaultService: "accounting"})
|
adapter := adapters.NewSimAdapter(services)
|
||||||
// defer net.Shutdown()
|
net := simulations.NewNetwork(adapter, &simulations.NetworkConfig{DefaultService: "accounting"})
|
||||||
|
defer net.Shutdown()
|
||||||
|
|
||||||
// // we send msgs messages per node, wait for all messages to arrive
|
// we send msgs messages per node, wait for all messages to arrive
|
||||||
// bal.wg.Add(*nodes * *msgs)
|
bal.wg.Add(*nodes * *msgs)
|
||||||
// trigger := make(chan enode.ID)
|
trigger := make(chan enode.ID)
|
||||||
// go func() {
|
go func() {
|
||||||
// // wait for all of them to arrive
|
// wait for all of them to arrive
|
||||||
// bal.wg.Wait()
|
bal.wg.Wait()
|
||||||
// // then trigger a check
|
// then trigger a check
|
||||||
// // the selected node for the trigger is irrelevant,
|
// the selected node for the trigger is irrelevant,
|
||||||
// // we just want to trigger the end of the simulation
|
// we just want to trigger the end of the simulation
|
||||||
// trigger <- net.Nodes[0].ID()
|
trigger <- net.Nodes[0].ID()
|
||||||
// }()
|
}()
|
||||||
|
|
||||||
// // create nodes and start them
|
// create nodes and start them
|
||||||
// for i := 0; i < *nodes; i++ {
|
for i := 0; i < *nodes; i++ {
|
||||||
// conf := adapters.RandomNodeConfig()
|
conf := adapters.RandomNodeConfig()
|
||||||
// bal.id2n[conf.ID] = i
|
bal.id2n[conf.ID] = i
|
||||||
// if _, err := net.NewNodeWithConfig(conf); err != nil {
|
if _, err := net.NewNodeWithConfig(conf); err != nil {
|
||||||
// t.Fatal(err)
|
t.Fatal(err)
|
||||||
// }
|
}
|
||||||
// if err := net.Start(conf.ID); err != nil {
|
if err := net.Start(conf.ID); err != nil {
|
||||||
// t.Fatal(err)
|
t.Fatal(err)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// // fully connect nodes
|
// fully connect nodes
|
||||||
// for i, n := range net.Nodes {
|
for i, n := range net.Nodes {
|
||||||
// for _, m := range net.Nodes[i+1:] {
|
for _, m := range net.Nodes[i+1:] {
|
||||||
// if err := net.Connect(n.ID(), m.ID()); err != nil {
|
if err := net.Connect(n.ID(), m.ID()); err != nil {
|
||||||
// t.Fatal(err)
|
t.Fatal(err)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // empty action
|
// empty action
|
||||||
// action := func(ctx context.Context) error {
|
action := func(ctx context.Context) error {
|
||||||
// return nil
|
return nil
|
||||||
// }
|
}
|
||||||
// // check always checks out
|
// check always checks out
|
||||||
// check := func(ctx context.Context, id enode.ID) (bool, error) {
|
check := func(ctx context.Context, id enode.ID) (bool, error) {
|
||||||
// return true, nil
|
return true, nil
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // run simulation
|
// run simulation
|
||||||
// timeout := 30 * time.Second
|
timeout := 30 * time.Second
|
||||||
// ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||||
// defer cancel()
|
defer cancel()
|
||||||
// result := simulations.NewSimulation(net).Run(ctx, &simulations.Step{
|
result := simulations.NewSimulation(net).Run(ctx, &simulations.Step{
|
||||||
// Action: action,
|
Action: action,
|
||||||
// Trigger: trigger,
|
Trigger: trigger,
|
||||||
// Expect: &simulations.Expectation{
|
Expect: &simulations.Expectation{
|
||||||
// Nodes: []enode.ID{net.Nodes[0].ID()},
|
Nodes: []enode.ID{net.Nodes[0].ID()},
|
||||||
// Check: check,
|
Check: check,
|
||||||
// },
|
},
|
||||||
// })
|
})
|
||||||
|
|
||||||
// if result.Error != nil {
|
if result.Error != nil {
|
||||||
// t.Fatal(result.Error)
|
t.Fatal(result.Error)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // check if balance matrix is symmetric
|
// check if balance matrix is symmetric
|
||||||
// if err := bal.symmetric(); err != nil {
|
if err := bal.symmetric(); err != nil {
|
||||||
// t.Fatal(err)
|
t.Fatal(err)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // matrix is a matrix of nodes and its balances
|
// matrix is a matrix of nodes and its balances
|
||||||
// // matrix is in fact a linear array of size n*n,
|
// matrix is in fact a linear array of size n*n,
|
||||||
// // so the balance for any node A with B is at index
|
// so the balance for any node A with B is at index
|
||||||
// // A*n + B, while the balance of node B with A is at
|
// A*n + B, while the balance of node B with A is at
|
||||||
// // B*n + A
|
// B*n + A
|
||||||
// // (n entries in the array will not be filled -
|
// (n entries in the array will not be filled -
|
||||||
// // the balance of a node with itself)
|
// the balance of a node with itself)
|
||||||
// type matrix struct {
|
type matrix struct {
|
||||||
// n int //number of nodes
|
n int //number of nodes
|
||||||
// m []int64 //array of balances
|
m []int64 //array of balances
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // create a new matrix
|
// create a new matrix
|
||||||
// func newMatrix(n int) *matrix {
|
func newMatrix(n int) *matrix {
|
||||||
// return &matrix{
|
return &matrix{
|
||||||
// n: n,
|
n: n,
|
||||||
// m: make([]int64, n*n),
|
m: make([]int64, n*n),
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // called from the testBalance's Add accounting function: register balance change
|
// called from the testBalance's Add accounting function: register balance change
|
||||||
// func (m *matrix) add(i, j int, v int64) error {
|
func (m *matrix) add(i, j int, v int64) error {
|
||||||
// // index for the balance of local node i with remote nodde j is
|
// index for the balance of local node i with remote nodde j is
|
||||||
// // i * number of nodes + remote node
|
// i * number of nodes + remote node
|
||||||
// mi := i*m.n + j
|
mi := i*m.n + j
|
||||||
// // register that balance
|
// register that balance
|
||||||
// m.m[mi] += v
|
m.m[mi] += v
|
||||||
// return nil
|
return nil
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // check that the balances are symmetric:
|
// check that the balances are symmetric:
|
||||||
// // balance of node i with node j is the same as j with i but with inverted signs
|
// balance of node i with node j is the same as j with i but with inverted signs
|
||||||
// func (m *matrix) symmetric() error {
|
func (m *matrix) symmetric() error {
|
||||||
// //iterate all nodes
|
//iterate all nodes
|
||||||
// for i := 0; i < m.n; i++ {
|
for i := 0; i < m.n; i++ {
|
||||||
// //iterate starting +1
|
//iterate starting +1
|
||||||
// for j := i + 1; j < m.n; j++ {
|
for j := i + 1; j < m.n; j++ {
|
||||||
// log.Debug("bal", "1", i, "2", j, "i,j", m.m[i*m.n+j], "j,i", m.m[j*m.n+i])
|
log.Debug("bal", "1", i, "2", j, "i,j", m.m[i*m.n+j], "j,i", m.m[j*m.n+i])
|
||||||
// if m.m[i*m.n+j] != -m.m[j*m.n+i] {
|
if m.m[i*m.n+j] != -m.m[j*m.n+i] {
|
||||||
// return fmt.Errorf("value mismatch. m[%v, %v] = %v; m[%v, %v] = %v", i, j, m.m[i*m.n+j], j, i, m.m[j*m.n+i])
|
return fmt.Errorf("value mismatch. m[%v, %v] = %v; m[%v, %v] = %v", i, j, m.m[i*m.n+j], j, i, m.m[j*m.n+i])
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// return nil
|
return nil
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // all the balances
|
// all the balances
|
||||||
// type balances struct {
|
type balances struct {
|
||||||
// i int
|
i int
|
||||||
// *matrix
|
*matrix
|
||||||
// id2n map[enode.ID]int
|
id2n map[enode.ID]int
|
||||||
// wg *sync.WaitGroup
|
wg *sync.WaitGroup
|
||||||
// }
|
}
|
||||||
|
|
||||||
// func newBalances(n int) *balances {
|
func newBalances(n int) *balances {
|
||||||
// return &balances{
|
return &balances{
|
||||||
// matrix: newMatrix(n),
|
matrix: newMatrix(n),
|
||||||
// id2n: make(map[enode.ID]int),
|
id2n: make(map[enode.ID]int),
|
||||||
// wg: &sync.WaitGroup{},
|
wg: &sync.WaitGroup{},
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // create a new testNode for every node created as part of the service
|
// create a new testNode for every node created as part of the service
|
||||||
// func (b *balances) newNode() *testNode {
|
func (b *balances) newNode() *testNode {
|
||||||
// defer func() { b.i++ }()
|
defer func() { b.i++ }()
|
||||||
// return &testNode{
|
return &testNode{
|
||||||
// bal: b,
|
bal: b,
|
||||||
// i: b.i,
|
i: b.i,
|
||||||
// peers: make([]*testPeer, b.n), //a node will be connected to n-1 peers
|
peers: make([]*testPeer, b.n), //a node will be connected to n-1 peers
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// type testNode struct {
|
type testNode struct {
|
||||||
// bal *balances
|
bal *balances
|
||||||
// i int
|
i int
|
||||||
// lock sync.Mutex
|
lock sync.Mutex
|
||||||
// peers []*testPeer
|
peers []*testPeer
|
||||||
// peerCount int
|
peerCount int
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // do the accounting for the peer's test protocol
|
// do the accounting for the peer's test protocol
|
||||||
// // testNode implements protocols.Balance
|
// testNode implements protocols.Balance
|
||||||
// func (t *testNode) Add(a int64, p *Peer) error {
|
func (t *testNode) Add(a int64, p *Peer) error {
|
||||||
// //get the index for the remote peer
|
//get the index for the remote peer
|
||||||
// remote := t.bal.id2n[p.ID()]
|
remote := t.bal.id2n[p.ID()]
|
||||||
// log.Debug("add", "local", t.i, "remote", remote, "amount", a)
|
log.Debug("add", "local", t.i, "remote", remote, "amount", a)
|
||||||
// return t.bal.add(t.i, remote, a)
|
return t.bal.add(t.i, remote, a)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// //run the p2p protocol
|
//run the p2p protocol
|
||||||
// //for every node, represented by testNode, create a remote testPeer
|
//for every node, represented by testNode, create a remote testPeer
|
||||||
// func (t *testNode) run(p *p2p.Peer, rw p2p.MsgReadWriter) error {
|
func (t *testNode) run(p *p2p.Peer, rw p2p.MsgReadWriter) error {
|
||||||
// spec := createTestSpec()
|
spec := createTestSpec()
|
||||||
// //create accounting hook
|
//create accounting hook
|
||||||
// spec.Hook = NewAccounting(t, &dummyPrices{})
|
spec.Hook = NewAccounting(t, &dummyPrices{})
|
||||||
|
|
||||||
// //create a peer for this node
|
//create a peer for this node
|
||||||
// tp := &testPeer{NewPeer(p, rw, spec), t.i, t.bal.id2n[p.ID()], t.bal.wg}
|
tp := &testPeer{NewPeer(p, rw, spec), t.i, t.bal.id2n[p.ID()], t.bal.wg}
|
||||||
// t.lock.Lock()
|
t.lock.Lock()
|
||||||
// t.peers[t.bal.id2n[p.ID()]] = tp
|
t.peers[t.bal.id2n[p.ID()]] = tp
|
||||||
// t.peerCount++
|
t.peerCount++
|
||||||
// if t.peerCount == t.bal.n-1 {
|
if t.peerCount == t.bal.n-1 {
|
||||||
// //when all peer connections are established, start sending messages from this peer
|
//when all peer connections are established, start sending messages from this peer
|
||||||
// go t.send()
|
go t.send()
|
||||||
// }
|
}
|
||||||
// t.lock.Unlock()
|
t.lock.Unlock()
|
||||||
// return tp.Run(tp.handle)
|
return tp.Run(tp.handle)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // p2p message receive handler function
|
// p2p message receive handler function
|
||||||
// func (tp *testPeer) handle(ctx context.Context, msg interface{}) error {
|
func (tp *testPeer) handle(ctx context.Context, msg interface{}) error {
|
||||||
// tp.wg.Done()
|
tp.wg.Done()
|
||||||
// log.Debug("receive", "from", tp.remote, "to", tp.local, "type", reflect.TypeOf(msg), "msg", msg)
|
log.Debug("receive", "from", tp.remote, "to", tp.local, "type", reflect.TypeOf(msg), "msg", msg)
|
||||||
// return nil
|
return nil
|
||||||
// }
|
}
|
||||||
|
|
||||||
// type testPeer struct {
|
type testPeer struct {
|
||||||
// *Peer
|
*Peer
|
||||||
// local, remote int
|
local, remote int
|
||||||
// wg *sync.WaitGroup
|
wg *sync.WaitGroup
|
||||||
// }
|
}
|
||||||
|
|
||||||
// func (t *testNode) send() {
|
func (t *testNode) send() {
|
||||||
// log.Debug("start sending")
|
log.Debug("start sending")
|
||||||
// for i := 0; i < *msgs; i++ {
|
for i := 0; i < *msgs; i++ {
|
||||||
// //determine randomly to which peer to send
|
//determine randomly to which peer to send
|
||||||
// whom := rand.Intn(t.bal.n - 1)
|
whom := rand.Intn(t.bal.n - 1)
|
||||||
// if whom >= t.i {
|
if whom >= t.i {
|
||||||
// whom++
|
whom++
|
||||||
// }
|
}
|
||||||
// t.lock.Lock()
|
t.lock.Lock()
|
||||||
// p := t.peers[whom]
|
p := t.peers[whom]
|
||||||
// t.lock.Unlock()
|
t.lock.Unlock()
|
||||||
|
|
||||||
// //determine a random message from the spec's messages to be sent
|
//determine a random message from the spec's messages to be sent
|
||||||
// which := rand.Intn(len(p.spec.Messages))
|
which := rand.Intn(len(p.spec.Messages))
|
||||||
// msg := p.spec.Messages[which]
|
msg := p.spec.Messages[which]
|
||||||
// switch msg.(type) {
|
switch msg.(type) {
|
||||||
// case *perBytesMsgReceiverPays:
|
case *perBytesMsgReceiverPays:
|
||||||
// msg = &perBytesMsgReceiverPays{Content: content[:rand.Intn(len(content))]}
|
msg = &perBytesMsgReceiverPays{Content: content[:rand.Intn(len(content))]}
|
||||||
// case *perBytesMsgSenderPays:
|
case *perBytesMsgSenderPays:
|
||||||
// msg = &perBytesMsgSenderPays{Content: content[:rand.Intn(len(content))]}
|
msg = &perBytesMsgSenderPays{Content: content[:rand.Intn(len(content))]}
|
||||||
// }
|
}
|
||||||
// log.Debug("send", "from", t.i, "to", whom, "type", reflect.TypeOf(msg), "msg", msg)
|
log.Debug("send", "from", t.i, "to", whom, "type", reflect.TypeOf(msg), "msg", msg)
|
||||||
// p.Send(context.TODO(), msg)
|
p.Send(context.TODO(), msg)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // define the protocol
|
// define the protocol
|
||||||
// func (t *testNode) Protocols() []p2p.Protocol {
|
func (t *testNode) Protocols() []p2p.Protocol {
|
||||||
// return []p2p.Protocol{{
|
return []p2p.Protocol{{
|
||||||
// Length: 100,
|
Length: 100,
|
||||||
// Run: t.run,
|
Run: t.run,
|
||||||
// }}
|
}}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// func (t *testNode) APIs() []rpc.API {
|
func (t *testNode) APIs() []rpc.API {
|
||||||
// return nil
|
return nil
|
||||||
// }
|
}
|
||||||
|
|
||||||
// func (t *testNode) Start(server *p2p.Server) error {
|
func (t *testNode) Start(server *p2p.Server) error {
|
||||||
// return nil
|
return nil
|
||||||
// }
|
}
|
||||||
|
|
||||||
// func (t *testNode) Stop() error {
|
func (t *testNode) Stop() error {
|
||||||
// return nil
|
return nil
|
||||||
// }
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,12 @@
|
||||||
package network
|
package network
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strings"
|
"strings"
|
||||||
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
|
@ -62,48 +64,49 @@ Nodes should only connect with other nodes with the same network ID.
|
||||||
After the setup phase, the test checks on each node if it has the
|
After the setup phase, the test checks on each node if it has the
|
||||||
expected node connections (excluding those not sharing the network ID).
|
expected node connections (excluding those not sharing the network ID).
|
||||||
*/
|
*/
|
||||||
// func TestNetworkID(t *testing.T) {
|
func TestNetworkID(t *testing.T) {
|
||||||
// log.Debug("Start test")
|
t.Skip("Test no longer work for XDC")
|
||||||
// //arbitrarily set the number of nodes. It could be any number
|
log.Debug("Start test")
|
||||||
// numNodes := 24
|
//arbitrarily set the number of nodes. It could be any number
|
||||||
// //the nodeMap maps all nodes (slice value) with the same network ID (key)
|
numNodes := 24
|
||||||
// nodeMap = make(map[int][]enode.ID)
|
//the nodeMap maps all nodes (slice value) with the same network ID (key)
|
||||||
// //set up the network and connect nodes
|
nodeMap = make(map[int][]enode.ID)
|
||||||
// net, err := setupNetwork(numNodes)
|
//set up the network and connect nodes
|
||||||
// if err != nil {
|
net, err := setupNetwork(numNodes)
|
||||||
// t.Fatalf("Error setting up network: %v", err)
|
if err != nil {
|
||||||
// }
|
t.Fatalf("Error setting up network: %v", err)
|
||||||
// //let's sleep to ensure all nodes are connected
|
}
|
||||||
// time.Sleep(1 * time.Second)
|
//let's sleep to ensure all nodes are connected
|
||||||
// // shutdown the the network to avoid race conditions
|
time.Sleep(1 * time.Second)
|
||||||
// // on accessing kademlias global map while network nodes
|
// shutdown the the network to avoid race conditions
|
||||||
// // are accepting messages
|
// on accessing kademlias global map while network nodes
|
||||||
// net.Shutdown()
|
// are accepting messages
|
||||||
// //for each group sharing the same network ID...
|
net.Shutdown()
|
||||||
// for _, netIDGroup := range nodeMap {
|
//for each group sharing the same network ID...
|
||||||
// log.Trace("netIDGroup size", "size", len(netIDGroup))
|
for _, netIDGroup := range nodeMap {
|
||||||
// //...check that their size of the kademlia is of the expected size
|
log.Trace("netIDGroup size", "size", len(netIDGroup))
|
||||||
// //the assumption is that it should be the size of the group minus 1 (the node itself)
|
//...check that their size of the kademlia is of the expected size
|
||||||
// for _, node := range netIDGroup {
|
//the assumption is that it should be the size of the group minus 1 (the node itself)
|
||||||
// if kademlias[node].addrs.Size() != len(netIDGroup)-1 {
|
for _, node := range netIDGroup {
|
||||||
// t.Fatalf("Kademlia size has not expected peer size. Kademlia size: %d, expected size: %d", kademlias[node].addrs.Size(), len(netIDGroup)-1)
|
if kademlias[node].addrs.Size() != len(netIDGroup)-1 {
|
||||||
// }
|
t.Fatalf("Kademlia size has not expected peer size. Kademlia size: %d, expected size: %d", kademlias[node].addrs.Size(), len(netIDGroup)-1)
|
||||||
// kademlias[node].EachAddr(nil, 0, func(addr *BzzAddr, _ int) bool {
|
}
|
||||||
// found := false
|
kademlias[node].EachAddr(nil, 0, func(addr *BzzAddr, _ int) bool {
|
||||||
// for _, nd := range netIDGroup {
|
found := false
|
||||||
// if bytes.Equal(kademlias[nd].BaseAddr(), addr.Address()) {
|
for _, nd := range netIDGroup {
|
||||||
// found = true
|
if bytes.Equal(kademlias[nd].BaseAddr(), addr.Address()) {
|
||||||
// }
|
found = true
|
||||||
// }
|
}
|
||||||
// if !found {
|
}
|
||||||
// t.Fatalf("Expected node not found for node %s", node.String())
|
if !found {
|
||||||
// }
|
t.Fatalf("Expected node not found for node %s", node.String())
|
||||||
// return true
|
}
|
||||||
// })
|
return true
|
||||||
// }
|
})
|
||||||
// }
|
}
|
||||||
// log.Info("Test terminated successfully")
|
}
|
||||||
// }
|
log.Info("Test terminated successfully")
|
||||||
|
}
|
||||||
|
|
||||||
// setup simulated network with bzz/discovery and pss services.
|
// setup simulated network with bzz/discovery and pss services.
|
||||||
// connects nodes in a circle
|
// connects nodes in a circle
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,18 @@
|
||||||
package simulation
|
package simulation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||||
"github.com/ethereum/go-ethereum/p2p/simulations"
|
"github.com/ethereum/go-ethereum/p2p/simulations"
|
||||||
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
|
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
|
||||||
|
"github.com/ethereum/go-ethereum/swarm/network"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUpDownNodeIDs(t *testing.T) {
|
func TestUpDownNodeIDs(t *testing.T) {
|
||||||
|
|
@ -270,43 +276,44 @@ func TestAddNodesAndConnectStar(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//To test that uploading a snapshot works
|
//To test that uploading a snapshot works
|
||||||
// func TestUploadSnapshot(t *testing.T) {
|
func TestUploadSnapshot(t *testing.T) {
|
||||||
// log.Debug("Creating simulation")
|
t.Skip("Broken test for XDC")
|
||||||
// s := New(map[string]ServiceFunc{
|
log.Debug("Creating simulation")
|
||||||
// "bzz": func(ctx *adapters.ServiceContext, b *sync.Map) (node.Service, func(), error) {
|
s := New(map[string]ServiceFunc{
|
||||||
// addr := network.NewAddr(ctx.Config.Node())
|
"bzz": func(ctx *adapters.ServiceContext, b *sync.Map) (node.Service, func(), error) {
|
||||||
// hp := network.NewHiveParams()
|
addr := network.NewAddr(ctx.Config.Node())
|
||||||
// hp.Discovery = false
|
hp := network.NewHiveParams()
|
||||||
// config := &network.BzzConfig{
|
hp.Discovery = false
|
||||||
// OverlayAddr: addr.Over(),
|
config := &network.BzzConfig{
|
||||||
// UnderlayAddr: addr.Under(),
|
OverlayAddr: addr.Over(),
|
||||||
// HiveParams: hp,
|
UnderlayAddr: addr.Under(),
|
||||||
// }
|
HiveParams: hp,
|
||||||
// kad := network.NewKademlia(addr.Over(), network.NewKadParams())
|
}
|
||||||
// return network.NewBzz(config, kad, nil, nil, nil), nil, nil
|
kad := network.NewKademlia(addr.Over(), network.NewKadParams())
|
||||||
// },
|
return network.NewBzz(config, kad, nil, nil, nil), nil, nil
|
||||||
// })
|
},
|
||||||
// defer s.Close()
|
})
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
// nodeCount := 16
|
nodeCount := 16
|
||||||
// log.Debug("Uploading snapshot")
|
log.Debug("Uploading snapshot")
|
||||||
// err := s.UploadSnapshot(fmt.Sprintf("../stream/testing/snapshot_%d.json", nodeCount))
|
err := s.UploadSnapshot(fmt.Sprintf("../stream/testing/snapshot_%d.json", nodeCount))
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// t.Fatalf("Error uploading snapshot to simulation network: %v", err)
|
t.Fatalf("Error uploading snapshot to simulation network: %v", err)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// ctx := context.Background()
|
ctx := context.Background()
|
||||||
// log.Debug("Starting simulation...")
|
log.Debug("Starting simulation...")
|
||||||
// s.Run(ctx, func(ctx context.Context, sim *Simulation) error {
|
s.Run(ctx, func(ctx context.Context, sim *Simulation) error {
|
||||||
// log.Debug("Checking")
|
log.Debug("Checking")
|
||||||
// nodes := sim.UpNodeIDs()
|
nodes := sim.UpNodeIDs()
|
||||||
// if len(nodes) != nodeCount {
|
if len(nodes) != nodeCount {
|
||||||
// t.Fatal("Simulation network node number doesn't match snapshot node number")
|
t.Fatal("Simulation network node number doesn't match snapshot node number")
|
||||||
// }
|
}
|
||||||
// return nil
|
return nil
|
||||||
// })
|
})
|
||||||
// log.Debug("Done.")
|
log.Debug("Done.")
|
||||||
// }
|
}
|
||||||
|
|
||||||
func TestStartStopNode(t *testing.T) {
|
func TestStartStopNode(t *testing.T) {
|
||||||
sim := New(noopServiceFuncMap)
|
sim := New(noopServiceFuncMap)
|
||||||
|
|
|
||||||
|
|
@ -121,9 +121,10 @@ func BenchmarkDiscovery_64_4(b *testing.B) { benchmarkDiscovery(b, 64, 4) }
|
||||||
func BenchmarkDiscovery_128_4(b *testing.B) { benchmarkDiscovery(b, 128, 4) }
|
func BenchmarkDiscovery_128_4(b *testing.B) { benchmarkDiscovery(b, 128, 4) }
|
||||||
func BenchmarkDiscovery_256_4(b *testing.B) { benchmarkDiscovery(b, 256, 4) }
|
func BenchmarkDiscovery_256_4(b *testing.B) { benchmarkDiscovery(b, 256, 4) }
|
||||||
|
|
||||||
// func TestDiscoverySimulationExecAdapter(t *testing.T) {
|
func TestDiscoverySimulationExecAdapter(t *testing.T) {
|
||||||
// testDiscoverySimulationExecAdapter(t, *nodeCount, *initCount)
|
t.Skip("Test no longer work for XDC")
|
||||||
// }
|
testDiscoverySimulationExecAdapter(t, *nodeCount, *initCount)
|
||||||
|
}
|
||||||
|
|
||||||
func testDiscoverySimulationExecAdapter(t *testing.T, nodes, conns int) {
|
func testDiscoverySimulationExecAdapter(t *testing.T, nodes, conns int) {
|
||||||
baseDir, err := ioutil.TempDir("", "swarm-test")
|
baseDir, err := ioutil.TempDir("", "swarm-test")
|
||||||
|
|
@ -134,13 +135,15 @@ func testDiscoverySimulationExecAdapter(t *testing.T, nodes, conns int) {
|
||||||
testDiscoverySimulation(t, nodes, conns, adapters.NewExecAdapter(baseDir))
|
testDiscoverySimulation(t, nodes, conns, adapters.NewExecAdapter(baseDir))
|
||||||
}
|
}
|
||||||
|
|
||||||
// func TestDiscoverySimulationSimAdapter(t *testing.T) {
|
func TestDiscoverySimulationSimAdapter(t *testing.T) {
|
||||||
// testDiscoverySimulationSimAdapter(t, *nodeCount, *initCount)
|
t.Skip("Test no longer work for XDC")
|
||||||
// }
|
testDiscoverySimulationSimAdapter(t, *nodeCount, *initCount)
|
||||||
|
}
|
||||||
|
|
||||||
// func TestDiscoveryPersistenceSimulationSimAdapter(t *testing.T) {
|
func TestDiscoveryPersistenceSimulationSimAdapter(t *testing.T) {
|
||||||
// testDiscoveryPersistenceSimulationSimAdapter(t, *nodeCount, *initCount)
|
t.Skip("Test no longer work for XDC")
|
||||||
// }
|
testDiscoveryPersistenceSimulationSimAdapter(t, *nodeCount, *initCount)
|
||||||
|
}
|
||||||
|
|
||||||
func testDiscoveryPersistenceSimulationSimAdapter(t *testing.T, nodes, conns int) {
|
func testDiscoveryPersistenceSimulationSimAdapter(t *testing.T, nodes, conns int) {
|
||||||
testDiscoveryPersistenceSimulation(t, nodes, conns, adapters.NewSimAdapter(services))
|
testDiscoveryPersistenceSimulation(t, nodes, conns, adapters.NewSimAdapter(services))
|
||||||
|
|
|
||||||
|
|
@ -42,27 +42,28 @@ const (
|
||||||
//provided to the test.
|
//provided to the test.
|
||||||
//Files are uploaded to nodes, other nodes try to retrieve the file
|
//Files are uploaded to nodes, other nodes try to retrieve the file
|
||||||
//Number of nodes can be provided via commandline too.
|
//Number of nodes can be provided via commandline too.
|
||||||
// func TestFileRetrieval(t *testing.T) {
|
func TestFileRetrieval(t *testing.T) {
|
||||||
// if *nodes != 0 {
|
t.Skip("Test no longer work for XDC")
|
||||||
// err := runFileRetrievalTest(*nodes)
|
if *nodes != 0 {
|
||||||
// if err != nil {
|
err := runFileRetrievalTest(*nodes)
|
||||||
// t.Fatal(err)
|
if err != nil {
|
||||||
// }
|
t.Fatal(err)
|
||||||
// } else {
|
}
|
||||||
// nodeCnt := []int{16}
|
} else {
|
||||||
// //if the `longrunning` flag has been provided
|
nodeCnt := []int{16}
|
||||||
// //run more test combinations
|
//if the `longrunning` flag has been provided
|
||||||
// if *longrunning {
|
//run more test combinations
|
||||||
// nodeCnt = append(nodeCnt, 32, 64, 128)
|
if *longrunning {
|
||||||
// }
|
nodeCnt = append(nodeCnt, 32, 64, 128)
|
||||||
// for _, n := range nodeCnt {
|
}
|
||||||
// err := runFileRetrievalTest(n)
|
for _, n := range nodeCnt {
|
||||||
// if err != nil {
|
err := runFileRetrievalTest(n)
|
||||||
// t.Fatal(err)
|
if err != nil {
|
||||||
// }
|
t.Fatal(err)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//This test is a retrieval test for nodes.
|
//This test is a retrieval test for nodes.
|
||||||
//One node is randomly selected to be the pivot node.
|
//One node is randomly selected to be the pivot node.
|
||||||
|
|
@ -70,39 +71,40 @@ const (
|
||||||
//provided to the test, the number of chunks is uploaded
|
//provided to the test, the number of chunks is uploaded
|
||||||
//to the pivot node and other nodes try to retrieve the chunk(s).
|
//to the pivot node and other nodes try to retrieve the chunk(s).
|
||||||
//Number of chunks and nodes can be provided via commandline too.
|
//Number of chunks and nodes can be provided via commandline too.
|
||||||
// func TestRetrieval(t *testing.T) {
|
func TestRetrieval(t *testing.T) {
|
||||||
// //if nodes/chunks have been provided via commandline,
|
t.Skip("Test no longer work for XDC")
|
||||||
// //run the tests with these values
|
//if nodes/chunks have been provided via commandline,
|
||||||
// if *nodes != 0 && *chunks != 0 {
|
//run the tests with these values
|
||||||
// err := runRetrievalTest(t, *chunks, *nodes)
|
if *nodes != 0 && *chunks != 0 {
|
||||||
// if err != nil {
|
err := runRetrievalTest(t, *chunks, *nodes)
|
||||||
// t.Fatal(err)
|
if err != nil {
|
||||||
// }
|
t.Fatal(err)
|
||||||
// } else {
|
}
|
||||||
// var nodeCnt []int
|
} else {
|
||||||
// var chnkCnt []int
|
var nodeCnt []int
|
||||||
// //if the `longrunning` flag has been provided
|
var chnkCnt []int
|
||||||
// //run more test combinations
|
//if the `longrunning` flag has been provided
|
||||||
// if *longrunning {
|
//run more test combinations
|
||||||
// nodeCnt = []int{16, 32, 128}
|
if *longrunning {
|
||||||
// chnkCnt = []int{4, 32, 256}
|
nodeCnt = []int{16, 32, 128}
|
||||||
// } else {
|
chnkCnt = []int{4, 32, 256}
|
||||||
// //default test
|
} else {
|
||||||
// nodeCnt = []int{16}
|
//default test
|
||||||
// chnkCnt = []int{32}
|
nodeCnt = []int{16}
|
||||||
// }
|
chnkCnt = []int{32}
|
||||||
// for _, n := range nodeCnt {
|
}
|
||||||
// for _, c := range chnkCnt {
|
for _, n := range nodeCnt {
|
||||||
// t.Run(fmt.Sprintf("TestRetrieval_%d_%d", n, c), func(t *testing.T) {
|
for _, c := range chnkCnt {
|
||||||
// err := runRetrievalTest(t, c, n)
|
t.Run(fmt.Sprintf("TestRetrieval_%d_%d", n, c), func(t *testing.T) {
|
||||||
// if err != nil {
|
err := runRetrievalTest(t, c, n)
|
||||||
// t.Fatal(err)
|
if err != nil {
|
||||||
// }
|
t.Fatal(err)
|
||||||
// })
|
}
|
||||||
// }
|
})
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var retrievalSimServiceMap = map[string]simulation.ServiceFunc{
|
var retrievalSimServiceMap = map[string]simulation.ServiceFunc{
|
||||||
"streamer": func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) {
|
"streamer": func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) {
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -74,45 +76,46 @@ func dummyRequestFromPeers(_ context.Context, req *network.Request) (*enode.ID,
|
||||||
//to the pivot node, and we check that nodes get the chunks
|
//to the pivot node, and we check that nodes get the chunks
|
||||||
//they are expected to store based on the syncing protocol.
|
//they are expected to store based on the syncing protocol.
|
||||||
//Number of chunks and nodes can be provided via commandline too.
|
//Number of chunks and nodes can be provided via commandline too.
|
||||||
// func TestSyncingViaGlobalSync(t *testing.T) {
|
func TestSyncingViaGlobalSync(t *testing.T) {
|
||||||
// if runtime.GOOS == "darwin" && os.Getenv("TRAVIS") == "true" {
|
t.Skip("Flaky test")
|
||||||
// t.Skip("Flaky on mac on travis")
|
if runtime.GOOS == "darwin" && os.Getenv("TRAVIS") == "true" {
|
||||||
// }
|
t.Skip("Flaky on mac on travis")
|
||||||
// //if nodes/chunks have been provided via commandline,
|
}
|
||||||
// //run the tests with these values
|
//if nodes/chunks have been provided via commandline,
|
||||||
// if *nodes != 0 && *chunks != 0 {
|
//run the tests with these values
|
||||||
// log.Info(fmt.Sprintf("Running test with %d chunks and %d nodes...", *chunks, *nodes))
|
if *nodes != 0 && *chunks != 0 {
|
||||||
// testSyncingViaGlobalSync(t, *chunks, *nodes)
|
log.Info(fmt.Sprintf("Running test with %d chunks and %d nodes...", *chunks, *nodes))
|
||||||
// } else {
|
testSyncingViaGlobalSync(t, *chunks, *nodes)
|
||||||
// var nodeCnt []int
|
} else {
|
||||||
// var chnkCnt []int
|
var nodeCnt []int
|
||||||
// //if the `longrunning` flag has been provided
|
var chnkCnt []int
|
||||||
// //run more test combinations
|
//if the `longrunning` flag has been provided
|
||||||
// if *longrunning {
|
//run more test combinations
|
||||||
// chnkCnt = []int{1, 8, 32, 256, 1024}
|
if *longrunning {
|
||||||
// nodeCnt = []int{16, 32, 64, 128, 256}
|
chnkCnt = []int{1, 8, 32, 256, 1024}
|
||||||
// } else if raceTest {
|
nodeCnt = []int{16, 32, 64, 128, 256}
|
||||||
// // TestSyncingViaGlobalSync allocates a lot of memory
|
} else if raceTest {
|
||||||
// // with race detector. By reducing the number of chunks
|
// TestSyncingViaGlobalSync allocates a lot of memory
|
||||||
// // and nodes, memory consumption is lower and data races
|
// with race detector. By reducing the number of chunks
|
||||||
// // are still checked, while correctness of syncing is
|
// and nodes, memory consumption is lower and data races
|
||||||
// // tested with more chunks and nodes in regular (!race)
|
// are still checked, while correctness of syncing is
|
||||||
// // tests.
|
// tested with more chunks and nodes in regular (!race)
|
||||||
// chnkCnt = []int{4}
|
// tests.
|
||||||
// nodeCnt = []int{16}
|
chnkCnt = []int{4}
|
||||||
// } else {
|
nodeCnt = []int{16}
|
||||||
// //default test
|
} else {
|
||||||
// chnkCnt = []int{4, 32}
|
//default test
|
||||||
// nodeCnt = []int{32, 16}
|
chnkCnt = []int{4, 32}
|
||||||
// }
|
nodeCnt = []int{32, 16}
|
||||||
// for _, chnk := range chnkCnt {
|
}
|
||||||
// for _, n := range nodeCnt {
|
for _, chnk := range chnkCnt {
|
||||||
// log.Info(fmt.Sprintf("Long running test with %d chunks and %d nodes...", chnk, n))
|
for _, n := range nodeCnt {
|
||||||
// testSyncingViaGlobalSync(t, chnk, n)
|
log.Info(fmt.Sprintf("Long running test with %d chunks and %d nodes...", chnk, n))
|
||||||
// }
|
testSyncingViaGlobalSync(t, chnk, n)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var simServiceMap = map[string]simulation.ServiceFunc{
|
var simServiceMap = map[string]simulation.ServiceFunc{
|
||||||
"streamer": func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) {
|
"streamer": func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) {
|
||||||
|
|
|
||||||
|
|
@ -22,15 +22,20 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||||
|
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
|
||||||
p2ptest "github.com/ethereum/go-ethereum/p2p/testing"
|
p2ptest "github.com/ethereum/go-ethereum/p2p/testing"
|
||||||
"github.com/ethereum/go-ethereum/swarm/network"
|
"github.com/ethereum/go-ethereum/swarm/network"
|
||||||
|
"github.com/ethereum/go-ethereum/swarm/network/simulation"
|
||||||
|
"github.com/ethereum/go-ethereum/swarm/state"
|
||||||
"golang.org/x/crypto/sha3"
|
"golang.org/x/crypto/sha3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -1171,162 +1176,163 @@ TestGetSubscriptionsRPC sets up a simulation network of `nodeCount` nodes,
|
||||||
starts the simulation, waits for SyncUpdateDelay in order to kick off
|
starts the simulation, waits for SyncUpdateDelay in order to kick off
|
||||||
stream registration, then tests that there are subscriptions.
|
stream registration, then tests that there are subscriptions.
|
||||||
*/
|
*/
|
||||||
// func TestGetSubscriptionsRPC(t *testing.T) {
|
func TestGetSubscriptionsRPC(t *testing.T) {
|
||||||
|
t.Skip("Test no longer work for XDC")
|
||||||
|
|
||||||
// // arbitrarily set to 4
|
// arbitrarily set to 4
|
||||||
// nodeCount := 4
|
nodeCount := 4
|
||||||
// // run with more nodes if `longrunning` flag is set
|
// run with more nodes if `longrunning` flag is set
|
||||||
// if *longrunning {
|
if *longrunning {
|
||||||
// nodeCount = 64
|
nodeCount = 64
|
||||||
// }
|
}
|
||||||
// // set the syncUpdateDelay for sync registrations to start
|
// set the syncUpdateDelay for sync registrations to start
|
||||||
// syncUpdateDelay := 200 * time.Millisecond
|
syncUpdateDelay := 200 * time.Millisecond
|
||||||
// // holds the msg code for SubscribeMsg
|
// holds the msg code for SubscribeMsg
|
||||||
// var subscribeMsgCode uint64
|
var subscribeMsgCode uint64
|
||||||
// var ok bool
|
var ok bool
|
||||||
// var expectedMsgCount counter
|
var expectedMsgCount counter
|
||||||
|
|
||||||
// // this channel signalizes that the expected amount of subscriptiosn is done
|
// this channel signalizes that the expected amount of subscriptiosn is done
|
||||||
// allSubscriptionsDone := make(chan struct{})
|
allSubscriptionsDone := make(chan struct{})
|
||||||
// // after the test, we need to reset the subscriptionFunc to the default
|
// after the test, we need to reset the subscriptionFunc to the default
|
||||||
// defer func() { subscriptionFunc = doRequestSubscription }()
|
defer func() { subscriptionFunc = doRequestSubscription }()
|
||||||
|
|
||||||
// // we use this subscriptionFunc for this test: just increases count and calls the actual subscription
|
// we use this subscriptionFunc for this test: just increases count and calls the actual subscription
|
||||||
// subscriptionFunc = func(r *Registry, p *network.Peer, bin uint8, subs map[enode.ID]map[Stream]struct{}) bool {
|
subscriptionFunc = func(r *Registry, p *network.Peer, bin uint8, subs map[enode.ID]map[Stream]struct{}) bool {
|
||||||
// expectedMsgCount.inc()
|
expectedMsgCount.inc()
|
||||||
// doRequestSubscription(r, p, bin, subs)
|
doRequestSubscription(r, p, bin, subs)
|
||||||
// return true
|
return true
|
||||||
// }
|
}
|
||||||
// // create a standard sim
|
// create a standard sim
|
||||||
// sim := simulation.New(map[string]simulation.ServiceFunc{
|
sim := simulation.New(map[string]simulation.ServiceFunc{
|
||||||
// "streamer": func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) {
|
"streamer": func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) {
|
||||||
// addr, netStore, delivery, clean, err := newNetStoreAndDeliveryWithRequestFunc(ctx, bucket, dummyRequestFromPeers)
|
addr, netStore, delivery, clean, err := newNetStoreAndDeliveryWithRequestFunc(ctx, bucket, dummyRequestFromPeers)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return nil, nil, err
|
return nil, nil, err
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // configure so that sync registrations actually happen
|
// configure so that sync registrations actually happen
|
||||||
// r := NewRegistry(addr.ID(), delivery, netStore, state.NewInmemoryStore(), &RegistryOptions{
|
r := NewRegistry(addr.ID(), delivery, netStore, state.NewInmemoryStore(), &RegistryOptions{
|
||||||
// Retrieval: RetrievalEnabled,
|
Retrieval: RetrievalEnabled,
|
||||||
// Syncing: SyncingAutoSubscribe, //enable sync registrations
|
Syncing: SyncingAutoSubscribe, //enable sync registrations
|
||||||
// SyncUpdateDelay: syncUpdateDelay,
|
SyncUpdateDelay: syncUpdateDelay,
|
||||||
// }, nil)
|
}, nil)
|
||||||
|
|
||||||
// // get the SubscribeMsg code
|
// get the SubscribeMsg code
|
||||||
// subscribeMsgCode, ok = r.GetSpec().GetCode(SubscribeMsg{})
|
subscribeMsgCode, ok = r.GetSpec().GetCode(SubscribeMsg{})
|
||||||
// if !ok {
|
if !ok {
|
||||||
// t.Fatal("Message code for SubscribeMsg not found")
|
t.Fatal("Message code for SubscribeMsg not found")
|
||||||
// }
|
}
|
||||||
|
|
||||||
// cleanup = func() {
|
cleanup = func() {
|
||||||
// r.Close()
|
r.Close()
|
||||||
// clean()
|
clean()
|
||||||
// }
|
}
|
||||||
|
|
||||||
// return r, cleanup, nil
|
return r, cleanup, nil
|
||||||
// },
|
},
|
||||||
// })
|
})
|
||||||
// defer sim.Close()
|
defer sim.Close()
|
||||||
|
|
||||||
// ctx, cancelSimRun := context.WithTimeout(context.Background(), 1*time.Minute)
|
ctx, cancelSimRun := context.WithTimeout(context.Background(), 1*time.Minute)
|
||||||
// defer cancelSimRun()
|
defer cancelSimRun()
|
||||||
|
|
||||||
// // upload a snapshot
|
// upload a snapshot
|
||||||
// err := sim.UploadSnapshot(fmt.Sprintf("testing/snapshot_%d.json", nodeCount))
|
err := sim.UploadSnapshot(fmt.Sprintf("testing/snapshot_%d.json", nodeCount))
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// t.Fatal(err)
|
t.Fatal(err)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // setup the filter for SubscribeMsg
|
// setup the filter for SubscribeMsg
|
||||||
// msgs := sim.PeerEvents(
|
msgs := sim.PeerEvents(
|
||||||
// context.Background(),
|
context.Background(),
|
||||||
// sim.NodeIDs(),
|
sim.NodeIDs(),
|
||||||
// simulation.NewPeerEventsFilter().ReceivedMessages().Protocol("stream").MsgCode(subscribeMsgCode),
|
simulation.NewPeerEventsFilter().ReceivedMessages().Protocol("stream").MsgCode(subscribeMsgCode),
|
||||||
// )
|
)
|
||||||
|
|
||||||
// // strategy: listen to all SubscribeMsg events; after every event we wait
|
// strategy: listen to all SubscribeMsg events; after every event we wait
|
||||||
// // if after `waitDuration` no more messages are being received, we assume the
|
// if after `waitDuration` no more messages are being received, we assume the
|
||||||
// // subscription phase has terminated!
|
// subscription phase has terminated!
|
||||||
|
|
||||||
// // the loop in this go routine will either wait for new message events
|
// the loop in this go routine will either wait for new message events
|
||||||
// // or times out after 1 second, which signals that we are not receiving
|
// or times out after 1 second, which signals that we are not receiving
|
||||||
// // any new subscriptions any more
|
// any new subscriptions any more
|
||||||
// go func() {
|
go func() {
|
||||||
// //for long running sims, waiting 1 sec will not be enough
|
//for long running sims, waiting 1 sec will not be enough
|
||||||
// waitDuration := time.Duration(nodeCount/16) * time.Second
|
waitDuration := time.Duration(nodeCount/16) * time.Second
|
||||||
// for {
|
for {
|
||||||
// select {
|
select {
|
||||||
// case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
// return
|
return
|
||||||
// case m := <-msgs: // just reset the loop
|
case m := <-msgs: // just reset the loop
|
||||||
// if m.Error != nil {
|
if m.Error != nil {
|
||||||
// log.Error("stream message", "err", m.Error)
|
log.Error("stream message", "err", m.Error)
|
||||||
// continue
|
continue
|
||||||
// }
|
}
|
||||||
// log.Trace("stream message", "node", m.NodeID, "peer", m.PeerID)
|
log.Trace("stream message", "node", m.NodeID, "peer", m.PeerID)
|
||||||
// case <-time.After(waitDuration):
|
case <-time.After(waitDuration):
|
||||||
// // one second passed, don't assume more subscriptions
|
// one second passed, don't assume more subscriptions
|
||||||
// allSubscriptionsDone <- struct{}{}
|
allSubscriptionsDone <- struct{}{}
|
||||||
// log.Info("All subscriptions received")
|
log.Info("All subscriptions received")
|
||||||
// return
|
return
|
||||||
|
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }()
|
}()
|
||||||
|
|
||||||
// //run the simulation
|
//run the simulation
|
||||||
// result := sim.Run(ctx, func(ctx context.Context, sim *simulation.Simulation) error {
|
result := sim.Run(ctx, func(ctx context.Context, sim *simulation.Simulation) error {
|
||||||
// log.Info("Simulation running")
|
log.Info("Simulation running")
|
||||||
// nodes := sim.Net.Nodes
|
nodes := sim.Net.Nodes
|
||||||
|
|
||||||
// //wait until all subscriptions are done
|
//wait until all subscriptions are done
|
||||||
// select {
|
select {
|
||||||
// case <-allSubscriptionsDone:
|
case <-allSubscriptionsDone:
|
||||||
// case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
// return errors.New("Context timed out")
|
return errors.New("Context timed out")
|
||||||
// }
|
}
|
||||||
|
|
||||||
// log.Debug("Expected message count: ", "expectedMsgCount", expectedMsgCount.count())
|
log.Debug("Expected message count: ", "expectedMsgCount", expectedMsgCount.count())
|
||||||
// //now iterate again, this time we call each node via RPC to get its subscriptions
|
//now iterate again, this time we call each node via RPC to get its subscriptions
|
||||||
// realCount := 0
|
realCount := 0
|
||||||
// for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
// //create rpc client
|
//create rpc client
|
||||||
// client, err := node.Client()
|
client, err := node.Client()
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return fmt.Errorf("create node 1 rpc client fail: %v", err)
|
return fmt.Errorf("create node 1 rpc client fail: %v", err)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// //ask it for subscriptions
|
//ask it for subscriptions
|
||||||
// pstreams := make(map[string][]string)
|
pstreams := make(map[string][]string)
|
||||||
// err = client.Call(&pstreams, "stream_getPeerSubscriptions")
|
err = client.Call(&pstreams, "stream_getPeerSubscriptions")
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return fmt.Errorf("client call stream_getPeerSubscriptions: %v", err)
|
return fmt.Errorf("client call stream_getPeerSubscriptions: %v", err)
|
||||||
// }
|
}
|
||||||
// //length of the subscriptions can not be smaller than number of peers
|
//length of the subscriptions can not be smaller than number of peers
|
||||||
// log.Debug("node subscriptions", "node", node.String())
|
log.Debug("node subscriptions", "node", node.String())
|
||||||
// for p, ps := range pstreams {
|
for p, ps := range pstreams {
|
||||||
// log.Debug("... with", "peer", p)
|
log.Debug("... with", "peer", p)
|
||||||
// for _, s := range ps {
|
for _, s := range ps {
|
||||||
// log.Debug(".......", "stream", s)
|
log.Debug(".......", "stream", s)
|
||||||
// // each node also has subscriptions to RETRIEVE_REQUEST streams,
|
// each node also has subscriptions to RETRIEVE_REQUEST streams,
|
||||||
// // we need to ignore those, we are only counting SYNC streams
|
// we need to ignore those, we are only counting SYNC streams
|
||||||
// if !strings.HasPrefix(s, "RETRIEVE_REQUEST") {
|
if !strings.HasPrefix(s, "RETRIEVE_REQUEST") {
|
||||||
// realCount++
|
realCount++
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// // every node is mutually subscribed to each other, so the actual count is half of it
|
// every node is mutually subscribed to each other, so the actual count is half of it
|
||||||
// emc := expectedMsgCount.count()
|
emc := expectedMsgCount.count()
|
||||||
// if realCount/2 != emc {
|
if realCount/2 != emc {
|
||||||
// return fmt.Errorf("Real subscriptions and expected amount don't match; real: %d, expected: %d", realCount/2, emc)
|
return fmt.Errorf("Real subscriptions and expected amount don't match; real: %d, expected: %d", realCount/2, emc)
|
||||||
// }
|
}
|
||||||
// return nil
|
return nil
|
||||||
// })
|
})
|
||||||
// if result.Error != nil {
|
if result.Error != nil {
|
||||||
// t.Fatal(result.Error)
|
t.Fatal(result.Error)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// counter is used to concurrently increment
|
// counter is used to concurrently increment
|
||||||
// and read an integer value.
|
// and read an integer value.
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package feed
|
package feed
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
func getTestQuery() *Query {
|
func getTestQuery() *Query {
|
||||||
id := getTestID()
|
id := getTestID()
|
||||||
return &Query{
|
return &Query{
|
||||||
|
|
@ -25,10 +27,11 @@ func getTestQuery() *Query {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// func TestQueryValues(t *testing.T) {
|
func TestQueryValues(t *testing.T) {
|
||||||
// var expected = KV{"hint.level": "25", "hint.time": "1000", "time": "5000", "topic": "0x776f726c64206e657773207265706f72742c20657665727920686f7572000000", "user": "0x876A8936A7Cd0b79Ef0735AD0896c1AFe278781c"}
|
t.Skip("Test no longer work for XDC")
|
||||||
|
var expected = KV{"hint.level": "25", "hint.time": "1000", "time": "5000", "topic": "0x776f726c64206e657773207265706f72742c20657665727920686f7572000000", "user": "0x876A8936A7Cd0b79Ef0735AD0896c1AFe278781c"}
|
||||||
|
|
||||||
// query := getTestQuery()
|
query := getTestQuery()
|
||||||
// testValueSerializer(t, query, expected)
|
testValueSerializer(t, query, expected)
|
||||||
|
|
||||||
// }
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,25 @@ var sharedKey = []byte("some arbitrary data here")
|
||||||
var sharedTopic TopicType = TopicType{0xF, 0x1, 0x2, 0}
|
var sharedTopic TopicType = TopicType{0xF, 0x1, 0x2, 0}
|
||||||
var expectedMessage = []byte("per rectum ad astra")
|
var expectedMessage = []byte("per rectum ad astra")
|
||||||
|
|
||||||
|
// This test does the following:
|
||||||
|
// 1. creates a chain of whisper nodes,
|
||||||
|
// 2. installs the filters with shared (predefined) parameters,
|
||||||
|
// 3. each node sends a number of random (undecryptable) messages,
|
||||||
|
// 4. first node sends one expected (decryptable) message,
|
||||||
|
// 5. checks if each node have received and decrypted exactly one message.
|
||||||
|
func TestSimulation(t *testing.T) {
|
||||||
|
t.Skip("Test no longer work for XDC")
|
||||||
|
initialize(t)
|
||||||
|
|
||||||
|
for i := 0; i < NumNodes; i++ {
|
||||||
|
sendMsg(t, false, i)
|
||||||
|
}
|
||||||
|
|
||||||
|
sendMsg(t, true, 0)
|
||||||
|
checkPropagation(t)
|
||||||
|
stopServers()
|
||||||
|
}
|
||||||
|
|
||||||
func initialize(t *testing.T) {
|
func initialize(t *testing.T) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue