github.com/core-coin/go-core/v2@v2.1.9/cmd/devp2p/internal/xcbtest/large.go (about)

     1  // Copyright 2020 by the Authors
     2  // This file is part of go-core.
     3  //
     4  // go-core is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU 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  // go-core 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 General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU General Public License
    15  // along with go-core. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package xcbtest
    18  
    19  import (
    20  	"crypto/rand"
    21  	"math/big"
    22  
    23  	"github.com/core-coin/go-core/v2/common"
    24  	"github.com/core-coin/go-core/v2/common/hexutil"
    25  	"github.com/core-coin/go-core/v2/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  		ReceiptHash: randHash(),
    65  		TxHash:      randHash(),
    66  		Nonce:       types.BlockNonce{},
    67  		Extra:       []byte{},
    68  		Bloom:       types.Bloom{},
    69  		EnergyUsed:  0,
    70  		Coinbase:    common.Address{},
    71  		EnergyLimit: 0,
    72  		UncleHash:   randHash(),
    73  		Time:        1337,
    74  		ParentHash:  randHash(),
    75  		Root:        randHash(),
    76  		Number:      largeNumber(2),
    77  		Difficulty:  largeNumber(2),
    78  	}
    79  }