2020-02-20 22:13:19 +00:00
|
|
|
// VulcanizeDB
|
|
|
|
// Copyright © 2019 Vulcanize
|
|
|
|
|
|
|
|
// 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/>.
|
|
|
|
|
|
|
|
package eth_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strconv"
|
|
|
|
|
2020-10-29 20:18:27 +00:00
|
|
|
"github.com/ethereum/go-ethereum/rlp"
|
|
|
|
|
2020-02-20 22:13:19 +00:00
|
|
|
"github.com/ethereum/go-ethereum"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
2020-08-31 15:47:06 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2020-02-20 22:13:19 +00:00
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
|
2020-09-02 15:19:25 +00:00
|
|
|
eth2 "github.com/vulcanize/ipld-eth-indexer/pkg/eth"
|
|
|
|
"github.com/vulcanize/ipld-eth-indexer/pkg/postgres"
|
2020-08-31 15:47:06 +00:00
|
|
|
|
|
|
|
"github.com/vulcanize/ipld-eth-server/pkg/eth"
|
2020-10-20 20:33:18 +00:00
|
|
|
"github.com/vulcanize/ipld-eth-server/pkg/eth/test_helpers"
|
2020-08-31 15:47:06 +00:00
|
|
|
"github.com/vulcanize/ipld-eth-server/pkg/shared"
|
2020-02-20 22:13:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-10-29 20:18:27 +00:00
|
|
|
number = rpc.BlockNumber(test_helpers.BlockNumber.Int64())
|
|
|
|
blockHash = test_helpers.MockBlock.Header().Hash()
|
|
|
|
ctx = context.Background()
|
2020-02-20 22:13:19 +00:00
|
|
|
expectedBlock = map[string]interface{}{
|
2020-10-20 20:33:18 +00:00
|
|
|
"number": (*hexutil.Big)(test_helpers.MockBlock.Number()),
|
|
|
|
"hash": test_helpers.MockBlock.Hash(),
|
|
|
|
"parentHash": test_helpers.MockBlock.ParentHash(),
|
|
|
|
"nonce": test_helpers.MockBlock.Header().Nonce,
|
|
|
|
"mixHash": test_helpers.MockBlock.MixDigest(),
|
|
|
|
"sha3Uncles": test_helpers.MockBlock.UncleHash(),
|
|
|
|
"logsBloom": test_helpers.MockBlock.Bloom(),
|
|
|
|
"stateRoot": test_helpers.MockBlock.Root(),
|
|
|
|
"miner": test_helpers.MockBlock.Coinbase(),
|
|
|
|
"difficulty": (*hexutil.Big)(test_helpers.MockBlock.Difficulty()),
|
|
|
|
"extraData": hexutil.Bytes(test_helpers.MockBlock.Header().Extra),
|
|
|
|
"gasLimit": hexutil.Uint64(test_helpers.MockBlock.GasLimit()),
|
|
|
|
"gasUsed": hexutil.Uint64(test_helpers.MockBlock.GasUsed()),
|
|
|
|
"timestamp": hexutil.Uint64(test_helpers.MockBlock.Time()),
|
|
|
|
"transactionsRoot": test_helpers.MockBlock.TxHash(),
|
|
|
|
"receiptsRoot": test_helpers.MockBlock.ReceiptHash(),
|
|
|
|
"totalDifficulty": (*hexutil.Big)(test_helpers.MockBlock.Difficulty()),
|
|
|
|
"size": hexutil.Uint64(test_helpers.MockBlock.Size()),
|
2020-02-20 22:13:19 +00:00
|
|
|
}
|
|
|
|
expectedHeader = map[string]interface{}{
|
2020-10-20 20:33:18 +00:00
|
|
|
"number": (*hexutil.Big)(test_helpers.MockBlock.Header().Number),
|
2020-10-29 20:18:27 +00:00
|
|
|
"hash": blockHash,
|
2020-10-20 20:33:18 +00:00
|
|
|
"parentHash": test_helpers.MockBlock.Header().ParentHash,
|
|
|
|
"nonce": test_helpers.MockBlock.Header().Nonce,
|
|
|
|
"mixHash": test_helpers.MockBlock.Header().MixDigest,
|
|
|
|
"sha3Uncles": test_helpers.MockBlock.Header().UncleHash,
|
|
|
|
"logsBloom": test_helpers.MockBlock.Header().Bloom,
|
|
|
|
"stateRoot": test_helpers.MockBlock.Header().Root,
|
|
|
|
"miner": test_helpers.MockBlock.Header().Coinbase,
|
|
|
|
"difficulty": (*hexutil.Big)(test_helpers.MockBlock.Header().Difficulty),
|
|
|
|
"extraData": hexutil.Bytes(test_helpers.MockBlock.Header().Extra),
|
|
|
|
"size": hexutil.Uint64(test_helpers.MockBlock.Header().Size()),
|
|
|
|
"gasLimit": hexutil.Uint64(test_helpers.MockBlock.Header().GasLimit),
|
|
|
|
"gasUsed": hexutil.Uint64(test_helpers.MockBlock.Header().GasUsed),
|
|
|
|
"timestamp": hexutil.Uint64(test_helpers.MockBlock.Header().Time),
|
|
|
|
"transactionsRoot": test_helpers.MockBlock.Header().TxHash,
|
|
|
|
"receiptsRoot": test_helpers.MockBlock.Header().ReceiptHash,
|
|
|
|
"totalDifficulty": (*hexutil.Big)(test_helpers.MockBlock.Header().Difficulty),
|
2020-02-20 22:13:19 +00:00
|
|
|
}
|
2020-10-29 19:59:09 +00:00
|
|
|
expectedUncle1 = map[string]interface{}{
|
|
|
|
"number": (*hexutil.Big)(test_helpers.MockUncles[0].Number),
|
|
|
|
"hash": test_helpers.MockUncles[0].Hash(),
|
|
|
|
"parentHash": test_helpers.MockUncles[0].ParentHash,
|
|
|
|
"nonce": test_helpers.MockUncles[0].Nonce,
|
|
|
|
"mixHash": test_helpers.MockUncles[0].MixDigest,
|
|
|
|
"sha3Uncles": test_helpers.MockUncles[0].UncleHash,
|
|
|
|
"logsBloom": test_helpers.MockUncles[0].Bloom,
|
|
|
|
"stateRoot": test_helpers.MockUncles[0].Root,
|
|
|
|
"miner": test_helpers.MockUncles[0].Coinbase,
|
|
|
|
"difficulty": (*hexutil.Big)(test_helpers.MockUncles[0].Difficulty),
|
|
|
|
"extraData": hexutil.Bytes(test_helpers.MockUncles[0].Extra),
|
|
|
|
"size": hexutil.Uint64(types.NewBlockWithHeader(test_helpers.MockUncles[0]).Size()),
|
|
|
|
"gasLimit": hexutil.Uint64(test_helpers.MockUncles[0].GasLimit),
|
|
|
|
"gasUsed": hexutil.Uint64(test_helpers.MockUncles[0].GasUsed),
|
|
|
|
"timestamp": hexutil.Uint64(test_helpers.MockUncles[0].Time),
|
|
|
|
"transactionsRoot": test_helpers.MockUncles[0].TxHash,
|
|
|
|
"receiptsRoot": test_helpers.MockUncles[0].ReceiptHash,
|
|
|
|
"uncles": []common.Hash{},
|
|
|
|
}
|
|
|
|
expectedUncle2 = map[string]interface{}{
|
|
|
|
"number": (*hexutil.Big)(test_helpers.MockUncles[1].Number),
|
|
|
|
"hash": test_helpers.MockUncles[1].Hash(),
|
|
|
|
"parentHash": test_helpers.MockUncles[1].ParentHash,
|
|
|
|
"nonce": test_helpers.MockUncles[1].Nonce,
|
|
|
|
"mixHash": test_helpers.MockUncles[1].MixDigest,
|
|
|
|
"sha3Uncles": test_helpers.MockUncles[1].UncleHash,
|
|
|
|
"logsBloom": test_helpers.MockUncles[1].Bloom,
|
|
|
|
"stateRoot": test_helpers.MockUncles[1].Root,
|
|
|
|
"miner": test_helpers.MockUncles[1].Coinbase,
|
|
|
|
"difficulty": (*hexutil.Big)(test_helpers.MockUncles[1].Difficulty),
|
|
|
|
"extraData": hexutil.Bytes(test_helpers.MockUncles[1].Extra),
|
|
|
|
"size": hexutil.Uint64(types.NewBlockWithHeader(test_helpers.MockUncles[1]).Size()),
|
|
|
|
"gasLimit": hexutil.Uint64(test_helpers.MockUncles[1].GasLimit),
|
|
|
|
"gasUsed": hexutil.Uint64(test_helpers.MockUncles[1].GasUsed),
|
|
|
|
"timestamp": hexutil.Uint64(test_helpers.MockUncles[1].Time),
|
|
|
|
"transactionsRoot": test_helpers.MockUncles[1].TxHash,
|
|
|
|
"receiptsRoot": test_helpers.MockUncles[1].ReceiptHash,
|
|
|
|
"uncles": []common.Hash{},
|
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
expectedTransaction = eth.NewRPCTransaction(test_helpers.MockTransactions[0], test_helpers.MockBlock.Hash(), test_helpers.MockBlock.NumberU64(), 0)
|
|
|
|
expectedTransaction2 = eth.NewRPCTransaction(test_helpers.MockTransactions[1], test_helpers.MockBlock.Hash(), test_helpers.MockBlock.NumberU64(), 1)
|
|
|
|
expectedTransaction3 = eth.NewRPCTransaction(test_helpers.MockTransactions[2], test_helpers.MockBlock.Hash(), test_helpers.MockBlock.NumberU64(), 2)
|
|
|
|
expectRawTx, _ = rlp.EncodeToBytes(test_helpers.MockTransactions[0])
|
|
|
|
expectRawTx2, _ = rlp.EncodeToBytes(test_helpers.MockTransactions[1])
|
|
|
|
expectRawTx3, _ = rlp.EncodeToBytes(test_helpers.MockTransactions[2])
|
2020-02-20 22:13:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("API", func() {
|
|
|
|
var (
|
2020-05-01 16:07:47 +00:00
|
|
|
db *postgres.DB
|
2020-08-31 15:47:06 +00:00
|
|
|
indexAndPublisher *eth2.IPLDPublisher
|
2020-05-01 16:07:47 +00:00
|
|
|
backend *eth.Backend
|
|
|
|
api *eth.PublicEthAPI
|
2020-02-20 22:13:19 +00:00
|
|
|
)
|
|
|
|
BeforeEach(func() {
|
|
|
|
var err error
|
|
|
|
db, err = shared.SetupDB()
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2020-08-31 15:47:06 +00:00
|
|
|
indexAndPublisher = eth2.NewIPLDPublisher(db)
|
2020-10-20 20:33:18 +00:00
|
|
|
backend, err = eth.NewEthBackend(db, ð.Config{})
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2020-10-27 17:42:38 +00:00
|
|
|
api = eth.NewPublicEthAPI(backend, nil)
|
2020-10-20 20:33:18 +00:00
|
|
|
err = indexAndPublisher.Publish(test_helpers.MockConvertedPayload)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2020-10-20 20:33:18 +00:00
|
|
|
uncles := test_helpers.MockBlock.Uncles()
|
2020-02-20 22:13:19 +00:00
|
|
|
uncleHashes := make([]common.Hash, len(uncles))
|
|
|
|
for i, uncle := range uncles {
|
|
|
|
uncleHashes[i] = uncle.Hash()
|
|
|
|
}
|
|
|
|
expectedBlock["uncles"] = uncleHashes
|
|
|
|
})
|
|
|
|
AfterEach(func() {
|
|
|
|
eth.TearDownDB(db)
|
|
|
|
})
|
2020-10-29 19:59:09 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
Headers and blocks
|
|
|
|
|
|
|
|
*/
|
|
|
|
Describe("GetHeaderByHash", func() {
|
|
|
|
It("Retrieves a header by hash", func() {
|
2020-10-29 20:18:27 +00:00
|
|
|
header := api.GetHeaderByHash(ctx, blockHash)
|
2020-10-29 19:59:09 +00:00
|
|
|
Expect(header).To(Equal(expectedHeader))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GetHeaderByNumber", func() {
|
|
|
|
It("Retrieves a header by number", func() {
|
2020-10-29 20:18:27 +00:00
|
|
|
header, err := api.GetHeaderByNumber(ctx, number)
|
2020-10-29 19:59:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(header).To(Equal(expectedHeader))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("Throws an error if a header cannot be found", func() {
|
2020-10-29 20:18:27 +00:00
|
|
|
header, err := api.GetHeaderByNumber(ctx, rpc.BlockNumber(number+1))
|
2020-10-29 19:59:09 +00:00
|
|
|
Expect(err).To(HaveOccurred())
|
|
|
|
Expect(err.Error()).To(ContainSubstring("sql: no rows in result set"))
|
|
|
|
Expect(header).To(BeNil())
|
|
|
|
_, err = api.B.DB.Beginx()
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-20 22:13:19 +00:00
|
|
|
Describe("BlockNumber", func() {
|
|
|
|
It("Retrieves the head block number", func() {
|
|
|
|
bn := api.BlockNumber()
|
|
|
|
ubn := (uint64)(bn)
|
|
|
|
subn := strconv.FormatUint(ubn, 10)
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(subn).To(Equal(test_helpers.BlockNumber.String()))
|
2020-02-20 22:13:19 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GetBlockByNumber", func() {
|
|
|
|
It("Retrieves a block by number", func() {
|
|
|
|
// without full txs
|
2020-10-29 20:18:27 +00:00
|
|
|
block, err := api.GetBlockByNumber(ctx, number, false)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2020-10-20 20:33:18 +00:00
|
|
|
transactionHashes := make([]interface{}, len(test_helpers.MockBlock.Transactions()))
|
|
|
|
for i, trx := range test_helpers.MockBlock.Transactions() {
|
2020-02-20 22:13:19 +00:00
|
|
|
transactionHashes[i] = trx.Hash()
|
|
|
|
}
|
|
|
|
expectedBlock["transactions"] = transactionHashes
|
|
|
|
for key, val := range expectedBlock {
|
|
|
|
Expect(val).To(Equal(block[key]))
|
|
|
|
}
|
|
|
|
// with full txs
|
2020-10-29 20:18:27 +00:00
|
|
|
block, err = api.GetBlockByNumber(ctx, number, true)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2020-10-20 20:33:18 +00:00
|
|
|
transactions := make([]interface{}, len(test_helpers.MockBlock.Transactions()))
|
|
|
|
for i, trx := range test_helpers.MockBlock.Transactions() {
|
|
|
|
transactions[i] = eth.NewRPCTransactionFromBlockHash(test_helpers.MockBlock, trx.Hash())
|
2020-02-20 22:13:19 +00:00
|
|
|
}
|
|
|
|
expectedBlock["transactions"] = transactions
|
|
|
|
for key, val := range expectedBlock {
|
|
|
|
Expect(val).To(Equal(block[key]))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GetBlockByHash", func() {
|
|
|
|
It("Retrieves a block by hash", func() {
|
|
|
|
// without full txs
|
2020-10-29 20:18:27 +00:00
|
|
|
block, err := api.GetBlockByHash(ctx, test_helpers.MockBlock.Hash(), false)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2020-10-20 20:33:18 +00:00
|
|
|
transactionHashes := make([]interface{}, len(test_helpers.MockBlock.Transactions()))
|
|
|
|
for i, trx := range test_helpers.MockBlock.Transactions() {
|
2020-02-20 22:13:19 +00:00
|
|
|
transactionHashes[i] = trx.Hash()
|
|
|
|
}
|
|
|
|
expectedBlock["transactions"] = transactionHashes
|
|
|
|
for key, val := range expectedBlock {
|
|
|
|
Expect(val).To(Equal(block[key]))
|
|
|
|
}
|
|
|
|
// with full txs
|
2020-10-29 20:18:27 +00:00
|
|
|
block, err = api.GetBlockByHash(ctx, test_helpers.MockBlock.Hash(), true)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2020-10-20 20:33:18 +00:00
|
|
|
transactions := make([]interface{}, len(test_helpers.MockBlock.Transactions()))
|
|
|
|
for i, trx := range test_helpers.MockBlock.Transactions() {
|
|
|
|
transactions[i] = eth.NewRPCTransactionFromBlockHash(test_helpers.MockBlock, trx.Hash())
|
2020-02-20 22:13:19 +00:00
|
|
|
}
|
|
|
|
expectedBlock["transactions"] = transactions
|
|
|
|
for key, val := range expectedBlock {
|
|
|
|
Expect(val).To(Equal(block[key]))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-10-29 19:59:09 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
Uncles
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
Describe("GetUncleByBlockNumberAndIndex", func() {
|
|
|
|
It("Retrieves the uncle at the provided index in the canoncial block with the provided hash", func() {
|
2020-10-29 20:18:27 +00:00
|
|
|
uncle1, err := api.GetUncleByBlockNumberAndIndex(ctx, number, 0)
|
2020-10-29 19:59:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(uncle1).To(Equal(expectedUncle1))
|
2020-10-29 20:18:27 +00:00
|
|
|
uncle2, err := api.GetUncleByBlockNumberAndIndex(ctx, number, 1)
|
2020-10-29 19:59:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(uncle2).To(Equal(expectedUncle2))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GetUncleByBlockHashAndIndex", func() {
|
|
|
|
It("Retrieves the uncle at the provided index in the block with the provided hash", func() {
|
2020-10-29 20:18:27 +00:00
|
|
|
uncle1, err := api.GetUncleByBlockHashAndIndex(ctx, blockHash, 0)
|
2020-10-29 19:59:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(uncle1).To(Equal(expectedUncle1))
|
2020-10-29 20:18:27 +00:00
|
|
|
uncle2, err := api.GetUncleByBlockHashAndIndex(ctx, blockHash, 1)
|
2020-10-29 19:59:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(uncle2).To(Equal(expectedUncle2))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GetUncleCountByBlockNumber", func() {
|
|
|
|
It("Retrieves the number of uncles for the canonical block with the provided number", func() {
|
2020-10-29 20:18:27 +00:00
|
|
|
count := api.GetUncleCountByBlockNumber(ctx, number)
|
2020-10-29 19:59:09 +00:00
|
|
|
Expect(uint64(*count)).To(Equal(uint64(2)))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GetUncleCountByBlockHash", func() {
|
|
|
|
It("Retrieves the number of uncles for the block with the provided hash", func() {
|
2020-10-29 20:18:27 +00:00
|
|
|
count := api.GetUncleCountByBlockHash(ctx, blockHash)
|
2020-10-29 19:59:09 +00:00
|
|
|
Expect(uint64(*count)).To(Equal(uint64(2)))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Transactions
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
Describe("GetTransactionCount", func() {
|
|
|
|
It("Retrieves the number of transactions the given address has sent for the given block number or block hash", func() {
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GetBlockTransactionCountByNumber", func() {
|
|
|
|
It("Retrieves the number of transactions in the canonical block with the provided number", func() {
|
2020-10-29 20:18:27 +00:00
|
|
|
count := api.GetBlockTransactionCountByNumber(ctx, number)
|
|
|
|
Expect(uint64(*count)).To(Equal(uint64(3)))
|
2020-10-29 19:59:09 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GetBlockTransactionCountByHash", func() {
|
|
|
|
It("Retrieves the number of transactions in the block with the provided hash ", func() {
|
2020-10-29 20:18:27 +00:00
|
|
|
count := api.GetBlockTransactionCountByHash(ctx, blockHash)
|
|
|
|
Expect(uint64(*count)).To(Equal(uint64(3)))
|
2020-10-29 19:59:09 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GetTransactionByBlockNumberAndIndex", func() {
|
|
|
|
It("Retrieves the tx with the provided index in the canonical block with the provided block number", func() {
|
2020-10-29 20:18:27 +00:00
|
|
|
tx := api.GetTransactionByBlockNumberAndIndex(ctx, number, 0)
|
|
|
|
Expect(tx).ToNot(BeNil())
|
|
|
|
Expect(tx).To(Equal(expectedTransaction))
|
2020-10-29 19:59:09 +00:00
|
|
|
|
2020-10-29 20:18:27 +00:00
|
|
|
tx = api.GetTransactionByBlockNumberAndIndex(ctx, number, 1)
|
|
|
|
Expect(tx).ToNot(BeNil())
|
|
|
|
Expect(tx).To(Equal(expectedTransaction2))
|
|
|
|
|
|
|
|
tx = api.GetTransactionByBlockNumberAndIndex(ctx, number, 2)
|
|
|
|
Expect(tx).ToNot(BeNil())
|
|
|
|
Expect(tx).To(Equal(expectedTransaction3))
|
2020-10-29 19:59:09 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GetTransactionByBlockHashAndIndex", func() {
|
|
|
|
It("Retrieves the tx with the provided index in the block with the provided hash", func() {
|
2020-10-29 20:18:27 +00:00
|
|
|
tx := api.GetTransactionByBlockHashAndIndex(ctx, blockHash, 0)
|
|
|
|
Expect(tx).ToNot(BeNil())
|
|
|
|
Expect(tx).To(Equal(expectedTransaction))
|
|
|
|
|
|
|
|
tx = api.GetTransactionByBlockHashAndIndex(ctx, blockHash, 1)
|
|
|
|
Expect(tx).ToNot(BeNil())
|
|
|
|
Expect(tx).To(Equal(expectedTransaction2))
|
2020-10-29 19:59:09 +00:00
|
|
|
|
2020-10-29 20:18:27 +00:00
|
|
|
tx = api.GetTransactionByBlockHashAndIndex(ctx, blockHash, 2)
|
|
|
|
Expect(tx).ToNot(BeNil())
|
|
|
|
Expect(tx).To(Equal(expectedTransaction3))
|
2020-10-29 19:59:09 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GetRawTransactionByBlockNumberAndIndex", func() {
|
|
|
|
It("Retrieves the raw tx with the provided index in the canonical block with the provided block number", func() {
|
2020-10-29 20:18:27 +00:00
|
|
|
tx := api.GetRawTransactionByBlockNumberAndIndex(ctx, number, 0)
|
|
|
|
Expect(tx).ToNot(BeNil())
|
|
|
|
Expect(tx).To(Equal(hexutil.Bytes(expectRawTx)))
|
2020-10-29 19:59:09 +00:00
|
|
|
|
2020-10-29 20:18:27 +00:00
|
|
|
tx = api.GetRawTransactionByBlockNumberAndIndex(ctx, number, 1)
|
|
|
|
Expect(tx).ToNot(BeNil())
|
|
|
|
Expect(tx).To(Equal(hexutil.Bytes(expectRawTx2)))
|
|
|
|
|
|
|
|
tx = api.GetRawTransactionByBlockNumberAndIndex(ctx, number, 2)
|
|
|
|
Expect(tx).ToNot(BeNil())
|
|
|
|
Expect(tx).To(Equal(hexutil.Bytes(expectRawTx3)))
|
2020-10-29 19:59:09 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GetRawTransactionByBlockHashAndIndex", func() {
|
|
|
|
It("Retrieves the raw tx with the provided index in the block with the provided hash", func() {
|
2020-10-29 20:18:27 +00:00
|
|
|
tx := api.GetRawTransactionByBlockHashAndIndex(ctx, blockHash, 0)
|
|
|
|
Expect(tx).ToNot(BeNil())
|
|
|
|
Expect(tx).To(Equal(hexutil.Bytes(expectRawTx)))
|
|
|
|
|
|
|
|
tx = api.GetRawTransactionByBlockHashAndIndex(ctx, blockHash, 1)
|
|
|
|
Expect(tx).ToNot(BeNil())
|
|
|
|
Expect(tx).To(Equal(hexutil.Bytes(expectRawTx2)))
|
2020-10-29 19:59:09 +00:00
|
|
|
|
2020-10-29 20:18:27 +00:00
|
|
|
tx = api.GetRawTransactionByBlockHashAndIndex(ctx, blockHash, 2)
|
|
|
|
Expect(tx).ToNot(BeNil())
|
|
|
|
Expect(tx).To(Equal(hexutil.Bytes(expectRawTx3)))
|
2020-10-29 19:59:09 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GetTransactionByHash", func() {
|
|
|
|
It("Retrieves a transaction by hash", func() {
|
|
|
|
hash := test_helpers.MockTransactions[0].Hash()
|
2020-10-29 20:18:27 +00:00
|
|
|
tx, err := api.GetTransactionByHash(ctx, hash)
|
2020-10-29 19:59:09 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(tx).To(Equal(expectedTransaction))
|
2020-10-29 20:18:27 +00:00
|
|
|
|
|
|
|
hash = test_helpers.MockTransactions[1].Hash()
|
|
|
|
tx, err = api.GetTransactionByHash(ctx, hash)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(tx).To(Equal(expectedTransaction2))
|
|
|
|
|
|
|
|
hash = test_helpers.MockTransactions[2].Hash()
|
|
|
|
tx, err = api.GetTransactionByHash(ctx, hash)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(tx).To(Equal(expectedTransaction3))
|
2020-10-29 19:59:09 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GetRawTransactionByHash", func() {
|
|
|
|
It("Retrieves a raw transaction by hash", func() {
|
2020-10-29 20:18:27 +00:00
|
|
|
hash := test_helpers.MockTransactions[0].Hash()
|
|
|
|
tx, err := api.GetRawTransactionByHash(ctx, hash)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(tx).To(Equal(hexutil.Bytes(expectRawTx)))
|
2020-10-29 19:59:09 +00:00
|
|
|
|
2020-10-29 20:18:27 +00:00
|
|
|
hash = test_helpers.MockTransactions[1].Hash()
|
|
|
|
tx, err = api.GetRawTransactionByHash(ctx, hash)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(tx).To(Equal(hexutil.Bytes(expectRawTx2)))
|
|
|
|
|
|
|
|
hash = test_helpers.MockTransactions[2].Hash()
|
|
|
|
tx, err = api.GetRawTransactionByHash(ctx, hash)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(tx).To(Equal(hexutil.Bytes(expectRawTx3)))
|
2020-10-29 19:59:09 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Receipts and logs
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
Describe("GetTransactionReceipt", func() {
|
|
|
|
It("Retrieves a receipt by tx hash", func() {
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-20 22:13:19 +00:00
|
|
|
Describe("GetLogs", func() {
|
2020-10-20 20:33:18 +00:00
|
|
|
It("Retrieves receipt logs that match the provided topics within the provided range", func() {
|
2020-02-20 22:13:19 +00:00
|
|
|
crit := ethereum.FilterQuery{
|
|
|
|
Topics: [][]common.Hash{
|
|
|
|
{
|
|
|
|
common.HexToHash("0x04"),
|
|
|
|
},
|
|
|
|
},
|
2020-10-20 20:33:18 +00:00
|
|
|
FromBlock: test_helpers.MockBlock.Number(),
|
|
|
|
ToBlock: test_helpers.MockBlock.Number(),
|
2020-02-20 22:13:19 +00:00
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err := api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(1))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(logs).To(Equal([]*types.Log{test_helpers.MockLog1}))
|
2020-02-20 22:13:19 +00:00
|
|
|
|
|
|
|
crit = ethereum.FilterQuery{
|
|
|
|
Topics: [][]common.Hash{
|
|
|
|
{
|
|
|
|
common.HexToHash("0x04"),
|
|
|
|
common.HexToHash("0x05"),
|
|
|
|
},
|
|
|
|
},
|
2020-10-20 20:33:18 +00:00
|
|
|
FromBlock: test_helpers.MockBlock.Number(),
|
|
|
|
ToBlock: test_helpers.MockBlock.Number(),
|
2020-02-20 22:13:19 +00:00
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err = api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(2))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(logs).To(Equal([]*types.Log{test_helpers.MockLog1, test_helpers.MockLog2}))
|
2020-02-20 22:13:19 +00:00
|
|
|
|
|
|
|
crit = ethereum.FilterQuery{
|
|
|
|
Topics: [][]common.Hash{
|
|
|
|
{
|
|
|
|
common.HexToHash("0x04"),
|
|
|
|
common.HexToHash("0x06"),
|
|
|
|
},
|
|
|
|
},
|
2020-10-20 20:33:18 +00:00
|
|
|
FromBlock: test_helpers.MockBlock.Number(),
|
|
|
|
ToBlock: test_helpers.MockBlock.Number(),
|
2020-02-20 22:13:19 +00:00
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err = api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(1))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(logs).To(Equal([]*types.Log{test_helpers.MockLog1}))
|
2020-02-20 22:13:19 +00:00
|
|
|
|
|
|
|
crit = ethereum.FilterQuery{
|
|
|
|
Topics: [][]common.Hash{
|
|
|
|
{
|
|
|
|
common.HexToHash("0x04"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
common.HexToHash("0x07"),
|
|
|
|
},
|
|
|
|
},
|
2020-10-20 20:33:18 +00:00
|
|
|
FromBlock: test_helpers.MockBlock.Number(),
|
|
|
|
ToBlock: test_helpers.MockBlock.Number(),
|
2020-02-20 22:13:19 +00:00
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err = api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(0))
|
|
|
|
|
|
|
|
crit = ethereum.FilterQuery{
|
|
|
|
Topics: [][]common.Hash{
|
|
|
|
{
|
|
|
|
common.HexToHash("0x04"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
common.HexToHash("0x06"),
|
|
|
|
},
|
|
|
|
},
|
2020-10-20 20:33:18 +00:00
|
|
|
FromBlock: test_helpers.MockBlock.Number(),
|
|
|
|
ToBlock: test_helpers.MockBlock.Number(),
|
2020-02-20 22:13:19 +00:00
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err = api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(1))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(logs).To(Equal([]*types.Log{test_helpers.MockLog1}))
|
2020-02-20 22:13:19 +00:00
|
|
|
|
|
|
|
crit = ethereum.FilterQuery{
|
|
|
|
Topics: [][]common.Hash{
|
|
|
|
{
|
|
|
|
common.HexToHash("0x05"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
common.HexToHash("0x07"),
|
|
|
|
},
|
|
|
|
},
|
2020-10-20 20:33:18 +00:00
|
|
|
FromBlock: test_helpers.MockBlock.Number(),
|
|
|
|
ToBlock: test_helpers.MockBlock.Number(),
|
2020-02-20 22:13:19 +00:00
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err = api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(1))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(logs).To(Equal([]*types.Log{test_helpers.MockLog2}))
|
2020-02-20 22:13:19 +00:00
|
|
|
|
|
|
|
crit = ethereum.FilterQuery{
|
|
|
|
Topics: [][]common.Hash{
|
|
|
|
{
|
|
|
|
common.HexToHash("0x05"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
common.HexToHash("0x06"),
|
|
|
|
common.HexToHash("0x07"),
|
|
|
|
},
|
|
|
|
},
|
2020-10-20 20:33:18 +00:00
|
|
|
FromBlock: test_helpers.MockBlock.Number(),
|
|
|
|
ToBlock: test_helpers.MockBlock.Number(),
|
2020-02-20 22:13:19 +00:00
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err = api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(1))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(logs).To(Equal([]*types.Log{test_helpers.MockLog2}))
|
2020-02-20 22:13:19 +00:00
|
|
|
|
|
|
|
crit = ethereum.FilterQuery{
|
|
|
|
Topics: [][]common.Hash{
|
|
|
|
{
|
|
|
|
common.HexToHash("0x04"),
|
|
|
|
common.HexToHash("0x05"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
common.HexToHash("0x06"),
|
|
|
|
common.HexToHash("0x07"),
|
|
|
|
},
|
|
|
|
},
|
2020-10-20 20:33:18 +00:00
|
|
|
FromBlock: test_helpers.MockBlock.Number(),
|
|
|
|
ToBlock: test_helpers.MockBlock.Number(),
|
2020-02-20 22:13:19 +00:00
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err = api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(2))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(logs).To(Equal([]*types.Log{test_helpers.MockLog1, test_helpers.MockLog2}))
|
2020-02-20 22:13:19 +00:00
|
|
|
|
|
|
|
crit = ethereum.FilterQuery{
|
|
|
|
Topics: [][]common.Hash{
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
common.HexToHash("0x07"),
|
|
|
|
},
|
|
|
|
},
|
2020-10-20 20:33:18 +00:00
|
|
|
FromBlock: test_helpers.MockBlock.Number(),
|
|
|
|
ToBlock: test_helpers.MockBlock.Number(),
|
2020-02-20 22:13:19 +00:00
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err = api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(1))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(logs).To(Equal([]*types.Log{test_helpers.MockLog2}))
|
2020-02-20 22:13:19 +00:00
|
|
|
|
|
|
|
crit = ethereum.FilterQuery{
|
|
|
|
Topics: [][]common.Hash{
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
common.HexToHash("0x06"),
|
|
|
|
},
|
|
|
|
},
|
2020-10-20 20:33:18 +00:00
|
|
|
FromBlock: test_helpers.MockBlock.Number(),
|
|
|
|
ToBlock: test_helpers.MockBlock.Number(),
|
2020-02-20 22:13:19 +00:00
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err = api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(1))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(logs).To(Equal([]*types.Log{test_helpers.MockLog1}))
|
2020-02-20 22:13:19 +00:00
|
|
|
|
|
|
|
crit = ethereum.FilterQuery{
|
|
|
|
Topics: [][]common.Hash{},
|
2020-10-20 20:33:18 +00:00
|
|
|
FromBlock: test_helpers.MockBlock.Number(),
|
|
|
|
ToBlock: test_helpers.MockBlock.Number(),
|
2020-02-20 22:13:19 +00:00
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err = api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(2))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(logs).To(Equal([]*types.Log{test_helpers.MockLog1, test_helpers.MockLog2}))
|
2020-02-20 22:13:19 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("Uses the provided blockhash if one is provided", func() {
|
2020-10-20 20:33:18 +00:00
|
|
|
hash := test_helpers.MockBlock.Hash()
|
2020-02-20 22:13:19 +00:00
|
|
|
crit := ethereum.FilterQuery{
|
|
|
|
BlockHash: &hash,
|
|
|
|
Topics: [][]common.Hash{
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
common.HexToHash("0x06"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err := api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(1))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(logs).To(Equal([]*types.Log{test_helpers.MockLog1}))
|
2020-02-20 22:13:19 +00:00
|
|
|
|
|
|
|
crit = ethereum.FilterQuery{
|
|
|
|
BlockHash: &hash,
|
|
|
|
Topics: [][]common.Hash{
|
|
|
|
{
|
|
|
|
common.HexToHash("0x04"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
common.HexToHash("0x06"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err = api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(1))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(logs).To(Equal([]*types.Log{test_helpers.MockLog1}))
|
2020-02-20 22:13:19 +00:00
|
|
|
|
|
|
|
crit = ethereum.FilterQuery{
|
|
|
|
BlockHash: &hash,
|
|
|
|
Topics: [][]common.Hash{
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
common.HexToHash("0x07"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err = api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(1))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(logs).To(Equal([]*types.Log{test_helpers.MockLog2}))
|
2020-02-20 22:13:19 +00:00
|
|
|
|
|
|
|
crit = ethereum.FilterQuery{
|
|
|
|
BlockHash: &hash,
|
|
|
|
Topics: [][]common.Hash{
|
|
|
|
{
|
|
|
|
common.HexToHash("0x05"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
common.HexToHash("0x07"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err = api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(1))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(logs).To(Equal([]*types.Log{test_helpers.MockLog2}))
|
2020-02-20 22:13:19 +00:00
|
|
|
|
|
|
|
crit = ethereum.FilterQuery{
|
|
|
|
BlockHash: &hash,
|
|
|
|
Topics: [][]common.Hash{
|
|
|
|
{
|
|
|
|
common.HexToHash("0x04"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
common.HexToHash("0x07"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err = api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(0))
|
|
|
|
|
|
|
|
crit = ethereum.FilterQuery{
|
|
|
|
BlockHash: &hash,
|
|
|
|
Topics: [][]common.Hash{
|
|
|
|
{
|
|
|
|
common.HexToHash("0x04"),
|
|
|
|
common.HexToHash("0x05"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
common.HexToHash("0x07"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err = api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(1))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(logs).To(Equal([]*types.Log{test_helpers.MockLog2}))
|
2020-02-20 22:13:19 +00:00
|
|
|
|
|
|
|
crit = ethereum.FilterQuery{
|
|
|
|
BlockHash: &hash,
|
|
|
|
Topics: [][]common.Hash{
|
|
|
|
{
|
|
|
|
common.HexToHash("0x04"),
|
|
|
|
common.HexToHash("0x05"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err = api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(2))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(logs).To(Equal([]*types.Log{test_helpers.MockLog1, test_helpers.MockLog2}))
|
2020-02-20 22:13:19 +00:00
|
|
|
|
|
|
|
crit = ethereum.FilterQuery{
|
|
|
|
BlockHash: &hash,
|
|
|
|
Topics: [][]common.Hash{
|
|
|
|
{
|
|
|
|
common.HexToHash("0x04"),
|
|
|
|
common.HexToHash("0x05"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
common.HexToHash("0x06"),
|
|
|
|
common.HexToHash("0x07"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err = api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(2))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(logs).To(Equal([]*types.Log{test_helpers.MockLog1, test_helpers.MockLog2}))
|
2020-02-20 22:13:19 +00:00
|
|
|
|
|
|
|
crit = ethereum.FilterQuery{
|
|
|
|
BlockHash: &hash,
|
|
|
|
Topics: [][]common.Hash{},
|
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err = api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(2))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(logs).To(Equal([]*types.Log{test_helpers.MockLog1, test_helpers.MockLog2}))
|
2020-02-20 22:13:19 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("Filters on contract address if any are provided", func() {
|
2020-10-20 20:33:18 +00:00
|
|
|
hash := test_helpers.MockBlock.Hash()
|
2020-02-20 22:13:19 +00:00
|
|
|
crit := ethereum.FilterQuery{
|
|
|
|
BlockHash: &hash,
|
|
|
|
Addresses: []common.Address{
|
2020-10-20 20:33:18 +00:00
|
|
|
test_helpers.Address,
|
2020-02-20 22:13:19 +00:00
|
|
|
},
|
|
|
|
Topics: [][]common.Hash{
|
|
|
|
{
|
|
|
|
common.HexToHash("0x04"),
|
|
|
|
common.HexToHash("0x05"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
common.HexToHash("0x06"),
|
|
|
|
common.HexToHash("0x07"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err := api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(1))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(logs).To(Equal([]*types.Log{test_helpers.MockLog1}))
|
2020-02-20 22:13:19 +00:00
|
|
|
|
2020-10-20 20:33:18 +00:00
|
|
|
hash = test_helpers.MockBlock.Hash()
|
2020-02-20 22:13:19 +00:00
|
|
|
crit = ethereum.FilterQuery{
|
|
|
|
BlockHash: &hash,
|
|
|
|
Addresses: []common.Address{
|
2020-10-20 20:33:18 +00:00
|
|
|
test_helpers.Address,
|
|
|
|
test_helpers.AnotherAddress,
|
2020-02-20 22:13:19 +00:00
|
|
|
},
|
|
|
|
Topics: [][]common.Hash{
|
|
|
|
{
|
|
|
|
common.HexToHash("0x04"),
|
|
|
|
common.HexToHash("0x05"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
common.HexToHash("0x06"),
|
|
|
|
common.HexToHash("0x07"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err = api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(2))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(logs).To(Equal([]*types.Log{test_helpers.MockLog1, test_helpers.MockLog2}))
|
2020-02-20 22:13:19 +00:00
|
|
|
|
2020-10-20 20:33:18 +00:00
|
|
|
hash = test_helpers.MockBlock.Hash()
|
2020-02-20 22:13:19 +00:00
|
|
|
crit = ethereum.FilterQuery{
|
|
|
|
BlockHash: &hash,
|
|
|
|
Addresses: []common.Address{
|
2020-10-20 20:33:18 +00:00
|
|
|
test_helpers.Address,
|
|
|
|
test_helpers.AnotherAddress,
|
2020-02-20 22:13:19 +00:00
|
|
|
},
|
|
|
|
}
|
2020-10-29 20:18:27 +00:00
|
|
|
logs, err = api.GetLogs(ctx, crit)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(logs)).To(Equal(2))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(logs).To(Equal([]*types.Log{test_helpers.MockLog1, test_helpers.MockLog2}))
|
2020-02-20 22:13:19 +00:00
|
|
|
})
|
|
|
|
})
|
2020-10-29 19:59:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
State and storage
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
Describe("GetBalance", func() {
|
|
|
|
It("Retrieves the eth balance for the provided account address at the block with the provided hash or number", func() {
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GetStorageAt", func() {
|
|
|
|
It("Retrieves the storage value at the provided contract address and storage leaf key at the block with the provided hash or number", func() {
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GetCode", func() {
|
|
|
|
It("Retrieves the code for the provided contract address at the block with the provied hash or number", func() {
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GetProof", func() {
|
|
|
|
It("Retrieves the Merkle-proof for a given account and optionally some storage keys at the block with the provided hash or number", func() {
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-20 22:13:19 +00:00
|
|
|
})
|