2018-05-02 16:17:02 +00:00
|
|
|
package common_test
|
2017-10-31 13:58:04 +00:00
|
|
|
|
|
|
|
import (
|
2018-03-27 21:06:12 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
2018-05-02 16:17:02 +00:00
|
|
|
"math/big"
|
2018-03-27 21:06:12 +00:00
|
|
|
"os"
|
|
|
|
|
2017-10-31 13:58:04 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2017-11-02 21:43:07 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
2017-10-31 13:58:04 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2018-05-02 16:17:02 +00:00
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
2018-05-02 16:17:02 +00:00
|
|
|
vulcCommon "github.com/vulcanize/vulcanizedb/pkg/geth/converters/common"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/geth/converters/rpc"
|
2017-10-31 13:58:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
|
|
|
|
2017-12-27 16:50:56 +00:00
|
|
|
It("converts basic Block metadata", func() {
|
2017-11-02 14:36:53 +00:00
|
|
|
difficulty := big.NewInt(1)
|
2018-03-07 21:29:21 +00:00
|
|
|
gasLimit := uint64(100000)
|
|
|
|
gasUsed := uint64(100000)
|
2017-12-27 16:50:56 +00:00
|
|
|
miner := common.HexToAddress("0x0000000000000000000000000000000000000123")
|
2017-12-27 18:10:08 +00:00
|
|
|
extraData, _ := hexutil.Decode("0xe4b883e5bda9e7a59ee4bb99e9b1bc")
|
2017-11-02 14:36:53 +00:00
|
|
|
nonce := types.BlockNonce{10}
|
|
|
|
number := int64(1)
|
2017-10-31 17:51:05 +00:00
|
|
|
time := int64(140000000)
|
2017-10-31 13:58:04 +00:00
|
|
|
|
2017-10-31 17:51:05 +00:00
|
|
|
header := types.Header{
|
2017-11-02 14:36:53 +00:00
|
|
|
Difficulty: difficulty,
|
2018-03-07 21:29:21 +00:00
|
|
|
GasLimit: uint64(gasLimit),
|
|
|
|
GasUsed: uint64(gasUsed),
|
2017-12-27 18:10:08 +00:00
|
|
|
Extra: extraData,
|
2017-12-27 16:50:56 +00:00
|
|
|
Coinbase: miner,
|
2017-11-02 14:36:53 +00:00
|
|
|
Nonce: nonce,
|
|
|
|
Number: big.NewInt(number),
|
|
|
|
ParentHash: common.Hash{64},
|
|
|
|
Time: big.NewInt(time),
|
|
|
|
UncleHash: common.Hash{128},
|
2017-10-31 17:51:05 +00:00
|
|
|
}
|
2017-10-31 13:58:04 +00:00
|
|
|
block := types.NewBlock(&header, []*types.Transaction{}, []*types.Header{}, []*types.Receipt{})
|
2018-07-20 16:37:46 +00:00
|
|
|
client := fakes.NewMockEthClient()
|
2018-05-02 16:17:02 +00:00
|
|
|
transactionConverter := rpc.NewRpcTransactionConverter(client)
|
|
|
|
blockConverter := vulcCommon.NewBlockConverter(transactionConverter)
|
|
|
|
|
|
|
|
coreBlock, err := blockConverter.ToCoreBlock(block)
|
2017-10-31 13:58:04 +00:00
|
|
|
|
2018-03-27 21:06:12 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2018-05-02 16:17:02 +00:00
|
|
|
Expect(coreBlock.Difficulty).To(Equal(difficulty.Int64()))
|
|
|
|
Expect(coreBlock.GasLimit).To(Equal(gasLimit))
|
|
|
|
Expect(coreBlock.Miner).To(Equal(miner.Hex()))
|
|
|
|
Expect(coreBlock.GasUsed).To(Equal(gasUsed))
|
|
|
|
Expect(coreBlock.Hash).To(Equal(block.Hash().Hex()))
|
|
|
|
Expect(coreBlock.Nonce).To(Equal(hexutil.Encode(header.Nonce[:])))
|
|
|
|
Expect(coreBlock.Number).To(Equal(number))
|
|
|
|
Expect(coreBlock.ParentHash).To(Equal(block.ParentHash().Hex()))
|
|
|
|
Expect(coreBlock.ExtraData).To(Equal(hexutil.Encode(block.Extra())))
|
|
|
|
Expect(coreBlock.Size).To(Equal(block.Size().String()))
|
|
|
|
Expect(coreBlock.Time).To(Equal(time))
|
|
|
|
Expect(coreBlock.UncleHash).To(Equal(block.UncleHash().Hex()))
|
|
|
|
Expect(coreBlock.IsFinal).To(BeFalse())
|
2017-10-31 13:58:04 +00:00
|
|
|
})
|
|
|
|
|
2017-12-28 16:06:13 +00:00
|
|
|
Describe("The block and uncle rewards calculations", func() {
|
|
|
|
It("calculates block rewards for a block", func() {
|
|
|
|
transaction := types.NewTransaction(
|
|
|
|
uint64(226823),
|
|
|
|
common.HexToAddress("0x108fedb097c1dcfed441480170144d8e19bb217f"),
|
|
|
|
big.NewInt(1080900090000000000),
|
2018-03-07 21:29:21 +00:00
|
|
|
uint64(90000),
|
2017-12-28 16:06:13 +00:00
|
|
|
big.NewInt(50000000000),
|
|
|
|
[]byte{},
|
|
|
|
)
|
2017-12-27 23:51:17 +00:00
|
|
|
transactions := []*types.Transaction{transaction}
|
|
|
|
|
|
|
|
txHash := transaction.Hash()
|
2018-01-05 17:55:00 +00:00
|
|
|
receipt := types.Receipt{
|
|
|
|
TxHash: txHash,
|
2018-03-07 21:29:21 +00:00
|
|
|
GasUsed: uint64(21000),
|
|
|
|
CumulativeGasUsed: uint64(21000),
|
2018-01-05 17:55:00 +00:00
|
|
|
}
|
2017-12-27 23:51:17 +00:00
|
|
|
receipts := []*types.Receipt{&receipt}
|
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
client := fakes.NewMockEthClient()
|
|
|
|
client.SetTransactionReceipts(receipts)
|
2018-01-05 17:55:00 +00:00
|
|
|
|
2017-12-28 16:06:13 +00:00
|
|
|
number := int64(1071819)
|
2017-12-27 23:51:17 +00:00
|
|
|
header := types.Header{
|
|
|
|
Number: big.NewInt(number),
|
|
|
|
}
|
2017-12-28 16:06:13 +00:00
|
|
|
uncles := []*types.Header{{Number: big.NewInt(1071817)}, {Number: big.NewInt(1071818)}}
|
2018-01-05 17:55:00 +00:00
|
|
|
block := types.NewBlock(&header, transactions, uncles, []*types.Receipt{&receipt})
|
2018-05-02 16:17:02 +00:00
|
|
|
transactionConverter := rpc.NewRpcTransactionConverter(client)
|
|
|
|
blockConverter := vulcCommon.NewBlockConverter(transactionConverter)
|
|
|
|
|
|
|
|
coreBlock, err := blockConverter.ToCoreBlock(block)
|
2017-12-27 23:51:17 +00:00
|
|
|
|
2018-03-27 21:06:12 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2018-05-02 16:17:02 +00:00
|
|
|
Expect(vulcCommon.CalcBlockReward(coreBlock, block.Uncles())).To(Equal(5.31355))
|
2017-12-27 23:51:17 +00:00
|
|
|
})
|
|
|
|
|
2017-12-28 16:06:13 +00:00
|
|
|
It("calculates the uncles reward for a block", func() {
|
|
|
|
transaction := types.NewTransaction(
|
|
|
|
uint64(226823),
|
|
|
|
common.HexToAddress("0x108fedb097c1dcfed441480170144d8e19bb217f"),
|
|
|
|
big.NewInt(1080900090000000000),
|
2018-03-07 21:29:21 +00:00
|
|
|
uint64(90000),
|
2017-12-28 16:06:13 +00:00
|
|
|
big.NewInt(50000000000),
|
|
|
|
[]byte{})
|
|
|
|
transactions := []*types.Transaction{transaction}
|
2017-12-27 23:51:17 +00:00
|
|
|
|
2017-12-28 16:06:13 +00:00
|
|
|
receipt := types.Receipt{
|
2018-01-05 17:55:00 +00:00
|
|
|
TxHash: transaction.Hash(),
|
2018-03-07 21:29:21 +00:00
|
|
|
GasUsed: uint64(21000),
|
|
|
|
CumulativeGasUsed: uint64(21000),
|
2017-12-28 16:06:13 +00:00
|
|
|
}
|
|
|
|
receipts := []*types.Receipt{&receipt}
|
2017-12-27 23:51:17 +00:00
|
|
|
|
|
|
|
header := types.Header{
|
2017-12-28 16:06:13 +00:00
|
|
|
Number: big.NewInt(int64(1071819)),
|
2017-12-27 23:51:17 +00:00
|
|
|
}
|
2017-12-28 16:06:13 +00:00
|
|
|
uncles := []*types.Header{
|
|
|
|
{Number: big.NewInt(1071816)},
|
|
|
|
{Number: big.NewInt(1071817)},
|
|
|
|
}
|
2018-01-05 17:55:00 +00:00
|
|
|
block := types.NewBlock(&header, transactions, uncles, receipts)
|
2017-12-27 23:51:17 +00:00
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
client := fakes.NewMockEthClient()
|
|
|
|
client.SetTransactionReceipts(receipts)
|
2018-05-02 16:17:02 +00:00
|
|
|
transactionConverter := rpc.NewRpcTransactionConverter(client)
|
|
|
|
blockConverter := vulcCommon.NewBlockConverter(transactionConverter)
|
2017-12-27 23:51:17 +00:00
|
|
|
|
2018-05-02 16:17:02 +00:00
|
|
|
coreBlock, err := blockConverter.ToCoreBlock(block)
|
2018-01-05 17:55:00 +00:00
|
|
|
|
2018-03-27 21:06:12 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2018-05-02 16:17:02 +00:00
|
|
|
Expect(vulcCommon.CalcUnclesReward(coreBlock, block.Uncles())).To(Equal(6.875))
|
2017-12-27 23:51:17 +00:00
|
|
|
})
|
|
|
|
|
2017-12-28 16:06:13 +00:00
|
|
|
It("decreases the static block reward from 5 to 3 for blocks after block 4,269,999", func() {
|
|
|
|
transactionOne := types.NewTransaction(
|
|
|
|
uint64(8072),
|
|
|
|
common.HexToAddress("0xebd17720aeb7ac5186c5dfa7bafeb0bb14c02551 "),
|
|
|
|
big.NewInt(0),
|
2018-03-07 21:29:21 +00:00
|
|
|
uint64(500000),
|
2017-12-28 16:06:13 +00:00
|
|
|
big.NewInt(42000000000),
|
|
|
|
[]byte{},
|
|
|
|
)
|
|
|
|
|
|
|
|
transactionTwo := types.NewTransaction(uint64(8071),
|
|
|
|
common.HexToAddress("0x3cdab63d764c8c5048ed5e8f0a4e95534ba7e1ea"),
|
|
|
|
big.NewInt(0),
|
2018-03-07 21:29:21 +00:00
|
|
|
uint64(500000),
|
2017-12-28 16:06:13 +00:00
|
|
|
big.NewInt(42000000000),
|
|
|
|
[]byte{})
|
2017-12-27 23:51:17 +00:00
|
|
|
|
2017-12-28 16:06:13 +00:00
|
|
|
transactions := []*types.Transaction{transactionOne, transactionTwo}
|
2017-12-27 23:51:17 +00:00
|
|
|
|
2017-12-28 16:06:13 +00:00
|
|
|
receiptOne := types.Receipt{
|
2018-01-05 17:55:00 +00:00
|
|
|
TxHash: transactionOne.Hash(),
|
2018-03-07 21:29:21 +00:00
|
|
|
GasUsed: uint64(297508),
|
|
|
|
CumulativeGasUsed: uint64(0),
|
2017-12-28 16:06:13 +00:00
|
|
|
}
|
|
|
|
receiptTwo := types.Receipt{
|
2018-01-05 17:55:00 +00:00
|
|
|
TxHash: transactionTwo.Hash(),
|
2018-03-07 21:29:21 +00:00
|
|
|
GasUsed: uint64(297508),
|
|
|
|
CumulativeGasUsed: uint64(0),
|
2017-12-28 16:06:13 +00:00
|
|
|
}
|
|
|
|
receipts := []*types.Receipt{&receiptOne, &receiptTwo}
|
|
|
|
|
|
|
|
number := int64(4370055)
|
2017-12-27 23:51:17 +00:00
|
|
|
header := types.Header{
|
|
|
|
Number: big.NewInt(number),
|
|
|
|
}
|
2017-12-28 16:06:13 +00:00
|
|
|
var uncles []*types.Header
|
|
|
|
block := types.NewBlock(&header, transactions, uncles, receipts)
|
2017-12-27 23:51:17 +00:00
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
client := fakes.NewMockEthClient()
|
|
|
|
client.SetTransactionReceipts(receipts)
|
2018-05-02 16:17:02 +00:00
|
|
|
transactionConverter := rpc.NewRpcTransactionConverter(client)
|
|
|
|
blockConverter := vulcCommon.NewBlockConverter(transactionConverter)
|
|
|
|
|
|
|
|
coreBlock, err := blockConverter.ToCoreBlock(block)
|
2017-12-27 23:51:17 +00:00
|
|
|
|
2018-03-27 21:06:12 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2018-05-02 16:17:02 +00:00
|
|
|
Expect(vulcCommon.CalcBlockReward(coreBlock, block.Uncles())).To(Equal(3.024990672))
|
2017-12-27 23:51:17 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-12-28 16:06:13 +00:00
|
|
|
Describe("the converted transactions", func() {
|
2017-10-31 13:58:04 +00:00
|
|
|
It("is empty", func() {
|
|
|
|
header := types.Header{}
|
|
|
|
block := types.NewBlock(&header, []*types.Transaction{}, []*types.Header{}, []*types.Receipt{})
|
2018-07-20 16:37:46 +00:00
|
|
|
client := fakes.NewMockEthClient()
|
2018-05-02 16:17:02 +00:00
|
|
|
transactionConverter := rpc.NewRpcTransactionConverter(client)
|
|
|
|
blockConverter := vulcCommon.NewBlockConverter(transactionConverter)
|
|
|
|
|
|
|
|
coreBlock, err := blockConverter.ToCoreBlock(block)
|
2017-10-31 13:58:04 +00:00
|
|
|
|
2018-03-27 21:06:12 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2017-10-31 13:58:04 +00:00
|
|
|
Expect(len(coreBlock.Transactions)).To(Equal(0))
|
|
|
|
})
|
|
|
|
|
2017-12-27 23:51:17 +00:00
|
|
|
It("converts a single transaction", func() {
|
2018-01-03 17:23:43 +00:00
|
|
|
gethTransaction := types.NewTransaction(
|
|
|
|
uint64(10000), common.Address{1},
|
|
|
|
big.NewInt(10),
|
2018-03-07 21:29:21 +00:00
|
|
|
uint64(5000),
|
2018-01-03 17:23:43 +00:00
|
|
|
big.NewInt(3),
|
|
|
|
hexutil.MustDecode("0xf7d8c8830000000000000000000000000000000000000000000000000000000000037788000000000000000000000000000000000000000000000000000000000003bd14"),
|
|
|
|
)
|
2017-10-31 13:58:04 +00:00
|
|
|
|
2018-01-03 17:23:43 +00:00
|
|
|
gethReceipt := &types.Receipt{
|
|
|
|
Bloom: types.BytesToBloom(hexutil.MustDecode("0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")),
|
|
|
|
ContractAddress: common.HexToAddress("x123"),
|
2018-03-07 21:29:21 +00:00
|
|
|
CumulativeGasUsed: uint64(7996119),
|
|
|
|
GasUsed: uint64(21000),
|
2018-01-03 17:23:43 +00:00
|
|
|
Logs: []*types.Log{},
|
|
|
|
Status: uint(1),
|
|
|
|
TxHash: gethTransaction.Hash(),
|
|
|
|
}
|
2017-12-27 23:51:17 +00:00
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
client := fakes.NewMockEthClient()
|
|
|
|
client.SetTransactionReceipts([]*types.Receipt{gethReceipt})
|
2017-12-27 23:51:17 +00:00
|
|
|
|
2018-01-03 17:23:43 +00:00
|
|
|
header := types.Header{}
|
2018-05-02 16:17:02 +00:00
|
|
|
block := types.NewBlock(
|
2018-01-03 17:23:43 +00:00
|
|
|
&header,
|
|
|
|
[]*types.Transaction{gethTransaction},
|
|
|
|
[]*types.Header{},
|
|
|
|
[]*types.Receipt{gethReceipt},
|
|
|
|
)
|
2018-05-02 16:17:02 +00:00
|
|
|
transactionConverter := rpc.NewRpcTransactionConverter(client)
|
|
|
|
blockConverter := vulcCommon.NewBlockConverter(transactionConverter)
|
|
|
|
|
|
|
|
coreBlock, err := blockConverter.ToCoreBlock(block)
|
2017-10-31 13:58:04 +00:00
|
|
|
|
2018-03-27 21:06:12 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2017-10-31 13:58:04 +00:00
|
|
|
Expect(len(coreBlock.Transactions)).To(Equal(1))
|
|
|
|
coreTransaction := coreBlock.Transactions[0]
|
2018-01-03 17:23:43 +00:00
|
|
|
Expect(coreTransaction.Data).To(Equal("0xf7d8c8830000000000000000000000000000000000000000000000000000000000037788000000000000000000000000000000000000000000000000000000000003bd14"))
|
2017-10-31 13:58:04 +00:00
|
|
|
Expect(coreTransaction.To).To(Equal(gethTransaction.To().Hex()))
|
2017-11-08 20:55:35 +00:00
|
|
|
Expect(coreTransaction.From).To(Equal("0x0000000000000000000000000000000000000123"))
|
2018-03-07 21:29:21 +00:00
|
|
|
Expect(coreTransaction.GasLimit).To(Equal(gethTransaction.Gas()))
|
2017-10-31 13:58:04 +00:00
|
|
|
Expect(coreTransaction.GasPrice).To(Equal(gethTransaction.GasPrice().Int64()))
|
2018-01-16 20:25:33 +00:00
|
|
|
Expect(coreTransaction.Value).To(Equal(gethTransaction.Value().String()))
|
2017-10-31 13:58:04 +00:00
|
|
|
Expect(coreTransaction.Nonce).To(Equal(gethTransaction.Nonce()))
|
2018-01-03 17:23:43 +00:00
|
|
|
|
|
|
|
coreReceipt := coreTransaction.Receipt
|
2018-05-02 16:17:02 +00:00
|
|
|
expectedReceipt := vulcCommon.ToCoreReceipt(gethReceipt)
|
2018-01-03 17:23:43 +00:00
|
|
|
Expect(coreReceipt).To(Equal(expectedReceipt))
|
2017-10-31 13:58:04 +00:00
|
|
|
})
|
|
|
|
|
2018-01-03 17:23:43 +00:00
|
|
|
It("has an empty 'To' field when transaction creates a new contract", func() {
|
|
|
|
gethTransaction := types.NewContractCreation(
|
|
|
|
uint64(10000),
|
|
|
|
big.NewInt(10),
|
2018-03-07 21:29:21 +00:00
|
|
|
uint64(5000),
|
2018-01-03 17:23:43 +00:00
|
|
|
big.NewInt(3),
|
|
|
|
[]byte("1234"),
|
|
|
|
)
|
|
|
|
|
|
|
|
gethReceipt := &types.Receipt{
|
2018-03-07 21:29:21 +00:00
|
|
|
CumulativeGasUsed: uint64(1),
|
|
|
|
GasUsed: uint64(1),
|
2018-01-03 17:23:43 +00:00
|
|
|
TxHash: gethTransaction.Hash(),
|
|
|
|
ContractAddress: common.HexToAddress("0x1023342345"),
|
|
|
|
}
|
2017-10-31 13:58:04 +00:00
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
client := fakes.NewMockEthClient()
|
|
|
|
client.SetTransactionReceipts([]*types.Receipt{gethReceipt})
|
2018-01-03 17:23:43 +00:00
|
|
|
|
2018-05-02 16:17:02 +00:00
|
|
|
block := types.NewBlock(
|
2018-01-03 17:23:43 +00:00
|
|
|
&types.Header{},
|
|
|
|
[]*types.Transaction{gethTransaction},
|
|
|
|
[]*types.Header{},
|
|
|
|
[]*types.Receipt{gethReceipt},
|
|
|
|
)
|
2018-05-02 16:17:02 +00:00
|
|
|
transactionConverter := rpc.NewRpcTransactionConverter(client)
|
|
|
|
blockConverter := vulcCommon.NewBlockConverter(transactionConverter)
|
2018-01-03 17:23:43 +00:00
|
|
|
|
2018-05-02 16:17:02 +00:00
|
|
|
coreBlock, err := blockConverter.ToCoreBlock(block)
|
2017-10-31 13:58:04 +00:00
|
|
|
|
2018-03-27 21:06:12 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2017-10-31 13:58:04 +00:00
|
|
|
coreTransaction := coreBlock.Transactions[0]
|
|
|
|
Expect(coreTransaction.To).To(Equal(""))
|
2018-01-03 17:23:43 +00:00
|
|
|
|
|
|
|
coreReceipt := coreTransaction.Receipt
|
2018-05-02 16:17:02 +00:00
|
|
|
expectedReceipt := vulcCommon.ToCoreReceipt(gethReceipt)
|
2018-01-03 17:23:43 +00:00
|
|
|
Expect(coreReceipt).To(Equal(expectedReceipt))
|
2017-10-31 13:58:04 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-03-27 21:06:12 +00:00
|
|
|
Describe("transaction error handling", func() {
|
|
|
|
var gethTransaction *types.Transaction
|
|
|
|
var gethReceipt *types.Receipt
|
|
|
|
var header *types.Header
|
2018-05-02 16:17:02 +00:00
|
|
|
var block *types.Block
|
2018-03-27 21:06:12 +00:00
|
|
|
|
|
|
|
BeforeEach(func() {
|
|
|
|
log.SetOutput(ioutil.Discard)
|
|
|
|
gethTransaction = types.NewTransaction(
|
|
|
|
uint64(0),
|
|
|
|
common.Address{},
|
|
|
|
big.NewInt(0),
|
|
|
|
uint64(0),
|
|
|
|
big.NewInt(0),
|
|
|
|
[]byte{},
|
|
|
|
)
|
|
|
|
gethReceipt = &types.Receipt{}
|
|
|
|
header = &types.Header{}
|
2018-05-02 16:17:02 +00:00
|
|
|
block = types.NewBlock(
|
2018-03-27 21:06:12 +00:00
|
|
|
header,
|
|
|
|
[]*types.Transaction{gethTransaction},
|
|
|
|
[]*types.Header{},
|
|
|
|
[]*types.Receipt{gethReceipt},
|
|
|
|
)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
AfterEach(func() {
|
|
|
|
defer log.SetOutput(os.Stdout)
|
|
|
|
})
|
|
|
|
|
|
|
|
It("returns an error when transaction sender call fails", func() {
|
2018-07-20 16:37:46 +00:00
|
|
|
client := fakes.NewMockEthClient()
|
|
|
|
client.SetTransactionSenderErr(fakes.FakeError)
|
2018-05-02 16:17:02 +00:00
|
|
|
transactionConverter := rpc.NewRpcTransactionConverter(client)
|
|
|
|
blockConverter := vulcCommon.NewBlockConverter(transactionConverter)
|
|
|
|
|
|
|
|
_, err := blockConverter.ToCoreBlock(block)
|
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
Expect(err).To(MatchError(fakes.FakeError))
|
2018-03-27 21:06:12 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("returns an error when transaction receipt call fails", func() {
|
2018-07-20 16:37:46 +00:00
|
|
|
client := fakes.NewMockEthClient()
|
|
|
|
client.SetTransactionReceiptErr(fakes.FakeError)
|
2018-05-02 16:17:02 +00:00
|
|
|
transactionConverter := rpc.NewRpcTransactionConverter(client)
|
|
|
|
blockConverter := vulcCommon.NewBlockConverter(transactionConverter)
|
|
|
|
|
|
|
|
_, err := blockConverter.ToCoreBlock(block)
|
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
Expect(err).To(MatchError(fakes.FakeError))
|
2018-03-27 21:06:12 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-31 13:58:04 +00:00
|
|
|
})
|