ipld-eth-server/integration_test/geth_blockchain_test.go
2017-10-25 09:02:12 -05:00

52 lines
1.2 KiB
Go

package integration_test
import (
"fmt"
"github.com/8thlight/vulcanizedb/core"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"math/big"
"path"
"path/filepath"
"runtime"
)
var (
_, filename, _, _ = runtime.Caller(0)
basepath = filepath.Dir(filename)
)
func RunTimePath() string {
return path.Join(path.Dir(filename), "../")
}
type ObserverWithChannel struct {
blocks chan core.Block
}
func (observer *ObserverWithChannel) NotifyBlockAdded(block core.Block) {
fmt.Println("Block: ", block.Number)
observer.blocks <- block
}
var _ = Describe("Reading from the Geth blockchain", func() {
It("reads two blocks with incrementing numbers", func(done Done) {
addedBlock := make(chan core.Block, 10)
observer := &ObserverWithChannel{addedBlock}
var blockchain core.Blockchain = core.NewGethBlockchain(RunTimePath() + "/test_data_dir/geth.ipc")
blockchain.RegisterObserver(observer)
go blockchain.SubscribeToEvents()
firstBlock := <-addedBlock
Expect(firstBlock).ShouldNot(BeNil())
secondBlock := <-addedBlock
Expect(firstBlock.Number.Add(firstBlock.Number, big.NewInt(1))).Should(Equal(secondBlock.Number))
close(done)
}, 10)
})