mirror of
https://github.com/corda/corda.git
synced 2025-05-30 14:14:29 +00:00
core, contracts: Add Generator<>.generateList to reduce boilerplate
This commit is contained in:
parent
6faf19cccc
commit
f11a587382
@ -29,7 +29,6 @@ class ContractStateGenerator : Generator<ContractState>(ContractState::class.jav
|
|||||||
|
|
||||||
class MoveGenerator : Generator<Cash.Commands.Move>(Cash.Commands.Move::class.java) {
|
class MoveGenerator : Generator<Cash.Commands.Move>(Cash.Commands.Move::class.java) {
|
||||||
override fun generate(random: SourceOfRandomness, status: GenerationStatus): Cash.Commands.Move {
|
override fun generate(random: SourceOfRandomness, status: GenerationStatus): Cash.Commands.Move {
|
||||||
// TODO generate null as well
|
|
||||||
return Cash.Commands.Move(SecureHashGenerator().generate(random, status))
|
return Cash.Commands.Move(SecureHashGenerator().generate(random, status))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -63,19 +62,11 @@ class CommandGenerator : Generator<Command>(Command::class.java) {
|
|||||||
|
|
||||||
class WiredTransactionGenerator: Generator<WireTransaction>(WireTransaction::class.java) {
|
class WiredTransactionGenerator: Generator<WireTransaction>(WireTransaction::class.java) {
|
||||||
override fun generate(random: SourceOfRandomness, status: GenerationStatus): WireTransaction {
|
override fun generate(random: SourceOfRandomness, status: GenerationStatus): WireTransaction {
|
||||||
val inputsGenerator = ArrayListGenerator()
|
val commands = CommandGenerator().generateList(random, status) + listOf(CommandGenerator().generate(random, status))
|
||||||
inputsGenerator.addComponentGenerators(listOf(StateRefGenerator()))
|
|
||||||
val attachmentsGenerator = ArrayListGenerator()
|
|
||||||
attachmentsGenerator.addComponentGenerators(listOf(SecureHashGenerator()))
|
|
||||||
val outputsGenerator = ArrayListGenerator()
|
|
||||||
outputsGenerator.addComponentGenerators(listOf(TransactionStateGenerator(ContractStateGenerator())))
|
|
||||||
val commandsGenerator = ArrayListGenerator()
|
|
||||||
commandsGenerator.addComponentGenerators(listOf(CommandGenerator()))
|
|
||||||
val commands = commandsGenerator.generate(random, status) as ArrayList<Command> + listOf(CommandGenerator().generate(random, status))
|
|
||||||
return WireTransaction(
|
return WireTransaction(
|
||||||
inputs = inputsGenerator.generate(random, status) as ArrayList<StateRef>,
|
inputs = StateRefGenerator().generateList(random, status),
|
||||||
attachments = attachmentsGenerator.generate(random, status) as ArrayList<SecureHash>,
|
attachments = SecureHashGenerator().generateList(random, status),
|
||||||
outputs = outputsGenerator.generate(random, status) as ArrayList<TransactionState<ContractState>>,
|
outputs = TransactionStateGenerator(ContractStateGenerator()).generateList(random, status),
|
||||||
commands = commands,
|
commands = commands,
|
||||||
notary = PartyGenerator().generate(random, status),
|
notary = PartyGenerator().generate(random, status),
|
||||||
signers = commands.flatMap { it.signers },
|
signers = commands.flatMap { it.signers },
|
||||||
|
@ -25,6 +25,13 @@ import java.util.*
|
|||||||
* TODO Split this into several files
|
* TODO Split this into several files
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
fun <A> Generator<A>.generateList(random: SourceOfRandomness, status: GenerationStatus): List<A> {
|
||||||
|
val arrayGenerator = ArrayListGenerator()
|
||||||
|
arrayGenerator.addComponentGenerators(listOf(this))
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
return arrayGenerator.generate(random, status) as List<A>
|
||||||
|
}
|
||||||
|
|
||||||
class PrivateKeyGenerator: Generator<EdDSAPrivateKey>(EdDSAPrivateKey::class.java) {
|
class PrivateKeyGenerator: Generator<EdDSAPrivateKey>(EdDSAPrivateKey::class.java) {
|
||||||
override fun generate(random: SourceOfRandomness, status: GenerationStatus): EdDSAPrivateKey {
|
override fun generate(random: SourceOfRandomness, status: GenerationStatus): EdDSAPrivateKey {
|
||||||
val seed = random.nextBytes(32)
|
val seed = random.nextBytes(32)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user