2018-07-26 18:57:38 +00:00
|
|
|
package pip_test
|
2018-07-24 16:38:49 +00:00
|
|
|
|
|
|
|
import (
|
2018-07-26 18:57:38 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2018-07-24 16:38:49 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
2018-07-26 18:57:38 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/price_feeds"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/price_feeds/pip"
|
2018-07-24 16:38:49 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/test_config"
|
|
|
|
)
|
|
|
|
|
2018-07-26 18:57:38 +00:00
|
|
|
var _ = Describe("Pip transformer", func() {
|
2018-07-24 16:38:49 +00:00
|
|
|
It("returns nil if no logs found", func() {
|
|
|
|
chain := fakes.NewMockBlockChain()
|
|
|
|
db := test_config.NewTestDB(core.Node{})
|
2018-07-26 18:57:38 +00:00
|
|
|
transformer := pip.NewPipTransformer(chain, db)
|
2018-07-24 16:38:49 +00:00
|
|
|
|
|
|
|
err := transformer.Execute(core.Header{}, 123)
|
|
|
|
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
})
|
|
|
|
|
2018-07-26 18:57:38 +00:00
|
|
|
It("creates pip row for found log", func() {
|
2018-07-24 16:38:49 +00:00
|
|
|
chain := fakes.NewMockBlockChain()
|
|
|
|
chain.SetGetEthLogsWithCustomQueryReturnLogs([]types.Log{{Data: []byte{1, 2, 3, 4, 5}}})
|
|
|
|
db := test_config.NewTestDB(core.Node{})
|
2018-07-26 18:57:38 +00:00
|
|
|
test_config.CleanTestDB(db)
|
2018-07-24 16:38:49 +00:00
|
|
|
headerRepository := repositories.NewHeaderRepository(db)
|
|
|
|
header := core.Header{BlockNumber: 12345}
|
|
|
|
headerID, err := headerRepository.CreateOrUpdateHeader(header)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-07-26 18:57:38 +00:00
|
|
|
transformer := pip.NewPipTransformer(chain, db)
|
2018-07-24 16:38:49 +00:00
|
|
|
|
|
|
|
err = transformer.Execute(header, headerID)
|
|
|
|
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-07-26 18:57:38 +00:00
|
|
|
var dbPip price_feeds.PriceUpdate
|
|
|
|
err = db.Get(&dbPip, `SELECT block_number, header_id, usd_value FROM maker.pips WHERE header_id = $1`, headerID)
|
2018-07-24 16:38:49 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-07-26 18:57:38 +00:00
|
|
|
Expect(dbPip.BlockNumber).To(Equal(header.BlockNumber))
|
2018-07-24 16:38:49 +00:00
|
|
|
})
|
|
|
|
})
|