2017-10-24 14:24:07 +00:00
|
|
|
package integration_test
|
|
|
|
|
|
|
|
import (
|
2018-02-02 21:53:16 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2018-03-27 21:06:12 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
2018-02-13 16:31:57 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/inmemory"
|
2018-01-06 20:31:53 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/geth"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/history"
|
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() {
|
|
|
|
|
2018-07-17 21:23:07 +00:00
|
|
|
var blockchain *geth.BlockChain
|
2018-02-12 16:54:05 +00:00
|
|
|
var inMemory *inmemory.InMemory
|
2017-11-03 13:54:32 +00:00
|
|
|
|
|
|
|
BeforeEach(func() {
|
2018-07-17 21:23:07 +00:00
|
|
|
blockchain = geth.NewBlockChain(test_config.InfuraClient.IPCPath)
|
2018-02-12 16:54:05 +00:00
|
|
|
inMemory = inmemory.NewInMemory()
|
2017-11-03 13:54:32 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("reads two blocks", func(done Done) {
|
2018-02-12 16:54:05 +00:00
|
|
|
blocks := &inmemory.BlockRepository{InMemory: inMemory}
|
2018-05-04 15:41:56 +00:00
|
|
|
lastBlock := blockchain.LastBlock()
|
|
|
|
queriedBlocks := []int64{lastBlock.Int64() - 5, lastBlock.Int64() - 6}
|
|
|
|
history.RetrieveAndUpdateBlocks(blockchain, blocks, queriedBlocks)
|
2018-02-12 16:54:05 +00:00
|
|
|
Expect(blocks.BlockCount()).To(Equal(2))
|
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-03-27 21:06:12 +00:00
|
|
|
genesisBlock, err := blockchain.GetBlockByNumber(int64(0))
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
firstBlock, err := blockchain.GetBlockByNumber(int64(1))
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2017-12-20 20:06:22 +00:00
|
|
|
lastBlockNumber := blockchain.LastBlock()
|
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) {
|
|
|
|
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)
|
|
|
|
|
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-- {
|
|
|
|
block, err := blockchain.GetBlockByNumber(int64(i))
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
blocks = append(blocks, block)
|
|
|
|
}
|
|
|
|
Expect(len(blocks)).To(Equal(n))
|
|
|
|
})
|
|
|
|
}, 10)
|
2017-10-24 14:24:07 +00:00
|
|
|
})
|