Update address formatting (#67)
* Add getSignatures command for list of signatures in constants * Update VatTune converter's formatting of addresses and added an integration test * Move VatTune and PriceFeeds integration tests to a common suite * Update VatGrab converter for address format * Update frob converter to fix urn and ilk formatting/decoding * Update formatting * Update make test command and add integrationtest command * Add integration test to travis build * Update creating headers in integration tests to include Raw and Timestamp fields
This commit is contained in:
parent
75246e9ce9
commit
3baca64903
@ -31,6 +31,7 @@ script:
|
|||||||
- yarn test
|
- yarn test
|
||||||
- cd ../
|
- cd ../
|
||||||
- make test
|
- make test
|
||||||
|
- make integrationtest
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
email: false
|
email: false
|
||||||
|
8
Makefile
8
Makefile
@ -44,7 +44,13 @@ lint:
|
|||||||
test: | $(GINKGO) $(LINT)
|
test: | $(GINKGO) $(LINT)
|
||||||
go vet ./...
|
go vet ./...
|
||||||
go fmt ./...
|
go fmt ./...
|
||||||
$(GINKGO) -r
|
$(GINKGO) -r --skipPackage=integration_tests
|
||||||
|
|
||||||
|
.PHONY: integrationtest
|
||||||
|
integrationtest: | $(GINKGO) $(LINT)
|
||||||
|
go vet ./...
|
||||||
|
go fmt ./...
|
||||||
|
$(GINKGO) -r --flakeAttempts=5 pkg/transformers/integration_tests/
|
||||||
|
|
||||||
.PHONY: dep
|
.PHONY: dep
|
||||||
dep: | $(DEP)
|
dep: | $(DEP)
|
||||||
|
@ -130,7 +130,8 @@ false
|
|||||||
If you have full rinkeby chaindata you can move it to `rinkeby_vulcanizedb_geth_data` docker volume to skip long wait of sync.
|
If you have full rinkeby chaindata you can move it to `rinkeby_vulcanizedb_geth_data` docker volume to skip long wait of sync.
|
||||||
|
|
||||||
## Running the Tests
|
## Running the Tests
|
||||||
- `make test`
|
- `make test` will run the unit tests and skip the integration tests
|
||||||
|
- `make integrationtest` will run the just the integration tests
|
||||||
- Note: requires Ganache chain setup and seeded with `flip-kick.js` and `frob.js` (in that order)
|
- Note: requires Ganache chain setup and seeded with `flip-kick.js` and `frob.js` (in that order)
|
||||||
|
|
||||||
## Deploying
|
## Deploying
|
||||||
|
63
cmd/getSignatures.go
Normal file
63
cmd/getSignatures.go
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
// Copyright © 2018 NAME HERE <EMAIL ADDRESS>
|
||||||
|
//
|
||||||
|
// 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 cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// getSignaturesCmd represents the getSignatures command
|
||||||
|
var getSignaturesCmd = &cobra.Command{
|
||||||
|
Use: "getSignatures",
|
||||||
|
Short: "A command to see transformer method and event signatures",
|
||||||
|
Long: `A convenience command to see method/event signatures for Maker transformers
|
||||||
|
vulcanizedb getSignatures`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(getSignaturesCmd)
|
||||||
|
signatures := make(map[string]string)
|
||||||
|
signatures["BiteSignature"] = shared.BiteSignature
|
||||||
|
signatures["DealSignature"] = shared.DealSignature
|
||||||
|
signatures["CatFileChopLumpSignature"] = shared.CatFileChopLumpSignature
|
||||||
|
signatures["CatFileFlipSignature"] = shared.CatFileFlipSignature
|
||||||
|
signatures["CatFilePitVowSignature"] = shared.CatFilePitVowSignature
|
||||||
|
signatures["DentFunctionSignature"] = shared.DentFunctionSignature
|
||||||
|
signatures["DripDripSignature"] = shared.DripDripSignature
|
||||||
|
signatures["DripFileIlkSignature"] = shared.DripFileIlkSignature
|
||||||
|
signatures["DripFileRepoSignature"] = shared.DripFileRepoSignature
|
||||||
|
signatures["DripFileVowSignature"] = shared.DripFileVowSignature
|
||||||
|
signatures["FlipKickSignature"] = shared.FlipKickSignature
|
||||||
|
signatures["FlopKickSignature"] = shared.FlopKickSignature
|
||||||
|
signatures["FrobSignature"] = shared.FrobSignature
|
||||||
|
signatures["LogValueSignature"] = shared.LogValueSignature
|
||||||
|
signatures["PitFileDebtCeilingSignature"] = shared.PitFileDebtCeilingSignature
|
||||||
|
signatures["PitFileIlkSignature"] = shared.PitFileIlkSignature
|
||||||
|
signatures["PitFileStabilityFeeSignature"] = shared.PitFileStabilityFeeSignature
|
||||||
|
signatures["TendFunctionSignature"] = shared.TendFunctionSignature
|
||||||
|
signatures["VatHealSignature"] = shared.VatHealSignature
|
||||||
|
signatures["VatGrabSignature"] = shared.VatGrabSignature
|
||||||
|
signatures["VatInitSignature"] = shared.VatInitSignature
|
||||||
|
signatures["VatFoldSignature"] = shared.VatFoldSignature
|
||||||
|
signatures["VatTollSignature"] = shared.VatTollSignature
|
||||||
|
signatures["VatTuneSignature"] = shared.VatTuneSignature
|
||||||
|
|
||||||
|
for name, sig := range signatures {
|
||||||
|
log.Println(name, ": ", sig)
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/geth"
|
"github.com/vulcanize/vulcanizedb/pkg/geth"
|
||||||
@ -57,8 +58,8 @@ func (FrobConverter) ToModels(entities []FrobEntity) ([]FrobModel, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
model := FrobModel{
|
model := FrobModel{
|
||||||
Ilk: common.BytesToAddress(entity.Ilk[:common.AddressLength]).String(),
|
Ilk: string(bytes.Trim(entity.Ilk[:], "\x00)")),
|
||||||
Urn: common.BytesToAddress(entity.Urn[:common.AddressLength]).String(),
|
Urn: common.BytesToAddress(entity.Urn[:]).String(),
|
||||||
Ink: entity.Ink.String(),
|
Ink: entity.Ink.String(),
|
||||||
Art: entity.Art.String(),
|
Art: entity.Art.String(),
|
||||||
Dink: entity.Dink.String(),
|
Dink: entity.Dink.String(),
|
||||||
|
@ -12,52 +12,57 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package frob_test
|
package integration_tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/ethclient"
|
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/geth"
|
"github.com/vulcanize/vulcanizedb/pkg/geth"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/geth/client"
|
|
||||||
vRpc "github.com/vulcanize/vulcanizedb/pkg/geth/converters/rpc"
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/geth/node"
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/frob"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/frob"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
||||||
"github.com/vulcanize/vulcanizedb/test_config"
|
"github.com/vulcanize/vulcanizedb/test_config"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("Integration tests", func() {
|
var _ = Describe("Frob Transformer", func() {
|
||||||
XIt("Fetches frob event logs from a local test chain", func() {
|
It("fetches and transforms a Frob event from Kovan chain", func() {
|
||||||
ipcPath := test_config.TestClient.IPCPath
|
blockNumber := int64(8935258)
|
||||||
|
config := frob.FrobConfig
|
||||||
|
config.StartingBlockNumber = blockNumber
|
||||||
|
config.EndingBlockNumber = blockNumber
|
||||||
|
|
||||||
rawRpcClient, err := rpc.Dial(ipcPath)
|
ipc := "https://kovan.infura.io/J5Vd2fRtGsw0zZ0Ov3BL"
|
||||||
|
rpcClient, ethClient, err := getClients(ipc)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
blockchain, err := getBlockChain(rpcClient, ethClient)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
rpcClient := client.NewRpcClient(rawRpcClient, ipcPath)
|
db := test_config.NewTestDB(blockchain.Node())
|
||||||
ethClient := ethclient.NewClient(rawRpcClient)
|
test_config.CleanTestDB(db)
|
||||||
blockChainClient := client.NewEthClient(ethClient)
|
|
||||||
realNode := node.MakeNode(rpcClient)
|
|
||||||
transactionConverter := vRpc.NewRpcTransactionConverter(ethClient)
|
|
||||||
realBlockChain := geth.NewBlockChain(blockChainClient, rpcClient, realNode, transactionConverter)
|
|
||||||
realFetcher := shared.NewFetcher(realBlockChain)
|
|
||||||
topic0 := common.HexToHash(shared.FrobSignature)
|
|
||||||
topics := [][]common.Hash{{topic0}}
|
|
||||||
|
|
||||||
result, err := realFetcher.FetchLogs(frob.FrobConfig.ContractAddresses, topics, int64(12))
|
err = persistHeader(rpcClient, db, blockNumber)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
Expect(len(result) > 0).To(BeTrue())
|
initializer := frob.FrobTransformerInitializer{Config: config}
|
||||||
Expect(result[0].Address).To(Equal(common.HexToAddress(shared.PitContractAddress)))
|
transformer := initializer.NewFrobTransformer(db, blockchain)
|
||||||
Expect(result[0].TxHash).To(Equal(test_data.EthFrobLog.TxHash))
|
err = transformer.Execute()
|
||||||
Expect(result[0].BlockNumber).To(Equal(test_data.EthFrobLog.BlockNumber))
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(result[0].Topics).To(Equal(test_data.EthFrobLog.Topics))
|
|
||||||
Expect(result[0].Index).To(Equal(test_data.EthFrobLog.Index))
|
var dbResult []frob.FrobModel
|
||||||
|
err = db.Select(&dbResult, `SELECT art, dart, dink, iart, ilk, ink, urn from maker.frob`)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
Expect(len(dbResult)).To(Equal(1))
|
||||||
|
Expect(dbResult[0].Art).To(Equal("10000000000000000"))
|
||||||
|
Expect(dbResult[0].Dart).To(Equal("0"))
|
||||||
|
Expect(dbResult[0].Dink).To(Equal("10000000000000"))
|
||||||
|
Expect(dbResult[0].IArt).To(Equal("1495509999999999999992"))
|
||||||
|
Expect(dbResult[0].Ilk).To(Equal("ETH"))
|
||||||
|
Expect(dbResult[0].Ink).To(Equal("10050100000000000"))
|
||||||
|
Expect(dbResult[0].Urn).To(Equal("0xc8E093e5f3F9B5Aa6A6b33ea45960b93C161430C"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("unpacks an event log", func() {
|
It("unpacks an event log", func() {
|
67
pkg/transformers/integration_tests/helpers.go
Normal file
67
pkg/transformers/integration_tests/helpers.go
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
// 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 (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
|
"github.com/ethereum/go-ethereum/ethclient"
|
||||||
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||||
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
|
||||||
|
"github.com/vulcanize/vulcanizedb/pkg/geth"
|
||||||
|
"github.com/vulcanize/vulcanizedb/pkg/geth/client"
|
||||||
|
rpc2 "github.com/vulcanize/vulcanizedb/pkg/geth/converters/rpc"
|
||||||
|
"github.com/vulcanize/vulcanizedb/pkg/geth/node"
|
||||||
|
"math/big"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getClients(ipc string) (client.RpcClient, *ethclient.Client, error) {
|
||||||
|
raw, err := rpc.Dial(ipc)
|
||||||
|
if err != nil {
|
||||||
|
return client.RpcClient{}, ðclient.Client{}, err
|
||||||
|
}
|
||||||
|
return client.NewRpcClient(raw, ipc), ethclient.NewClient(raw), nil
|
||||||
|
}
|
||||||
|
func getBlockChain(rpcClient client.RpcClient, ethClient *ethclient.Client) (core.BlockChain, error) {
|
||||||
|
client := client.NewEthClient(ethClient)
|
||||||
|
node := node.MakeNode(rpcClient)
|
||||||
|
transactionConverter := rpc2.NewRpcTransactionConverter(client)
|
||||||
|
blockChain := geth.NewBlockChain(client, rpcClient, node, transactionConverter)
|
||||||
|
return blockChain, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func persistHeader(rpcClient client.RpcClient, db *postgres.DB, blockNumber int64) error {
|
||||||
|
var poaHeader core.POAHeader
|
||||||
|
blockNumberArg := hexutil.EncodeBig(big.NewInt(int64(blockNumber)))
|
||||||
|
err := rpcClient.CallContext(context.Background(), &poaHeader, "eth_getBlockByNumber", blockNumberArg, false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rawHeader, err := json.Marshal(poaHeader)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
headerRepository := repositories.NewHeaderRepository(db)
|
||||||
|
_, err = headerRepository.CreateOrUpdateHeader(core.Header{
|
||||||
|
BlockNumber: poaHeader.Number.ToInt().Int64(),
|
||||||
|
Hash: poaHeader.Hash.String(),
|
||||||
|
Raw: rawHeader,
|
||||||
|
Timestamp: poaHeader.Time.ToInt().String(),
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package integration_tests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestIntegrationTests(t *testing.T) {
|
||||||
|
RegisterFailHandler(Fail)
|
||||||
|
RunSpecs(t, "IntegrationTests Suite")
|
||||||
|
}
|
@ -1,24 +1,27 @@
|
|||||||
package price_feeds_test
|
// 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 (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"math/big"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
||||||
"github.com/ethereum/go-ethereum/ethclient"
|
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/geth"
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/geth/client"
|
|
||||||
rpc2 "github.com/vulcanize/vulcanizedb/pkg/geth/converters/rpc"
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/geth/node"
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/price_feeds"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/price_feeds"
|
||||||
"github.com/vulcanize/vulcanizedb/test_config"
|
"github.com/vulcanize/vulcanizedb/test_config"
|
||||||
)
|
)
|
||||||
@ -107,40 +110,3 @@ var _ = Describe("Price feeds transformer", func() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
func getClients(ipc string) (client.RpcClient, *ethclient.Client, error) {
|
|
||||||
raw, err := rpc.Dial(ipc)
|
|
||||||
if err != nil {
|
|
||||||
return client.RpcClient{}, ðclient.Client{}, err
|
|
||||||
}
|
|
||||||
return client.NewRpcClient(raw, ipc), ethclient.NewClient(raw), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getBlockChain(rpcClient client.RpcClient, ethClient *ethclient.Client) (core.BlockChain, error) {
|
|
||||||
client := client.NewEthClient(ethClient)
|
|
||||||
node := node.MakeNode(rpcClient)
|
|
||||||
transactionConverter := rpc2.NewRpcTransactionConverter(client)
|
|
||||||
blockChain := geth.NewBlockChain(client, rpcClient, node, transactionConverter)
|
|
||||||
return blockChain, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func persistHeader(rpcClient client.RpcClient, db *postgres.DB, blockNumber int64) error {
|
|
||||||
var poaHeader core.POAHeader
|
|
||||||
blockNumberArg := hexutil.EncodeBig(big.NewInt(int64(blockNumber)))
|
|
||||||
err := rpcClient.CallContext(context.Background(), &poaHeader, "eth_getBlockByNumber", blockNumberArg, false)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
rawHeader, err := json.Marshal(poaHeader)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
headerRepository := repositories.NewHeaderRepository(db)
|
|
||||||
_, err = headerRepository.CreateOrUpdateHeader(core.Header{
|
|
||||||
BlockNumber: poaHeader.Number.ToInt().Int64(),
|
|
||||||
Hash: poaHeader.Hash.String(),
|
|
||||||
Raw: rawHeader,
|
|
||||||
Timestamp: poaHeader.Time.ToInt().String(),
|
|
||||||
})
|
|
||||||
return err
|
|
||||||
}
|
|
68
pkg/transformers/integration_tests/vat_grab.go
Normal file
68
pkg/transformers/integration_tests/vat_grab.go
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
// 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 (
|
||||||
|
"math/big"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/vat_grab"
|
||||||
|
"github.com/vulcanize/vulcanizedb/test_config"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = Describe("Vat Grab Transformer", func() {
|
||||||
|
It("transforms VatGrab log events", func() {
|
||||||
|
blockNumber := int64(8958230)
|
||||||
|
config := vat_grab.VatGrabConfig
|
||||||
|
config.StartingBlockNumber = blockNumber
|
||||||
|
config.EndingBlockNumber = blockNumber
|
||||||
|
|
||||||
|
ipc := "https://kovan.infura.io/J5Vd2fRtGsw0zZ0Ov3BL"
|
||||||
|
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_grab.VatGrabTransformerInitializer{Config: config}
|
||||||
|
transformer := initializer.NewVatGrabTransformer(db, blockchain)
|
||||||
|
err = transformer.Execute()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
var dbResult []vat_grab.VatGrabModel
|
||||||
|
err = db.Select(&dbResult, `SELECT ilk, urn, v, w, dink, dart from maker.vat_grab`)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
Expect(len(dbResult)).To(Equal(1))
|
||||||
|
Expect(dbResult[0].Ilk).To(Equal("REP"))
|
||||||
|
Expect(dbResult[0].Urn).To(Equal("0x6a3AE20C315E845B2E398e68EfFe39139eC6060C"))
|
||||||
|
Expect(dbResult[0].V).To(Equal("0x2F34f22a00eE4b7a8F8BBC4eAee1658774c624e0")) //cat contract address
|
||||||
|
Expect(dbResult[0].W).To(Equal("0x3728e9777B2a0a611ee0F89e00E01044ce4736d1"))
|
||||||
|
expectedDink := new(big.Int)
|
||||||
|
expectedDink.SetString("115792089237316195423570985008687907853269984665640564039455584007913129639936", 10)
|
||||||
|
Expect(dbResult[0].Dink).To(Equal(expectedDink.String()))
|
||||||
|
expectedDart := new(big.Int)
|
||||||
|
expectedDart.SetString("115792089237316195423570985008687907853269984665640564039441803007913129639936", 10)
|
||||||
|
Expect(dbResult[0].Dart).To(Equal(expectedDart.String()))
|
||||||
|
Expect(dbResult[0].TransactionIndex).To(Equal(uint(0)))
|
||||||
|
})
|
||||||
|
})
|
66
pkg/transformers/integration_tests/vat_tune.go
Normal file
66
pkg/transformers/integration_tests/vat_tune.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
// 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 (
|
||||||
|
"math/big"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/vat_tune"
|
||||||
|
"github.com/vulcanize/vulcanizedb/test_config"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = Describe("VatTune Transformer", func() {
|
||||||
|
It("transforms VatTune log events", func() {
|
||||||
|
blockNumber := int64(8761670)
|
||||||
|
config := vat_tune.VatTuneConfig
|
||||||
|
config.StartingBlockNumber = blockNumber
|
||||||
|
config.EndingBlockNumber = blockNumber
|
||||||
|
|
||||||
|
ipc := "https://kovan.infura.io/J5Vd2fRtGsw0zZ0Ov3BL"
|
||||||
|
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_tune.VatTuneTransformerInitializer{Config: config}
|
||||||
|
transformer := initializer.NewVatTuneTransformer(db, blockchain)
|
||||||
|
err = transformer.Execute()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
var dbResult []vat_tune.VatTuneModel
|
||||||
|
err = db.Select(&dbResult, `SELECT ilk, urn, v, w, dink, dart from maker.vat_tune`)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
Expect(len(dbResult)).To(Equal(1))
|
||||||
|
Expect(dbResult[0].Ilk).To(Equal("ETH"))
|
||||||
|
Expect(dbResult[0].Urn).To(Equal("0x4F26FfBe5F04ED43630fdC30A87638d53D0b0876"))
|
||||||
|
Expect(dbResult[0].V).To(Equal("0x4F26FfBe5F04ED43630fdC30A87638d53D0b0876"))
|
||||||
|
Expect(dbResult[0].W).To(Equal("0x4F26FfBe5F04ED43630fdC30A87638d53D0b0876"))
|
||||||
|
Expect(dbResult[0].Dink).To(Equal("0"))
|
||||||
|
expectedDart := new(big.Int)
|
||||||
|
expectedDart.SetString("115792089237316195423570985008687907853269984665640564039455584007913129639936", 10)
|
||||||
|
Expect(dbResult[0].Dart).To(Equal(expectedDart.String()))
|
||||||
|
Expect(dbResult[0].TransactionIndex).To(Equal(uint(0)))
|
||||||
|
})
|
||||||
|
})
|
@ -41,8 +41,8 @@ var (
|
|||||||
gem, _ = big.NewInt(0).SetString("115792089237316195423570985008687907853269984665640564039457584007913129639926", 10)
|
gem, _ = big.NewInt(0).SetString("115792089237316195423570985008687907853269984665640564039457584007913129639926", 10)
|
||||||
ink = big.NewInt(15)
|
ink = big.NewInt(15)
|
||||||
ilk = [32]byte{102, 97, 107, 101, 32, 105, 108, 107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
ilk = [32]byte{102, 97, 107, 101, 32, 105, 108, 107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||||
frobIlkString = "0x66616b6520696c6B000000000000000000000000"
|
frobIlkString = "fake ilk"
|
||||||
frobUrnString = "0x00000000000000000000000064D922894153BE9E"
|
frobUrnString = "0x64d922894153BE9EEf7b7218dc565d1D0Ce2a092"
|
||||||
)
|
)
|
||||||
|
|
||||||
var EthFrobLog = types.Log{
|
var EthFrobLog = types.Log{
|
||||||
|
@ -13,11 +13,11 @@ var EthVatGrabLog = types.Log{
|
|||||||
Address: common.HexToAddress(shared.VatContractAddress),
|
Address: common.HexToAddress(shared.VatContractAddress),
|
||||||
Topics: []common.Hash{
|
Topics: []common.Hash{
|
||||||
common.HexToHash("0x3690ae4c00000000000000000000000000000000000000000000000000000000"),
|
common.HexToHash("0x3690ae4c00000000000000000000000000000000000000000000000000000000"),
|
||||||
common.HexToHash("0x66616b6520696c6b000000000000000000000000000000000000000000000000"),
|
common.HexToHash("0x5245500000000000000000000000000000000000000000000000000000000000"),
|
||||||
common.HexToHash("0x07fa9ef6609ca7921112231f8f195138ebba2977000000000000000000000000"),
|
common.HexToHash("0x0000000000000000000000006a3ae20c315e845b2e398e68effe39139ec6060c"),
|
||||||
common.HexToHash("0x7340e006f4135ba6970d43bf43d88dcad4e7a8ca000000000000000000000000"),
|
common.HexToHash("0x0000000000000000000000002f34f22a00ee4b7a8f8bbc4eaee1658774c624e0"),
|
||||||
},
|
},
|
||||||
Data: hexutil.MustDecode("0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000c43690ae4c66616b6520696c6b00000000000000000000000000000000000000000000000007fa9ef6609ca7921112231f8f195138ebba29770000000000000000000000007340e006f4135ba6970d43bf43d88dcad4e7a8ca0000000000000000000000007526eb4f95e2a1394797cb38a921fb1eba09291b00000000000000000000000000000000000000000000000000000000000000000000000000000000069f6bc7000000000000000000000000000000000000000000000000000000000d3ed78e"),
|
Data: hexutil.MustDecode("0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000c43690ae4c52455000000000000000000000000000000000000000000000000000000000000000000000000000000000006a3ae20c315e845b2e398e68effe39139ec6060c0000000000000000000000002f34f22a00ee4b7a8f8bbc4eaee1658774c624e00000000000000000000000003728e9777b2a0a611ee0f89e00e01044ce4736d1ffffffffffffffffffffffffffffffffffffffffffffffffe43e9298b1380000ffffffffffffffffffffffffffffffffffffffffffffffff24fea01c7f8f8000"),
|
||||||
BlockNumber: 23,
|
BlockNumber: 23,
|
||||||
TxHash: common.HexToHash("0x7cb84c750ce4985f7811abf641d52ffcb35306d943081475226484cf1470c6fa"),
|
TxHash: common.HexToHash("0x7cb84c750ce4985f7811abf641d52ffcb35306d943081475226484cf1470c6fa"),
|
||||||
TxIndex: 4,
|
TxIndex: 4,
|
||||||
@ -28,12 +28,12 @@ var EthVatGrabLog = types.Log{
|
|||||||
|
|
||||||
var rawVatGrabLog, _ = json.Marshal(EthVatGrabLog)
|
var rawVatGrabLog, _ = json.Marshal(EthVatGrabLog)
|
||||||
var VatGrabModel = vat_grab.VatGrabModel{
|
var VatGrabModel = vat_grab.VatGrabModel{
|
||||||
Ilk: "fake ilk",
|
Ilk: "REP",
|
||||||
Urn: "0x07Fa9eF6609cA7921112231F8f195138ebbA2977",
|
Urn: "0x6a3AE20C315E845B2E398e68EfFe39139eC6060C",
|
||||||
V: "0x7340e006f4135BA6970D43bf43d88DCAD4e7a8CA",
|
V: "0x2F34f22a00eE4b7a8F8BBC4eAee1658774c624e0",
|
||||||
W: "0x7526EB4f95e2a1394797Cb38a921Fb1EbA09291B",
|
W: "0x3728e9777B2a0a611ee0F89e00E01044ce4736d1",
|
||||||
Dink: "111111111",
|
Dink: "115792089237316195423570985008687907853269984665640564039455584007913129639936",
|
||||||
Dart: "222222222",
|
Dart: "115792089237316195423570985008687907853269984665640564039441803007913129639936",
|
||||||
TransactionIndex: EthVatGrabLog.TxIndex,
|
TransactionIndex: EthVatGrabLog.TxIndex,
|
||||||
Raw: rawVatGrabLog,
|
Raw: rawVatGrabLog,
|
||||||
}
|
}
|
||||||
|
@ -12,30 +12,33 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var EthVatTuneLog = types.Log{
|
var EthVatTuneLog = types.Log{
|
||||||
Address: common.HexToAddress("0x239E6f0AB02713f1F8AA90ebeDeD9FC66Dc96CD6"),
|
Address: common.HexToAddress("0xCD726790550aFcd77e9a7a47e86A3F9010af126B"),
|
||||||
Topics: []common.Hash{
|
Topics: []common.Hash{
|
||||||
common.HexToHash("0x5dd6471a00000000000000000000000000000000000000000000000000000000"),
|
common.HexToHash("0x5dd6471a00000000000000000000000000000000000000000000000000000000"),
|
||||||
common.HexToHash("0x66616b6520696c6b000000000000000000000000000000000000000000000000"),
|
common.HexToHash("0x4554480000000000000000000000000000000000000000000000000000000000"),
|
||||||
common.HexToHash("0x7d7bee5fcfd8028cf7b00876c5b1421c800561a6000000000000000000000000"),
|
common.HexToHash("0x0000000000000000000000004f26ffbe5f04ed43630fdc30a87638d53d0b0876"),
|
||||||
common.HexToHash("0xa3e37186e017747dba34042e83e3f76ad3cce9b0000000000000000000000000"),
|
common.HexToHash("0x0000000000000000000000004f26ffbe5f04ed43630fdc30a87638d53d0b0876"),
|
||||||
},
|
},
|
||||||
Data: hexutil.MustDecode("0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000c45dd6471a66616b6520696c6b0000000000000000000000000000000000000000000000007d7bee5fcfd8028cf7b00876c5b1421c800561a6000000000000000000000000a3e37186e017747dba34042e83e3f76ad3cce9b00000000000000000000000000f243e26db94b5426032e6dfa6007802dea2a61400000000000000000000000000000000000000000000000000000000000000000000000000000000075bcd15000000000000000000000000000000000000000000000000000000003ade68b1"),
|
Data: hexutil.MustDecode("0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000c45dd6471a45544800000000000000000000000000000000000000000000000000000000000000000000000000000000004f26ffbe5f04ed43630fdc30a87638d53d0b08760000000000000000000000004f26ffbe5f04ed43630fdc30a87638d53d0b08760000000000000000000000004f26ffbe5f04ed43630fdc30a87638d53d0b08760000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffe43e9298b1380000"),
|
||||||
BlockNumber: 22,
|
BlockNumber: 8761670,
|
||||||
TxHash: common.HexToHash("0x2b19ef3965420d2d5eb8792eafbd5e365b2866200cfc4473835971f6965f831c"),
|
TxHash: common.HexToHash("0x95eb3d6cbd83032efa29714d4a391ce163d7d215db668aadd7d33dd5c20b1ec7"),
|
||||||
TxIndex: 3,
|
TxIndex: 0,
|
||||||
BlockHash: common.HexToHash("0xf3a4a9ecb79a721421b347424dc9fa072ca762f3ba340557b54a205f058f59a6"),
|
BlockHash: common.HexToHash("0xd35188df40a741f4bf4ccacc6be0154e338652660d0b56cc9058c1bca53b09ee"),
|
||||||
Index: 6,
|
Index: 6,
|
||||||
Removed: false,
|
Removed: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
var rawVatTuneLog, _ = json.Marshal(EthVatTuneLog)
|
var rawVatTuneLog, _ = json.Marshal(EthVatTuneLog)
|
||||||
|
var dartString = "115792089237316195423570985008687907853269984665640564039455584007913129639936"
|
||||||
|
var vatTuneDart, _ = new(big.Int).SetString(dartString, 10)
|
||||||
|
var urnAddress = "0x4F26FfBe5F04ED43630fdC30A87638d53D0b0876"
|
||||||
var VatTuneModel = vat_tune.VatTuneModel{
|
var VatTuneModel = vat_tune.VatTuneModel{
|
||||||
Ilk: "fake ilk",
|
Ilk: "ETH",
|
||||||
Urn: "0x7d7bEe5fCfD8028cf7b00876C5b1421c800561A6",
|
Urn: urnAddress,
|
||||||
V: "0xA3E37186E017747DbA34042e83e3F76Ad3CcE9b0",
|
V: urnAddress,
|
||||||
W: "0x0F243E26db94B5426032E6DFA6007802Dea2a614",
|
W: urnAddress,
|
||||||
Dink: big.NewInt(123456789).String(),
|
Dink: big.NewInt(0).String(),
|
||||||
Dart: big.NewInt(987654321).String(),
|
Dart: vatTuneDart.String(),
|
||||||
TransactionIndex: EthVatTuneLog.TxIndex,
|
TransactionIndex: EthVatTuneLog.TxIndex,
|
||||||
Raw: rawVatTuneLog,
|
Raw: rawVatTuneLog,
|
||||||
}
|
}
|
||||||
|
@ -24,10 +24,10 @@ func (VatGrabConverter) ToModels(ethLogs []types.Log) ([]VatGrabModel, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ilk := string(bytes.Trim(ethLog.Topics[1].Bytes(), "\x00"))
|
ilk := string(bytes.Trim(ethLog.Topics[1].Bytes(), "\x00"))
|
||||||
urn := common.BytesToAddress(ethLog.Topics[2].Bytes()[:common.AddressLength])
|
urn := common.BytesToAddress(ethLog.Topics[2].Bytes())
|
||||||
v := common.BytesToAddress(ethLog.Topics[3].Bytes()[:common.AddressLength])
|
v := common.BytesToAddress(ethLog.Topics[3].Bytes())
|
||||||
wBytes := shared.GetDataBytesAtIndex(-3, ethLog.Data)
|
wBytes := shared.GetDataBytesAtIndex(-3, ethLog.Data)
|
||||||
w := common.BytesToAddress(wBytes[:common.AddressLength])
|
w := common.BytesToAddress(wBytes)
|
||||||
dinkBytes := shared.GetDataBytesAtIndex(-2, ethLog.Data)
|
dinkBytes := shared.GetDataBytesAtIndex(-2, ethLog.Data)
|
||||||
dink := big.NewInt(0).SetBytes(dinkBytes).String()
|
dink := big.NewInt(0).SetBytes(dinkBytes).String()
|
||||||
dartBytes := shared.GetDataBytesAtIndex(-1, ethLog.Data)
|
dartBytes := shared.GetDataBytesAtIndex(-1, ethLog.Data)
|
||||||
|
@ -26,10 +26,10 @@ func (VatTuneConverter) ToModels(ethLogs []types.Log) ([]VatTuneModel, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ilk := string(bytes.Trim(ethLog.Topics[1].Bytes(), "\x00"))
|
ilk := string(bytes.Trim(ethLog.Topics[1].Bytes(), "\x00"))
|
||||||
urn := common.BytesToAddress(ethLog.Topics[2].Bytes()[:common.AddressLength])
|
urn := common.BytesToAddress(ethLog.Topics[2].Bytes())
|
||||||
v := common.BytesToAddress(ethLog.Topics[3].Bytes()[:common.AddressLength])
|
v := common.BytesToAddress(ethLog.Topics[3].Bytes())
|
||||||
wBytes := shared.GetDataBytesAtIndex(-3, ethLog.Data)
|
wBytes := shared.GetDataBytesAtIndex(-3, ethLog.Data)
|
||||||
w := common.BytesToAddress(wBytes[:common.AddressLength])
|
w := common.BytesToAddress(wBytes)
|
||||||
dinkBytes := shared.GetDataBytesAtIndex(-2, ethLog.Data)
|
dinkBytes := shared.GetDataBytesAtIndex(-2, ethLog.Data)
|
||||||
dink := big.NewInt(0).SetBytes(dinkBytes).String()
|
dink := big.NewInt(0).SetBytes(dinkBytes).String()
|
||||||
dartBytes := shared.GetDataBytesAtIndex(-1, ethLog.Data)
|
dartBytes := shared.GetDataBytesAtIndex(-1, ethLog.Data)
|
||||||
|
@ -36,7 +36,7 @@ func (transformer VatTuneTransformer) Execute() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Printf("Fetching vat init event logs for %d headers \n", len(missingHeaders))
|
log.Printf("Fetching vat tune event logs for %d headers \n", len(missingHeaders))
|
||||||
for _, header := range missingHeaders {
|
for _, header := range missingHeaders {
|
||||||
topics := [][]common.Hash{{common.HexToHash(shared.VatTuneSignature)}}
|
topics := [][]common.Hash{{common.HexToHash(shared.VatTuneSignature)}}
|
||||||
matchingLogs, err := transformer.Fetcher.FetchLogs(VatTuneConfig.ContractAddresses, topics, header.BlockNumber)
|
matchingLogs, err := transformer.Fetcher.FetchLogs(VatTuneConfig.ContractAddresses, topics, header.BlockNumber)
|
||||||
|
Loading…
Reference in New Issue
Block a user