2018-07-17 21:23:07 +00:00
|
|
|
package common_test
|
|
|
|
|
|
|
|
import (
|
2018-10-11 20:25:14 +00:00
|
|
|
"encoding/json"
|
|
|
|
"math/big"
|
|
|
|
|
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-10-11 20:25:14 +00:00
|
|
|
|
2018-07-17 21:23:07 +00:00
|
|
|
common2 "github.com/vulcanize/vulcanizedb/pkg/geth/converters/common"
|
|
|
|
)
|
|
|
|
|
|
|
|
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"),
|
2018-10-11 20:25:14 +00:00
|
|
|
Time: big.NewInt(123456789),
|
2018-07-17 21:23:07 +00:00
|
|
|
TxHash: common.HexToHash("0xTransaction"),
|
|
|
|
UncleHash: common.HexToHash("0xUncle"),
|
|
|
|
}
|
|
|
|
converter := common2.HeaderConverter{}
|
|
|
|
|
|
|
|
coreHeader, err := converter.Convert(gethHeader)
|
|
|
|
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(coreHeader.BlockNumber).To(Equal(gethHeader.Number.Int64()))
|
|
|
|
Expect(coreHeader.Hash).To(Equal(gethHeader.Hash().Hex()))
|
2018-10-11 20:25:14 +00:00
|
|
|
Expect(coreHeader.Timestamp).To(Equal(gethHeader.Time.String()))
|
2018-07-17 21:23:07 +00:00
|
|
|
})
|
|
|
|
|
2018-10-11 20:25:14 +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{}
|
|
|
|
|
|
|
|
coreHeader, err := converter.Convert(&gethHeader)
|
|
|
|
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-10-11 20:25:14 +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
|
|
|
})
|
|
|
|
})
|