2019-08-26 02:13:40 +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-26 02:13:40 +00:00
|
|
|
|
|
|
|
import (
|
2019-09-30 20:12:02 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2019-08-26 02:13:40 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
|
2020-02-03 18:22:29 +00:00
|
|
|
mocks2 "github.com/vulcanize/vulcanizedb/pkg/ipfs/mocks"
|
2020-01-17 23:16:01 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/super_node/eth"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/super_node/eth/mocks"
|
2019-08-26 02:13:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-03-17 18:05:19 +00:00
|
|
|
mockHeaderDagPutter *mocks2.MappedDagPutter
|
|
|
|
mockTrxDagPutter *mocks2.MappedDagPutter
|
|
|
|
mockTrxTrieDagPutter *mocks2.DagPutter
|
|
|
|
mockRctDagPutter *mocks2.MappedDagPutter
|
|
|
|
mockRctTrieDagPutter *mocks2.DagPutter
|
2020-02-03 18:22:29 +00:00
|
|
|
mockStateDagPutter *mocks2.MappedDagPutter
|
2020-03-17 18:05:19 +00:00
|
|
|
mockStorageDagPutter *mocks2.MappedDagPutter
|
2019-08-26 02:13:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Publisher", func() {
|
|
|
|
BeforeEach(func() {
|
2020-03-17 18:05:19 +00:00
|
|
|
mockHeaderDagPutter = new(mocks2.MappedDagPutter)
|
|
|
|
mockTrxDagPutter = new(mocks2.MappedDagPutter)
|
|
|
|
mockTrxTrieDagPutter = new(mocks2.DagPutter)
|
|
|
|
mockRctDagPutter = new(mocks2.MappedDagPutter)
|
|
|
|
mockRctTrieDagPutter = new(mocks2.DagPutter)
|
2020-02-03 18:22:29 +00:00
|
|
|
mockStateDagPutter = new(mocks2.MappedDagPutter)
|
2020-03-17 18:05:19 +00:00
|
|
|
mockStorageDagPutter = new(mocks2.MappedDagPutter)
|
2019-08-26 02:13:40 +00:00
|
|
|
})
|
2019-08-28 22:07:36 +00:00
|
|
|
|
2019-08-26 02:13:40 +00:00
|
|
|
Describe("Publish", func() {
|
|
|
|
It("Publishes the passed IPLDPayload objects to IPFS and returns a CIDPayload for indexing", func() {
|
2020-03-17 18:05:19 +00:00
|
|
|
mockHeaderDagPutter.CIDsToReturn = map[common.Hash]string{
|
|
|
|
common.BytesToHash(mocks.HeaderIPLD.RawData()): mocks.HeaderCID.String(),
|
|
|
|
}
|
|
|
|
mockTrxDagPutter.CIDsToReturn = map[common.Hash]string{
|
|
|
|
common.BytesToHash(mocks.Trx1IPLD.RawData()): mocks.Trx1CID.String(),
|
|
|
|
common.BytesToHash(mocks.Trx2IPLD.RawData()): mocks.Trx2CID.String(),
|
2020-04-02 03:34:06 +00:00
|
|
|
common.BytesToHash(mocks.Trx3IPLD.RawData()): mocks.Trx3CID.String(),
|
2020-03-17 18:05:19 +00:00
|
|
|
}
|
|
|
|
mockRctDagPutter.CIDsToReturn = map[common.Hash]string{
|
|
|
|
common.BytesToHash(mocks.Rct1IPLD.RawData()): mocks.Rct1CID.String(),
|
|
|
|
common.BytesToHash(mocks.Rct2IPLD.RawData()): mocks.Rct2CID.String(),
|
2020-04-02 03:34:06 +00:00
|
|
|
common.BytesToHash(mocks.Rct3IPLD.RawData()): mocks.Rct3CID.String(),
|
2020-03-17 18:05:19 +00:00
|
|
|
}
|
|
|
|
mockStateDagPutter.CIDsToReturn = map[common.Hash]string{
|
|
|
|
common.BytesToHash(mocks.State1IPLD.RawData()): mocks.State1CID.String(),
|
|
|
|
common.BytesToHash(mocks.State2IPLD.RawData()): mocks.State2CID.String(),
|
|
|
|
}
|
|
|
|
mockStorageDagPutter.CIDsToReturn = map[common.Hash]string{
|
|
|
|
common.BytesToHash(mocks.StorageIPLD.RawData()): mocks.StorageCID.String(),
|
2019-09-30 20:12:02 +00:00
|
|
|
}
|
2020-01-17 23:16:01 +00:00
|
|
|
publisher := eth.IPLDPublisher{
|
2020-03-17 18:05:19 +00:00
|
|
|
HeaderPutter: mockHeaderDagPutter,
|
|
|
|
TransactionPutter: mockTrxDagPutter,
|
|
|
|
TransactionTriePutter: mockTrxTrieDagPutter,
|
|
|
|
ReceiptPutter: mockRctDagPutter,
|
|
|
|
ReceiptTriePutter: mockRctTrieDagPutter,
|
|
|
|
StatePutter: mockStateDagPutter,
|
|
|
|
StoragePutter: mockStorageDagPutter,
|
2019-08-26 02:13:40 +00:00
|
|
|
}
|
2020-02-20 22:12:52 +00:00
|
|
|
payload, err := publisher.Publish(mocks.MockConvertedPayload)
|
2019-08-26 02:13:40 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2020-01-17 23:16:01 +00:00
|
|
|
cidPayload, ok := payload.(*eth.CIDPayload)
|
|
|
|
Expect(ok).To(BeTrue())
|
2020-02-20 22:12:52 +00:00
|
|
|
Expect(cidPayload.HeaderCID.TotalDifficulty).To(Equal(mocks.MockConvertedPayload.TotalDifficulty.String()))
|
2020-01-17 23:16:01 +00:00
|
|
|
Expect(cidPayload.HeaderCID.BlockNumber).To(Equal(mocks.MockCIDPayload.HeaderCID.BlockNumber))
|
|
|
|
Expect(cidPayload.HeaderCID.BlockHash).To(Equal(mocks.MockCIDPayload.HeaderCID.BlockHash))
|
2020-02-20 22:13:19 +00:00
|
|
|
Expect(cidPayload.HeaderCID.Reward).To(Equal(mocks.MockCIDPayload.HeaderCID.Reward))
|
2019-08-29 19:57:58 +00:00
|
|
|
Expect(cidPayload.UncleCIDs).To(Equal(mocks.MockCIDPayload.UncleCIDs))
|
|
|
|
Expect(cidPayload.HeaderCID).To(Equal(mocks.MockCIDPayload.HeaderCID))
|
2020-04-02 03:34:06 +00:00
|
|
|
Expect(len(cidPayload.TransactionCIDs)).To(Equal(3))
|
2020-01-17 23:16:01 +00:00
|
|
|
Expect(cidPayload.TransactionCIDs[0]).To(Equal(mocks.MockCIDPayload.TransactionCIDs[0]))
|
|
|
|
Expect(cidPayload.TransactionCIDs[1]).To(Equal(mocks.MockCIDPayload.TransactionCIDs[1]))
|
2020-04-02 03:34:06 +00:00
|
|
|
Expect(cidPayload.TransactionCIDs[2]).To(Equal(mocks.MockCIDPayload.TransactionCIDs[2]))
|
|
|
|
Expect(len(cidPayload.ReceiptCIDs)).To(Equal(3))
|
2019-08-29 19:57:58 +00:00
|
|
|
Expect(cidPayload.ReceiptCIDs[mocks.MockTransactions[0].Hash()]).To(Equal(mocks.MockCIDPayload.ReceiptCIDs[mocks.MockTransactions[0].Hash()]))
|
|
|
|
Expect(cidPayload.ReceiptCIDs[mocks.MockTransactions[1].Hash()]).To(Equal(mocks.MockCIDPayload.ReceiptCIDs[mocks.MockTransactions[1].Hash()]))
|
2020-04-02 03:34:06 +00:00
|
|
|
Expect(cidPayload.ReceiptCIDs[mocks.MockTransactions[2].Hash()]).To(Equal(mocks.MockCIDPayload.ReceiptCIDs[mocks.MockTransactions[2].Hash()]))
|
2019-08-29 19:57:58 +00:00
|
|
|
Expect(len(cidPayload.StateNodeCIDs)).To(Equal(2))
|
2020-01-17 23:16:01 +00:00
|
|
|
Expect(cidPayload.StateNodeCIDs[0]).To(Equal(mocks.MockCIDPayload.StateNodeCIDs[0]))
|
|
|
|
Expect(cidPayload.StateNodeCIDs[1]).To(Equal(mocks.MockCIDPayload.StateNodeCIDs[1]))
|
2019-08-29 19:57:58 +00:00
|
|
|
Expect(cidPayload.StorageNodeCIDs).To(Equal(mocks.MockCIDPayload.StorageNodeCIDs))
|
2019-08-26 02:13:40 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|