port over lightSync updates from maker repo

This commit is contained in:
Ian Norden
2018-11-29 20:33:21 -06:00
parent 26aaa8319b
commit 390a60f7f6
40 changed files with 626 additions and 296 deletions
+13
View File
@@ -53,6 +53,10 @@ type InfuraClient struct {
PropertiesReader
}
type GanacheClient struct {
PropertiesReader
}
func MakeNode(rpcClient core.RpcClient) core.Node {
pr := makePropertiesReader(rpcClient)
id, name := pr.NodeInfo()
@@ -72,6 +76,8 @@ func makePropertiesReader(client core.RpcClient) IPropertiesReader {
return ParityClient{PropertiesReader: PropertiesReader{client: client}}
case core.INFURA:
return InfuraClient{PropertiesReader: PropertiesReader{client: client}}
case core.GANACHE:
return GanacheClient{PropertiesReader: PropertiesReader{client: client}}
default:
return PropertiesReader{client: client}
}
@@ -81,6 +87,9 @@ func getNodeType(client core.RpcClient) core.NodeType {
if strings.Contains(client.IpcPath(), "infura") {
return core.INFURA
}
if strings.Contains(client.IpcPath(), "127.0.0.1") || strings.Contains(client.IpcPath(), "localhost") {
return core.GANACHE
}
modules, _ := client.SupportedModules()
if _, ok := modules["admin"]; ok {
return core.GETH
@@ -122,6 +131,10 @@ func (client InfuraClient) NodeInfo() (string, string) {
return "infura", "infura"
}
func (client GanacheClient) NodeInfo() (string, string) {
return "ganache", "ganache"
}
func (client ParityClient) parityNodeInfo() string {
var nodeInfo core.ParityNodeInfo
client.client.CallContext(context.Background(), &nodeInfo, "parity_versionInfo")
+51 -34
View File
@@ -21,6 +21,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/geth/node"
@@ -28,12 +29,12 @@ import (
var EmpytHeaderHash = "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
var _ = Describe("Parity Node Info", func() {
It("verifies parity_versionInfo can be unmarshalled into ParityNodeInfo", func() {
var parityNodeInfo core.ParityNodeInfo
nodeInfoJSON := []byte(
`{
var _ = Describe("Node Info", func() {
Describe("Parity Node Info", func() {
It("verifies parity_versionInfo can be unmarshalled into ParityNodeInfo", func() {
var parityNodeInfo core.ParityNodeInfo
nodeInfoJSON := []byte(
`{
"hash": "0x2ae8b4ca278dd7b896090366615fef81cbbbc0e0",
"track": "null",
"version": {
@@ -42,25 +43,34 @@ var _ = Describe("Parity Node Info", func() {
"patch": 0
}
}`)
json.Unmarshal(nodeInfoJSON, &parityNodeInfo)
Expect(parityNodeInfo.Hash).To(Equal("0x2ae8b4ca278dd7b896090366615fef81cbbbc0e0"))
Expect(parityNodeInfo.Track).To(Equal("null"))
Expect(parityNodeInfo.Major).To(Equal(1))
Expect(parityNodeInfo.Minor).To(Equal(6))
Expect(parityNodeInfo.Patch).To(Equal(0))
})
json.Unmarshal(nodeInfoJSON, &parityNodeInfo)
Expect(parityNodeInfo.Hash).To(Equal("0x2ae8b4ca278dd7b896090366615fef81cbbbc0e0"))
Expect(parityNodeInfo.Track).To(Equal("null"))
Expect(parityNodeInfo.Major).To(Equal(1))
Expect(parityNodeInfo.Minor).To(Equal(6))
Expect(parityNodeInfo.Patch).To(Equal(0))
})
It("Creates client string", func() {
parityNodeInfo := core.ParityNodeInfo{
Track: "null",
ParityVersion: core.ParityVersion{
Major: 1,
Minor: 6,
Patch: 0,
},
Hash: "0x1232144j",
}
Expect(parityNodeInfo.String()).To(Equal("Parity/v1.6.0/"))
It("Creates client string", func() {
parityNodeInfo := core.ParityNodeInfo{
Track: "null",
ParityVersion: core.ParityVersion{
Major: 1,
Minor: 6,
Patch: 0,
},
Hash: "0x1232144j",
}
Expect(parityNodeInfo.String()).To(Equal("Parity/v1.6.0/"))
})
It("returns parity ID and client name for parity node", func() {
client := fakes.NewMockRpcClient()
n := node.MakeNode(client)
Expect(n.ID).To(Equal("ParityNode"))
Expect(n.ClientName).To(Equal("Parity/v1.2.3/"))
})
})
It("returns the genesis block for any client", func() {
@@ -75,17 +85,12 @@ var _ = Describe("Parity Node Info", func() {
Expect(n.NetworkID).To(Equal(float64(1234)))
})
It("returns parity ID and client name for parity node", func() {
client := fakes.NewMockRpcClient()
client.SetNodeType(core.PARITY)
n := node.MakeNode(client)
Expect(n.ID).To(Equal("ParityNode"))
Expect(n.ClientName).To(Equal("Parity/v1.2.3/"))
})
It("returns geth ID and client name for geth node", func() {
client := fakes.NewMockRpcClient()
client.SetNodeType(core.GETH)
supportedModules := make(map[string]string)
supportedModules["admin"] = "ok"
client.SetSupporedModules(supportedModules)
n := node.MakeNode(client)
Expect(n.ID).To(Equal("enode://GethNode@172.17.0.1:30303"))
Expect(n.ClientName).To(Equal("Geth/v1.7"))
@@ -93,10 +98,22 @@ var _ = Describe("Parity Node Info", func() {
It("returns infura ID and client name for infura node", func() {
client := fakes.NewMockRpcClient()
client.SetNodeType(core.INFURA)
client.SetIpcPath("infura/path")
n := node.MakeNode(client)
Expect(n.ID).To(Equal("infura"))
Expect(n.ClientName).To(Equal("infura"))
})
It("returns local id and client name for Local node", func() {
client := fakes.NewMockRpcClient()
client.SetIpcPath("127.0.0.1")
n := node.MakeNode(client)
Expect(n.ID).To(Equal("ganache"))
Expect(n.ClientName).To(Equal("ganache"))
client.SetIpcPath("localhost")
n = node.MakeNode(client)
Expect(n.ID).To(Equal("ganache"))
Expect(n.ClientName).To(Equal("ganache"))
})
})