2017-10-24 14:24:07 +00:00
|
|
|
package integration_test
|
|
|
|
|
|
|
|
import (
|
2017-11-06 18:53:43 +00:00
|
|
|
"github.com/8thlight/vulcanizedb/pkg/blockchain_listener"
|
|
|
|
"github.com/8thlight/vulcanizedb/pkg/config"
|
|
|
|
"github.com/8thlight/vulcanizedb/pkg/core"
|
|
|
|
"github.com/8thlight/vulcanizedb/pkg/fakes"
|
|
|
|
"github.com/8thlight/vulcanizedb/pkg/geth"
|
2017-10-30 19:39:00 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2017-10-24 14:24:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Reading from the Geth blockchain", func() {
|
|
|
|
|
2017-11-03 13:54:32 +00:00
|
|
|
var listener blockchain_listener.BlockchainListener
|
|
|
|
var observer *fakes.BlockchainObserver
|
2017-11-06 20:36:12 +00:00
|
|
|
var blockchain *geth.GethBlockchain
|
2017-11-03 13:54:32 +00:00
|
|
|
|
|
|
|
BeforeEach(func() {
|
2017-11-06 16:52:07 +00:00
|
|
|
observer = fakes.NewFakeBlockchainObserver()
|
2017-11-09 14:00:02 +00:00
|
|
|
cfg, _ := config.NewConfig("private")
|
2017-11-06 20:36:12 +00:00
|
|
|
blockchain = geth.NewGethBlockchain(cfg.Client.IPCPath)
|
2017-11-02 11:41:24 +00:00
|
|
|
observers := []core.BlockchainObserver{observer}
|
2017-11-03 13:54:32 +00:00
|
|
|
listener = blockchain_listener.NewBlockchainListener(blockchain, observers)
|
|
|
|
})
|
|
|
|
|
|
|
|
AfterEach(func() {
|
|
|
|
listener.Stop()
|
|
|
|
})
|
|
|
|
|
|
|
|
It("reads two blocks", func(done Done) {
|
2017-11-02 11:41:24 +00:00
|
|
|
go listener.Start()
|
2017-10-24 14:24:07 +00:00
|
|
|
|
2017-11-02 11:41:24 +00:00
|
|
|
<-observer.WasNotified
|
|
|
|
firstBlock := observer.LastBlock()
|
|
|
|
Expect(firstBlock).NotTo(BeNil())
|
2017-10-24 14:24:07 +00:00
|
|
|
|
2017-11-02 11:41:24 +00:00
|
|
|
<-observer.WasNotified
|
|
|
|
secondBlock := observer.LastBlock()
|
|
|
|
Expect(secondBlock).NotTo(BeNil())
|
2017-10-24 14:24:07 +00:00
|
|
|
|
2017-10-31 17:51:05 +00:00
|
|
|
Expect(firstBlock.Number + 1).Should(Equal(secondBlock.Number))
|
2017-10-24 14:24:07 +00:00
|
|
|
|
|
|
|
close(done)
|
2017-10-25 14:02:12 +00:00
|
|
|
}, 10)
|
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))
|
|
|
|
|
|
|
|
Expect(genesisBlock.Number).To(Equal(int64(0)))
|
|
|
|
Expect(firstBlock.Number).To(Equal(int64(1)))
|
|
|
|
|
|
|
|
close(done)
|
|
|
|
}, 10)
|
|
|
|
|
2017-10-24 14:24:07 +00:00
|
|
|
})
|