From 21088eb3a2312f3bbc8cfc6fb5bebbfd24510015 Mon Sep 17 00:00:00 2001 From: Taka Goto Date: Wed, 17 Oct 2018 16:25:12 -0500 Subject: [PATCH] integration test for vat flux --- .../integration_tests/vat_flux.go | 59 +++++++++++++++++++ pkg/transformers/test_data/vat_flux.go | 4 +- pkg/transformers/vat_flux/converter.go | 5 +- 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 pkg/transformers/integration_tests/vat_flux.go diff --git a/pkg/transformers/integration_tests/vat_flux.go b/pkg/transformers/integration_tests/vat_flux.go new file mode 100644 index 00000000..f9b9197f --- /dev/null +++ b/pkg/transformers/integration_tests/vat_flux.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/onsi/ginkgo" + . "github.com/onsi/gomega" + + "github.com/vulcanize/vulcanizedb/pkg/transformers/vat_flux" + "github.com/vulcanize/vulcanizedb/test_config" +) + +var _ = Describe("VatFlux Transformer", func() { + It("transforms VatFlux log events", func() { + blockNumber := int64(9004474) + config := vat_flux.VatFluxConfig + 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_flux.VatFluxTransformerInitializer{Config: config} + transformer := initializer.NewVatFluxTransformer(db, blockchain) + err = transformer.Execute() + Expect(err).NotTo(HaveOccurred()) + + var dbResult []vat_flux.VatFluxModel + err = db.Select(&dbResult, `SELECT ilk, src, dst, rad from maker.vat_flux`) + Expect(err).NotTo(HaveOccurred()) + + Expect(len(dbResult)).To(Equal(1)) + Expect(dbResult[0].Ilk).To(Equal("REP")) + Expect(dbResult[0].Src).To(Equal("0xC0851F73CC8DD5c0765E71980eC7E7Fd1EF74434")) + Expect(dbResult[0].Dst).To(Equal("0x0000d8b4147eDa80Fec7122AE16DA2479Cbd7ffB")) + Expect(dbResult[0].Rad).To(Equal("1800000000000000000000000000000000000000000000")) + Expect(dbResult[0].TransactionIndex).To(Equal(uint(0))) + }) +}) diff --git a/pkg/transformers/test_data/vat_flux.go b/pkg/transformers/test_data/vat_flux.go index 5eb98bc5..e00310bf 100644 --- a/pkg/transformers/test_data/vat_flux.go +++ b/pkg/transformers/test_data/vat_flux.go @@ -28,7 +28,7 @@ var VatFluxLog = types.Log{ Address: common.HexToAddress("0x239e6f0ab02713f1f8aa90ebeded9fc66dc96cd6"), Topics: []common.Hash{ common.HexToHash("0xa6e4182100000000000000000000000000000000000000000000000000000000"), - common.HexToHash("0x0000000000000000000000007340e006f4135BA6970D43bf43d88DCAD4e7a8CA"), + common.HexToHash("0x5245500000000000000000000000000000000000000000000000000000000000"), common.HexToHash("0x0000000000000000000000007FA9EF6609Ca7921112231f8f195138ebba29770"), common.HexToHash("0x00000000000000000000000093086347c52a8878af71bb818509d484c6a2e1bf"), }, @@ -43,7 +43,7 @@ var VatFluxLog = types.Log{ var rawFluxLog, _ = json.Marshal(VatFluxLog) var VatFluxModel = vat_flux.VatFluxModel{ - Ilk: "0x7340e006f4135BA6970D43bf43d88DCAD4e7a8CA", + Ilk: "REP", Src: "0x7FA9EF6609Ca7921112231f8f195138ebba29770", Dst: "0x93086347c52a8878af71bB818509d484c6a2e1bF", Rad: "123", diff --git a/pkg/transformers/vat_flux/converter.go b/pkg/transformers/vat_flux/converter.go index 817a00d3..ad35a67e 100644 --- a/pkg/transformers/vat_flux/converter.go +++ b/pkg/transformers/vat_flux/converter.go @@ -15,6 +15,7 @@ package vat_flux import ( + "bytes" "encoding/json" "errors" "github.com/ethereum/go-ethereum/common" @@ -37,7 +38,7 @@ func (VatFluxConverter) ToModels(ethLogs []types.Log) ([]VatFluxModel, error) { return nil, err } - ilk := common.BytesToAddress(ethLog.Topics[1].Bytes()) + ilk := string(bytes.Trim(ethLog.Topics[1].Bytes(), "\x00")) src := common.BytesToAddress(ethLog.Topics[2].Bytes()) dst := common.BytesToAddress(ethLog.Topics[3].Bytes()) radBytes := shared.GetDataBytesAtIndex(-1, ethLog.Data) @@ -53,7 +54,7 @@ func (VatFluxConverter) ToModels(ethLogs []types.Log) ([]VatFluxModel, error) { } model := VatFluxModel{ - Ilk: ilk.String(), + Ilk: ilk, Src: src.String(), Dst: dst.String(), Rad: rad,