Skip to content

Instantly share code, notes, and snippets.

@santicomp2014
Created March 4, 2020 15:45
Show Gist options
  • Save santicomp2014/b8262192a7d2583dd6f96daa7e8fefa0 to your computer and use it in GitHub Desktop.
Save santicomp2014/b8262192a7d2583dd6f96daa7e8fefa0 to your computer and use it in GitHub Desktop.
Swap TestSwapConfigCmdLineOverrides
func TestSwapConfigCmdLineOverrides(t *testing.T) {
dir, err := ioutil.TempDir("", "swapflagtest")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
//testBackend := newTestBackend(t)
//defer testBackend.Close()
// // a simple rpc endpoint for testing dialing
// ipcEndpoint := path.Join(dir, "bzzd.ipc")
// // windows namedpipes are not on filesystem but on NPFS
// if runtime.GOOS == "windows" {
// b := make([]byte, 8)
// rand.Read(b)
// ipcEndpoint = `\\.\pipe\TestSwarm-` + hex.EncodeToString(b)
// }
// _, server, err := rpc.StartIPCEndpoint(ipcEndpoint, nil)
// if err != nil {
// t.Error(err)
// }
// defer server.Stop()
conf, account := getTestAccount(t, dir)
node := &testNode{Dir: dir}
swapTestLogPath := path.Join(dir, "swaptest")
swapTestLogLevel := 3
// assign ports
httpPort, err := assignTCPPort()
if err != nil {
t.Fatal(err)
}
flags := []string{
fmt.Sprintf("--%s", SwarmNetworkIdFlag.Name), "5",
fmt.Sprintf("--%s", SwarmPortFlag.Name), httpPort,
fmt.Sprintf("--%s", utils.ListenPortFlag.Name), "0",
fmt.Sprintf("--%s", SwarmNoSyncFlag.Name),
fmt.Sprintf("--%s", CorsStringFlag.Name), "*",
fmt.Sprintf("--%s", SwarmAccountFlag.Name), account.Address.String(),
fmt.Sprintf("--%s", EnsAPIFlag.Name), "",
fmt.Sprintf("--%s", utils.DataDirFlag.Name), dir,
fmt.Sprintf("--%s", utils.IPCPathFlag.Name), conf.IPCPath,
"--verbosity", fmt.Sprintf("%d", *testutil.Loglevel),
fmt.Sprintf("--%s", SwarmSwapEnabledFlag.Name),
fmt.Sprintf("--%s", SwarmSwapBackendURLFlag.Name), conf.IPCPath,
fmt.Sprintf("--%s", utils.WSEnabledFlag.Name),
fmt.Sprintf("--%s", utils.WSApiFlag.Name), "admin,accounting,bzz,swap",
fmt.Sprintf("--%s", utils.WSListenAddrFlag.Name), "0.0.0.0",
fmt.Sprintf("--%s", utils.WSAllowedOriginsFlag.Name), "\\*",
fmt.Sprintf("--%s", SwarmSwapPaymentThresholdFlag.Name), strconv.FormatUint(swap.DefaultPaymentThreshold+1, 10),
fmt.Sprintf("--%s", SwarmSwapDisconnectThresholdFlag.Name), strconv.FormatUint(swap.DefaultDisconnectThreshold+1, 10),
fmt.Sprintf("--%s", SwarmSwapLogPathFlag.Name), swapTestLogPath,
fmt.Sprintf("--%s", SwarmSwapLogLevelFlag.Name), strconv.FormatInt(int64(swapTestLogLevel), 10),
fmt.Sprintf("--%s", SwarmEnablePinningFlag.Name),
}
node.Cmd = runSwarm(t, flags...)
node.Cmd.InputLine(testPassphrase)
defer func() {
if t.Failed() {
node.Shutdown()
}
}()
// wait for the node to start
for start := time.Now(); time.Since(start) < 10*time.Second; time.Sleep(50 * time.Millisecond) {
node.Client, err = rpc.Dial(conf.IPCEndpoint())
if err == nil {
break
}
}
if node.Client == nil {
t.Fatal(err)
}
// load info
var info swarm.Info
if err := node.Client.Call(&info, "bzz_info"); err != nil {
t.Fatal(err)
}
if info.Port != httpPort {
t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port)
}
if info.NetworkID != 42 {
t.Fatalf("Expected network ID to be %d, got %d", 42, info.NetworkID)
}
if info.SyncEnabled {
t.Fatal("Expected Sync to be disabled, but is true")
}
if info.PushSyncEnabled {
t.Fatal("Expected Push Sync to be disabled, but is true")
}
if info.Cors != "*" {
t.Fatalf("Expected Cors flag to be set to %s, got %s", "*", info.Cors)
}
if info.SwapPaymentThreshold != (swap.DefaultPaymentThreshold + 1) {
t.Fatalf("Expected SwapPaymentThreshold to be %d, but got %d", swap.DefaultPaymentThreshold+1, info.SwapPaymentThreshold)
}
if info.SwapDisconnectThreshold != (swap.DefaultDisconnectThreshold + 1) {
t.Fatalf("Expected SwapDisconnectThreshold to be %d, but got %d", swap.DefaultDisconnectThreshold+1, info.SwapDisconnectThreshold)
}
if info.SwapLogPath != swapTestLogPath {
t.Fatalf("Expected SwapLogPath to be %s, but got %s", swapTestLogPath, info.SwapLogPath)
}
if info.SwapLogLevel != swapTestLogLevel {
t.Fatalf("Expected SwapLogLevel to be %d, but got %d", swapTestLogLevel, info.SwapLogLevel)
}
if info.EnablePinning != true {
t.Fatalf("expected EnablePinning to be %t but got %t", true, info.EnablePinning)
}
node.Shutdown()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment