large.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2020 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package ethtest
  17. import (
  18. "crypto/rand"
  19. "math/big"
  20. "github.com/ethereum/go-ethereum/common"
  21. "github.com/ethereum/go-ethereum/common/hexutil"
  22. "github.com/ethereum/go-ethereum/core/types"
  23. )
  24. // largeNumber returns a very large big.Int.
  25. func largeNumber(megabytes int) *big.Int {
  26. buf := make([]byte, megabytes*1024*1024)
  27. rand.Read(buf)
  28. bigint := new(big.Int)
  29. bigint.SetBytes(buf)
  30. return bigint
  31. }
  32. // largeBuffer returns a very large buffer.
  33. func largeBuffer(megabytes int) []byte {
  34. buf := make([]byte, megabytes*1024*1024)
  35. rand.Read(buf)
  36. return buf
  37. }
  38. // largeString returns a very large string.
  39. func largeString(megabytes int) string {
  40. buf := make([]byte, megabytes*1024*1024)
  41. rand.Read(buf)
  42. return hexutil.Encode(buf)
  43. }
  44. func largeBlock() *types.Block {
  45. return types.NewBlockWithHeader(largeHeader())
  46. }
  47. // Returns a random hash
  48. func randHash() common.Hash {
  49. var h common.Hash
  50. rand.Read(h[:])
  51. return h
  52. }
  53. func largeHeader() *types.Header {
  54. return &types.Header{
  55. MixDigest: randHash(),
  56. ReceiptHash: randHash(),
  57. TxHash: randHash(),
  58. Nonce: types.BlockNonce{},
  59. Extra: []byte{},
  60. Bloom: types.Bloom{},
  61. GasUsed: 0,
  62. Coinbase: common.Address{},
  63. GasLimit: 0,
  64. UncleHash: types.EmptyUncleHash,
  65. Time: 1337,
  66. ParentHash: randHash(),
  67. Root: randHash(),
  68. Number: largeNumber(2),
  69. Difficulty: largeNumber(2),
  70. }
  71. }