forked from cerc-io/ipld-eth-server
Allow Parity as ingest node (#36)
* Upgrade go-ethereum to v1.8 * Add Node Info for parity nodes * Upgrade start_private_blockchain to use v1.8
This commit is contained in:
+3
-3
@@ -4,15 +4,15 @@ type Block struct {
|
||||
Reward float64 `db:"reward"`
|
||||
Difficulty int64 `db:"difficulty"`
|
||||
ExtraData string `db:"extra_data"`
|
||||
GasLimit int64 `db:"gaslimit"`
|
||||
GasUsed int64 `db:"gasused"`
|
||||
GasLimit uint64 `db:"gaslimit"`
|
||||
GasUsed uint64 `db:"gasused"`
|
||||
Hash string `db:"hash"`
|
||||
IsFinal bool `db:"is_final"`
|
||||
Miner string `db:"miner"`
|
||||
Nonce string `db:"nonce"`
|
||||
Number int64 `db:"number"`
|
||||
ParentHash string `db:"parenthash"`
|
||||
Size int64 `db:"size"`
|
||||
Size string `db:"size"`
|
||||
Time int64 `db:"time"`
|
||||
Transactions []Transaction
|
||||
UncleHash string `db:"uncle_hash"`
|
||||
|
||||
@@ -1,8 +1,36 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type NodeType int
|
||||
|
||||
const (
|
||||
GETH NodeType = iota
|
||||
PARITY
|
||||
INFURA
|
||||
)
|
||||
|
||||
type Node struct {
|
||||
GenesisBlock string
|
||||
NetworkID float64
|
||||
ID string
|
||||
ClientName string
|
||||
}
|
||||
|
||||
type ParityNodeInfo struct {
|
||||
Track string
|
||||
ParityVersion `json:"version"`
|
||||
Hash string
|
||||
}
|
||||
|
||||
func (pn ParityNodeInfo) String() string {
|
||||
return fmt.Sprintf("Parity/v%d.%d.%d/", pn.Major, pn.Minor, pn.Patch)
|
||||
}
|
||||
|
||||
type ParityVersion struct {
|
||||
Major int
|
||||
Minor int
|
||||
Patch int
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ package core
|
||||
type Receipt struct {
|
||||
Bloom string
|
||||
ContractAddress string
|
||||
CumulativeGasUsed int64
|
||||
GasUsed int64
|
||||
CumulativeGasUsed uint64
|
||||
GasUsed uint64
|
||||
Logs []Log
|
||||
StateRoot string
|
||||
Status int
|
||||
|
||||
@@ -6,7 +6,7 @@ type Transaction struct {
|
||||
Nonce uint64 `db:"nonce"`
|
||||
To string `db:"tx_to"`
|
||||
From string `db:"tx_from"`
|
||||
GasLimit int64 `db:"gaslimit"`
|
||||
GasLimit uint64 `db:"gaslimit"`
|
||||
GasPrice int64 `db:"gasprice"`
|
||||
Receipt
|
||||
Value string `db:"value"`
|
||||
|
||||
@@ -48,8 +48,8 @@ var _ = Describe("Saving blocks", func() {
|
||||
|
||||
It("saves the attributes of the block", func() {
|
||||
blockNumber := int64(123)
|
||||
gasLimit := int64(1000000)
|
||||
gasUsed := int64(10)
|
||||
gasLimit := uint64(1000000)
|
||||
gasUsed := uint64(10)
|
||||
blockHash := "x123"
|
||||
blockParentHash := "x456"
|
||||
blockNonce := "0x881db2ca900682e9a9"
|
||||
@@ -57,7 +57,7 @@ var _ = Describe("Saving blocks", func() {
|
||||
extraData := "xextraData"
|
||||
blockTime := int64(1508981640)
|
||||
uncleHash := "x789"
|
||||
blockSize := int64(1000)
|
||||
blockSize := string("1000")
|
||||
difficulty := int64(10)
|
||||
blockReward := float64(5.132)
|
||||
unclesReward := float64(3.580)
|
||||
@@ -178,7 +178,7 @@ var _ = Describe("Saving blocks", func() {
|
||||
})
|
||||
|
||||
It("saves the attributes associated to a transaction", func() {
|
||||
gasLimit := int64(5000)
|
||||
gasLimit := uint64(5000)
|
||||
gasPrice := int64(3)
|
||||
nonce := uint64(10000)
|
||||
to := "1234567890"
|
||||
|
||||
@@ -37,8 +37,8 @@ func (receiptRepository ReceiptRepository) GetReceipt(txHash string) (core.Recei
|
||||
func loadReceipt(receiptsRow *sql.Row) (core.Receipt, error) {
|
||||
var contractAddress string
|
||||
var txHash string
|
||||
var cumulativeGasUsed int64
|
||||
var gasUsed int64
|
||||
var cumulativeGasUsed uint64
|
||||
var gasUsed uint64
|
||||
var stateRoot string
|
||||
var status int
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ func calcTransactionFees(block core.Block) float64 {
|
||||
var transactionFees float64
|
||||
for _, transaction := range block.Transactions {
|
||||
receipt := transaction.Receipt
|
||||
transactionFees += float64(transaction.GasPrice * receipt.GasUsed)
|
||||
transactionFees += float64(uint64(transaction.GasPrice) * receipt.GasUsed)
|
||||
}
|
||||
return transactionFees / params.Ether
|
||||
}
|
||||
|
||||
@@ -22,14 +22,14 @@ func ToCoreBlock(gethBlock *types.Block, client Client) core.Block {
|
||||
coreBlock := core.Block{
|
||||
Difficulty: gethBlock.Difficulty().Int64(),
|
||||
ExtraData: hexutil.Encode(gethBlock.Extra()),
|
||||
GasLimit: gethBlock.GasLimit().Int64(),
|
||||
GasUsed: gethBlock.GasUsed().Int64(),
|
||||
GasLimit: gethBlock.GasLimit(),
|
||||
GasUsed: gethBlock.GasUsed(),
|
||||
Hash: gethBlock.Hash().Hex(),
|
||||
Miner: strings.ToLower(gethBlock.Coinbase().Hex()),
|
||||
Nonce: hexutil.Encode(gethBlock.Header().Nonce[:]),
|
||||
Number: gethBlock.Number().Int64(),
|
||||
ParentHash: gethBlock.ParentHash().Hex(),
|
||||
Size: gethBlock.Size().Int64(),
|
||||
Size: gethBlock.Size().String(),
|
||||
Time: gethBlock.Time().Int64(),
|
||||
Transactions: transactions,
|
||||
UncleHash: gethBlock.UncleHash().Hex(),
|
||||
@@ -74,7 +74,7 @@ func transToCoreTrans(transaction *types.Transaction, from *common.Address) core
|
||||
Nonce: transaction.Nonce(),
|
||||
To: strings.ToLower(addressToHex(transaction.To())),
|
||||
From: strings.ToLower(addressToHex(from)),
|
||||
GasLimit: transaction.Gas().Int64(),
|
||||
GasLimit: transaction.Gas(),
|
||||
GasPrice: transaction.GasPrice().Int64(),
|
||||
Value: transaction.Value().String(),
|
||||
Data: data,
|
||||
|
||||
@@ -33,7 +33,7 @@ func (client *FakeGethClient) TransactionReceipt(ctx context.Context, txHash com
|
||||
if gasUsed, ok := client.receipts[txHash.Hex()]; ok {
|
||||
return gasUsed, nil
|
||||
}
|
||||
return &types.Receipt{GasUsed: big.NewInt(0)}, nil
|
||||
return &types.Receipt{GasUsed: uint64(0)}, nil
|
||||
}
|
||||
|
||||
func (client *FakeGethClient) TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error) {
|
||||
@@ -44,8 +44,8 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
|
||||
It("converts basic Block metadata", func() {
|
||||
difficulty := big.NewInt(1)
|
||||
gasLimit := int64(100000)
|
||||
gasUsed := int64(100000)
|
||||
gasLimit := uint64(100000)
|
||||
gasUsed := uint64(100000)
|
||||
miner := common.HexToAddress("0x0000000000000000000000000000000000000123")
|
||||
extraData, _ := hexutil.Decode("0xe4b883e5bda9e7a59ee4bb99e9b1bc")
|
||||
nonce := types.BlockNonce{10}
|
||||
@@ -54,8 +54,8 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
|
||||
header := types.Header{
|
||||
Difficulty: difficulty,
|
||||
GasLimit: big.NewInt(gasLimit),
|
||||
GasUsed: big.NewInt(gasUsed),
|
||||
GasLimit: uint64(gasLimit),
|
||||
GasUsed: uint64(gasUsed),
|
||||
Extra: extraData,
|
||||
Coinbase: miner,
|
||||
Nonce: nonce,
|
||||
@@ -77,7 +77,7 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
Expect(gethBlock.Number).To(Equal(number))
|
||||
Expect(gethBlock.ParentHash).To(Equal(block.ParentHash().Hex()))
|
||||
Expect(gethBlock.ExtraData).To(Equal(hexutil.Encode(block.Extra())))
|
||||
Expect(gethBlock.Size).To(Equal(block.Size().Int64()))
|
||||
Expect(gethBlock.Size).To(Equal(block.Size().String()))
|
||||
Expect(gethBlock.Time).To(Equal(time))
|
||||
Expect(gethBlock.UncleHash).To(Equal(block.UncleHash().Hex()))
|
||||
Expect(gethBlock.IsFinal).To(BeFalse())
|
||||
@@ -90,7 +90,7 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
uint64(226823),
|
||||
common.HexToAddress("0x108fedb097c1dcfed441480170144d8e19bb217f"),
|
||||
big.NewInt(1080900090000000000),
|
||||
big.NewInt(90000),
|
||||
uint64(90000),
|
||||
big.NewInt(50000000000),
|
||||
[]byte{},
|
||||
)
|
||||
@@ -99,8 +99,8 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
txHash := transaction.Hash()
|
||||
receipt := types.Receipt{
|
||||
TxHash: txHash,
|
||||
GasUsed: big.NewInt(21000),
|
||||
CumulativeGasUsed: big.NewInt(21000),
|
||||
GasUsed: uint64(21000),
|
||||
CumulativeGasUsed: uint64(21000),
|
||||
}
|
||||
receipts := []*types.Receipt{&receipt}
|
||||
|
||||
@@ -123,15 +123,15 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
uint64(226823),
|
||||
common.HexToAddress("0x108fedb097c1dcfed441480170144d8e19bb217f"),
|
||||
big.NewInt(1080900090000000000),
|
||||
big.NewInt(90000),
|
||||
uint64(90000),
|
||||
big.NewInt(50000000000),
|
||||
[]byte{})
|
||||
transactions := []*types.Transaction{transaction}
|
||||
|
||||
receipt := types.Receipt{
|
||||
TxHash: transaction.Hash(),
|
||||
GasUsed: big.NewInt(21000),
|
||||
CumulativeGasUsed: big.NewInt(21000),
|
||||
GasUsed: uint64(21000),
|
||||
CumulativeGasUsed: uint64(21000),
|
||||
}
|
||||
receipts := []*types.Receipt{&receipt}
|
||||
|
||||
@@ -157,7 +157,7 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
uint64(8072),
|
||||
common.HexToAddress("0xebd17720aeb7ac5186c5dfa7bafeb0bb14c02551 "),
|
||||
big.NewInt(0),
|
||||
big.NewInt(500000),
|
||||
uint64(500000),
|
||||
big.NewInt(42000000000),
|
||||
[]byte{},
|
||||
)
|
||||
@@ -165,7 +165,7 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
transactionTwo := types.NewTransaction(uint64(8071),
|
||||
common.HexToAddress("0x3cdab63d764c8c5048ed5e8f0a4e95534ba7e1ea"),
|
||||
big.NewInt(0),
|
||||
big.NewInt(500000),
|
||||
uint64(500000),
|
||||
big.NewInt(42000000000),
|
||||
[]byte{})
|
||||
|
||||
@@ -173,13 +173,13 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
|
||||
receiptOne := types.Receipt{
|
||||
TxHash: transactionOne.Hash(),
|
||||
GasUsed: big.NewInt(297508),
|
||||
CumulativeGasUsed: big.NewInt(0),
|
||||
GasUsed: uint64(297508),
|
||||
CumulativeGasUsed: uint64(0),
|
||||
}
|
||||
receiptTwo := types.Receipt{
|
||||
TxHash: transactionTwo.Hash(),
|
||||
GasUsed: big.NewInt(297508),
|
||||
CumulativeGasUsed: big.NewInt(0),
|
||||
GasUsed: uint64(297508),
|
||||
CumulativeGasUsed: uint64(0),
|
||||
}
|
||||
receipts := []*types.Receipt{&receiptOne, &receiptTwo}
|
||||
|
||||
@@ -212,7 +212,7 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
gethTransaction := types.NewTransaction(
|
||||
uint64(10000), common.Address{1},
|
||||
big.NewInt(10),
|
||||
big.NewInt(5000),
|
||||
uint64(5000),
|
||||
big.NewInt(3),
|
||||
hexutil.MustDecode("0xf7d8c8830000000000000000000000000000000000000000000000000000000000037788000000000000000000000000000000000000000000000000000000000003bd14"),
|
||||
)
|
||||
@@ -220,8 +220,8 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
gethReceipt := &types.Receipt{
|
||||
Bloom: types.BytesToBloom(hexutil.MustDecode("0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")),
|
||||
ContractAddress: common.HexToAddress("x123"),
|
||||
CumulativeGasUsed: big.NewInt(7996119),
|
||||
GasUsed: big.NewInt(21000),
|
||||
CumulativeGasUsed: uint64(7996119),
|
||||
GasUsed: uint64(21000),
|
||||
Logs: []*types.Log{},
|
||||
Status: uint(1),
|
||||
TxHash: gethTransaction.Hash(),
|
||||
@@ -244,7 +244,7 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
Expect(coreTransaction.Data).To(Equal("0xf7d8c8830000000000000000000000000000000000000000000000000000000000037788000000000000000000000000000000000000000000000000000000000003bd14"))
|
||||
Expect(coreTransaction.To).To(Equal(gethTransaction.To().Hex()))
|
||||
Expect(coreTransaction.From).To(Equal("0x0000000000000000000000000000000000000123"))
|
||||
Expect(coreTransaction.GasLimit).To(Equal(gethTransaction.Gas().Int64()))
|
||||
Expect(coreTransaction.GasLimit).To(Equal(gethTransaction.Gas()))
|
||||
Expect(coreTransaction.GasPrice).To(Equal(gethTransaction.GasPrice().Int64()))
|
||||
Expect(coreTransaction.Value).To(Equal(gethTransaction.Value().String()))
|
||||
Expect(coreTransaction.Nonce).To(Equal(gethTransaction.Nonce()))
|
||||
@@ -259,14 +259,14 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
gethTransaction := types.NewContractCreation(
|
||||
uint64(10000),
|
||||
big.NewInt(10),
|
||||
big.NewInt(5000),
|
||||
uint64(5000),
|
||||
big.NewInt(3),
|
||||
[]byte("1234"),
|
||||
)
|
||||
|
||||
gethReceipt := &types.Receipt{
|
||||
CumulativeGasUsed: big.NewInt(1),
|
||||
GasUsed: big.NewInt(1),
|
||||
CumulativeGasUsed: uint64(1),
|
||||
GasUsed: uint64(1),
|
||||
TxHash: gethTransaction.Hash(),
|
||||
ContractAddress: common.HexToAddress("0x1023342345"),
|
||||
}
|
||||
|
||||
+2
-15
@@ -3,8 +3,6 @@ package geth
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"strings"
|
||||
|
||||
"log"
|
||||
|
||||
"github.com/ethereum/go-ethereum"
|
||||
@@ -29,26 +27,15 @@ func NewBlockchain(ipcPath string) *Blockchain {
|
||||
blockchain := Blockchain{}
|
||||
rpcClient, err := rpc.Dial(ipcPath)
|
||||
if err != nil {
|
||||
log.Println("Unable to connect to node")
|
||||
log.Fatal(err)
|
||||
}
|
||||
client := ethclient.NewClient(rpcClient)
|
||||
blockchain.node = node.Info(rpcClient)
|
||||
if infura := isInfuraNode(ipcPath); infura {
|
||||
blockchain.node.ID = "infura"
|
||||
blockchain.node.ClientName = "infura"
|
||||
}
|
||||
clientWrapper := node.ClientWrapper{ContextCaller: rpcClient, IPCPath: ipcPath}
|
||||
blockchain.node = node.MakeNode(clientWrapper)
|
||||
blockchain.client = client
|
||||
return &blockchain
|
||||
}
|
||||
|
||||
func isInfuraNode(ipcPath string) bool {
|
||||
if strings.Contains(ipcPath, "infura") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (blockchain *Blockchain) GetLogs(contract core.Contract, startingBlockNumber *big.Int, endingBlockNumber *big.Int) ([]core.Log, error) {
|
||||
if endingBlockNumber == nil {
|
||||
endingBlockNumber = startingBlockNumber
|
||||
|
||||
+100
-23
@@ -5,45 +5,122 @@ import (
|
||||
|
||||
"strconv"
|
||||
|
||||
"regexp"
|
||||
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
)
|
||||
|
||||
func Info(client *rpc.Client) core.Node {
|
||||
node := core.Node{}
|
||||
node.NetworkID = NetworkID(client)
|
||||
node.GenesisBlock = GenesisBlock(client)
|
||||
node.ID, node.ClientName = IDClientName(client)
|
||||
return node
|
||||
type PropertiesReader interface {
|
||||
NodeInfo() (id string, name string)
|
||||
NetworkId() float64
|
||||
GenesisBlock() string
|
||||
}
|
||||
|
||||
func IDClientName(client *rpc.Client) (string, string) {
|
||||
var info p2p.NodeInfo
|
||||
modules, _ := client.SupportedModules()
|
||||
if _, ok := modules["admin"]; ok {
|
||||
client.CallContext(context.Background(), &info, "admin_nodeInfo")
|
||||
return info.ID, info.Name
|
||||
type ClientWrapper struct {
|
||||
ContextCaller
|
||||
IPCPath string
|
||||
}
|
||||
|
||||
type ContextCaller interface {
|
||||
CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
|
||||
SupportedModules() (map[string]string, error)
|
||||
}
|
||||
|
||||
type ParityClient struct {
|
||||
ClientWrapper
|
||||
}
|
||||
|
||||
type GethClient struct {
|
||||
ClientWrapper
|
||||
}
|
||||
|
||||
type InfuraClient struct {
|
||||
ClientWrapper
|
||||
}
|
||||
|
||||
func (clientWrapper ClientWrapper) NodeType() core.NodeType {
|
||||
if strings.Contains(clientWrapper.IPCPath, "infura") {
|
||||
return core.INFURA
|
||||
}
|
||||
return "", ""
|
||||
modules, _ := clientWrapper.SupportedModules()
|
||||
if _, ok := modules["admin"]; ok {
|
||||
return core.GETH
|
||||
}
|
||||
return core.PARITY
|
||||
}
|
||||
|
||||
func NetworkID(client *rpc.Client) float64 {
|
||||
func makePropertiesReader(wrapper ClientWrapper) PropertiesReader {
|
||||
switch wrapper.NodeType() {
|
||||
case core.GETH:
|
||||
return GethClient{ClientWrapper: wrapper}
|
||||
case core.PARITY:
|
||||
return ParityClient{ClientWrapper: wrapper}
|
||||
case core.INFURA:
|
||||
return InfuraClient{ClientWrapper: wrapper}
|
||||
default:
|
||||
return wrapper
|
||||
}
|
||||
}
|
||||
|
||||
func MakeNode(wrapper ClientWrapper) core.Node {
|
||||
pr := makePropertiesReader(wrapper)
|
||||
id, name := pr.NodeInfo()
|
||||
return core.Node{
|
||||
GenesisBlock: pr.GenesisBlock(),
|
||||
NetworkID: pr.NetworkId(),
|
||||
ID: id,
|
||||
ClientName: name,
|
||||
}
|
||||
}
|
||||
|
||||
func (client ClientWrapper) NetworkId() float64 {
|
||||
var version string
|
||||
client.CallContext(context.Background(), &version, "net_version")
|
||||
networkId, _ := strconv.ParseFloat(version, 64)
|
||||
return networkId
|
||||
}
|
||||
|
||||
func ProtocolVersion(client *rpc.Client) string {
|
||||
var protocolVersion string
|
||||
client.CallContext(context.Background(), &protocolVersion, "eth_protocolVersion")
|
||||
return protocolVersion
|
||||
}
|
||||
|
||||
func GenesisBlock(client *rpc.Client) string {
|
||||
func (client ClientWrapper) GenesisBlock() string {
|
||||
var header *types.Header
|
||||
client.CallContext(context.Background(), &header, "eth_getBlockByNumber", "0x0", false)
|
||||
blockZero := "0x0"
|
||||
includeTransactions := false
|
||||
client.CallContext(context.Background(), &header, "eth_getBlockByNumber", blockZero, includeTransactions)
|
||||
return header.Hash().Hex()
|
||||
}
|
||||
|
||||
func (client ClientWrapper) NodeInfo() (string, string) {
|
||||
var info p2p.NodeInfo
|
||||
client.CallContext(context.Background(), &info, "admin_nodeInfo")
|
||||
return info.ID, info.Name
|
||||
}
|
||||
|
||||
func (client ParityClient) NodeInfo() (string, string) {
|
||||
nodeInfo := client.parityNodeInfo()
|
||||
id := client.parityID()
|
||||
return id, nodeInfo
|
||||
}
|
||||
|
||||
func (client InfuraClient) NodeInfo() (string, string) {
|
||||
return "infura", "infura"
|
||||
}
|
||||
|
||||
func (client ParityClient) parityNodeInfo() string {
|
||||
var nodeInfo core.ParityNodeInfo
|
||||
client.CallContext(context.Background(), &nodeInfo, "parity_versionInfo")
|
||||
return nodeInfo.String()
|
||||
}
|
||||
|
||||
func (client ParityClient) parityID() string {
|
||||
var enodeId = regexp.MustCompile(`^enode://(.+)@.+$`)
|
||||
var enodeURL string
|
||||
client.CallContext(context.Background(), &enodeURL, "parity_enode")
|
||||
enode := enodeId.FindStringSubmatch(enodeURL)
|
||||
if len(enode) < 2 {
|
||||
return ""
|
||||
}
|
||||
return enode[1]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package node_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func TestNode(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Node Suite")
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package node_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"context"
|
||||
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/geth/node"
|
||||
)
|
||||
|
||||
type MockContextCaller struct {
|
||||
nodeType core.NodeType
|
||||
}
|
||||
|
||||
var EmpytHeaderHash = "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
|
||||
|
||||
func (MockContextCaller) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error {
|
||||
switch method {
|
||||
case "admin_nodeInfo":
|
||||
if p, ok := result.(*p2p.NodeInfo); ok {
|
||||
p.ID = "enode://GethNode@172.17.0.1:30303"
|
||||
p.Name = "Geth/v1.7"
|
||||
}
|
||||
case "eth_getBlockByNumber":
|
||||
if p, ok := result.(*types.Header); ok {
|
||||
*p = types.Header{}
|
||||
}
|
||||
|
||||
case "parity_versionInfo":
|
||||
if p, ok := result.(*core.ParityNodeInfo); ok {
|
||||
*p = core.ParityNodeInfo{
|
||||
Track: "",
|
||||
ParityVersion: core.ParityVersion{
|
||||
Major: 1,
|
||||
Minor: 2,
|
||||
Patch: 3,
|
||||
},
|
||||
Hash: "",
|
||||
}
|
||||
}
|
||||
case "parity_enode":
|
||||
if p, ok := result.(*string); ok {
|
||||
*p = "enode://ParityNode@172.17.0.1:30303"
|
||||
}
|
||||
case "net_version":
|
||||
if p, ok := result.(*string); ok {
|
||||
*p = "1234"
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mcc MockContextCaller) SupportedModules() (map[string]string, error) {
|
||||
result := make(map[string]string)
|
||||
if mcc.nodeType == core.GETH {
|
||||
result["admin"] = "ok"
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
var _ = 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": {
|
||||
"major": 1,
|
||||
"minor": 6,
|
||||
"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))
|
||||
})
|
||||
|
||||
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 the genesis block for any client", func() {
|
||||
mcc := MockContextCaller{}
|
||||
cw := node.ClientWrapper{ContextCaller: mcc}
|
||||
n := node.MakeNode(cw)
|
||||
Expect(n.GenesisBlock).To(Equal(EmpytHeaderHash))
|
||||
})
|
||||
|
||||
It("returns the network id for any client", func() {
|
||||
mcc := MockContextCaller{}
|
||||
cw := node.ClientWrapper{ContextCaller: mcc}
|
||||
n := node.MakeNode(cw)
|
||||
Expect(n.NetworkID).To(Equal(float64(1234)))
|
||||
})
|
||||
|
||||
It("returns parity ID and client name for parity node", func() {
|
||||
mcc := MockContextCaller{core.PARITY}
|
||||
cw := node.ClientWrapper{ContextCaller: mcc}
|
||||
n := node.MakeNode(cw)
|
||||
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() {
|
||||
mcc := MockContextCaller{core.GETH}
|
||||
cw := node.ClientWrapper{ContextCaller: mcc}
|
||||
n := node.MakeNode(cw)
|
||||
Expect(n.ID).To(Equal("enode://GethNode@172.17.0.1:30303"))
|
||||
Expect(n.ClientName).To(Equal("Geth/v1.7"))
|
||||
})
|
||||
|
||||
It("returns infura ID and client name for infura node", func() {
|
||||
mcc := MockContextCaller{core.INFURA}
|
||||
cw := node.ClientWrapper{mcc, "https://mainnet.infura.io/123"}
|
||||
n := node.MakeNode(cw)
|
||||
Expect(n.ID).To(Equal("infura"))
|
||||
Expect(n.ClientName).To(Equal("infura"))
|
||||
})
|
||||
})
|
||||
@@ -29,8 +29,8 @@ func ReceiptToCoreReceipt(gethReceipt *types.Receipt) core.Receipt {
|
||||
return core.Receipt{
|
||||
Bloom: bloom,
|
||||
ContractAddress: contractAddress,
|
||||
CumulativeGasUsed: gethReceipt.CumulativeGasUsed.Int64(),
|
||||
GasUsed: gethReceipt.GasUsed.Int64(),
|
||||
CumulativeGasUsed: gethReceipt.CumulativeGasUsed,
|
||||
GasUsed: gethReceipt.GasUsed,
|
||||
Logs: logs,
|
||||
StateRoot: postState,
|
||||
TxHash: gethReceipt.TxHash.Hex(),
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package geth_test
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
@@ -18,8 +16,8 @@ var _ = Describe("Conversion of GethReceipt to core.Receipt", func() {
|
||||
receipt := types.Receipt{
|
||||
Bloom: types.BytesToBloom(hexutil.MustDecode("0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")),
|
||||
ContractAddress: common.Address{},
|
||||
CumulativeGasUsed: big.NewInt(21000),
|
||||
GasUsed: big.NewInt(21000),
|
||||
CumulativeGasUsed: uint64(25000),
|
||||
GasUsed: uint64(21000),
|
||||
Logs: []*types.Log{},
|
||||
PostState: hexutil.MustDecode("0x88abf7e73128227370aa7baa3dd4e18d0af70e92ef1f9ef426942fbe2dddb733"),
|
||||
TxHash: common.HexToHash("0x97d99bc7729211111a21b12c933c949d4f31684f1d6954ff477d0477538ff017"),
|
||||
@@ -28,7 +26,7 @@ var _ = Describe("Conversion of GethReceipt to core.Receipt", func() {
|
||||
expected := core.Receipt{
|
||||
Bloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
ContractAddress: "",
|
||||
CumulativeGasUsed: 21000,
|
||||
CumulativeGasUsed: 25000,
|
||||
GasUsed: 21000,
|
||||
Logs: []core.Log{},
|
||||
StateRoot: "0x88abf7e73128227370aa7baa3dd4e18d0af70e92ef1f9ef426942fbe2dddb733",
|
||||
@@ -52,8 +50,8 @@ var _ = Describe("Conversion of GethReceipt to core.Receipt", func() {
|
||||
receipt := types.Receipt{
|
||||
Bloom: types.BytesToBloom(hexutil.MustDecode("0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")),
|
||||
ContractAddress: common.HexToAddress("x0123"),
|
||||
CumulativeGasUsed: big.NewInt(7996119),
|
||||
GasUsed: big.NewInt(21000),
|
||||
CumulativeGasUsed: uint64(7996119),
|
||||
GasUsed: uint64(21000),
|
||||
Logs: []*types.Log{},
|
||||
Status: uint(1),
|
||||
TxHash: common.HexToHash("0xe340558980f89d5f86045ac11e5cc34e4bcec20f9f1e2a427aa39d87114e8223"),
|
||||
|
||||
Reference in New Issue
Block a user