updated CONSOLECMD_TEST.GO

This commit is contained in:
AnilChinchawale 2018-05-24 15:13:39 +05:30
parent d1111a0be2
commit bf041d1d7b

View file

@ -40,25 +40,25 @@ const (
func TestConsoleWelcome(t *testing.T) { func TestConsoleWelcome(t *testing.T) {
coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182" coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
// Start a geth console, make sure it's cleaned up and terminate the console // Start a XDC console, make sure it's cleaned up and terminate the console
geth := runGeth(t, XDC := runGeth(t,
"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none", "--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none",
"--etherbase", coinbase, "--shh", "--etherbase", coinbase, "--shh",
"console") "console")
// Gather all the infos the welcome message needs to contain // Gather all the infos the welcome message needs to contain
geth.SetTemplateFunc("goos", func() string { return runtime.GOOS }) XDC.SetTemplateFunc("goos", func() string { return runtime.GOOS })
geth.SetTemplateFunc("goarch", func() string { return runtime.GOARCH }) XDC.SetTemplateFunc("goarch", func() string { return runtime.GOARCH })
geth.SetTemplateFunc("gover", runtime.Version) XDC.SetTemplateFunc("gover", runtime.Version)
geth.SetTemplateFunc("gethver", func() string { return params.Version }) XDC.SetTemplateFunc("gethver", func() string { return params.Version })
geth.SetTemplateFunc("niltime", func() string { return time.Unix(0, 0).Format(time.RFC1123) }) XDC.SetTemplateFunc("niltime", func() string { return time.Unix(0, 0).Format(time.RFC1123) })
geth.SetTemplateFunc("apis", func() string { return ipcAPIs }) XDC.SetTemplateFunc("apis", func() string { return ipcAPIs })
// Verify the actual welcome message to the required template // Verify the actual welcome message to the required template
geth.Expect(` XDC.Expect(`
Welcome to the Geth JavaScript console! Welcome to the XDC JavaScript console!
instance: Geth/v{{gethver}}/{{goos}}-{{goarch}}/{{gover}} instance: XDC/v{{XDCver}}/{{goos}}-{{goarch}}/{{gover}}
coinbase: {{.Etherbase}} coinbase: {{.Etherbase}}
at block: 0 ({{niltime}}) at block: 0 ({{niltime}})
datadir: {{.Datadir}} datadir: {{.Datadir}}
@ -66,7 +66,7 @@ at block: 0 ({{niltime}})
> {{.InputLine "exit"}} > {{.InputLine "exit"}}
`) `)
geth.ExpectExit() XDC.ExpectExit()
} }
// Tests that a console can be attached to a running node via various means. // Tests that a console can be attached to a running node via various means.
@ -75,56 +75,56 @@ func TestIPCAttachWelcome(t *testing.T) {
coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182" coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
var ipc string var ipc string
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
ipc = `\\.\pipe\geth` + strconv.Itoa(trulyRandInt(100000, 999999)) ipc = `\\.\pipe\XDC` + strconv.Itoa(trulyRandInt(100000, 999999))
} else { } else {
ws := tmpdir(t) ws := tmpdir(t)
defer os.RemoveAll(ws) defer os.RemoveAll(ws)
ipc = filepath.Join(ws, "geth.ipc") ipc = filepath.Join(ws, "XDC.ipc")
} }
// Note: we need --shh because testAttachWelcome checks for default // Note: we need --shh because testAttachWelcome checks for default
// list of ipc modules and shh is included there. // list of ipc modules and shh is included there.
geth := runGeth(t, XDC := runGeth(t,
"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none", "--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none",
"--etherbase", coinbase, "--shh", "--ipcpath", ipc) "--etherbase", coinbase, "--shh", "--ipcpath", ipc)
time.Sleep(2 * time.Second) // Simple way to wait for the RPC endpoint to open time.Sleep(2 * time.Second) // Simple way to wait for the RPC endpoint to open
testAttachWelcome(t, geth, "ipc:"+ipc, ipcAPIs) testAttachWelcome(t, XDC, "ipc:"+ipc, ipcAPIs)
geth.Interrupt() XDC.Interrupt()
geth.ExpectExit() XDC.ExpectExit()
} }
func TestHTTPAttachWelcome(t *testing.T) { func TestHTTPAttachWelcome(t *testing.T) {
coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182" coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
port := strconv.Itoa(trulyRandInt(1024, 65536)) // Yeah, sometimes this will fail, sorry :P port := strconv.Itoa(trulyRandInt(1024, 65536)) // Yeah, sometimes this will fail, sorry :P
geth := runGeth(t, XDC := runGeth(t,
"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none", "--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none",
"--etherbase", coinbase, "--rpc", "--rpcport", port) "--etherbase", coinbase, "--rpc", "--rpcport", port)
time.Sleep(2 * time.Second) // Simple way to wait for the RPC endpoint to open time.Sleep(2 * time.Second) // Simple way to wait for the RPC endpoint to open
testAttachWelcome(t, geth, "http://localhost:"+port, httpAPIs) testAttachWelcome(t, XDC, "http://localhost:"+port, httpAPIs)
geth.Interrupt() XDC.Interrupt()
geth.ExpectExit() XDC.ExpectExit()
} }
func TestWSAttachWelcome(t *testing.T) { func TestWSAttachWelcome(t *testing.T) {
coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182" coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
port := strconv.Itoa(trulyRandInt(1024, 65536)) // Yeah, sometimes this will fail, sorry :P port := strconv.Itoa(trulyRandInt(1024, 65536)) // Yeah, sometimes this will fail, sorry :P
geth := runGeth(t, XDC := runGeth(t,
"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none", "--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none",
"--etherbase", coinbase, "--ws", "--wsport", port) "--etherbase", coinbase, "--ws", "--wsport", port)
time.Sleep(2 * time.Second) // Simple way to wait for the RPC endpoint to open time.Sleep(2 * time.Second) // Simple way to wait for the RPC endpoint to open
testAttachWelcome(t, geth, "ws://localhost:"+port, httpAPIs) testAttachWelcome(t, XDC, "ws://localhost:"+port, httpAPIs)
geth.Interrupt() XDC.Interrupt()
geth.ExpectExit() XDC.ExpectExit()
} }
func testAttachWelcome(t *testing.T, geth *testgeth, endpoint, apis string) { func testAttachWelcome(t *testing.T, XDC *testXDC, endpoint, apis string) {
// Attach to a running geth note and terminate immediately // Attach to a running XDC note and terminate 1immediately
attach := runGeth(t, "attach", endpoint) attach := runGeth(t, "attach", endpoint)
defer attach.ExpectExit() defer attach.ExpectExit()
attach.CloseStdin() attach.CloseStdin()
@ -133,20 +133,20 @@ func testAttachWelcome(t *testing.T, geth *testgeth, endpoint, apis string) {
attach.SetTemplateFunc("goos", func() string { return runtime.GOOS }) attach.SetTemplateFunc("goos", func() string { return runtime.GOOS })
attach.SetTemplateFunc("goarch", func() string { return runtime.GOARCH }) attach.SetTemplateFunc("goarch", func() string { return runtime.GOARCH })
attach.SetTemplateFunc("gover", runtime.Version) attach.SetTemplateFunc("gover", runtime.Version)
attach.SetTemplateFunc("gethver", func() string { return params.Version }) attach.SetTemplateFunc("XDCver", func() string { return params.Version })
attach.SetTemplateFunc("etherbase", func() string { return geth.Etherbase }) attach.SetTemplateFunc("etherbase", func() string { return XDC.Etherbase })
attach.SetTemplateFunc("niltime", func() string { return time.Unix(0, 0).Format(time.RFC1123) }) attach.SetTemplateFunc("niltime", func() string { return time.Unix(0, 0).Format(time.RFC1123) })
attach.SetTemplateFunc("ipc", func() bool { return strings.HasPrefix(endpoint, "ipc") }) attach.SetTemplateFunc("ipc", func() bool { return strings.HasPrefix(endpoint, "ipc") })
attach.SetTemplateFunc("datadir", func() string { return geth.Datadir }) attach.SetTemplateFunc("datadir", func() string { return XDC.Datadir })
attach.SetTemplateFunc("apis", func() string { return apis }) attach.SetTemplateFunc("apis", func() string { return apis })
// Verify the actual welcome message to the required template // Verify the actual welcome message to the required template
attach.Expect(` attach.Expect(`
Welcome to the Geth JavaScript console! Welcome to the XDC JavaScript console!
instance: Geth/v{{gethver}}/{{goos}}-{{goarch}}/{{gover}} instance: XDC/v{{XDCver}}/{{goos}}-{{goarch}}/{{gover}}
coinbase: {{etherbase}} coinbase: {{etherbase}}
at block: 0 ({{niltime}}){{if ipc}} at block: 0 ({{nil1time}}){{if ipc}}
datadir: {{datadir}}{{end}} datadir: {{datadir}}{{end}}
modules: {{apis}} modules: {{apis}}