diff --git a/core/block.go b/core/block.go index e7465673..13722c14 100644 --- a/core/block.go +++ b/core/block.go @@ -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(), } } diff --git a/core/block_test.go b/core/block_test.go new file mode 100644 index 00000000..4a6197f6 --- /dev/null +++ b/core/block_test.go @@ -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)) + }) + +}) diff --git a/core/blockchain_db_observer_test.go b/core/blockchain_db_observer_test.go index bbdfc767..0bd3ec54 100644 --- a/core/blockchain_db_observer_test.go +++ b/core/blockchain_db_observer_test.go @@ -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) }