2018-08-22 17:44:35 +00:00
|
|
|
/*
|
|
|
|
* 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 bite_test
|
|
|
|
|
|
|
|
import (
|
2018-08-31 15:37:02 +00:00
|
|
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/ethclient"
|
2018-08-22 17:44:35 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
2018-08-31 15:37:02 +00:00
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
|
|
|
"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/bite"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
|
|
|
|
"github.com/vulcanize/vulcanizedb/test_config"
|
2018-08-22 17:44:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Integration tests", func() {
|
2018-08-31 15:37:02 +00:00
|
|
|
XIt("Fetches bite event logs from a local test chain", func() {
|
|
|
|
ipcPath := test_config.TestClient.IPCPath
|
|
|
|
|
|
|
|
rawRpcClient, err := rpc.Dial(ipcPath)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
rpcClient := client.NewRpcClient(rawRpcClient, ipcPath)
|
|
|
|
ethClient := ethclient.NewClient(rawRpcClient)
|
|
|
|
blockChainClient := client.NewEthClient(ethClient)
|
|
|
|
realNode := node.MakeNode(rpcClient)
|
|
|
|
transactionConverter := rpc2.NewRpcTransactionConverter(ethClient)
|
2018-09-18 19:46:16 +00:00
|
|
|
realBlockChain := geth.NewBlockChain(blockChainClient, rpcClient, realNode, transactionConverter)
|
2018-08-31 15:37:02 +00:00
|
|
|
realFetcher := shared.NewFetcher(realBlockChain)
|
2018-09-04 21:01:23 +00:00
|
|
|
topic0 := common.HexToHash(shared.BiteSignature)
|
2018-08-31 15:37:02 +00:00
|
|
|
topics := [][]common.Hash{{topic0}}
|
|
|
|
|
2018-09-27 15:12:29 +00:00
|
|
|
result, err := realFetcher.FetchLogs(bite.BiteConfig.ContractAddresses, topics, int64(26))
|
2018-08-31 15:37:02 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(len(result) > 0).To(BeTrue())
|
2018-09-11 17:01:12 +00:00
|
|
|
Expect(result[0].Address).To(Equal(common.HexToAddress(shared.CatContractAddress)))
|
2018-08-31 15:37:02 +00:00
|
|
|
Expect(result[0].TxHash).To(Equal(test_data.EthBiteLog.TxHash))
|
|
|
|
Expect(result[0].BlockNumber).To(Equal(test_data.EthBiteLog.BlockNumber))
|
|
|
|
Expect(result[0].Topics).To(Equal(test_data.EthBiteLog.Topics))
|
|
|
|
Expect(result[0].Index).To(Equal(test_data.EthBiteLog.Index))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("unpacks an event log", func() {
|
2018-09-11 17:01:12 +00:00
|
|
|
address := common.HexToAddress(shared.CatContractAddress)
|
2018-09-04 21:01:23 +00:00
|
|
|
abi, err := geth.ParseAbi(shared.CatABI)
|
2018-08-31 15:37:02 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
contract := bind.NewBoundContract(address, abi, nil, nil, nil)
|
|
|
|
entity := &bite.BiteEntity{}
|
|
|
|
|
|
|
|
var eventLog = test_data.EthBiteLog
|
|
|
|
|
|
|
|
err = contract.UnpackLog(entity, "Bite", eventLog)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
expectedEntity := test_data.BiteEntity
|
|
|
|
Expect(entity.Art).To(Equal(expectedEntity.Art))
|
|
|
|
Expect(entity.Ilk).To(Equal(expectedEntity.Ilk))
|
|
|
|
Expect(entity.Ink).To(Equal(expectedEntity.Ink))
|
|
|
|
})
|
2018-08-22 17:44:35 +00:00
|
|
|
})
|