* simv2: wip * simulation: exec adapter start/stop * simulation: add node status to exec adapter * simulation: initial simulation code * simulation: exec adapter, configure path to executable * simulation: initial docker adapter * simulation: wip kubernetes adapter * simulation: kubernetes adapter proxy * simulation: implement GetAll/StartAll/StopAll * simulation: kuberentes adapter - set env vars and resource limits * simulation: discovery test * simulation: remove port definitions within docker adapter * simulation: simplify wait for healthy loop * simulation: get nat ip addr from interface * simulation: pull docker images automatically * simulation: NodeStatus -> NodeInfo * simulation: move discovery test to example dir * simulation: example snapshot usage * simulation: add goclient specific simulation * simulation: add peer connections to snapshot * simulation: close rpc client * simulation: don't export kubernetes proxy server * simulation: merge simulation code * simulation: don't export nodemap * simulation: rename SimulationSnapshot -> Snapshot * simulation: linting fixes * simulation: add k8s available helper func * simulation: vendor * simulation: fix 'no non-test Go files' when building * simulation: remove errors from interface methods where non were returned * simulation: run getHealthInfo check in parallel
95 lines
1.8 KiB
Go
95 lines
1.8 KiB
Go
package simulation
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
|
)
|
|
|
|
func TestExecAdapter(t *testing.T) {
|
|
|
|
execPath := "../build/bin/swarm"
|
|
|
|
// Skip test if binary doesn't exist
|
|
if _, err := os.Stat(execPath); err != nil {
|
|
if os.IsNotExist(err) {
|
|
t.Skip("swarm binary not found. build it before running the test")
|
|
}
|
|
}
|
|
|
|
tmpdir, err := ioutil.TempDir("", "test-adapter-exec")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer os.RemoveAll(tmpdir)
|
|
|
|
adapter, err := NewExecAdapter(ExecAdapterConfig{
|
|
ExecutablePath: execPath,
|
|
BaseDataDirectory: tmpdir,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("could not create exec adapter: %v", err)
|
|
}
|
|
|
|
bzzkey, err := crypto.GenerateKey()
|
|
if err != nil {
|
|
t.Fatalf("could not generate key: %v", err)
|
|
}
|
|
bzzkeyhex := hex.EncodeToString(crypto.FromECDSA(bzzkey))
|
|
|
|
nodekey, err := crypto.GenerateKey()
|
|
if err != nil {
|
|
t.Fatalf("could not generate key: %v", err)
|
|
}
|
|
nodekeyhex := hex.EncodeToString(crypto.FromECDSA(nodekey))
|
|
|
|
args := []string{
|
|
"--bootnodes", "",
|
|
"--bzzkeyhex", bzzkeyhex,
|
|
"--nodekeyhex", nodekeyhex,
|
|
"--bzznetworkid", "499",
|
|
}
|
|
nodeconfig := NodeConfig{
|
|
ID: "node1",
|
|
Args: args,
|
|
Stdout: os.Stdout,
|
|
Stderr: os.Stderr,
|
|
}
|
|
node := adapter.NewNode(nodeconfig)
|
|
info := node.Info()
|
|
if info.ID != "node1" {
|
|
t.Fatal("node id is different")
|
|
}
|
|
|
|
err = node.Start()
|
|
if err != nil {
|
|
t.Fatalf("node did not start: %v", err)
|
|
}
|
|
|
|
infoA := node.Info()
|
|
|
|
err = node.Stop()
|
|
if err != nil {
|
|
t.Fatalf("node didn't stop: %v", err)
|
|
}
|
|
|
|
err = node.Start()
|
|
if err != nil {
|
|
t.Fatalf("node didn't start again: %v", err)
|
|
}
|
|
|
|
infoB := node.Info()
|
|
|
|
if infoA.BzzAddr != infoB.BzzAddr {
|
|
t.Errorf("bzzaddr should be the same: %s - %s", infoA.Enode, infoB.Enode)
|
|
}
|
|
|
|
err = node.Stop()
|
|
if err != nil {
|
|
t.Fatalf("node didn't stop: %v", err)
|
|
}
|
|
}
|