Test GethBlockToCoreBlock

This commit is contained in:
Matt Krump 2017-10-27 15:47:13 -05:00
parent e05b1a59dd
commit 5c0e39eb9f
3 changed files with 34 additions and 3 deletions

View File

@ -22,6 +22,6 @@ func GethBlockToCoreBlock(gethBlock *types.Block) Block {
GasLimit: gethBlock.GasLimit(), GasLimit: gethBlock.GasLimit(),
GasUsed: gethBlock.GasUsed(), GasUsed: gethBlock.GasUsed(),
Time: gethBlock.Time(), Time: gethBlock.Time(),
NumberOfTransactions: len(gethBlock.Transactions()), NumberOfTransactions: gethBlock.Transactions().Len(),
} }
} }

31
core/block_test.go Normal file
View File

@ -0,0 +1,31 @@
package core
import (
"math/big"
"github.com/ethereum/go-ethereum/core/types"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Conversion of GethBlock to core.Block", func() {
It("Converts a GethBlock to core.Block (metadata, without transactions)", func() {
blockNumber := big.NewInt(1)
gasUsed := big.NewInt(100000)
gasLimit := big.NewInt(100000)
time := big.NewInt(140000000)
transaction := types.Transaction{}
header := types.Header{Number: blockNumber, GasUsed: gasUsed, Time: time, GasLimit: gasLimit}
block := types.NewBlock(&header, []*types.Transaction{&transaction}, []*types.Header{}, []*types.Receipt{})
gethBlock := GethBlockToCoreBlock(block)
Expect(gethBlock.Number).To(Equal(blockNumber))
Expect(gethBlock.GasUsed).To(Equal(gasUsed))
Expect(gethBlock.GasLimit).To(Equal(gasLimit))
Expect(gethBlock.Time).To(Equal(time))
Expect(gethBlock.NumberOfTransactions).To(Equal(1))
})
})