Test GethBlockToCoreBlock
This commit is contained in:
parent
e05b1a59dd
commit
5c0e39eb9f
@ -22,6 +22,6 @@ func GethBlockToCoreBlock(gethBlock *types.Block) Block {
|
||||
GasLimit: gethBlock.GasLimit(),
|
||||
GasUsed: gethBlock.GasUsed(),
|
||||
Time: gethBlock.Time(),
|
||||
NumberOfTransactions: len(gethBlock.Transactions()),
|
||||
NumberOfTransactions: gethBlock.Transactions().Len(),
|
||||
}
|
||||
}
|
||||
|
31
core/block_test.go
Normal file
31
core/block_test.go
Normal 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))
|
||||
})
|
||||
|
||||
})
|
@ -86,10 +86,10 @@ var _ = Describe("Saving blocks to the database", func() {
|
||||
var gasUsed float64
|
||||
rows.Scan(&blockNumber, &gasLimit, &gasUsed, &blockTime)
|
||||
savedBlock := core.Block{
|
||||
GasUsed: big.NewInt(int64(gasUsed)),
|
||||
GasUsed: big.NewInt(int64(gasUsed)),
|
||||
GasLimit: big.NewInt(int64(gasLimit)),
|
||||
Number: big.NewInt(blockNumber),
|
||||
Time: big.NewInt(int64(blockTime)),
|
||||
Time: big.NewInt(int64(blockTime)),
|
||||
}
|
||||
savedBlocks = append(savedBlocks, savedBlock)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user