ipld-eth-server/core/fake_blockchain_test.go
Eric Meyer de2cb3b5cc Start introducing domain concepts
* Potential observers include a logger and/or an observer that writes to the DB
2017-10-23 12:08:59 -05:00

49 lines
1.4 KiB
Go

package core_test
import (
"math/big"
"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("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: big.NewInt(123)})
Expect(blockchainObserver.LastAddedBlock.Number).ShouldNot(BeNil())
Expect(blockchainObserver.LastAddedBlock.Number).Should(Equal(big.NewInt(123)))
})
})