ipld-eth-server/pkg/transformers/integration_tests/vat_slip.go

137 lines
5.2 KiB
Go
Raw Normal View History

2018-10-15 20:04:17 +00:00
package integration_tests
import (
"github.com/ethereum/go-ethereum/common"
2018-10-15 20:04:17 +00:00
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
2018-10-25 00:42:42 +00:00
2018-10-15 20:04:17 +00:00
"github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
2018-10-25 00:42:42 +00:00
"github.com/vulcanize/vulcanizedb/pkg/transformers/factories"
2018-10-15 20:04:17 +00:00
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/vat_slip"
"github.com/vulcanize/vulcanizedb/test_config"
)
var _ = Describe("Vat slip transformer", func() {
var (
db *postgres.DB
blockChain core.BlockChain
)
BeforeEach(func() {
2018-10-15 20:04:17 +00:00
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-10-15 20:04:17 +00:00
It("persists vat slip event", func() {
blockNumber := int64(8953655)
config := shared.TransformerConfig{
TransformerName: constants.VatSlipLabel,
ContractAddresses: []string{test_data.KovanVatContractAddress},
ContractAbi: test_data.KovanVatABI,
Topic: test_data.KovanVatSlipSignature,
StartingBlockNumber: blockNumber,
EndingBlockNumber: blockNumber,
}
header, err := persistHeader(db, blockNumber, blockChain)
Expect(err).NotTo(HaveOccurred())
fetcher := shared.NewFetcher(blockChain)
logs, err := fetcher.FetchLogs(
shared.HexStringsToAddresses(config.ContractAddresses),
[]common.Hash{common.HexToHash(config.Topic)},
header)
2018-10-15 20:04:17 +00:00
Expect(err).NotTo(HaveOccurred())
transformer := factories.LogNoteTransformer{
2018-10-25 00:42:42 +00:00
Config: config,
Converter: &vat_slip.VatSlipConverter{},
Repository: &vat_slip.VatSlipRepository{},
}.NewLogNoteTransformer(db)
2018-10-15 20:04:17 +00:00
err = transformer.Execute(logs, header, constants.HeaderMissing)
2018-10-15 20:04:17 +00:00
Expect(err).NotTo(HaveOccurred())
var headerID int64
err = db.Get(&headerID, `SELECT id FROM public.headers WHERE block_number = $1`, blockNumber)
2018-10-15 20:04:17 +00:00
Expect(err).NotTo(HaveOccurred())
var model vat_slip.VatSlipModel
err = db.Get(&model, `SELECT ilk, guy, rad, tx_idx FROM maker.vat_slip WHERE header_id = $1`, headerID)
Expect(err).NotTo(HaveOccurred())
Expect(model.Ilk).To(Equal("4554480000000000000000000000000000000000000000000000000000000000"))
Expect(model.Guy).To(Equal("000000000000000000000000da15dce70ab462e66779f23ee14f21d993789ee3"))
2018-10-15 20:04:17 +00:00
Expect(model.Rad).To(Equal("100000000000000000000000000000000000000000000000"))
Expect(model.TransactionIndex).To(Equal(uint(0)))
var headerChecked bool
err = db.Get(&headerChecked, `SELECT vat_slip_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
Expect(err).NotTo(HaveOccurred())
Expect(headerChecked).To(BeTrue())
})
It("rechecks vat slip event", func() {
blockNumber := int64(8953655)
config := shared.TransformerConfig{
TransformerName: constants.VatSlipLabel,
ContractAddresses: []string{test_data.KovanVatContractAddress},
ContractAbi: test_data.KovanVatABI,
Topic: test_data.KovanVatSlipSignature,
StartingBlockNumber: blockNumber,
EndingBlockNumber: blockNumber,
}
header, err := persistHeader(db, blockNumber, blockChain)
Expect(err).NotTo(HaveOccurred())
fetcher := shared.NewFetcher(blockChain)
logs, err := fetcher.FetchLogs(
shared.HexStringsToAddresses(config.ContractAddresses),
[]common.Hash{common.HexToHash(config.Topic)},
header)
Expect(err).NotTo(HaveOccurred())
transformer := factories.LogNoteTransformer{
Config: config,
Converter: &vat_slip.VatSlipConverter{},
Repository: &vat_slip.VatSlipRepository{},
}.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 vatSlipChecked []int
err = db.Select(&vatSlipChecked, `SELECT vat_slip_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
Expect(err).NotTo(HaveOccurred())
Expect(vatSlipChecked[0]).To(Equal(2))
err = db.Get(&headerID, `SELECT id FROM public.headers WHERE block_number = $1`, blockNumber)
Expect(err).NotTo(HaveOccurred())
var model vat_slip.VatSlipModel
err = db.Get(&model, `SELECT ilk, guy, rad, tx_idx FROM maker.vat_slip WHERE header_id = $1`, headerID)
Expect(err).NotTo(HaveOccurred())
Expect(model.Ilk).To(Equal("4554480000000000000000000000000000000000000000000000000000000000"))
Expect(model.Guy).To(Equal("000000000000000000000000da15dce70ab462e66779f23ee14f21d993789ee3"))
Expect(model.Rad).To(Equal("100000000000000000000000000000000000000000000000"))
Expect(model.TransactionIndex).To(Equal(uint(0)))
var headerChecked int
err = db.Get(&headerChecked, `SELECT vat_slip_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
Expect(err).NotTo(HaveOccurred())
Expect(headerChecked).To(Equal(2))
})
2018-10-15 20:04:17 +00:00
})