forked from cerc-io/ipld-eth-server
Add fields to block tables
This commit is contained in:
1 parent
4733b25f54
commit
df09cf8d93
8 files changed
+111
-28
No files matched your search
@@ -4,6 +4,7 @@ import (
|
||||
"github.com/8thlight/vulcanizedb/core"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func gethTransToCoreTrans(transaction *types.Transaction) core.Transaction {
|
||||
@@ -26,11 +27,17 @@ func GethBlockToCoreBlock(gethBlock *types.Block) core.Block {
|
||||
transactions = append(transactions, gethTransToCoreTrans(gethTransaction))
|
||||
}
|
||||
return core.Block{
|
||||
Number: gethBlock.Number().Int64(),
|
||||
Difficulty: gethBlock.Difficulty().Int64(),
|
||||
GasLimit: gethBlock.GasLimit().Int64(),
|
||||
GasUsed: gethBlock.GasUsed().Int64(),
|
||||
Hash: gethBlock.Hash().Hex(),
|
||||
Nonce: strconv.FormatUint(gethBlock.Nonce(), 10),
|
||||
Number: gethBlock.Number().Int64(),
|
||||
ParentHash: gethBlock.ParentHash().Hex(),
|
||||
Size: gethBlock.Size().Int64(),
|
||||
Time: gethBlock.Time().Int64(),
|
||||
Transactions: transactions,
|
||||
UncleHash: gethBlock.UncleHash().Hex(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,29 +8,42 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
|
||||
It("converts basic Block metada", func() {
|
||||
blockNumber := int64(1)
|
||||
gasUsed := int64(100000)
|
||||
difficulty := big.NewInt(1)
|
||||
gasLimit := int64(100000)
|
||||
gasUsed := int64(100000)
|
||||
nonce := types.BlockNonce{10}
|
||||
number := int64(1)
|
||||
time := int64(140000000)
|
||||
|
||||
header := types.Header{
|
||||
GasUsed: big.NewInt(gasUsed),
|
||||
Number: big.NewInt(blockNumber),
|
||||
Time: big.NewInt(time),
|
||||
GasLimit: big.NewInt(gasLimit),
|
||||
Difficulty: difficulty,
|
||||
GasLimit: big.NewInt(gasLimit),
|
||||
GasUsed: big.NewInt(gasUsed),
|
||||
Nonce: nonce,
|
||||
Number: big.NewInt(number),
|
||||
ParentHash: common.Hash{64},
|
||||
Time: big.NewInt(time),
|
||||
UncleHash: common.Hash{128},
|
||||
}
|
||||
block := types.NewBlock(&header, []*types.Transaction{}, []*types.Header{}, []*types.Receipt{})
|
||||
gethBlock := geth.GethBlockToCoreBlock(block)
|
||||
|
||||
Expect(gethBlock.Number).To(Equal(blockNumber))
|
||||
Expect(gethBlock.GasUsed).To(Equal(gasUsed))
|
||||
Expect(gethBlock.Difficulty).To(Equal(difficulty.Int64()))
|
||||
Expect(gethBlock.GasLimit).To(Equal(gasLimit))
|
||||
Expect(gethBlock.GasUsed).To(Equal(gasUsed))
|
||||
Expect(gethBlock.Hash).To(Equal(block.Hash().Hex()))
|
||||
Expect(gethBlock.Nonce).To(Equal((strconv.FormatUint(block.Nonce(), 10))))
|
||||
Expect(gethBlock.Number).To(Equal(number))
|
||||
Expect(gethBlock.ParentHash).To(Equal(block.ParentHash().Hex()))
|
||||
Expect(gethBlock.Size).To(Equal(block.Size().Int64()))
|
||||
Expect(gethBlock.Time).To(Equal(time))
|
||||
Expect(gethBlock.UncleHash).To(Equal(block.UncleHash().Hex()))
|
||||
})
|
||||
|
||||
Describe("the converted transations", func() {
|
||||
|
||||
Reference in new issue
Block a user