@@ -256,16 +256,45 @@ func ReferenceUnlock(index uint16) *iotago.ReferenceUnlock {
256256
257257// RandTransactionEssence returns a random transaction essence.
258258func RandTransactionEssence () * iotago.TransactionEssence {
259+ return RandTransactionEssenceWithInputOutputCount (rand .Intn (iotago .MaxInputsCount )+ 1 , rand .Intn (iotago .MaxOutputsCount )+ 1 )
260+ }
261+
262+ // RandTransactionEssenceWithInputCount returns a random transaction essence with a specific amount of inputs..
263+ func RandTransactionEssenceWithInputCount (inputCount int ) * iotago.TransactionEssence {
264+ return RandTransactionEssenceWithInputOutputCount (inputCount , rand .Intn (iotago .MaxOutputsCount )+ 1 )
265+ }
266+
267+ // RandTransactionEssenceWithOutputCount returns a random transaction essence with a specific amount of outputs.
268+ func RandTransactionEssenceWithOutputCount (outputCount int ) * iotago.TransactionEssence {
269+ return RandTransactionEssenceWithInputOutputCount (rand .Intn (iotago .MaxInputsCount )+ 1 , outputCount )
270+ }
271+
272+ // RandTransactionEssenceWithInputOutputCount returns a random transaction essence with a specific amount of inputs and outputs.
273+ func RandTransactionEssenceWithInputOutputCount (inputCount int , outputCount int ) * iotago.TransactionEssence {
259274 tx := & iotago.TransactionEssence {
260275 NetworkID : TestNetworkID ,
261276 }
262277
263- inputCount := rand .Intn (10 ) + 1
264278 for i := inputCount ; i > 0 ; i -- {
265279 tx .Inputs = append (tx .Inputs , RandUTXOInput ())
266280 }
267281
268- outputCount := rand .Intn (10 ) + 1
282+ for i := outputCount ; i > 0 ; i -- {
283+ tx .Outputs = append (tx .Outputs , RandBasicOutput (iotago .AddressEd25519 ))
284+ }
285+
286+ return tx
287+ }
288+
289+ // RandTransactionEssenceWithInputs returns a random transaction essence with a specific slice of inputs.
290+ func RandTransactionEssenceWithInputs (inputs iotago.Inputs ) * iotago.TransactionEssence {
291+ tx := & iotago.TransactionEssence {
292+ NetworkID : TestNetworkID ,
293+ }
294+
295+ tx .Inputs = inputs
296+
297+ outputCount := rand .Intn (iotago .MaxOutputsCount ) + 1
269298 for i := outputCount ; i > 0 ; i -- {
270299 tx .Outputs = append (tx .Outputs , RandBasicOutput (iotago .AddressEd25519 ))
271300 }
@@ -377,10 +406,9 @@ func RandBlock(withPayloadType iotago.PayloadType) *iotago.Block {
377406 }
378407}
379408
380- // RandTransaction returns a random transaction.
381- func RandTransaction ( ) * iotago.Transaction {
409+ // RandTransactionWithEssence returns a random transaction with a specific essence .
410+ func RandTransactionWithEssence ( essence * iotago. TransactionEssence ) * iotago.Transaction {
382411 sigTxPayload := & iotago.Transaction {}
383- essence := RandTransactionEssence ()
384412 sigTxPayload .Essence = essence
385413
386414 unlocksCount := len (essence .Inputs )
@@ -391,6 +419,26 @@ func RandTransaction() *iotago.Transaction {
391419 return sigTxPayload
392420}
393421
422+ // RandTransaction returns a random transaction.
423+ func RandTransaction () * iotago.Transaction {
424+ return RandTransactionWithEssence (RandTransactionEssence ())
425+ }
426+
427+ // RandTransactionWithInputCount returns a random transaction with a specific amount of inputs.
428+ func RandTransactionWithInputCount (inputCount int ) * iotago.Transaction {
429+ return RandTransactionWithEssence (RandTransactionEssenceWithInputCount (inputCount ))
430+ }
431+
432+ // RandTransactionWithOutputCount returns a random transaction with a specific amount of outputs.
433+ func RandTransactionWithOutputCount (outputCount int ) * iotago.Transaction {
434+ return RandTransactionWithEssence (RandTransactionEssenceWithOutputCount (outputCount ))
435+ }
436+
437+ // RandTransactionWithInputOutputCount returns a random transaction with a specific amount of inputs and outputs.
438+ func RandTransactionWithInputOutputCount (inputCount int , outputCount int ) * iotago.Transaction {
439+ return RandTransactionWithEssence (RandTransactionEssenceWithInputOutputCount (inputCount , outputCount ))
440+ }
441+
394442// RandTreasuryInput returns a random treasury input.
395443func RandTreasuryInput () * iotago.TreasuryInput {
396444 treasuryInput := & iotago.TreasuryInput {}
@@ -401,11 +449,15 @@ func RandTreasuryInput() *iotago.TreasuryInput {
401449
402450// RandUTXOInput returns a random UTXO input.
403451func RandUTXOInput () * iotago.UTXOInput {
452+ return RandUTXOInputWithIndex (uint16 (rand .Intn (iotago .RefUTXOIndexMax )))
453+ }
454+
455+ // RandUTXOInputWithIndex returns a random UTXO input with a specific index.
456+ func RandUTXOInputWithIndex (index uint16 ) * iotago.UTXOInput {
404457 utxoInput := & iotago.UTXOInput {}
405458 txID := RandBytes (iotago .TransactionIDLength )
406459 copy (utxoInput .TransactionID [:], txID )
407460
408- index := uint16 (rand .Intn (iotago .RefUTXOIndexMax ))
409461 utxoInput .TransactionOutputIndex = index
410462 return utxoInput
411463}
0 commit comments