Add tests for pkg/geth/blockchain

- inject dependencies instead of initializing them in the constructor
This commit is contained in:
Rob Mulholand
2018-07-18 16:34:13 -05:00
parent 1355271011
commit 63434f6bc9
20 changed files with 538 additions and 106 deletions
@@ -15,29 +15,51 @@
package every_block_test
import (
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/examples/constants"
"github.com/vulcanize/vulcanizedb/examples/erc20_watcher/every_block"
"github.com/vulcanize/vulcanizedb/examples/mocks"
"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"
)
var _ = Describe("ERC20 Fetcher", func() {
blockNumber := int64(5502914)
infuraIPC := "https://mainnet.infura.io/J5Vd2fRtGsw0zZ0Ov3BL"
realBlockchain := geth.NewBlockChain(infuraIPC)
realFetcher := every_block.NewFetcher(realBlockchain)
var errorFetcher every_block.Fetcher
var realFetcher every_block.Fetcher
var testFetcher every_block.Fetcher
var fakeBlockchain *mocks.Blockchain
var testAbi string
var testContractAddress string
fakeBlockchain := &mocks.Blockchain{}
testFetcher := every_block.NewFetcher(fakeBlockchain)
testAbi := "testAbi"
testContractAddress := "testContractAddress"
BeforeEach(func() {
rpcClient, err := rpc.Dial(infuraIPC)
Expect(err).NotTo(HaveOccurred())
ethClient := ethclient.NewClient(rpcClient)
blockChainClient := client.NewClient(ethClient)
clientWrapper := node.ClientWrapper{
ContextCaller: rpcClient,
IPCPath: infuraIPC,
}
node := node.MakeNode(clientWrapper)
transactionConverter := rpc2.NewRpcTransactionConverter(ethClient)
realBlockChain := geth.NewBlockChain(blockChainClient, node, transactionConverter)
realFetcher = every_block.NewFetcher(realBlockChain)
fakeBlockchain = &mocks.Blockchain{}
testFetcher = every_block.NewFetcher(fakeBlockchain)
testAbi = "testAbi"
testContractAddress = "testContractAddress"
errorBlockchain := &mocks.FailureBlockchain{}
errorFetcher := every_block.NewFetcher(errorBlockchain)
errorBlockchain := &mocks.FailureBlockchain{}
errorFetcher = every_block.NewFetcher(errorBlockchain)
})
Describe("FetchSupplyOf", func() {
It("fetches data from the blockchain with the correct arguments", func() {