2019-08-28 18:41:49 +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/>.
|
|
|
|
|
2020-01-17 23:16:01 +00:00
|
|
|
package eth_test
|
2019-08-28 18:41:49 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
|
2020-01-17 23:16:01 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/super_node/shared"
|
|
|
|
|
2019-08-28 18:41:49 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
|
2019-11-01 19:03:28 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
2020-01-17 23:16:01 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/super_node/config"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/super_node/eth"
|
|
|
|
eth2 "github.com/vulcanize/vulcanizedb/pkg/super_node/eth"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/super_node/eth/mocks"
|
2019-08-28 18:41:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-01-17 23:16:01 +00:00
|
|
|
openFilter = &config.EthSubscription{
|
|
|
|
Start: big.NewInt(0),
|
|
|
|
End: big.NewInt(1),
|
2019-08-28 22:07:36 +00:00
|
|
|
HeaderFilter: config.HeaderFilter{},
|
2020-01-17 23:16:01 +00:00
|
|
|
TxFilter: config.TxFilter{},
|
2019-08-28 22:07:36 +00:00
|
|
|
ReceiptFilter: config.ReceiptFilter{},
|
|
|
|
StateFilter: config.StateFilter{},
|
|
|
|
StorageFilter: config.StorageFilter{},
|
|
|
|
}
|
2020-01-17 23:16:01 +00:00
|
|
|
rctContractFilter = &config.EthSubscription{
|
|
|
|
Start: big.NewInt(0),
|
|
|
|
End: big.NewInt(1),
|
2019-08-28 22:07:36 +00:00
|
|
|
HeaderFilter: config.HeaderFilter{
|
|
|
|
Off: true,
|
|
|
|
},
|
2020-01-17 23:16:01 +00:00
|
|
|
TxFilter: config.TxFilter{
|
2019-08-28 22:07:36 +00:00
|
|
|
Off: true,
|
|
|
|
},
|
|
|
|
ReceiptFilter: config.ReceiptFilter{
|
|
|
|
Contracts: []string{"0x0000000000000000000000000000000000000001"},
|
|
|
|
},
|
|
|
|
StateFilter: config.StateFilter{
|
|
|
|
Off: true,
|
|
|
|
},
|
|
|
|
StorageFilter: config.StorageFilter{
|
|
|
|
Off: true,
|
|
|
|
},
|
|
|
|
}
|
2020-01-17 23:16:01 +00:00
|
|
|
rctTopicsFilter = &config.EthSubscription{
|
|
|
|
Start: big.NewInt(0),
|
|
|
|
End: big.NewInt(1),
|
2019-08-28 22:07:36 +00:00
|
|
|
HeaderFilter: config.HeaderFilter{
|
|
|
|
Off: true,
|
|
|
|
},
|
2020-01-17 23:16:01 +00:00
|
|
|
TxFilter: config.TxFilter{
|
2019-08-28 22:07:36 +00:00
|
|
|
Off: true,
|
|
|
|
},
|
|
|
|
ReceiptFilter: config.ReceiptFilter{
|
|
|
|
Topic0s: []string{"0x0000000000000000000000000000000000000000000000000000000000000004"},
|
|
|
|
},
|
|
|
|
StateFilter: config.StateFilter{
|
|
|
|
Off: true,
|
|
|
|
},
|
|
|
|
StorageFilter: config.StorageFilter{
|
|
|
|
Off: true,
|
|
|
|
},
|
|
|
|
}
|
2020-01-17 23:16:01 +00:00
|
|
|
rctTopicsAndContractFilter = &config.EthSubscription{
|
|
|
|
Start: big.NewInt(0),
|
|
|
|
End: big.NewInt(1),
|
2019-08-28 22:07:36 +00:00
|
|
|
HeaderFilter: config.HeaderFilter{
|
|
|
|
Off: true,
|
|
|
|
},
|
2020-01-17 23:16:01 +00:00
|
|
|
TxFilter: config.TxFilter{
|
2019-08-28 22:07:36 +00:00
|
|
|
Off: true,
|
|
|
|
},
|
|
|
|
ReceiptFilter: config.ReceiptFilter{
|
|
|
|
Topic0s: []string{"0x0000000000000000000000000000000000000000000000000000000000000004", "0x0000000000000000000000000000000000000000000000000000000000000005"},
|
|
|
|
Contracts: []string{"0x0000000000000000000000000000000000000000"},
|
|
|
|
},
|
|
|
|
StateFilter: config.StateFilter{
|
|
|
|
Off: true,
|
|
|
|
},
|
|
|
|
StorageFilter: config.StorageFilter{
|
|
|
|
Off: true,
|
|
|
|
},
|
|
|
|
}
|
2020-01-17 23:16:01 +00:00
|
|
|
rctContractsAndTopicFilter = &config.EthSubscription{
|
|
|
|
Start: big.NewInt(0),
|
|
|
|
End: big.NewInt(1),
|
2019-08-28 22:07:36 +00:00
|
|
|
HeaderFilter: config.HeaderFilter{
|
|
|
|
Off: true,
|
|
|
|
},
|
2020-01-17 23:16:01 +00:00
|
|
|
TxFilter: config.TxFilter{
|
2019-08-28 22:07:36 +00:00
|
|
|
Off: true,
|
|
|
|
},
|
|
|
|
ReceiptFilter: config.ReceiptFilter{
|
|
|
|
Topic0s: []string{"0x0000000000000000000000000000000000000000000000000000000000000005"},
|
|
|
|
Contracts: []string{"0x0000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000001"},
|
|
|
|
},
|
|
|
|
StateFilter: config.StateFilter{
|
|
|
|
Off: true,
|
|
|
|
},
|
|
|
|
StorageFilter: config.StorageFilter{
|
|
|
|
Off: true,
|
|
|
|
},
|
|
|
|
}
|
2020-01-17 23:16:01 +00:00
|
|
|
rctsForAllCollectedTrxs = &config.EthSubscription{
|
|
|
|
Start: big.NewInt(0),
|
|
|
|
End: big.NewInt(1),
|
2019-08-28 22:07:36 +00:00
|
|
|
HeaderFilter: config.HeaderFilter{
|
|
|
|
Off: true,
|
|
|
|
},
|
2020-01-17 23:16:01 +00:00
|
|
|
TxFilter: config.TxFilter{}, // Trx filter open so we will collect all trxs, therefore we will also collect all corresponding rcts despite rct filter
|
2019-08-28 22:07:36 +00:00
|
|
|
ReceiptFilter: config.ReceiptFilter{
|
2020-01-16 20:48:38 +00:00
|
|
|
MatchTxs: true,
|
2019-08-28 22:07:36 +00:00
|
|
|
Topic0s: []string{"0x0000000000000000000000000000000000000000000000000000000000000006"}, // Topic isn't one of the topics we have
|
|
|
|
Contracts: []string{"0x0000000000000000000000000000000000000002"}, // Contract isn't one of the contracts we have
|
|
|
|
},
|
|
|
|
StateFilter: config.StateFilter{
|
|
|
|
Off: true,
|
|
|
|
},
|
|
|
|
StorageFilter: config.StorageFilter{
|
|
|
|
Off: true,
|
|
|
|
},
|
|
|
|
}
|
2020-01-17 23:16:01 +00:00
|
|
|
rctsForSelectCollectedTrxs = &config.EthSubscription{
|
|
|
|
Start: big.NewInt(0),
|
|
|
|
End: big.NewInt(1),
|
2019-08-28 22:07:36 +00:00
|
|
|
HeaderFilter: config.HeaderFilter{
|
|
|
|
Off: true,
|
|
|
|
},
|
2020-01-17 23:16:01 +00:00
|
|
|
TxFilter: config.TxFilter{
|
2019-08-28 22:07:36 +00:00
|
|
|
Dst: []string{"0x0000000000000000000000000000000000000001"}, // We only filter for one of the trxs so we will only get the one corresponding receipt
|
|
|
|
},
|
|
|
|
ReceiptFilter: config.ReceiptFilter{
|
2020-01-16 20:48:38 +00:00
|
|
|
MatchTxs: true,
|
2019-08-28 22:07:36 +00:00
|
|
|
Topic0s: []string{"0x0000000000000000000000000000000000000000000000000000000000000006"}, // Topic isn't one of the topics we have
|
|
|
|
Contracts: []string{"0x0000000000000000000000000000000000000002"}, // Contract isn't one of the contracts we have
|
|
|
|
},
|
|
|
|
StateFilter: config.StateFilter{
|
|
|
|
Off: true,
|
|
|
|
},
|
|
|
|
StorageFilter: config.StorageFilter{
|
|
|
|
Off: true,
|
|
|
|
},
|
|
|
|
}
|
2020-01-17 23:16:01 +00:00
|
|
|
stateFilter = &config.EthSubscription{
|
|
|
|
Start: big.NewInt(0),
|
|
|
|
End: big.NewInt(1),
|
2019-08-28 22:07:36 +00:00
|
|
|
HeaderFilter: config.HeaderFilter{
|
|
|
|
Off: true,
|
|
|
|
},
|
2020-01-17 23:16:01 +00:00
|
|
|
TxFilter: config.TxFilter{
|
2019-08-28 22:07:36 +00:00
|
|
|
Off: true,
|
|
|
|
},
|
|
|
|
ReceiptFilter: config.ReceiptFilter{
|
|
|
|
Off: true,
|
|
|
|
},
|
|
|
|
StateFilter: config.StateFilter{
|
|
|
|
Addresses: []string{mocks.Address.Hex()},
|
|
|
|
},
|
|
|
|
StorageFilter: config.StorageFilter{
|
|
|
|
Off: true,
|
|
|
|
},
|
|
|
|
}
|
2019-08-28 18:41:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Retriever", func() {
|
2019-11-01 19:03:28 +00:00
|
|
|
var (
|
2020-01-17 23:16:01 +00:00
|
|
|
db *postgres.DB
|
|
|
|
repo *eth2.CIDIndexer
|
|
|
|
retriever *eth2.CIDRetriever
|
2019-11-01 19:03:28 +00:00
|
|
|
)
|
2019-08-28 18:41:49 +00:00
|
|
|
BeforeEach(func() {
|
2019-11-01 19:03:28 +00:00
|
|
|
var err error
|
2020-01-17 23:16:01 +00:00
|
|
|
db, err = eth.SetupDB()
|
2019-08-28 18:41:49 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2020-01-17 23:16:01 +00:00
|
|
|
repo = eth2.NewCIDIndexer(db)
|
|
|
|
retriever = eth2.NewCIDRetriever(db)
|
2019-08-28 18:41:49 +00:00
|
|
|
})
|
|
|
|
AfterEach(func() {
|
2020-01-17 23:16:01 +00:00
|
|
|
eth.TearDownDB(db)
|
2019-08-28 18:41:49 +00:00
|
|
|
})
|
2019-08-28 22:07:36 +00:00
|
|
|
|
2020-01-17 23:16:01 +00:00
|
|
|
Describe("Retrieve", func() {
|
2019-11-01 19:03:28 +00:00
|
|
|
BeforeEach(func() {
|
2020-01-16 20:48:38 +00:00
|
|
|
err := repo.Index(mocks.MockCIDPayload)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2019-11-01 19:03:28 +00:00
|
|
|
})
|
2019-08-28 22:07:36 +00:00
|
|
|
It("Retrieves all CIDs for the given blocknumber when provided an open filter", func() {
|
2020-01-17 23:16:01 +00:00
|
|
|
cids, empty, err := retriever.Retrieve(openFilter, 1)
|
2019-08-28 18:41:49 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2020-01-17 23:16:01 +00:00
|
|
|
Expect(empty).ToNot(BeTrue())
|
|
|
|
cidWrapper, ok := cids.(*eth.CIDWrapper)
|
|
|
|
Expect(ok).To(BeTrue())
|
2019-08-28 18:41:49 +00:00
|
|
|
Expect(cidWrapper.BlockNumber).To(Equal(mocks.MockCIDWrapper.BlockNumber))
|
|
|
|
Expect(len(cidWrapper.Headers)).To(Equal(1))
|
2020-01-17 23:16:01 +00:00
|
|
|
expectedHeaderCIDs := mocks.MockCIDWrapper.Headers
|
|
|
|
expectedHeaderCIDs[0].ID = cidWrapper.Headers[0].ID
|
|
|
|
Expect(cidWrapper.Headers).To(Equal(expectedHeaderCIDs))
|
2019-08-28 18:41:49 +00:00
|
|
|
Expect(len(cidWrapper.Transactions)).To(Equal(2))
|
2020-01-17 23:16:01 +00:00
|
|
|
Expect(eth.TxModelsContainsCID(cidWrapper.Transactions, mocks.MockCIDWrapper.Transactions[0].CID)).To(BeTrue())
|
|
|
|
Expect(eth.TxModelsContainsCID(cidWrapper.Transactions, mocks.MockCIDWrapper.Transactions[1].CID)).To(BeTrue())
|
2019-08-28 18:41:49 +00:00
|
|
|
Expect(len(cidWrapper.Receipts)).To(Equal(2))
|
2020-01-17 23:16:01 +00:00
|
|
|
Expect(eth.ReceiptModelsContainsCID(cidWrapper.Receipts, mocks.MockCIDWrapper.Receipts[0].CID)).To(BeTrue())
|
|
|
|
Expect(eth.ReceiptModelsContainsCID(cidWrapper.Receipts, mocks.MockCIDWrapper.Receipts[1].CID)).To(BeTrue())
|
2019-08-28 18:41:49 +00:00
|
|
|
Expect(len(cidWrapper.StateNodes)).To(Equal(2))
|
|
|
|
for _, stateNode := range cidWrapper.StateNodes {
|
|
|
|
if stateNode.CID == "mockStateCID1" {
|
2020-01-17 23:16:01 +00:00
|
|
|
Expect(stateNode.StateKey).To(Equal(mocks.ContractLeafKey.Hex()))
|
2019-08-28 18:41:49 +00:00
|
|
|
Expect(stateNode.Leaf).To(Equal(true))
|
|
|
|
}
|
|
|
|
if stateNode.CID == "mockStateCID2" {
|
2020-01-17 23:16:01 +00:00
|
|
|
Expect(stateNode.StateKey).To(Equal(mocks.AnotherContractLeafKey.Hex()))
|
2019-08-28 18:41:49 +00:00
|
|
|
Expect(stateNode.Leaf).To(Equal(true))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Expect(len(cidWrapper.StorageNodes)).To(Equal(1))
|
2020-01-17 23:16:01 +00:00
|
|
|
expectedStorageNodeCIDs := mocks.MockCIDWrapper.StorageNodes
|
|
|
|
expectedStorageNodeCIDs[0].ID = cidWrapper.StorageNodes[0].ID
|
|
|
|
expectedStorageNodeCIDs[0].StateID = cidWrapper.StorageNodes[0].StateID
|
|
|
|
Expect(cidWrapper.StorageNodes).To(Equal(expectedStorageNodeCIDs))
|
2019-08-28 18:41:49 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("Applies filters from the provided config.Subscription", func() {
|
2020-01-17 23:16:01 +00:00
|
|
|
cids1, empty, err := retriever.Retrieve(rctContractFilter, 1)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(empty).ToNot(BeTrue())
|
|
|
|
cidWrapper1, ok := cids1.(*eth.CIDWrapper)
|
|
|
|
Expect(ok).To(BeTrue())
|
2019-08-28 18:41:49 +00:00
|
|
|
Expect(cidWrapper1.BlockNumber).To(Equal(mocks.MockCIDWrapper.BlockNumber))
|
|
|
|
Expect(len(cidWrapper1.Headers)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper1.Transactions)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper1.StateNodes)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper1.StorageNodes)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper1.Receipts)).To(Equal(1))
|
2020-01-17 23:16:01 +00:00
|
|
|
expectedReceiptCID := mocks.MockCIDWrapper.Receipts[1]
|
|
|
|
expectedReceiptCID.ID = cidWrapper1.Receipts[0].ID
|
|
|
|
expectedReceiptCID.TxID = cidWrapper1.Receipts[0].TxID
|
|
|
|
Expect(cidWrapper1.Receipts[0]).To(Equal(expectedReceiptCID))
|
2019-08-28 18:41:49 +00:00
|
|
|
|
2020-01-17 23:16:01 +00:00
|
|
|
cids2, empty, err := retriever.Retrieve(rctTopicsFilter, 1)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(empty).ToNot(BeTrue())
|
|
|
|
cidWrapper2, ok := cids2.(*eth.CIDWrapper)
|
|
|
|
Expect(ok).To(BeTrue())
|
2019-08-28 18:41:49 +00:00
|
|
|
Expect(cidWrapper2.BlockNumber).To(Equal(mocks.MockCIDWrapper.BlockNumber))
|
|
|
|
Expect(len(cidWrapper2.Headers)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper2.Transactions)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper2.StateNodes)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper2.StorageNodes)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper2.Receipts)).To(Equal(1))
|
2020-01-17 23:16:01 +00:00
|
|
|
expectedReceiptCID = mocks.MockCIDWrapper.Receipts[0]
|
|
|
|
expectedReceiptCID.ID = cidWrapper2.Receipts[0].ID
|
|
|
|
expectedReceiptCID.TxID = cidWrapper2.Receipts[0].TxID
|
|
|
|
Expect(cidWrapper2.Receipts[0]).To(Equal(expectedReceiptCID))
|
2019-08-28 18:41:49 +00:00
|
|
|
|
2020-01-17 23:16:01 +00:00
|
|
|
cids3, empty, err := retriever.Retrieve(rctTopicsAndContractFilter, 1)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(empty).ToNot(BeTrue())
|
|
|
|
cidWrapper3, ok := cids3.(*eth.CIDWrapper)
|
|
|
|
Expect(ok).To(BeTrue())
|
2019-08-28 18:41:49 +00:00
|
|
|
Expect(cidWrapper3.BlockNumber).To(Equal(mocks.MockCIDWrapper.BlockNumber))
|
|
|
|
Expect(len(cidWrapper3.Headers)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper3.Transactions)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper3.StateNodes)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper3.StorageNodes)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper3.Receipts)).To(Equal(1))
|
2020-01-17 23:16:01 +00:00
|
|
|
expectedReceiptCID = mocks.MockCIDWrapper.Receipts[0]
|
|
|
|
expectedReceiptCID.ID = cidWrapper3.Receipts[0].ID
|
|
|
|
expectedReceiptCID.TxID = cidWrapper3.Receipts[0].TxID
|
|
|
|
Expect(cidWrapper3.Receipts[0]).To(Equal(expectedReceiptCID))
|
2019-08-28 18:41:49 +00:00
|
|
|
|
2020-01-17 23:16:01 +00:00
|
|
|
cids4, empty, err := retriever.Retrieve(rctContractsAndTopicFilter, 1)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(empty).ToNot(BeTrue())
|
|
|
|
cidWrapper4, ok := cids4.(*eth.CIDWrapper)
|
|
|
|
Expect(ok).To(BeTrue())
|
2019-08-28 18:41:49 +00:00
|
|
|
Expect(cidWrapper4.BlockNumber).To(Equal(mocks.MockCIDWrapper.BlockNumber))
|
|
|
|
Expect(len(cidWrapper4.Headers)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper4.Transactions)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper4.StateNodes)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper4.StorageNodes)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper4.Receipts)).To(Equal(1))
|
2020-01-17 23:16:01 +00:00
|
|
|
expectedReceiptCID = mocks.MockCIDWrapper.Receipts[1]
|
|
|
|
expectedReceiptCID.ID = cidWrapper4.Receipts[0].ID
|
|
|
|
expectedReceiptCID.TxID = cidWrapper4.Receipts[0].TxID
|
|
|
|
Expect(cidWrapper4.Receipts[0]).To(Equal(expectedReceiptCID))
|
2019-08-28 18:41:49 +00:00
|
|
|
|
2020-01-17 23:16:01 +00:00
|
|
|
cids5, empty, err := retriever.Retrieve(rctsForAllCollectedTrxs, 1)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(empty).ToNot(BeTrue())
|
|
|
|
cidWrapper5, ok := cids5.(*eth.CIDWrapper)
|
|
|
|
Expect(ok).To(BeTrue())
|
2019-08-28 18:41:49 +00:00
|
|
|
Expect(cidWrapper5.BlockNumber).To(Equal(mocks.MockCIDWrapper.BlockNumber))
|
|
|
|
Expect(len(cidWrapper5.Headers)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper5.Transactions)).To(Equal(2))
|
2020-01-17 23:16:01 +00:00
|
|
|
Expect(eth.TxModelsContainsCID(cidWrapper5.Transactions, "mockTrxCID1")).To(BeTrue())
|
|
|
|
Expect(eth.TxModelsContainsCID(cidWrapper5.Transactions, "mockTrxCID2")).To(BeTrue())
|
2019-08-28 18:41:49 +00:00
|
|
|
Expect(len(cidWrapper5.StateNodes)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper5.StorageNodes)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper5.Receipts)).To(Equal(2))
|
2020-01-17 23:16:01 +00:00
|
|
|
Expect(eth.ReceiptModelsContainsCID(cidWrapper5.Receipts, "mockRctCID1")).To(BeTrue())
|
|
|
|
Expect(eth.ReceiptModelsContainsCID(cidWrapper5.Receipts, "mockRctCID2")).To(BeTrue())
|
2019-08-28 18:41:49 +00:00
|
|
|
|
2020-01-17 23:16:01 +00:00
|
|
|
cids6, empty, err := retriever.Retrieve(rctsForSelectCollectedTrxs, 1)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(empty).ToNot(BeTrue())
|
|
|
|
cidWrapper6, ok := cids6.(*eth.CIDWrapper)
|
|
|
|
Expect(ok).To(BeTrue())
|
2019-08-28 18:41:49 +00:00
|
|
|
Expect(cidWrapper6.BlockNumber).To(Equal(mocks.MockCIDWrapper.BlockNumber))
|
|
|
|
Expect(len(cidWrapper6.Headers)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper6.Transactions)).To(Equal(1))
|
2020-01-17 23:16:01 +00:00
|
|
|
expectedTxCID := mocks.MockCIDWrapper.Transactions[1]
|
|
|
|
expectedTxCID.ID = cidWrapper6.Transactions[0].ID
|
|
|
|
expectedTxCID.HeaderID = cidWrapper6.Transactions[0].HeaderID
|
|
|
|
Expect(cidWrapper6.Transactions[0]).To(Equal(expectedTxCID))
|
2019-08-28 18:41:49 +00:00
|
|
|
Expect(len(cidWrapper6.StateNodes)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper6.StorageNodes)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper6.Receipts)).To(Equal(1))
|
2020-01-17 23:16:01 +00:00
|
|
|
expectedReceiptCID = mocks.MockCIDWrapper.Receipts[1]
|
|
|
|
expectedReceiptCID.ID = cidWrapper6.Receipts[0].ID
|
|
|
|
expectedReceiptCID.TxID = cidWrapper6.Receipts[0].TxID
|
|
|
|
Expect(cidWrapper6.Receipts[0]).To(Equal(expectedReceiptCID))
|
2019-08-28 18:41:49 +00:00
|
|
|
|
2020-01-17 23:16:01 +00:00
|
|
|
cids7, empty, err := retriever.Retrieve(stateFilter, 1)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(empty).ToNot(BeTrue())
|
|
|
|
cidWrapper7, ok := cids7.(*eth.CIDWrapper)
|
|
|
|
Expect(ok).To(BeTrue())
|
2019-08-28 18:41:49 +00:00
|
|
|
Expect(cidWrapper7.BlockNumber).To(Equal(mocks.MockCIDWrapper.BlockNumber))
|
|
|
|
Expect(len(cidWrapper7.Headers)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper7.Transactions)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper7.Receipts)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper7.StorageNodes)).To(Equal(0))
|
|
|
|
Expect(len(cidWrapper7.StateNodes)).To(Equal(1))
|
2020-01-17 23:16:01 +00:00
|
|
|
Expect(cidWrapper7.StateNodes[0]).To(Equal(eth.StateNodeModel{
|
|
|
|
ID: cidWrapper7.StateNodes[0].ID,
|
|
|
|
HeaderID: cidWrapper7.StateNodes[0].HeaderID,
|
|
|
|
Leaf: true,
|
|
|
|
StateKey: mocks.ContractLeafKey.Hex(),
|
|
|
|
CID: "mockStateCID1",
|
2019-08-28 18:41:49 +00:00
|
|
|
}))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("RetrieveFirstBlockNumber", func() {
|
|
|
|
It("Gets the number of the first block that has data in the database", func() {
|
2020-01-16 20:48:38 +00:00
|
|
|
err := repo.Index(mocks.MockCIDPayload)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
num, err := retriever.RetrieveFirstBlockNumber()
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2019-08-28 18:41:49 +00:00
|
|
|
Expect(num).To(Equal(int64(1)))
|
|
|
|
})
|
2019-11-01 19:03:28 +00:00
|
|
|
|
|
|
|
It("Gets the number of the first block that has data in the database", func() {
|
|
|
|
payload := *mocks.MockCIDPayload
|
2020-01-17 23:16:01 +00:00
|
|
|
payload.HeaderCID.BlockNumber = "1010101"
|
2020-01-16 20:48:38 +00:00
|
|
|
err := repo.Index(&payload)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
num, err := retriever.RetrieveFirstBlockNumber()
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2019-11-01 19:03:28 +00:00
|
|
|
Expect(num).To(Equal(int64(1010101)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("Gets the number of the first block that has data in the database", func() {
|
|
|
|
payload1 := *mocks.MockCIDPayload
|
2020-01-17 23:16:01 +00:00
|
|
|
payload1.HeaderCID.BlockNumber = "1010101"
|
2019-11-01 19:03:28 +00:00
|
|
|
payload2 := payload1
|
2020-01-17 23:16:01 +00:00
|
|
|
payload2.HeaderCID.BlockNumber = "5"
|
2020-01-16 20:48:38 +00:00
|
|
|
err := repo.Index(&payload1)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
err = repo.Index(&payload2)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
num, err := retriever.RetrieveFirstBlockNumber()
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2019-11-01 19:03:28 +00:00
|
|
|
Expect(num).To(Equal(int64(5)))
|
|
|
|
})
|
2019-08-28 18:41:49 +00:00
|
|
|
})
|
2019-08-28 22:07:36 +00:00
|
|
|
|
2019-08-28 18:41:49 +00:00
|
|
|
Describe("RetrieveLastBlockNumber", func() {
|
|
|
|
It("Gets the number of the latest block that has data in the database", func() {
|
2020-01-16 20:48:38 +00:00
|
|
|
err := repo.Index(mocks.MockCIDPayload)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
num, err := retriever.RetrieveLastBlockNumber()
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2019-08-28 18:41:49 +00:00
|
|
|
Expect(num).To(Equal(int64(1)))
|
|
|
|
})
|
2019-11-01 19:03:28 +00:00
|
|
|
|
|
|
|
It("Gets the number of the latest block that has data in the database", func() {
|
|
|
|
payload := *mocks.MockCIDPayload
|
2020-01-17 23:16:01 +00:00
|
|
|
payload.HeaderCID.BlockNumber = "1010101"
|
2020-01-16 20:48:38 +00:00
|
|
|
err := repo.Index(&payload)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
num, err := retriever.RetrieveLastBlockNumber()
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2019-11-01 19:03:28 +00:00
|
|
|
Expect(num).To(Equal(int64(1010101)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("Gets the number of the latest block that has data in the database", func() {
|
|
|
|
payload1 := *mocks.MockCIDPayload
|
2020-01-17 23:16:01 +00:00
|
|
|
payload1.HeaderCID.BlockNumber = "1010101"
|
2019-11-01 19:03:28 +00:00
|
|
|
payload2 := payload1
|
2020-01-17 23:16:01 +00:00
|
|
|
payload2.HeaderCID.BlockNumber = "5"
|
2020-01-16 20:48:38 +00:00
|
|
|
err := repo.Index(&payload1)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
err = repo.Index(&payload2)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
num, err := retriever.RetrieveLastBlockNumber()
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2019-11-01 19:03:28 +00:00
|
|
|
Expect(num).To(Equal(int64(1010101)))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("RetrieveGapsInData", func() {
|
|
|
|
It("Doesn't return gaps if there are none", func() {
|
|
|
|
payload1 := *mocks.MockCIDPayload
|
2020-01-17 23:16:01 +00:00
|
|
|
payload1.HeaderCID.BlockNumber = "2"
|
2019-11-01 19:03:28 +00:00
|
|
|
payload2 := payload1
|
2020-01-17 23:16:01 +00:00
|
|
|
payload2.HeaderCID.BlockNumber = "3"
|
2020-01-16 20:48:38 +00:00
|
|
|
err := repo.Index(mocks.MockCIDPayload)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
err = repo.Index(&payload1)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
err = repo.Index(&payload2)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
gaps, err := retriever.RetrieveGapsInData()
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2019-11-01 19:03:28 +00:00
|
|
|
Expect(len(gaps)).To(Equal(0))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("Doesn't return the gap from 0 to the earliest block", func() {
|
|
|
|
payload := *mocks.MockCIDPayload
|
2020-01-17 23:16:01 +00:00
|
|
|
payload.HeaderCID.BlockNumber = "5"
|
2020-01-16 20:48:38 +00:00
|
|
|
err := repo.Index(&payload)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
gaps, err := retriever.RetrieveGapsInData()
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2019-11-01 19:03:28 +00:00
|
|
|
Expect(len(gaps)).To(Equal(0))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("Finds gap between two entries", func() {
|
|
|
|
payload1 := *mocks.MockCIDPayload
|
2020-01-17 23:16:01 +00:00
|
|
|
payload1.HeaderCID.BlockNumber = "1010101"
|
2019-11-01 19:03:28 +00:00
|
|
|
payload2 := payload1
|
2020-01-17 23:16:01 +00:00
|
|
|
payload2.HeaderCID.BlockNumber = "5"
|
2020-01-16 20:48:38 +00:00
|
|
|
err := repo.Index(&payload1)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
err = repo.Index(&payload2)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
gaps, err := retriever.RetrieveGapsInData()
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2019-11-01 19:03:28 +00:00
|
|
|
Expect(len(gaps)).To(Equal(1))
|
2020-01-17 23:16:01 +00:00
|
|
|
Expect(gaps[0].Start).To(Equal(uint64(6)))
|
|
|
|
Expect(gaps[0].Stop).To(Equal(uint64(1010100)))
|
2019-11-01 19:03:28 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("Finds gaps between multiple entries", func() {
|
|
|
|
payload1 := *mocks.MockCIDPayload
|
2020-01-17 23:16:01 +00:00
|
|
|
payload1.HeaderCID.BlockNumber = "1010101"
|
2019-11-01 19:03:28 +00:00
|
|
|
payload2 := payload1
|
2020-01-17 23:16:01 +00:00
|
|
|
payload2.HeaderCID.BlockNumber = "5"
|
2019-11-01 19:03:28 +00:00
|
|
|
payload3 := payload2
|
2020-01-17 23:16:01 +00:00
|
|
|
payload3.HeaderCID.BlockNumber = "100"
|
2019-11-01 19:03:28 +00:00
|
|
|
payload4 := payload3
|
2020-01-17 23:16:01 +00:00
|
|
|
payload4.HeaderCID.BlockNumber = "101"
|
2019-11-01 19:03:28 +00:00
|
|
|
payload5 := payload4
|
2020-01-17 23:16:01 +00:00
|
|
|
payload5.HeaderCID.BlockNumber = "102"
|
2019-11-01 19:03:28 +00:00
|
|
|
payload6 := payload5
|
2020-01-17 23:16:01 +00:00
|
|
|
payload6.HeaderCID.BlockNumber = "1000"
|
2020-01-16 20:48:38 +00:00
|
|
|
err := repo.Index(&payload1)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
err = repo.Index(&payload2)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
err = repo.Index(&payload3)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
err = repo.Index(&payload4)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
err = repo.Index(&payload5)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
err = repo.Index(&payload6)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
gaps, err := retriever.RetrieveGapsInData()
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2019-11-01 19:03:28 +00:00
|
|
|
Expect(len(gaps)).To(Equal(3))
|
2020-01-17 23:16:01 +00:00
|
|
|
Expect(shared.ListContainsGap(gaps, shared.Gap{Start: 6, Stop: 99})).To(BeTrue())
|
|
|
|
Expect(shared.ListContainsGap(gaps, shared.Gap{Start: 103, Stop: 999})).To(BeTrue())
|
|
|
|
Expect(shared.ListContainsGap(gaps, shared.Gap{Start: 1001, Stop: 1010100})).To(BeTrue())
|
2019-11-01 19:03:28 +00:00
|
|
|
})
|
2019-08-28 18:41:49 +00:00
|
|
|
})
|
|
|
|
})
|