ipld-eth-server/pkg/eth/ipld_fetcher_test.go

76 lines
2.7 KiB
Go
Raw Permalink Normal View History

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/>.
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/cerc-io/ipld-eth-server/v4/pkg/eth"
"github.com/cerc-io/ipld-eth-server/v4/pkg/eth/test_helpers"
"github.com/cerc-io/ipld-eth-server/v4/pkg/shared"
2019-08-23 21:34:54 +00:00
)
var _ = Describe("IPLDFetcher", func() {
var (
2022-03-11 04:32:22 +00:00
db *sqlx.DB
pubAndIndexer interfaces.StateDiffIndexer
fetcher *eth.IPLDFetcher
)
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-17 10:48:18 +00:00
db = shared.SetupDB()
pubAndIndexer = shared.SetupTestStateDiffIndexer(ctx, params.TestChainConfig, test_helpers.Genesis.Hash())
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())
fetcher = eth.NewIPLDFetcher(db)
2021-08-12 06:23:41 +00:00
})
AfterEach(func() {
2022-03-17 10:48:18 +00:00
shared.TearDownDB(db)
2019-08-23 21:34:54 +00:00
})
It("Fetches and returns IPLDs for the CIDs provided in the CIDWrapper", func() {
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())
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))
Expect(len(iplds.Uncles)).To(Equal(0))
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
})
})
})