gitee.com/liu-zhao234568/cntest@v1.0.0/cmd/devp2p/internal/ethtest/large.go (about) 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 17 package ethtest 18 19 import ( 20 "crypto/rand" 21 "math/big" 22 23 "gitee.com/liu-zhao234568/cntest/common" 24 "gitee.com/liu-zhao234568/cntest/common/hexutil" 25 "gitee.com/liu-zhao234568/cntest/core/types" 26 ) 27 28 // largeNumber returns a very large big.Int. 29 func largeNumber(megabytes int) *big.Int { 30 buf := make([]byte, megabytes*1024*1024) 31 rand.Read(buf) 32 bigint := new(big.Int) 33 bigint.SetBytes(buf) 34 return bigint 35 } 36 37 // largeBuffer returns a very large buffer. 38 func largeBuffer(megabytes int) []byte { 39 buf := make([]byte, megabytes*1024*1024) 40 rand.Read(buf) 41 return buf 42 } 43 44 // largeString returns a very large string. 45 func largeString(megabytes int) string { 46 buf := make([]byte, megabytes*1024*1024) 47 rand.Read(buf) 48 return hexutil.Encode(buf) 49 } 50 51 func largeBlock() *types.Block { 52 return types.NewBlockWithHeader(largeHeader()) 53 } 54 55 // Returns a random hash 56 func randHash() common.Hash { 57 var h common.Hash 58 rand.Read(h[:]) 59 return h 60 } 61 62 func largeHeader() *types.Header { 63 return &types.Header{ 64 MixDigest: randHash(), 65 ReceiptHash: randHash(), 66 TxHash: randHash(), 67 Nonce: types.BlockNonce{}, 68 Extra: []byte{}, 69 Bloom: types.Bloom{}, 70 GasUsed: 0, 71 Coinbase: common.Address{}, 72 GasLimit: 0, 73 UncleHash: types.EmptyUncleHash, 74 Time: 1337, 75 ParentHash: randHash(), 76 Root: randHash(), 77 Number: largeNumber(2), 78 Difficulty: largeNumber(2), 79 } 80 }