2017-10-24 14:24:07 +00:00
|
|
|
package integration_test
|
|
|
|
|
|
|
|
import (
|
2017-12-19 20:14:41 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
|
2017-11-06 18:53:43 +00:00
|
|
|
"github.com/8thlight/vulcanizedb/pkg/config"
|
|
|
|
"github.com/8thlight/vulcanizedb/pkg/geth"
|
2018-01-05 17:55:00 +00:00
|
|
|
"github.com/8thlight/vulcanizedb/pkg/history"
|
|
|
|
"github.com/8thlight/vulcanizedb/pkg/repositories"
|
2017-10-30 19:39:00 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2017-10-24 14:24:07 +00:00
|
|
|
)
|
|
|
|
|
2017-12-19 20:14:41 +00:00
|
|
|
func init() {
|
|
|
|
log.SetOutput(ioutil.Discard)
|
|
|
|
}
|
|
|
|
|
2017-10-24 14:24:07 +00:00
|
|
|
var _ = Describe("Reading from the Geth blockchain", func() {
|
|
|
|
|
2018-01-05 17:55:00 +00:00
|
|
|
var blockchain *geth.Blockchain
|
|
|
|
var repository *repositories.InMemory
|
2017-11-03 13:54:32 +00:00
|
|
|
|
|
|
|
BeforeEach(func() {
|
2017-11-09 14:00:02 +00:00
|
|
|
cfg, _ := config.NewConfig("private")
|
2018-01-05 17:55:00 +00:00
|
|
|
blockchain = geth.NewBlockchain(cfg.Client.IPCPath)
|
|
|
|
repository = repositories.NewInMemory()
|
2017-11-03 13:54:32 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("reads two blocks", func(done Done) {
|
2018-01-05 17:55:00 +00:00
|
|
|
validator := history.NewBlockValidator(blockchain, repository, 2)
|
|
|
|
validator.ValidateBlocks()
|
|
|
|
Expect(repository.BlockCount()).To(Equal(2))
|
2017-10-24 14:24:07 +00:00
|
|
|
close(done)
|
2017-12-04 18:54:33 +00:00
|
|
|
}, 15)
|
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) {
|
|
|
|
genesisBlock := blockchain.GetBlockByNumber(int64(0))
|
|
|
|
firstBlock := blockchain.GetBlockByNumber(int64(1))
|
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()
|
|
|
|
devNetworkGenesisBlock := "0xe5be92145a301820111f91866566e3e99ee344d155569e4556a39bc71238f3bc"
|
|
|
|
devNetworkNodeId := float64(1)
|
|
|
|
|
|
|
|
Expect(node.GenesisBlock).To(Equal(devNetworkGenesisBlock))
|
|
|
|
Expect(node.NetworkId).To(Equal(devNetworkNodeId))
|
|
|
|
|
|
|
|
close(done)
|
|
|
|
}, 15)
|
|
|
|
|
2017-10-24 14:24:07 +00:00
|
|
|
})
|