ipld-eth-server/core/fake_blockchain_test.go
Matt K c961e85099 Refactor block conversion (#38)
Move more of block conversion out of observer
2017-10-31 12:51:05 -05:00

52 lines
1.5 KiB
Go

package core_test
import (
"github.com/8thlight/vulcanizedb/core"
"github.com/8thlight/vulcanizedb/fakes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("The fake blockchain", func() {
It("conforms to the Blockchain interface", func() {
var blockchain core.Blockchain = &fakes.Blockchain{}
Expect(blockchain).ShouldNot(BeNil())
})
It("lets the only observer know when a block was added", func() {
blockchain := fakes.Blockchain{}
blockchainObserver := &fakes.BlockchainObserver{}
blockchain.RegisterObserver(blockchainObserver)
blockchain.AddBlock(core.Block{})
Expect(blockchainObserver.WasToldBlockAdded()).Should(Equal(true))
})
It("lets the second observer know when a block was added", func() {
blockchain := fakes.Blockchain{}
blockchainObserverOne := &fakes.BlockchainObserver{}
blockchainObserverTwo := &fakes.BlockchainObserver{}
blockchain.RegisterObserver(blockchainObserverOne)
blockchain.RegisterObserver(blockchainObserverTwo)
blockchain.AddBlock(core.Block{})
Expect(blockchainObserverTwo.WasToldBlockAdded()).Should(Equal(true))
})
It("passes the added block to the observer", func() {
blockchain := fakes.Blockchain{}
blockchainObserver := &fakes.BlockchainObserver{}
blockchain.RegisterObserver(blockchainObserver)
blockchain.AddBlock(core.Block{Number: int64(123)})
Expect(blockchainObserver.LastAddedBlock().Number).ShouldNot(BeNil())
Expect(blockchainObserver.LastAddedBlock().Number).Should(Equal(int64(123)))
})
})