Add Vat heal integration test
This commit is contained in:
parent
a7b9b825c8
commit
fdbe0b0b44
@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE maker.vat_heal ALTER COLUMN rad SET DATA TYPE int;
|
1
db/migrations/1539809713_update_vat_heal_rad_type.up.sql
Normal file
1
db/migrations/1539809713_update_vat_heal_rad_type.up.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE maker.vat_heal ALTER COLUMN rad SET DATA TYPE numeric;
|
@ -815,7 +815,7 @@ CREATE TABLE maker.vat_heal (
|
|||||||
header_id integer NOT NULL,
|
header_id integer NOT NULL,
|
||||||
urn character varying,
|
urn character varying,
|
||||||
v character varying,
|
v character varying,
|
||||||
rad integer,
|
rad numeric,
|
||||||
tx_idx integer NOT NULL,
|
tx_idx integer NOT NULL,
|
||||||
raw_log jsonb
|
raw_log jsonb
|
||||||
);
|
);
|
||||||
|
59
pkg/transformers/integration_tests/vat_heal.go
Normal file
59
pkg/transformers/integration_tests/vat_heal.go
Normal file
@ -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"))
|
||||||
|
})
|
||||||
|
})
|
@ -26,8 +26,8 @@ var VatHealLog = types.Log{
|
|||||||
Address: common.HexToAddress("0xa970ed54e41d9db6d91db5e7ff7a9451dad98993"),
|
Address: common.HexToAddress("0xa970ed54e41d9db6d91db5e7ff7a9451dad98993"),
|
||||||
Topics: []common.Hash{
|
Topics: []common.Hash{
|
||||||
common.HexToHash("0x990a5f6300000000000000000000000000000000000000000000000000000000"),
|
common.HexToHash("0x990a5f6300000000000000000000000000000000000000000000000000000000"),
|
||||||
common.HexToHash("0x7d7bee5fcfd8028cf7b00876c5b1421c800561a6000000000000000000000000"),
|
common.HexToHash("0x0000000000000000000000007d7bee5fcfd8028cf7b00876c5b1421c800561a6"),
|
||||||
common.HexToHash("0x7340e006f4135ba6970d43bf43d88dcad4e7a8ca000000000000000000000000"),
|
common.HexToHash("0x0000000000000000000000007340e006f4135ba6970d43bf43d88dcad4e7a8ca"),
|
||||||
common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000078"),
|
common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000078"),
|
||||||
},
|
},
|
||||||
Data: hexutil.MustDecode("0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000064990a5f637d7bee5fcfd8028cf7b00876c5b1421c800561a600000000000000000000000074686520762076616c75650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000078"),
|
Data: hexutil.MustDecode("0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000064990a5f637d7bee5fcfd8028cf7b00876c5b1421c800561a600000000000000000000000074686520762076616c75650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000078"),
|
||||||
@ -43,7 +43,7 @@ var rawHealLog, _ = json.Marshal(VatHealLog)
|
|||||||
var VatHealModel = vat_heal.VatHealModel{
|
var VatHealModel = vat_heal.VatHealModel{
|
||||||
Urn: "0x7d7bEe5fCfD8028cf7b00876C5b1421c800561A6",
|
Urn: "0x7d7bEe5fCfD8028cf7b00876C5b1421c800561A6",
|
||||||
V: "0x7340e006f4135BA6970D43bf43d88DCAD4e7a8CA",
|
V: "0x7340e006f4135BA6970D43bf43d88DCAD4e7a8CA",
|
||||||
Rad: 120,
|
Rad: "120",
|
||||||
TransactionIndex: 2,
|
TransactionIndex: 2,
|
||||||
Raw: rawHealLog,
|
Raw: rawHealLog,
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,9 @@ package vat_heal
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Converter interface {
|
type Converter interface {
|
||||||
@ -36,9 +36,9 @@ func (VatHealConverter) ToModels(ethLogs []types.Log) ([]VatHealModel, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
urn := common.BytesToAddress(ethLog.Topics[1].Bytes()[:common.AddressLength])
|
urn := common.BytesToAddress(ethLog.Topics[1].Bytes())
|
||||||
v := common.BytesToAddress(ethLog.Topics[2].Bytes()[:common.AddressLength])
|
v := common.BytesToAddress(ethLog.Topics[2].Bytes())
|
||||||
radInt, err := strconv.ParseInt(ethLog.Topics[3].Hex(), 0, 64)
|
radInt := ethLog.Topics[3].Big()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ func (VatHealConverter) ToModels(ethLogs []types.Log) ([]VatHealModel, error) {
|
|||||||
model := VatHealModel{
|
model := VatHealModel{
|
||||||
Urn: urn.String(),
|
Urn: urn.String(),
|
||||||
V: v.String(),
|
V: v.String(),
|
||||||
Rad: int(radInt),
|
Rad: radInt.String(),
|
||||||
TransactionIndex: ethLog.TxIndex,
|
TransactionIndex: ethLog.TxIndex,
|
||||||
Raw: rawLogJson,
|
Raw: rawLogJson,
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ package vat_heal
|
|||||||
type VatHealModel struct {
|
type VatHealModel struct {
|
||||||
Urn string
|
Urn string
|
||||||
V string
|
V string
|
||||||
Rad int
|
Rad string
|
||||||
TransactionIndex uint `db:"tx_idx"`
|
TransactionIndex uint `db:"tx_idx"`
|
||||||
Raw []byte `db:"raw_log"`
|
Raw []byte `db:"raw_log"`
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ func (repository VatHealRepository) Create(headerId int64, models []VatHealModel
|
|||||||
|
|
||||||
for _, model := range models {
|
for _, model := range models {
|
||||||
_, err := tx.Exec(`INSERT INTO maker.vat_heal (header_id, urn, v, rad, tx_idx, raw_log)
|
_, 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)
|
headerId, model.Urn, model.V, model.Rad, model.TransactionIndex, model.Raw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
|
Loading…
Reference in New Issue
Block a user