Created
July 18, 2016 01:20
-
-
Save Christewart/a8e0bd42e2b339ee8cdab349503cbc06 to your computer and use it in GitHub Desktop.
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
trait BlockchainElementsGenerator { | |
def block : Gen[Block] = for { | |
header <- blockHeader | |
txs <- Gen.listOfN(randomNumber(10), TransactionGenerators.transactions) | |
} yield Block(header, txs) | |
def blockHeader : Gen[BlockHeader] = for { | |
version <- NumberGenerator.uInt32s | |
previousBlockHash <- CryptoGenerators.doubleSha256Digest | |
merkleRootHash <- CryptoGenerators.doubleSha256Digest | |
time <- NumberGenerator.uInt32s | |
nBits <- NumberGenerator.uInt32s | |
nonce <- NumberGenerator.uInt32s | |
} yield BlockHeader(version, previousBlockHash, merkleRootHash, time, nBits, nonce) | |
private def randomNumber(lessThan : Int) : Int = (scala.util.Random.nextInt() % lessThan).abs | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment