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"
|
|
|
|
|
|
|
|
"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 (
|
|
|
|
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),
|
|
|
|
"hash": test_helpers.MockBlock.Header().Hash(),
|
|
|
|
"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-20 20:33:18 +00:00
|
|
|
expectedTransaction = eth.NewRPCTransaction(test_helpers.MockTransactions[0], test_helpers.MockBlock.Hash(), test_helpers.MockBlock.NumberU64(), 0)
|
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)
|
|
|
|
})
|
|
|
|
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("GetTransactionByHash", func() {
|
2020-08-05 03:34:49 +00:00
|
|
|
It("Retrieves a transaction by hash", func() {
|
2020-10-20 20:33:18 +00:00
|
|
|
hash := test_helpers.MockTransactions[0].Hash()
|
2020-02-20 22:13:19 +00:00
|
|
|
tx, err := api.GetTransactionByHash(context.Background(), hash)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(tx).To(Equal(expectedTransaction))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GetBlockByNumber", func() {
|
|
|
|
It("Retrieves a block by number", func() {
|
|
|
|
// without full txs
|
2020-10-20 20:33:18 +00:00
|
|
|
number, err := strconv.ParseInt(test_helpers.BlockNumber.String(), 10, 64)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
block, err := api.GetBlockByNumber(context.Background(), rpc.BlockNumber(number), false)
|
|
|
|
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
|
|
|
|
block, err = api.GetBlockByNumber(context.Background(), rpc.BlockNumber(number), true)
|
|
|
|
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("GetHeaderByNumber", func() {
|
|
|
|
It("Retrieves a header by number", func() {
|
2020-10-20 20:33:18 +00:00
|
|
|
number, err := strconv.ParseInt(test_helpers.BlockNumber.String(), 10, 64)
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
header, err := api.GetHeaderByNumber(context.Background(), rpc.BlockNumber(number))
|
2020-05-01 21:25:58 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(header).To(Equal(expectedHeader))
|
|
|
|
})
|
2020-05-01 21:25:58 +00:00
|
|
|
|
|
|
|
It("Throws an error if a header cannot be found", func() {
|
2020-10-20 20:33:18 +00:00
|
|
|
number, err := strconv.ParseInt(test_helpers.BlockNumber.String(), 10, 64)
|
2020-05-01 21:25:58 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
header, err := api.GetHeaderByNumber(context.Background(), rpc.BlockNumber(number+1))
|
|
|
|
Expect(err).To(HaveOccurred())
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(err.Error()).To(ContainSubstring("sql: no rows in result set"))
|
2020-05-01 21:25:58 +00:00
|
|
|
Expect(header).To(BeNil())
|
|
|
|
_, err = api.B.DB.Beginx()
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
})
|
2020-02-20 22:13:19 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GetBlockByHash", func() {
|
|
|
|
It("Retrieves a block by hash", func() {
|
|
|
|
// without full txs
|
2020-10-20 20:33:18 +00:00
|
|
|
block, err := api.GetBlockByHash(context.Background(), 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-20 20:33:18 +00:00
|
|
|
block, err = api.GetBlockByHash(context.Background(), 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]))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
logs, err := api.GetLogs(context.Background(), crit)
|
|
|
|
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
|
|
|
}
|
|
|
|
logs, err = api.GetLogs(context.Background(), crit)
|
|
|
|
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
|
|
|
}
|
|
|
|
logs, err = api.GetLogs(context.Background(), crit)
|
|
|
|
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
|
|
|
}
|
|
|
|
logs, err = api.GetLogs(context.Background(), crit)
|
|
|
|
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
|
|
|
}
|
|
|
|
logs, err = api.GetLogs(context.Background(), crit)
|
|
|
|
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
|
|
|
}
|
|
|
|
logs, err = api.GetLogs(context.Background(), crit)
|
|
|
|
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
|
|
|
}
|
|
|
|
logs, err = api.GetLogs(context.Background(), crit)
|
|
|
|
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
|
|
|
}
|
|
|
|
logs, err = api.GetLogs(context.Background(), crit)
|
|
|
|
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
|
|
|
}
|
|
|
|
logs, err = api.GetLogs(context.Background(), crit)
|
|
|
|
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
|
|
|
}
|
|
|
|
logs, err = api.GetLogs(context.Background(), crit)
|
|
|
|
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
|
|
|
}
|
|
|
|
logs, err = api.GetLogs(context.Background(), crit)
|
|
|
|
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"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
logs, err := api.GetLogs(context.Background(), crit)
|
|
|
|
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"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
logs, err = api.GetLogs(context.Background(), crit)
|
|
|
|
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"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
logs, err = api.GetLogs(context.Background(), crit)
|
|
|
|
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"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
logs, err = api.GetLogs(context.Background(), crit)
|
|
|
|
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"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
logs, err = api.GetLogs(context.Background(), crit)
|
|
|
|
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"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
logs, err = api.GetLogs(context.Background(), crit)
|
|
|
|
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"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
logs, err = api.GetLogs(context.Background(), crit)
|
|
|
|
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"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
logs, err = api.GetLogs(context.Background(), crit)
|
|
|
|
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{},
|
|
|
|
}
|
|
|
|
logs, err = api.GetLogs(context.Background(), crit)
|
|
|
|
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"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
logs, err := api.GetLogs(context.Background(), crit)
|
|
|
|
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"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
logs, err = api.GetLogs(context.Background(), crit)
|
|
|
|
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
|
|
|
},
|
|
|
|
}
|
|
|
|
logs, err = api.GetLogs(context.Background(), crit)
|
|
|
|
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
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|