2018-11-07 21:50:43 +00:00
|
|
|
// VulcanizeDB
|
2019-03-12 15:46:42 +00:00
|
|
|
// Copyright © 2019 Vulcanize
|
2018-11-07 21:50:43 +00:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-10-24 14:24:07 +00:00
|
|
|
package integration_test
|
|
|
|
|
|
|
|
import (
|
2019-03-27 18:49:44 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2018-07-18 20:59:40 +00:00
|
|
|
"github.com/ethereum/go-ethereum/ethclient"
|
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
2018-02-02 21:53:16 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2018-08-31 19:48:43 +00:00
|
|
|
|
2019-10-28 11:30:24 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/eth"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/eth/client"
|
|
|
|
rpc2 "github.com/vulcanize/vulcanizedb/pkg/eth/converters/rpc"
|
2020-01-30 22:35:31 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/eth/core"
|
2020-01-29 19:00:07 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/eth/fakes"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/eth/history"
|
2020-01-30 22:35:31 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/eth/node"
|
2018-02-13 16:31:57 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/test_config"
|
2017-10-24 14:24:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Reading from the Geth blockchain", func() {
|
2019-10-28 11:30:24 +00:00
|
|
|
var blockChain *eth.BlockChain
|
2017-11-03 13:54:32 +00:00
|
|
|
|
|
|
|
BeforeEach(func() {
|
2019-10-18 16:16:19 +00:00
|
|
|
rawRPCClient, err := rpc.Dial(test_config.TestClient.IPCPath)
|
2018-07-18 20:59:40 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2019-10-18 16:16:19 +00:00
|
|
|
rpcClient := client.NewRPCClient(rawRPCClient, test_config.TestClient.IPCPath)
|
|
|
|
ethClient := ethclient.NewClient(rawRPCClient)
|
2018-07-20 16:37:46 +00:00
|
|
|
blockChainClient := client.NewEthClient(ethClient)
|
|
|
|
node := node.MakeNode(rpcClient)
|
2019-10-18 16:16:19 +00:00
|
|
|
transactionConverter := rpc2.NewRPCTransactionConverter(ethClient)
|
2019-10-28 11:30:24 +00:00
|
|
|
blockChain = eth.NewBlockChain(blockChainClient, rpcClient, node, transactionConverter)
|
2017-11-03 13:54:32 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("reads two blocks", func(done Done) {
|
2018-07-20 16:37:46 +00:00
|
|
|
blocks := fakes.NewMockBlockRepository()
|
2019-02-20 11:01:19 +00:00
|
|
|
lastBlock, err := blockChain.LastBlock()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
2018-05-04 15:41:56 +00:00
|
|
|
queriedBlocks := []int64{lastBlock.Int64() - 5, lastBlock.Int64() - 6}
|
2019-02-20 11:01:19 +00:00
|
|
|
_, err = history.RetrieveAndUpdateBlocks(blockChain, blocks, queriedBlocks)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
blocks.AssertCreateOrUpdateBlocksCallCountAndBlockNumbersEquals(2, []int64{lastBlock.Int64() - 5, lastBlock.Int64() - 6})
|
2017-10-24 14:24:07 +00:00
|
|
|
close(done)
|
2018-03-21 18:44:01 +00:00
|
|
|
}, 30)
|
2017-10-24 14:24:07 +00:00
|
|
|
|
2017-11-06 20:36:12 +00:00
|
|
|
It("retrieves the genesis block and first block", func(done Done) {
|
2018-07-18 20:59:40 +00:00
|
|
|
genesisBlock, err := blockChain.GetBlockByNumber(int64(0))
|
2018-03-27 21:06:12 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2018-07-18 20:59:40 +00:00
|
|
|
firstBlock, err := blockChain.GetBlockByNumber(int64(1))
|
2018-03-27 21:06:12 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2019-02-20 11:01:19 +00:00
|
|
|
lastBlockNumber, err := blockChain.LastBlock()
|
2017-11-06 20:36:12 +00:00
|
|
|
|
2019-02-20 11:01:19 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2017-11-06 20:36:12 +00:00
|
|
|
Expect(genesisBlock.Number).To(Equal(int64(0)))
|
|
|
|
Expect(firstBlock.Number).To(Equal(int64(1)))
|
2017-12-20 20:06:22 +00:00
|
|
|
Expect(lastBlockNumber.Int64()).To(BeNumerically(">", 0))
|
2017-11-06 20:36:12 +00:00
|
|
|
close(done)
|
2017-12-04 18:54:33 +00:00
|
|
|
}, 15)
|
2017-11-06 20:36:12 +00:00
|
|
|
|
2017-12-07 19:32:16 +00:00
|
|
|
It("retrieves the node info", func(done Done) {
|
2018-07-18 20:59:40 +00:00
|
|
|
node := blockChain.Node()
|
2018-03-27 21:06:12 +00:00
|
|
|
mainnetID := float64(1)
|
2017-12-07 19:32:16 +00:00
|
|
|
|
2018-03-07 21:29:21 +00:00
|
|
|
Expect(node.GenesisBlock).ToNot(BeNil())
|
2018-03-27 21:06:12 +00:00
|
|
|
Expect(node.NetworkID).To(Equal(mainnetID))
|
2018-03-21 18:44:01 +00:00
|
|
|
Expect(len(node.ID)).ToNot(BeZero())
|
|
|
|
Expect(node.ClientName).ToNot(BeZero())
|
2017-12-07 19:32:16 +00:00
|
|
|
|
|
|
|
close(done)
|
|
|
|
}, 15)
|
|
|
|
|
2019-03-27 18:49:44 +00:00
|
|
|
It("retrieves transaction", func() {
|
|
|
|
// actual transaction: https://etherscan.io/tx/0x44d462f2a19ad267e276b234a62c542fc91c974d2e4754a325ca405f95440255
|
|
|
|
txHash := common.HexToHash("0x44d462f2a19ad267e276b234a62c542fc91c974d2e4754a325ca405f95440255")
|
|
|
|
transactions, err := blockChain.GetTransactions([]common.Hash{txHash})
|
|
|
|
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(len(transactions)).To(Equal(1))
|
|
|
|
expectedData := []byte{149, 227, 197, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
1, 160, 85, 105, 13, 157, 184, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,
|
|
|
|
241, 202, 218, 90, 30, 178, 234, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 92, 155, 193, 43}
|
|
|
|
expectedRaw := []byte{248, 201, 9, 132, 59, 154, 202, 0, 131, 1, 102, 93, 148, 44, 75, 208, 100, 185, 152, 131,
|
|
|
|
128, 118, 250, 52, 26, 131, 208, 7, 252, 47, 165, 9, 87, 128, 184, 100, 149, 227, 197, 11, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 160, 85, 105, 13, 157, 184, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 241, 202, 218, 90, 30, 178, 234, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 92, 155, 193, 43, 37, 160, 237, 184, 236, 248, 23, 152,
|
|
|
|
53, 238, 44, 215, 181, 234, 229, 157, 246, 212, 178, 88, 25, 116, 134, 163, 124, 64, 2, 66, 25, 118, 1, 253, 27,
|
|
|
|
101, 160, 36, 226, 116, 43, 147, 236, 124, 76, 227, 250, 228, 168, 22, 19, 248, 155, 248, 151, 219, 14, 1, 186,
|
|
|
|
159, 35, 154, 22, 222, 123, 254, 147, 63, 221}
|
|
|
|
expectedModel := core.TransactionModel{
|
|
|
|
Data: expectedData,
|
|
|
|
From: "0x3b08b99441086edd66f36f9f9aee733280698378",
|
|
|
|
GasLimit: 91741,
|
|
|
|
GasPrice: 1000000000,
|
|
|
|
Hash: "0x44d462f2a19ad267e276b234a62c542fc91c974d2e4754a325ca405f95440255",
|
|
|
|
Nonce: 9,
|
|
|
|
Raw: expectedRaw,
|
|
|
|
Receipt: core.Receipt{},
|
|
|
|
To: "0x2c4bd064b998838076fa341a83d007fc2fa50957",
|
|
|
|
TxIndex: 30,
|
|
|
|
Value: "0",
|
|
|
|
}
|
|
|
|
Expect(transactions[0]).To(Equal(expectedModel))
|
|
|
|
})
|
|
|
|
|
2018-03-27 21:06:12 +00:00
|
|
|
//Benchmarking test: remove skip to test performance of block retrieval
|
|
|
|
XMeasure("retrieving n blocks", func(b Benchmarker) {
|
|
|
|
b.Time("runtime", func() {
|
|
|
|
var blocks []core.Block
|
|
|
|
n := 10
|
|
|
|
for i := 5327459; i > 5327459-n; i-- {
|
2018-07-18 20:59:40 +00:00
|
|
|
block, err := blockChain.GetBlockByNumber(int64(i))
|
2018-03-27 21:06:12 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
blocks = append(blocks, block)
|
|
|
|
}
|
|
|
|
Expect(len(blocks)).To(Equal(n))
|
|
|
|
})
|
|
|
|
}, 10)
|
2017-10-24 14:24:07 +00:00
|
|
|
})
|