block_processor_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package core
  2. import (
  3. "math/big"
  4. "testing"
  5. "github.com/ethereum/go-ethereum/common"
  6. "github.com/ethereum/go-ethereum/core/state"
  7. "github.com/ethereum/go-ethereum/core/types"
  8. "github.com/ethereum/go-ethereum/ethdb"
  9. "github.com/ethereum/go-ethereum/event"
  10. "github.com/ethereum/go-ethereum/pow/ezp"
  11. )
  12. func proc() (*BlockProcessor, *ChainManager) {
  13. db, _ := ethdb.NewMemDatabase()
  14. var mux event.TypeMux
  15. chainMan := NewChainManager(db, db, thePow(), &mux)
  16. return NewBlockProcessor(db, db, ezp.New(), chainMan, &mux), chainMan
  17. }
  18. func TestNumber(t *testing.T) {
  19. bp, chain := proc()
  20. block1 := chain.NewBlock(common.Address{})
  21. block1.Header().Number = big.NewInt(3)
  22. block1.Header().Time--
  23. err := bp.ValidateHeader(block1.Header(), chain.Genesis().Header(), false)
  24. if err != BlockNumberErr {
  25. t.Errorf("expected block number error %v", err)
  26. }
  27. block1 = chain.NewBlock(common.Address{})
  28. err = bp.ValidateHeader(block1.Header(), chain.Genesis().Header(), false)
  29. if err == BlockNumberErr {
  30. t.Errorf("didn't expect block number error")
  31. }
  32. }
  33. func TestPutReceipt(t *testing.T) {
  34. db, _ := ethdb.NewMemDatabase()
  35. var addr common.Address
  36. addr[0] = 1
  37. var hash common.Hash
  38. hash[0] = 2
  39. receipt := new(types.Receipt)
  40. receipt.SetLogs(state.Logs{&state.Log{
  41. Address: addr,
  42. Topics: []common.Hash{hash},
  43. Data: []byte("hi"),
  44. Number: 42,
  45. TxHash: hash,
  46. TxIndex: 0,
  47. BlockHash: hash,
  48. Index: 0,
  49. }})
  50. putReceipts(db, hash, types.Receipts{receipt})
  51. receipts, err := getBlockReceipts(db, hash)
  52. if err != nil {
  53. t.Error("got err:", err)
  54. }
  55. if len(receipts) != 1 {
  56. t.Error("expected to get 1 receipt, got", len(receipts))
  57. }
  58. }