Improve transaction syncing test coverage
This commit is contained in:
parent
81dfd12665
commit
f5b32a11b0
@ -17,6 +17,7 @@
|
||||
package integration_test
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
. "github.com/onsi/ginkgo"
|
||||
@ -85,6 +86,41 @@ var _ = Describe("Reading from the Geth blockchain", func() {
|
||||
close(done)
|
||||
}, 15)
|
||||
|
||||
It("retrieves transaction", func() {
|
||||
// actual transaction: https://etherscan.io/tx/0x44d462f2a19ad267e276b234a62c542fc91c974d2e4754a325ca405f95440255
|
||||
txHash := common.HexToHash("0x44d462f2a19ad267e276b234a62c542fc91c974d2e4754a325ca405f95440255")
|
||||
transactions, err := blockChain.GetTransactions([]common.Hash{txHash})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(len(transactions)).To(Equal(1))
|
||||
expectedData := []byte{149, 227, 197, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 160, 85, 105, 13, 157, 184, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,
|
||||
241, 202, 218, 90, 30, 178, 234, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 92, 155, 193, 43}
|
||||
expectedRaw := []byte{248, 201, 9, 132, 59, 154, 202, 0, 131, 1, 102, 93, 148, 44, 75, 208, 100, 185, 152, 131,
|
||||
128, 118, 250, 52, 26, 131, 208, 7, 252, 47, 165, 9, 87, 128, 184, 100, 149, 227, 197, 11, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 160, 85, 105, 13, 157, 184, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 241, 202, 218, 90, 30, 178, 234, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 92, 155, 193, 43, 37, 160, 237, 184, 236, 248, 23, 152,
|
||||
53, 238, 44, 215, 181, 234, 229, 157, 246, 212, 178, 88, 25, 116, 134, 163, 124, 64, 2, 66, 25, 118, 1, 253, 27,
|
||||
101, 160, 36, 226, 116, 43, 147, 236, 124, 76, 227, 250, 228, 168, 22, 19, 248, 155, 248, 151, 219, 14, 1, 186,
|
||||
159, 35, 154, 22, 222, 123, 254, 147, 63, 221}
|
||||
expectedModel := core.TransactionModel{
|
||||
Data: expectedData,
|
||||
From: "0x3b08b99441086edd66f36f9f9aee733280698378",
|
||||
GasLimit: 91741,
|
||||
GasPrice: 1000000000,
|
||||
Hash: "0x44d462f2a19ad267e276b234a62c542fc91c974d2e4754a325ca405f95440255",
|
||||
Nonce: 9,
|
||||
Raw: expectedRaw,
|
||||
Receipt: core.Receipt{},
|
||||
To: "0x2c4bd064b998838076fa341a83d007fc2fa50957",
|
||||
TxIndex: 30,
|
||||
Value: "0",
|
||||
}
|
||||
Expect(transactions[0]).To(Equal(expectedModel))
|
||||
})
|
||||
|
||||
//Benchmarking test: remove skip to test performance of block retrieval
|
||||
XMeasure("retrieving n blocks", func(b Benchmarker) {
|
||||
b.Time("runtime", func() {
|
||||
|
@ -36,7 +36,7 @@ type RpcTransaction struct {
|
||||
GasLimit string `json:"gas"`
|
||||
Recipient string `json:"to"`
|
||||
Amount string `json:"value"`
|
||||
Payload []byte `json:"input"`
|
||||
Payload string `json:"input"`
|
||||
V string `json:"v"`
|
||||
R string `json:"r"`
|
||||
S string `json:"s"`
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"log"
|
||||
"math/big"
|
||||
"strings"
|
||||
@ -70,7 +71,7 @@ func (converter *RpcTransactionConverter) ConvertRpcTransactionsToModels(transac
|
||||
return nil, txIndexErr
|
||||
}
|
||||
transactionModel := core.TransactionModel{
|
||||
Data: transaction.Payload,
|
||||
Data: txData.Payload,
|
||||
From: transaction.From,
|
||||
GasLimit: txData.GasLimit,
|
||||
GasPrice: txData.Price.Int64(),
|
||||
@ -187,7 +188,7 @@ func getTransactionData(transaction core.RpcTransaction) (transactionData, error
|
||||
GasLimit: gasLimit.Uint64(),
|
||||
Recipient: &recipient,
|
||||
Amount: amount,
|
||||
Payload: transaction.Payload,
|
||||
Payload: hexutil.MustDecode(transaction.Payload),
|
||||
V: v,
|
||||
R: r,
|
||||
S: s,
|
||||
|
@ -9,8 +9,13 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("RPC transaction converter", func() {
|
||||
var converter rpc.RpcTransactionConverter
|
||||
|
||||
BeforeEach(func() {
|
||||
converter = rpc.RpcTransactionConverter{}
|
||||
})
|
||||
|
||||
It("converts hex fields to integers", func() {
|
||||
converter := rpc.RpcTransactionConverter{}
|
||||
rpcTransaction := getFakeRpcTransaction("0x1")
|
||||
|
||||
transactionModels, err := converter.ConvertRpcTransactionsToModels([]core.RpcTransaction{rpcTransaction})
|
||||
@ -25,7 +30,6 @@ var _ = Describe("RPC transaction converter", func() {
|
||||
})
|
||||
|
||||
It("returns error if invalid hex cannot be converted", func() {
|
||||
converter := rpc.RpcTransactionConverter{}
|
||||
invalidTransaction := getFakeRpcTransaction("invalid")
|
||||
|
||||
_, err := converter.ConvertRpcTransactionsToModels([]core.RpcTransaction{invalidTransaction})
|
||||
@ -34,7 +38,6 @@ var _ = Describe("RPC transaction converter", func() {
|
||||
})
|
||||
|
||||
It("copies RPC transaction hash, from, and to values to model", func() {
|
||||
converter := rpc.RpcTransactionConverter{}
|
||||
rpcTransaction := getFakeRpcTransaction("0x1")
|
||||
|
||||
transactionModels, err := converter.ConvertRpcTransactionsToModels([]core.RpcTransaction{rpcTransaction})
|
||||
@ -46,14 +49,37 @@ var _ = Describe("RPC transaction converter", func() {
|
||||
Expect(transactionModels[0].To).To(Equal(rpcTransaction.Recipient))
|
||||
})
|
||||
|
||||
XIt("derives transaction RLP", func() {
|
||||
// actual transaction: https://kovan.etherscan.io/tx/0x73aefdf70fc5650e0dd82affbb59d107f12dfabc50a78625b434ea68b7a69ee6
|
||||
// actual RLP hex: 0x2926af093b6b72e3f10089bde6da0f99b0d4e13354f6f37c8334efc9d7e99a47
|
||||
It("derives transaction RLP", func() {
|
||||
// actual transaction: https://kovan.etherscan.io/tx/0x3b29ef265425d304069c57e5145cd1c7558568b06d231775f50a693bee1aad4f
|
||||
rpcTransaction := core.RpcTransaction{
|
||||
Nonce: "0x7aa9",
|
||||
GasPrice: "0x3b9aca00",
|
||||
GasLimit: "0x7a120",
|
||||
Recipient: "0xf88bbdc1e2718f8857f30a180076ec38d53cf296",
|
||||
Amount: "0x0",
|
||||
Payload: "0x18178358",
|
||||
V: "0x78",
|
||||
R: "0x79f6a78ababfdb37b87a4d52795a49b08b5b5171443d1f2fb8f373431e77439c",
|
||||
S: "0x3f1a210dd3b59d161735a314b88568fa91552dfe207c00a2fdbcd52ccb081409",
|
||||
Hash: "0x3b29ef265425d304069c57e5145cd1c7558568b06d231775f50a693bee1aad4f",
|
||||
From: "0x694032e172d9b0ee6aff5d36749bad4947a36e4e",
|
||||
TransactionIndex: "0xa",
|
||||
}
|
||||
|
||||
transactionModels, err := converter.ConvertRpcTransactionsToModels([]core.RpcTransaction{rpcTransaction})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(len(transactionModels)).To(Equal(1))
|
||||
model := transactionModels[0]
|
||||
expectedRLP := []byte{248, 106, 130, 122, 169, 132, 59, 154, 202, 0, 131, 7, 161, 32, 148, 248, 139, 189, 193,
|
||||
226, 113, 143, 136, 87, 243, 10, 24, 0, 118, 236, 56, 213, 60, 242, 150, 128, 132, 24, 23, 131, 88, 120, 160,
|
||||
121, 246, 167, 138, 186, 191, 219, 55, 184, 122, 77, 82, 121, 90, 73, 176, 139, 91, 81, 113, 68, 61, 31, 47,
|
||||
184, 243, 115, 67, 30, 119, 67, 156, 160, 63, 26, 33, 13, 211, 181, 157, 22, 23, 53, 163, 20, 184, 133, 104,
|
||||
250, 145, 85, 45, 254, 32, 124, 0, 162, 253, 188, 213, 44, 203, 8, 20, 9}
|
||||
Expect(model.Raw).To(Equal(expectedRLP))
|
||||
})
|
||||
|
||||
It("does not include transaction receipt", func() {
|
||||
converter := rpc.RpcTransactionConverter{}
|
||||
rpcTransaction := getFakeRpcTransaction("0x1")
|
||||
|
||||
transactionModels, err := converter.ConvertRpcTransactionsToModels([]core.RpcTransaction{rpcTransaction})
|
||||
@ -76,7 +102,7 @@ func getFakeRpcTransaction(hex string) core.RpcTransaction {
|
||||
V: "0x2",
|
||||
R: "0x2",
|
||||
S: "0x2",
|
||||
Payload: nil,
|
||||
Payload: "0x12",
|
||||
TransactionIndex: hex,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user