Skip to content

Commit

Permalink
Merge pull request #2186 from abhijit360/feature/testcase-fee-inout-m…
Browse files Browse the repository at this point in the history
…ultiple-transactions

Added test case for fee inputs into multiple transactions
  • Loading branch information
kushti authored Oct 11, 2024
2 parents a86cf29 + c55cad1 commit 75fc07d
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,46 @@ class CandidateGeneratorPropSpec extends ErgoCorePropertyTest {

}

property("should break up fee inputs into multiple transactions if there are too many") {
val bh = boxesHolderGen.sample.get
val us = createUtxoState(bh,parameters)
val height = us.stateContext.currentHeight

// Generate a large number of fee boxes
val feeBoxes= (1 to 1000).map(_ =>
val value = Gen.choose(1,100).sample.get(100L, 10000L).sample.get
createBox(value,feeProp, creationHeight = Some(height))
)

// Create transactions spending these fee boxes
val feeTransactions = feeBoxes.map { box =>
val input = Input(box.id, ProverResult.empty)
val output = new ErgoBoxCandidate(box.value, feeProp, height)
new ErgoTransaction(IndexedSeq(input), IndexedSeq(output))

val txs = CandidateGenerator.collectFees(height, feeTransactions, defaultMinerPk, emptyStateContext).toSeq

// check that multiple transactions were created
txs.length shouldBe > (1)

// check that each transacton does not exceed a reasonable input limit
val maxInputsPerTx = 100
txs.foreach { tx =>
tx.inputs.size should be <= maxInputsPerTx
}

// Check that all fee inputs were collected
val collectedInputs = txs.flatMap(_.inputs).map(_.boxId).toSet
val originalInputs = feeTransactions.flatMap(_.inputs).map(_.boxId).toSet
collectedInputs should equal(originalInputs)
}

// Check that all outputs go to the miner
txs.flatMap(_.outputs).foreach { output =>
output.propositionBytes shouldEqual expectedRewardOutputScriptBytes(defaultMinerPk)
}
}

property("should not be able to spend recent fee boxes") {

val delta = 1
Expand Down

0 comments on commit 75fc07d

Please sign in to comment.