forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/devp2p/internal/ethtest: add 'large announcement' tests (ethereum…
…#21792) * cmd/devp2p/internal/ethtest: added large announcement tests * cmd/devp2p/internal/ethtest: added large announcement tests * cmd/devp2p/internal/ethtest: refactored stuff a bit * cmd/devp2p/internal/ethtest: added TestMaliciousStatus/Handshake * cmd/devp2p/internal/ethtest: fixed rebasing issue * happy linter, happy life * cmd/devp2p/internal/ethtest: used readAndServe * stuff * cmd/devp2p/internal/ethtest: fixed test cases
- Loading branch information
1 parent
4ae0590
commit 9b33653
Showing
3 changed files
with
284 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2020 The go-ethereum Authors | ||
// This file is part of the go-ethereum library. | ||
// | ||
// The go-ethereum library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-ethereum library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package ethtest | ||
|
||
import ( | ||
"crypto/rand" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
) | ||
|
||
// largeNumber returns a very large big.Int. | ||
func largeNumber(megabytes int) *big.Int { | ||
buf := make([]byte, megabytes*1024*1024) | ||
rand.Read(buf) | ||
bigint := new(big.Int) | ||
bigint.SetBytes(buf) | ||
return bigint | ||
} | ||
|
||
// largeBuffer returns a very large buffer. | ||
func largeBuffer(megabytes int) []byte { | ||
buf := make([]byte, megabytes*1024*1024) | ||
rand.Read(buf) | ||
return buf | ||
} | ||
|
||
// largeString returns a very large string. | ||
func largeString(megabytes int) string { | ||
buf := make([]byte, megabytes*1024*1024) | ||
rand.Read(buf) | ||
return hexutil.Encode(buf) | ||
} | ||
|
||
func largeBlock() *types.Block { | ||
return types.NewBlockWithHeader(largeHeader()) | ||
} | ||
|
||
// Returns a random hash | ||
func randHash() common.Hash { | ||
var h common.Hash | ||
rand.Read(h[:]) | ||
return h | ||
} | ||
|
||
func largeHeader() *types.Header { | ||
return &types.Header{ | ||
MixDigest: randHash(), | ||
ReceiptHash: randHash(), | ||
TxHash: randHash(), | ||
Nonce: types.BlockNonce{}, | ||
Extra: []byte{}, | ||
Bloom: types.Bloom{}, | ||
GasUsed: 0, | ||
Coinbase: common.Address{}, | ||
GasLimit: 0, | ||
UncleHash: randHash(), | ||
Time: 1337, | ||
ParentHash: randHash(), | ||
Root: randHash(), | ||
Number: largeNumber(2), | ||
Difficulty: largeNumber(2), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.