2018-11-07 21:50:43 +00:00
|
|
|
// VulcanizeDB
|
2019-03-12 15:46:42 +00:00
|
|
|
// Copyright © 2019 Vulcanize
|
2018-11-07 21:50:43 +00:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-12-11 21:08:00 +00:00
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
|
2018-02-13 16:31:57 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2018-07-18 20:59:40 +00:00
|
|
|
"github.com/ethereum/go-ethereum/ethclient"
|
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
2018-02-08 16:12:08 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2018-08-31 19:48:43 +00:00
|
|
|
|
2019-10-28 11:30:24 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/eth"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/eth/client"
|
|
|
|
rpc2 "github.com/vulcanize/vulcanizedb/pkg/eth/converters/rpc"
|
2020-01-30 22:35:31 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/eth/core"
|
2019-10-28 11:30:24 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/eth/node"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/eth/testing"
|
2018-02-13 16:31:57 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/test_config"
|
2017-12-11 21:08:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Reading contracts", func() {
|
|
|
|
|
2018-01-08 17:41:01 +00:00
|
|
|
Describe("Getting a contract attribute", func() {
|
2017-12-11 21:08:00 +00:00
|
|
|
It("retrieves the event log for a specific block and contract", func() {
|
2019-08-06 21:57:08 +00:00
|
|
|
expectedLogZero := core.FullSyncLog{
|
2017-12-11 21:08:00 +00:00
|
|
|
BlockNumber: 4703824,
|
|
|
|
TxHash: "0xf896bfd1eb539d881a1a31102b78de9f25cd591bf1fe1924b86148c0b205fd5d",
|
2018-01-15 20:44:47 +00:00
|
|
|
Address: "0xd26114cd6ee289accf82350c8d8487fedb8a0c07",
|
|
|
|
Topics: core.Topics{
|
2017-12-12 21:55:26 +00:00
|
|
|
0: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
|
|
|
|
1: "0x000000000000000000000000fbb1b73c4f0bda4f67dca266ce6ef42f520fbb98",
|
|
|
|
2: "0x000000000000000000000000d26114cd6ee289accf82350c8d8487fedb8a0c07",
|
2017-12-11 21:08:00 +00:00
|
|
|
},
|
2017-12-12 21:55:26 +00:00
|
|
|
Index: 19,
|
|
|
|
Data: "0x0000000000000000000000000000000000000000000000000c7d713b49da0000"}
|
2019-10-18 16:16:19 +00:00
|
|
|
rawRPCClient, err := rpc.Dial(test_config.TestClient.IPCPath)
|
2018-07-18 20:59:40 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2019-10-18 16:16:19 +00:00
|
|
|
rpcClient := client.NewRPCClient(rawRPCClient, test_config.TestClient.IPCPath)
|
|
|
|
ethClient := ethclient.NewClient(rawRPCClient)
|
2018-07-20 16:37:46 +00:00
|
|
|
blockChainClient := client.NewEthClient(ethClient)
|
|
|
|
node := node.MakeNode(rpcClient)
|
2019-10-18 16:16:19 +00:00
|
|
|
transactionConverter := rpc2.NewRPCTransactionConverter(ethClient)
|
2019-10-28 11:30:24 +00:00
|
|
|
blockChain := eth.NewBlockChain(blockChainClient, rpcClient, node, transactionConverter)
|
2017-12-11 21:08:00 +00:00
|
|
|
contract := testing.SampleContract()
|
|
|
|
|
2019-08-06 21:57:08 +00:00
|
|
|
logs, err := blockChain.GetFullSyncLogs(contract, big.NewInt(4703824), nil)
|
2017-12-11 21:08:00 +00:00
|
|
|
|
|
|
|
Expect(err).To(BeNil())
|
|
|
|
Expect(len(logs)).To(Equal(3))
|
|
|
|
Expect(logs[0]).To(Equal(expectedLogZero))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("returns and empty log array when no events for a given block / contract combo", func() {
|
2019-10-18 16:16:19 +00:00
|
|
|
rawRPCClient, err := rpc.Dial(test_config.TestClient.IPCPath)
|
2018-07-18 20:59:40 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2019-10-18 16:16:19 +00:00
|
|
|
rpcClient := client.NewRPCClient(rawRPCClient, test_config.TestClient.IPCPath)
|
|
|
|
ethClient := ethclient.NewClient(rawRPCClient)
|
2018-07-20 16:37:46 +00:00
|
|
|
blockChainClient := client.NewEthClient(ethClient)
|
|
|
|
node := node.MakeNode(rpcClient)
|
2019-10-18 16:16:19 +00:00
|
|
|
transactionConverter := rpc2.NewRPCTransactionConverter(ethClient)
|
2019-10-28 11:30:24 +00:00
|
|
|
blockChain := eth.NewBlockChain(blockChainClient, rpcClient, node, transactionConverter)
|
2017-12-11 21:08:00 +00:00
|
|
|
|
2019-08-06 21:57:08 +00:00
|
|
|
logs, err := blockChain.GetFullSyncLogs(core.Contract{Hash: "0x123"}, big.NewInt(4703824), nil)
|
2017-12-11 21:08:00 +00:00
|
|
|
|
|
|
|
Expect(err).To(BeNil())
|
|
|
|
Expect(len(logs)).To(Equal(0))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-02-13 16:31:57 +00:00
|
|
|
Describe("Fetching Contract data", func() {
|
|
|
|
It("returns the correct attribute for a real contract", func() {
|
2019-10-18 16:16:19 +00:00
|
|
|
rawRPCClient, err := rpc.Dial(test_config.TestClient.IPCPath)
|
2018-07-18 20:59:40 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2019-10-18 16:16:19 +00:00
|
|
|
rpcClient := client.NewRPCClient(rawRPCClient, test_config.TestClient.IPCPath)
|
|
|
|
ethClient := ethclient.NewClient(rawRPCClient)
|
2018-07-20 16:37:46 +00:00
|
|
|
blockChainClient := client.NewEthClient(ethClient)
|
|
|
|
node := node.MakeNode(rpcClient)
|
2019-10-18 16:16:19 +00:00
|
|
|
transactionConverter := rpc2.NewRPCTransactionConverter(ethClient)
|
2019-10-28 11:30:24 +00:00
|
|
|
blockChain := eth.NewBlockChain(blockChainClient, rpcClient, node, transactionConverter)
|
2018-02-13 16:31:57 +00:00
|
|
|
|
|
|
|
contract := testing.SampleContract()
|
|
|
|
var balance = new(big.Int)
|
2018-08-09 16:58:06 +00:00
|
|
|
|
2019-01-23 06:55:26 +00:00
|
|
|
args := make([]interface{}, 1)
|
2019-01-23 06:37:26 +00:00
|
|
|
args[0] = common.HexToHash("0xd26114cd6ee289accf82350c8d8487fedb8a0c07")
|
2018-08-09 16:58:06 +00:00
|
|
|
|
2018-07-18 20:59:40 +00:00
|
|
|
err = blockChain.FetchContractData(contract.Abi, "0xd26114cd6ee289accf82350c8d8487fedb8a0c07", "balanceOf", args, &balance, 5167471)
|
2018-02-13 16:31:57 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
expected := new(big.Int)
|
|
|
|
expected.SetString("10897295492887612977137", 10)
|
|
|
|
Expect(balance).To(Equal(expected))
|
|
|
|
})
|
|
|
|
})
|
2017-12-11 21:08:00 +00:00
|
|
|
})
|