forked from cerc-io/ipld-eth-server
Test GethBlockToCoreBlock
This commit is contained in:
parent
e05b1a59dd
commit
5c0e39eb9f
@ -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
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))
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user