2018-10-17 18:04:55 +00:00
|
|
|
// Copyright 2018 Vulcanize
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package integration_tests
|
2018-09-18 15:55:46 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2018-10-11 20:25:14 +00:00
|
|
|
|
2018-09-18 15:55:46 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
2018-10-25 18:25:36 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
|
2018-09-18 15:55:46 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/price_feeds"
|
2018-10-25 18:25:36 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
2018-11-08 15:14:35 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
2018-09-18 15:55:46 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/test_config"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Price feeds transformer", func() {
|
|
|
|
var (
|
|
|
|
db *postgres.DB
|
|
|
|
blockChain core.BlockChain
|
|
|
|
)
|
|
|
|
|
|
|
|
BeforeEach(func() {
|
|
|
|
rpcClient, ethClient, err := getClients(ipc)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
blockChain, err = getBlockChain(rpcClient, ethClient)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
db = test_config.NewTestDB(blockChain.Node())
|
|
|
|
test_config.CleanTestDB(db)
|
|
|
|
})
|
|
|
|
|
|
|
|
It("persists a ETH/USD price feed event", func() {
|
2018-10-22 19:54:09 +00:00
|
|
|
blockNumber := int64(8763054)
|
2018-11-12 20:59:16 +00:00
|
|
|
err := persistHeader(db, blockNumber, blockChain)
|
2018-10-22 19:54:09 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-10-25 18:25:36 +00:00
|
|
|
config := price_feeds.PriceFeedConfig
|
2018-11-08 15:14:35 +00:00
|
|
|
config.ContractAddresses = []string{constants.PipContractAddress}
|
2018-10-25 18:25:36 +00:00
|
|
|
config.StartingBlockNumber = blockNumber
|
|
|
|
config.EndingBlockNumber = blockNumber
|
|
|
|
|
2018-10-26 18:26:10 +00:00
|
|
|
transformerInitializer := factories.LogNoteTransformer{
|
2018-10-25 18:25:36 +00:00
|
|
|
Config: config,
|
|
|
|
Converter: &price_feeds.PriceFeedConverter{},
|
|
|
|
Repository: &price_feeds.PriceFeedRepository{},
|
|
|
|
Fetcher: &shared.Fetcher{},
|
2018-09-18 15:55:46 +00:00
|
|
|
}
|
2018-10-26 18:26:10 +00:00
|
|
|
transformer := transformerInitializer.NewLogNoteTransformer(db, blockChain)
|
2018-09-18 15:55:46 +00:00
|
|
|
|
2018-10-22 19:54:09 +00:00
|
|
|
err = transformer.Execute()
|
2018-09-18 15:55:46 +00:00
|
|
|
|
2018-10-22 19:54:09 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
var model price_feeds.PriceFeedModel
|
|
|
|
err = db.Get(&model, `SELECT block_number, medianizer_address, usd_value, tx_idx, raw_log FROM maker.price_feeds WHERE block_number = $1`, config.StartingBlockNumber)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-11-09 20:53:20 +00:00
|
|
|
Expect(model.UsdValue).To(Equal("207.314891143000011198"))
|
2018-10-22 19:54:09 +00:00
|
|
|
Expect(model.MedianizerAddress).To(Equal(config.ContractAddresses[0]))
|
2018-09-18 15:55:46 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("persists a MKR/USD price feed event", func() {
|
2018-10-22 19:54:09 +00:00
|
|
|
blockNumber := int64(8763059)
|
2018-11-12 20:59:16 +00:00
|
|
|
err := persistHeader(db, blockNumber, blockChain)
|
2018-10-22 19:54:09 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-10-25 18:25:36 +00:00
|
|
|
config := price_feeds.PriceFeedConfig
|
2018-11-08 15:14:35 +00:00
|
|
|
config.ContractAddresses = []string{constants.PepContractAddress}
|
2018-10-25 18:25:36 +00:00
|
|
|
config.StartingBlockNumber = blockNumber
|
|
|
|
config.EndingBlockNumber = blockNumber
|
|
|
|
|
2018-10-26 18:26:10 +00:00
|
|
|
transformerInitializer := factories.LogNoteTransformer{
|
2018-10-25 18:25:36 +00:00
|
|
|
Config: config,
|
|
|
|
Converter: &price_feeds.PriceFeedConverter{},
|
|
|
|
Repository: &price_feeds.PriceFeedRepository{},
|
|
|
|
Fetcher: &shared.Fetcher{},
|
2018-09-18 15:55:46 +00:00
|
|
|
}
|
2018-10-26 18:26:10 +00:00
|
|
|
transformer := transformerInitializer.NewLogNoteTransformer(db, blockChain)
|
2018-09-18 15:55:46 +00:00
|
|
|
|
2018-10-22 19:54:09 +00:00
|
|
|
err = transformer.Execute()
|
2018-09-18 15:55:46 +00:00
|
|
|
|
2018-10-22 19:54:09 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
var model price_feeds.PriceFeedModel
|
|
|
|
err = db.Get(&model, `SELECT block_number, medianizer_address, usd_value, tx_idx, raw_log FROM maker.price_feeds WHERE block_number = $1`, config.StartingBlockNumber)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-11-09 20:53:20 +00:00
|
|
|
Expect(model.UsdValue).To(Equal("391.803979212000001553"))
|
2018-10-22 19:54:09 +00:00
|
|
|
Expect(model.MedianizerAddress).To(Equal(config.ContractAddresses[0]))
|
2018-09-18 15:55:46 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("persists a REP/USD price feed event", func() {
|
2018-10-22 19:54:09 +00:00
|
|
|
blockNumber := int64(8763062)
|
2018-11-12 20:59:16 +00:00
|
|
|
err := persistHeader(db, blockNumber, blockChain)
|
2018-10-22 19:54:09 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-10-25 18:25:36 +00:00
|
|
|
config := price_feeds.PriceFeedConfig
|
2018-11-08 15:14:35 +00:00
|
|
|
config.ContractAddresses = []string{constants.RepContractAddress}
|
2018-10-25 18:25:36 +00:00
|
|
|
config.StartingBlockNumber = blockNumber
|
|
|
|
config.EndingBlockNumber = blockNumber
|
|
|
|
|
2018-10-26 18:26:10 +00:00
|
|
|
transformerInitializer := factories.LogNoteTransformer{
|
2018-10-25 18:25:36 +00:00
|
|
|
Config: config,
|
|
|
|
Converter: &price_feeds.PriceFeedConverter{},
|
|
|
|
Repository: &price_feeds.PriceFeedRepository{},
|
|
|
|
Fetcher: &shared.Fetcher{},
|
2018-09-18 15:55:46 +00:00
|
|
|
}
|
2018-10-26 18:26:10 +00:00
|
|
|
transformer := transformerInitializer.NewLogNoteTransformer(db, blockChain)
|
2018-09-18 15:55:46 +00:00
|
|
|
|
2018-10-22 19:54:09 +00:00
|
|
|
err = transformer.Execute()
|
2018-09-18 15:55:46 +00:00
|
|
|
|
2018-10-22 19:54:09 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
var model price_feeds.PriceFeedModel
|
|
|
|
err = db.Get(&model, `SELECT block_number, medianizer_address, usd_value, tx_idx, raw_log FROM maker.price_feeds WHERE block_number = $1`, config.StartingBlockNumber)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-11-09 20:53:20 +00:00
|
|
|
Expect(model.UsdValue).To(Equal("12.816928482699999847"))
|
2018-10-22 19:54:09 +00:00
|
|
|
Expect(model.MedianizerAddress).To(Equal(config.ContractAddresses[0]))
|
2018-09-18 15:55:46 +00:00
|
|
|
})
|
|
|
|
})
|