2017-10-24 14:24:07 +00:00
|
|
|
package integration_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path"
|
|
|
|
"runtime"
|
2017-10-30 19:39:00 +00:00
|
|
|
|
2017-11-02 19:37:07 +00:00
|
|
|
"github.com/8thlight/vulcanizedb/blockchain_listener"
|
2017-10-30 19:39:00 +00:00
|
|
|
"github.com/8thlight/vulcanizedb/core"
|
2017-11-02 11:41:24 +00:00
|
|
|
"github.com/8thlight/vulcanizedb/fakes"
|
2017-11-02 19:37:07 +00:00
|
|
|
"github.com/8thlight/vulcanizedb/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 (
|
|
|
|
_, filename, _, _ = runtime.Caller(0)
|
|
|
|
)
|
|
|
|
|
|
|
|
func RunTimePath() string {
|
|
|
|
return path.Join(path.Dir(filename), "../")
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ = Describe("Reading from the Geth blockchain", func() {
|
|
|
|
|
2017-11-02 19:37:07 +00:00
|
|
|
It("reads two blocks", func(done Done) {
|
2017-11-02 11:41:24 +00:00
|
|
|
observer := fakes.NewFakeBlockchainObserverTwo()
|
2017-11-02 19:37:07 +00:00
|
|
|
blockchain := geth.NewGethBlockchain(RunTimePath() + "/test_data_dir/geth.ipc")
|
2017-11-02 11:41:24 +00:00
|
|
|
observers := []core.BlockchainObserver{observer}
|
2017-11-02 19:37:07 +00:00
|
|
|
listener := blockchain_listener.NewBlockchainListener(blockchain, observers)
|
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
|
|
|
|
|
|
|
})
|