2017-10-23 15:56:29 +00:00
|
|
|
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() {
|
|
|
|
|
2017-10-23 18:58:33 +00:00
|
|
|
It("conforms to the Blockchain interface", func() {
|
|
|
|
var blockchain core.Blockchain = &fakes.Blockchain{}
|
|
|
|
Expect(blockchain).ShouldNot(BeNil())
|
|
|
|
})
|
|
|
|
|
2017-10-23 15:56:29 +00:00
|
|
|
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)
|
|
|
|
|
2017-10-31 17:51:05 +00:00
|
|
|
blockchain.AddBlock(core.Block{Number: int64(123)})
|
2017-10-23 15:56:29 +00:00
|
|
|
|
2017-10-24 14:24:07 +00:00
|
|
|
Expect(blockchainObserver.LastAddedBlock().Number).ShouldNot(BeNil())
|
2017-10-31 17:51:05 +00:00
|
|
|
Expect(blockchainObserver.LastAddedBlock().Number).Should(Equal(int64(123)))
|
2017-10-23 15:56:29 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
})
|