2018-11-07 21:50:43 +00:00
|
|
|
// VulcanizeDB
|
2019-03-12 15:46:42 +00:00
|
|
|
// Copyright © 2019 Vulcanize
|
2018-11-07 21:50:43 +00:00
|
|
|
|
|
|
|
// 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/>.
|
|
|
|
|
2018-07-17 21:23:07 +00:00
|
|
|
package common_test
|
|
|
|
|
|
|
|
import (
|
2018-11-15 18:53:08 +00:00
|
|
|
"encoding/json"
|
|
|
|
"math/big"
|
2019-07-15 22:08:40 +00:00
|
|
|
"strconv"
|
2018-11-15 18:53:08 +00:00
|
|
|
|
2018-07-17 21:23:07 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2018-11-15 18:53:08 +00:00
|
|
|
|
2019-10-28 11:30:24 +00:00
|
|
|
common2 "github.com/vulcanize/vulcanizedb/pkg/eth/converters/common"
|
2018-11-15 18:53:08 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/fakes"
|
2018-07-17 21:23:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Block header converter", func() {
|
|
|
|
It("converts geth header to core header", func() {
|
|
|
|
gethHeader := &types.Header{
|
|
|
|
Difficulty: big.NewInt(1),
|
|
|
|
Number: big.NewInt(2),
|
|
|
|
ParentHash: common.HexToHash("0xParent"),
|
|
|
|
ReceiptHash: common.HexToHash("0xReceipt"),
|
|
|
|
Root: common.HexToHash("0xRoot"),
|
2019-07-15 22:08:40 +00:00
|
|
|
Time: uint64(123456789),
|
2018-07-17 21:23:07 +00:00
|
|
|
TxHash: common.HexToHash("0xTransaction"),
|
|
|
|
UncleHash: common.HexToHash("0xUncle"),
|
|
|
|
}
|
|
|
|
converter := common2.HeaderConverter{}
|
2018-11-15 18:53:08 +00:00
|
|
|
hash := fakes.FakeHash.String()
|
2018-07-17 21:23:07 +00:00
|
|
|
|
2019-02-14 15:04:12 +00:00
|
|
|
coreHeader := converter.Convert(gethHeader, hash)
|
2018-07-17 21:23:07 +00:00
|
|
|
|
|
|
|
Expect(coreHeader.BlockNumber).To(Equal(gethHeader.Number.Int64()))
|
2018-11-15 18:53:08 +00:00
|
|
|
Expect(coreHeader.Hash).To(Equal(hash))
|
2019-07-15 22:08:40 +00:00
|
|
|
Expect(coreHeader.Timestamp).To(Equal(strconv.FormatUint(gethHeader.Time, 10)))
|
2018-07-17 21:23:07 +00:00
|
|
|
})
|
|
|
|
|
2018-11-15 18:53:08 +00:00
|
|
|
It("includes raw bytes for header as JSON", func() {
|
|
|
|
gethHeader := types.Header{Number: big.NewInt(123)}
|
2018-07-17 21:23:07 +00:00
|
|
|
converter := common2.HeaderConverter{}
|
|
|
|
|
2019-02-14 15:04:12 +00:00
|
|
|
coreHeader := converter.Convert(&gethHeader, fakes.FakeHash.String())
|
2018-07-17 21:23:07 +00:00
|
|
|
|
2018-11-15 18:53:08 +00:00
|
|
|
expectedJSON, err := json.Marshal(gethHeader)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(coreHeader.Raw).To(Equal(expectedJSON))
|
2018-07-17 21:23:07 +00:00
|
|
|
})
|
|
|
|
})
|