2019-01-24 20:41:30 +00:00
|
|
|
// VulcanizeDB // Copyright © 2018 Vulcanize // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-10-17 18:04:55 +00:00
|
|
|
|
|
|
|
package integration_tests
|
2018-09-18 15:55:46 +00:00
|
|
|
|
|
|
|
import (
|
2018-12-07 17:10:36 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2018-09-18 15:55:46 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2019-01-23 18:44:09 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
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-09-18 15:55:46 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/test_config"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Price feeds transformer", func() {
|
|
|
|
var (
|
2018-12-07 17:10:36 +00:00
|
|
|
db *postgres.DB
|
|
|
|
blockChain core.BlockChain
|
|
|
|
config shared.TransformerConfig
|
2018-12-12 14:41:44 +00:00
|
|
|
fetcher *shared.Fetcher
|
2018-12-07 17:10:36 +00:00
|
|
|
initializer factories.LogNoteTransformer
|
2018-12-10 16:12:51 +00:00
|
|
|
topics []common.Hash
|
2018-09-18 15:55:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
2018-12-10 16:12:51 +00:00
|
|
|
|
2019-01-23 18:44:09 +00:00
|
|
|
config = shared.TransformerConfig{
|
|
|
|
TransformerName: constants.PriceFeedLabel,
|
|
|
|
ContractAddresses: []string{
|
|
|
|
test_data.KovanPepContractAddress,
|
|
|
|
test_data.KovanPipContractAddress,
|
|
|
|
test_data.KovanRepContractAddress,
|
|
|
|
},
|
|
|
|
ContractAbi: test_data.KovanMedianizerABI,
|
|
|
|
Topic: test_data.KovanLogValueSignature,
|
|
|
|
StartingBlockNumber: 0,
|
|
|
|
EndingBlockNumber: -1,
|
|
|
|
}
|
|
|
|
|
2018-12-10 16:12:51 +00:00
|
|
|
topics = []common.Hash{common.HexToHash(config.Topic)}
|
|
|
|
|
2018-12-07 17:10:36 +00:00
|
|
|
fetcher = shared.NewFetcher(blockChain)
|
2018-10-25 18:25:36 +00:00
|
|
|
|
2018-12-07 17:10:36 +00:00
|
|
|
initializer = factories.LogNoteTransformer{
|
2018-10-25 18:25:36 +00:00
|
|
|
Config: config,
|
|
|
|
Converter: &price_feeds.PriceFeedConverter{},
|
|
|
|
Repository: &price_feeds.PriceFeedRepository{},
|
2018-09-18 15:55:46 +00:00
|
|
|
}
|
2018-12-07 17:10:36 +00:00
|
|
|
})
|
2018-09-18 15:55:46 +00:00
|
|
|
|
2018-12-07 17:10:36 +00:00
|
|
|
It("persists a ETH/USD price feed event", func() {
|
|
|
|
blockNumber := int64(8763054)
|
|
|
|
header, err := persistHeader(db, blockNumber, blockChain)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2019-01-23 18:44:09 +00:00
|
|
|
addresses := []string{test_data.KovanPipContractAddress}
|
2018-12-10 16:12:51 +00:00
|
|
|
initializer.Config.ContractAddresses = addresses
|
2018-12-07 17:10:36 +00:00
|
|
|
initializer.Config.StartingBlockNumber = blockNumber
|
|
|
|
initializer.Config.EndingBlockNumber = blockNumber
|
|
|
|
|
|
|
|
logs, err := fetcher.FetchLogs(
|
2018-12-10 16:12:51 +00:00
|
|
|
shared.HexStringsToAddresses(addresses),
|
|
|
|
topics,
|
2018-12-07 17:10:36 +00:00
|
|
|
header)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
transformer := initializer.NewLogNoteTransformer(db)
|
2019-02-08 16:35:46 +00:00
|
|
|
err = transformer.Execute(logs, header, constants.HeaderMissing)
|
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
|
2018-12-07 17:10:36 +00:00
|
|
|
err = db.Get(&model, `SELECT block_number, medianizer_address, usd_value, tx_idx, raw_log FROM maker.price_feeds WHERE block_number = $1`, initializer.Config.StartingBlockNumber)
|
2018-10-22 19:54:09 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-11-09 20:53:20 +00:00
|
|
|
Expect(model.UsdValue).To(Equal("207.314891143000011198"))
|
2018-12-10 16:12:51 +00:00
|
|
|
Expect(model.MedianizerAddress).To(Equal(addresses[0]))
|
2018-09-18 15:55:46 +00:00
|
|
|
})
|
|
|
|
|
2019-02-08 16:35:46 +00:00
|
|
|
It("rechecks price feed event", func() {
|
|
|
|
blockNumber := int64(8763054)
|
|
|
|
header, err := persistHeader(db, blockNumber, blockChain)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
addresses := []string{test_data.KovanPipContractAddress}
|
|
|
|
initializer.Config.ContractAddresses = addresses
|
|
|
|
initializer.Config.StartingBlockNumber = blockNumber
|
|
|
|
initializer.Config.EndingBlockNumber = blockNumber
|
|
|
|
|
|
|
|
logs, err := fetcher.FetchLogs(
|
|
|
|
shared.HexStringsToAddresses(addresses),
|
|
|
|
topics,
|
|
|
|
header)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
transformer := initializer.NewLogNoteTransformer(db)
|
|
|
|
err = transformer.Execute(logs, header, constants.HeaderMissing)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
err = transformer.Execute(logs, header, constants.HeaderRecheck)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
var headerID int64
|
|
|
|
err = db.Get(&headerID, `SELECT id FROM public.headers WHERE block_number = $1`, blockNumber)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
var priceFeedChecked []int
|
|
|
|
err = db.Select(&priceFeedChecked, `SELECT price_feeds_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(priceFeedChecked[0]).To(Equal(2))
|
|
|
|
|
|
|
|
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`, initializer.Config.StartingBlockNumber)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(model.UsdValue).To(Equal("207.314891143000011198"))
|
|
|
|
Expect(model.MedianizerAddress).To(Equal(addresses[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-12-07 17:10:36 +00:00
|
|
|
header, err := persistHeader(db, blockNumber, blockChain)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2019-01-23 18:44:09 +00:00
|
|
|
addresses := []string{test_data.KovanPepContractAddress}
|
2018-12-10 16:12:51 +00:00
|
|
|
initializer.Config.ContractAddresses = addresses
|
2018-12-07 17:10:36 +00:00
|
|
|
initializer.Config.StartingBlockNumber = blockNumber
|
|
|
|
initializer.Config.EndingBlockNumber = blockNumber
|
|
|
|
|
|
|
|
logs, err := fetcher.FetchLogs(
|
2018-12-10 16:12:51 +00:00
|
|
|
shared.HexStringsToAddresses(addresses),
|
|
|
|
topics,
|
2018-12-07 17:10:36 +00:00
|
|
|
header)
|
2018-10-22 19:54:09 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-09-18 15:55:46 +00:00
|
|
|
|
2018-12-07 17:10:36 +00:00
|
|
|
transformer := initializer.NewLogNoteTransformer(db)
|
2019-02-08 16:35:46 +00:00
|
|
|
err = transformer.Execute(logs, header, constants.HeaderMissing)
|
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
|
2018-12-07 17:10:36 +00:00
|
|
|
err = db.Get(&model, `SELECT block_number, medianizer_address, usd_value, tx_idx, raw_log FROM maker.price_feeds WHERE block_number = $1`, initializer.Config.StartingBlockNumber)
|
2018-10-22 19:54:09 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-11-09 20:53:20 +00:00
|
|
|
Expect(model.UsdValue).To(Equal("391.803979212000001553"))
|
2018-12-10 16:12:51 +00:00
|
|
|
Expect(model.MedianizerAddress).To(Equal(addresses[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-12-07 17:10:36 +00:00
|
|
|
header, err := persistHeader(db, blockNumber, blockChain)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2019-01-23 18:44:09 +00:00
|
|
|
addresses := []string{test_data.KovanRepContractAddress}
|
2018-12-10 16:12:51 +00:00
|
|
|
initializer.Config.ContractAddresses = addresses
|
2018-12-07 17:10:36 +00:00
|
|
|
initializer.Config.StartingBlockNumber = blockNumber
|
|
|
|
initializer.Config.EndingBlockNumber = blockNumber
|
|
|
|
|
|
|
|
logs, err := fetcher.FetchLogs(
|
2018-12-10 16:12:51 +00:00
|
|
|
shared.HexStringsToAddresses(addresses),
|
|
|
|
topics,
|
2018-12-07 17:10:36 +00:00
|
|
|
header)
|
2018-10-22 19:54:09 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-09-18 15:55:46 +00:00
|
|
|
|
2018-12-07 17:10:36 +00:00
|
|
|
transformer := initializer.NewLogNoteTransformer(db)
|
2019-02-08 16:35:46 +00:00
|
|
|
err = transformer.Execute(logs, header, constants.HeaderMissing)
|
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
|
2018-12-07 17:10:36 +00:00
|
|
|
err = db.Get(&model, `SELECT block_number, medianizer_address, usd_value, tx_idx, raw_log FROM maker.price_feeds WHERE block_number = $1`, initializer.Config.StartingBlockNumber)
|
2018-10-22 19:54:09 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-11-09 20:53:20 +00:00
|
|
|
Expect(model.UsdValue).To(Equal("12.816928482699999847"))
|
2018-12-10 16:12:51 +00:00
|
|
|
Expect(model.MedianizerAddress).To(Equal(addresses[0]))
|
2018-09-18 15:55:46 +00:00
|
|
|
})
|
|
|
|
})
|