From fdbe0b0b445157fa75d73e52c7f528f4db5a30d2 Mon Sep 17 00:00:00 2001 From: Rob Mulholand Date: Wed, 17 Oct 2018 16:01:48 -0500 Subject: [PATCH] Add Vat heal integration test --- ...39809713_update_vat_heal_rad_type.down.sql | 1 + ...1539809713_update_vat_heal_rad_type.up.sql | 1 + db/schema.sql | 2 +- .../integration_tests/vat_heal.go | 59 +++++++++++++++++++ pkg/transformers/test_data/vat_heal.go | 6 +- pkg/transformers/vat_heal/converter.go | 10 ++-- pkg/transformers/vat_heal/model.go | 2 +- pkg/transformers/vat_heal/repository.go | 2 +- 8 files changed, 72 insertions(+), 11 deletions(-) create mode 100644 db/migrations/1539809713_update_vat_heal_rad_type.down.sql create mode 100644 db/migrations/1539809713_update_vat_heal_rad_type.up.sql create mode 100644 pkg/transformers/integration_tests/vat_heal.go diff --git a/db/migrations/1539809713_update_vat_heal_rad_type.down.sql b/db/migrations/1539809713_update_vat_heal_rad_type.down.sql new file mode 100644 index 00000000..b581b5a6 --- /dev/null +++ b/db/migrations/1539809713_update_vat_heal_rad_type.down.sql @@ -0,0 +1 @@ +ALTER TABLE maker.vat_heal ALTER COLUMN rad SET DATA TYPE int; \ No newline at end of file diff --git a/db/migrations/1539809713_update_vat_heal_rad_type.up.sql b/db/migrations/1539809713_update_vat_heal_rad_type.up.sql new file mode 100644 index 00000000..aeade49d --- /dev/null +++ b/db/migrations/1539809713_update_vat_heal_rad_type.up.sql @@ -0,0 +1 @@ +ALTER TABLE maker.vat_heal ALTER COLUMN rad SET DATA TYPE numeric; \ No newline at end of file diff --git a/db/schema.sql b/db/schema.sql index e20e7297..14426a85 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -815,7 +815,7 @@ CREATE TABLE maker.vat_heal ( header_id integer NOT NULL, urn character varying, v character varying, - rad integer, + rad numeric, tx_idx integer NOT NULL, raw_log jsonb ); diff --git a/pkg/transformers/integration_tests/vat_heal.go b/pkg/transformers/integration_tests/vat_heal.go new file mode 100644 index 00000000..dd6c37aa --- /dev/null +++ b/pkg/transformers/integration_tests/vat_heal.go @@ -0,0 +1,59 @@ +// 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 + +import ( + "github.com/ethereum/go-ethereum/common" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + "github.com/vulcanize/vulcanizedb/pkg/transformers/vat_heal" + "github.com/vulcanize/vulcanizedb/test_config" +) + +var _ = Describe("VatHeal Transformer", func() { + It("transforms VatHeal log events", func() { + blockNumber := int64(8935578) + config := vat_heal.VatHealConfig + config.StartingBlockNumber = blockNumber + config.EndingBlockNumber = blockNumber + + 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) + + err = persistHeader(rpcClient, db, blockNumber) + Expect(err).NotTo(HaveOccurred()) + + initializer := vat_heal.VatHealTransformerInitializer{Config: config} + transformer := initializer.NewVatHealTransformer(db, blockchain) + err = transformer.Execute() + Expect(err).NotTo(HaveOccurred()) + + var dbResults []vat_heal.VatHealModel + err = db.Select(&dbResults, `SELECT urn, v, rad from maker.vat_heal`) + Expect(err).NotTo(HaveOccurred()) + + Expect(len(dbResults)).To(Equal(1)) + dbResult := dbResults[0] + Expect(dbResult.Urn).To(Equal(common.HexToAddress("0x0000000000000000000000003728e9777b2a0a611ee0f89e00e01044ce4736d1").String())) + Expect(dbResult.V).To(Equal(common.HexToAddress("0x0000000000000000000000003728e9777b2a0a611ee0f89e00e01044ce4736d1").String())) + Expect(dbResult.Rad).To(Equal("1000000000000000000000000000")) + }) +}) diff --git a/pkg/transformers/test_data/vat_heal.go b/pkg/transformers/test_data/vat_heal.go index 871be81a..6c6bdce3 100644 --- a/pkg/transformers/test_data/vat_heal.go +++ b/pkg/transformers/test_data/vat_heal.go @@ -26,8 +26,8 @@ var VatHealLog = types.Log{ Address: common.HexToAddress("0xa970ed54e41d9db6d91db5e7ff7a9451dad98993"), Topics: []common.Hash{ common.HexToHash("0x990a5f6300000000000000000000000000000000000000000000000000000000"), - common.HexToHash("0x7d7bee5fcfd8028cf7b00876c5b1421c800561a6000000000000000000000000"), - common.HexToHash("0x7340e006f4135ba6970d43bf43d88dcad4e7a8ca000000000000000000000000"), + common.HexToHash("0x0000000000000000000000007d7bee5fcfd8028cf7b00876c5b1421c800561a6"), + common.HexToHash("0x0000000000000000000000007340e006f4135ba6970d43bf43d88dcad4e7a8ca"), common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000078"), }, Data: hexutil.MustDecode("0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000064990a5f637d7bee5fcfd8028cf7b00876c5b1421c800561a600000000000000000000000074686520762076616c75650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000078"), @@ -43,7 +43,7 @@ var rawHealLog, _ = json.Marshal(VatHealLog) var VatHealModel = vat_heal.VatHealModel{ Urn: "0x7d7bEe5fCfD8028cf7b00876C5b1421c800561A6", V: "0x7340e006f4135BA6970D43bf43d88DCAD4e7a8CA", - Rad: 120, + Rad: "120", TransactionIndex: 2, Raw: rawHealLog, } diff --git a/pkg/transformers/vat_heal/converter.go b/pkg/transformers/vat_heal/converter.go index eda40eac..d00c9bae 100644 --- a/pkg/transformers/vat_heal/converter.go +++ b/pkg/transformers/vat_heal/converter.go @@ -17,9 +17,9 @@ package vat_heal import ( "encoding/json" "errors" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "strconv" ) type Converter interface { @@ -36,9 +36,9 @@ func (VatHealConverter) ToModels(ethLogs []types.Log) ([]VatHealModel, error) { return nil, err } - urn := common.BytesToAddress(ethLog.Topics[1].Bytes()[:common.AddressLength]) - v := common.BytesToAddress(ethLog.Topics[2].Bytes()[:common.AddressLength]) - radInt, err := strconv.ParseInt(ethLog.Topics[3].Hex(), 0, 64) + urn := common.BytesToAddress(ethLog.Topics[1].Bytes()) + v := common.BytesToAddress(ethLog.Topics[2].Bytes()) + radInt := ethLog.Topics[3].Big() if err != nil { return nil, err } @@ -51,7 +51,7 @@ func (VatHealConverter) ToModels(ethLogs []types.Log) ([]VatHealModel, error) { model := VatHealModel{ Urn: urn.String(), V: v.String(), - Rad: int(radInt), + Rad: radInt.String(), TransactionIndex: ethLog.TxIndex, Raw: rawLogJson, } diff --git a/pkg/transformers/vat_heal/model.go b/pkg/transformers/vat_heal/model.go index 304a7224..0a309118 100644 --- a/pkg/transformers/vat_heal/model.go +++ b/pkg/transformers/vat_heal/model.go @@ -17,7 +17,7 @@ package vat_heal type VatHealModel struct { Urn string V string - Rad int + Rad string TransactionIndex uint `db:"tx_idx"` Raw []byte `db:"raw_log"` } diff --git a/pkg/transformers/vat_heal/repository.go b/pkg/transformers/vat_heal/repository.go index 55e862d9..cef55f43 100644 --- a/pkg/transformers/vat_heal/repository.go +++ b/pkg/transformers/vat_heal/repository.go @@ -41,7 +41,7 @@ func (repository VatHealRepository) Create(headerId int64, models []VatHealModel for _, model := range models { _, err := tx.Exec(`INSERT INTO maker.vat_heal (header_id, urn, v, rad, tx_idx, raw_log) - VALUES($1, $2, $3, $4, $5, $6)`, + VALUES($1, $2, $3, $4::NUMERIC, $5, $6)`, headerId, model.Urn, model.V, model.Rad, model.TransactionIndex, model.Raw) if err != nil { tx.Rollback()