2019-08-23 21:34:54 +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-23 21:34:54 +00:00
|
|
|
|
|
|
|
import (
|
2021-08-12 06:23:41 +00:00
|
|
|
"github.com/ethereum/go-ethereum/params"
|
2022-03-11 04:32:22 +00:00
|
|
|
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
|
|
|
|
"github.com/jmoiron/sqlx"
|
2019-08-23 21:34:54 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
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"
|
2019-08-23 21:34:54 +00:00
|
|
|
)
|
|
|
|
|
2020-08-10 18:04:07 +00:00
|
|
|
var _ = Describe("IPLDFetcher", func() {
|
2020-10-20 20:33:18 +00:00
|
|
|
var (
|
2022-03-11 04:32:22 +00:00
|
|
|
db *sqlx.DB
|
|
|
|
pubAndIndexer interfaces.StateDiffIndexer
|
2020-10-20 20:33:18 +00:00
|
|
|
fetcher *eth.IPLDFetcher
|
|
|
|
)
|
2020-04-30 21:26:32 +00:00
|
|
|
Describe("Fetch", func() {
|
2019-08-23 21:34:54 +00:00
|
|
|
BeforeEach(func() {
|
2021-08-12 06:23:41 +00:00
|
|
|
var (
|
|
|
|
err error
|
2022-03-11 04:32:22 +00:00
|
|
|
tx interfaces.Batch
|
2021-08-12 06:23:41 +00:00
|
|
|
)
|
2022-03-11 04:32:22 +00:00
|
|
|
db = eth.SetupTestDB()
|
|
|
|
pubAndIndexer = eth.SetupTestStateDiffIndexer(ctx, params.TestChainConfig, test_helpers.Genesis.Hash())
|
2021-10-07 09:35:11 +00:00
|
|
|
|
2021-08-12 06:23:41 +00:00
|
|
|
tx, err = pubAndIndexer.PushBlock(test_helpers.MockBlock, test_helpers.MockReceipts, test_helpers.MockBlock.Difficulty())
|
|
|
|
for _, node := range test_helpers.MockStateNodes {
|
2022-03-11 04:32:22 +00:00
|
|
|
err = pubAndIndexer.PushStateNode(tx, node, test_helpers.MockBlock.Hash().String())
|
2021-08-12 06:23:41 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
}
|
|
|
|
|
2022-03-11 04:32:22 +00:00
|
|
|
err = tx.Submit(err)
|
2019-08-23 21:34:54 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2020-08-10 18:04:07 +00:00
|
|
|
fetcher = eth.NewIPLDFetcher(db)
|
2021-08-12 06:23:41 +00:00
|
|
|
|
2020-08-10 17:46:03 +00:00
|
|
|
})
|
|
|
|
AfterEach(func() {
|
2022-03-11 04:32:22 +00:00
|
|
|
eth.TearDownTestDB(db)
|
2019-08-23 21:34:54 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("Fetches and returns IPLDs for the CIDs provided in the CIDWrapper", func() {
|
2020-10-20 20:33:18 +00:00
|
|
|
iplds, err := fetcher.Fetch(*test_helpers.MockCIDWrapper)
|
2019-08-23 21:34:54 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2020-08-31 15:47:06 +00:00
|
|
|
Expect(iplds).ToNot(BeNil())
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(iplds.TotalDifficulty).To(Equal(test_helpers.MockConvertedPayload.TotalDifficulty))
|
|
|
|
Expect(iplds.BlockNumber).To(Equal(test_helpers.MockConvertedPayload.Block.Number()))
|
|
|
|
Expect(iplds.Header).To(Equal(test_helpers.MockIPLDs.Header))
|
2020-08-10 17:46:03 +00:00
|
|
|
Expect(len(iplds.Uncles)).To(Equal(0))
|
2020-10-20 20:33:18 +00:00
|
|
|
Expect(iplds.Transactions).To(Equal(test_helpers.MockIPLDs.Transactions))
|
|
|
|
Expect(iplds.Receipts).To(Equal(test_helpers.MockIPLDs.Receipts))
|
|
|
|
Expect(iplds.StateNodes).To(Equal(test_helpers.MockIPLDs.StateNodes))
|
|
|
|
Expect(iplds.StorageNodes).To(Equal(test_helpers.MockIPLDs.StorageNodes))
|
2019-08-23 21:34:54 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|