2017-11-02 19:37:07 +00:00
|
|
|
package observers_test
|
2017-10-25 15:57:59 +00:00
|
|
|
|
|
|
|
import (
|
2017-11-06 18:53:43 +00:00
|
|
|
"github.com/8thlight/vulcanizedb/pkg/core"
|
|
|
|
"github.com/8thlight/vulcanizedb/pkg/observers"
|
|
|
|
"github.com/8thlight/vulcanizedb/pkg/repositories"
|
2017-10-25 15:57:59 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Saving blocks to the database", func() {
|
|
|
|
|
2017-11-06 16:52:07 +00:00
|
|
|
var repository *repositories.InMemory
|
2017-10-25 15:57:59 +00:00
|
|
|
|
|
|
|
BeforeEach(func() {
|
2017-11-06 16:52:07 +00:00
|
|
|
repository = repositories.NewInMemory()
|
2017-11-01 15:17:01 +00:00
|
|
|
})
|
|
|
|
|
2017-10-25 15:57:59 +00:00
|
|
|
It("implements the observer interface", func() {
|
2017-11-06 16:52:07 +00:00
|
|
|
var observer core.BlockchainObserver = observers.NewBlockchainDbObserver(repository)
|
2017-10-25 15:57:59 +00:00
|
|
|
Expect(observer).NotTo(BeNil())
|
|
|
|
})
|
|
|
|
|
2017-11-03 13:01:35 +00:00
|
|
|
It("saves a block with one transaction", func() {
|
2017-11-02 14:36:53 +00:00
|
|
|
block := core.Block{
|
2017-11-03 13:01:35 +00:00
|
|
|
Number: 123,
|
|
|
|
Transactions: []core.Transaction{{}},
|
2017-11-02 14:36:53 +00:00
|
|
|
}
|
2017-10-25 15:57:59 +00:00
|
|
|
|
2017-11-06 16:52:07 +00:00
|
|
|
observer := observers.NewBlockchainDbObserver(repository)
|
2017-10-25 15:57:59 +00:00
|
|
|
observer.NotifyBlockAdded(block)
|
|
|
|
|
2017-12-13 16:51:11 +00:00
|
|
|
savedBlock, err := repository.FindBlockByNumber(123)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2017-11-03 13:01:35 +00:00
|
|
|
Expect(len(savedBlock.Transactions)).To(Equal(1))
|
2017-10-31 13:58:04 +00:00
|
|
|
})
|
|
|
|
|
2017-10-25 15:57:59 +00:00
|
|
|
})
|