Skip to content

Commit 75fc07d

Browse files
authored
Merge pull request #2186 from abhijit360/feature/testcase-fee-inout-multiple-transactions
Added test case for fee inputs into multiple transactions
2 parents a86cf29 + c55cad1 commit 75fc07d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/test/scala/org/ergoplatform/mining/CandidateGeneratorPropSpec.scala

+40
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,46 @@ class CandidateGeneratorPropSpec extends ErgoCorePropertyTest {
196196

197197
}
198198

199+
property("should break up fee inputs into multiple transactions if there are too many") {
200+
val bh = boxesHolderGen.sample.get
201+
val us = createUtxoState(bh,parameters)
202+
val height = us.stateContext.currentHeight
203+
204+
// Generate a large number of fee boxes
205+
val feeBoxes= (1 to 1000).map(_ =>
206+
val value = Gen.choose(1,100).sample.get(100L, 10000L).sample.get
207+
createBox(value,feeProp, creationHeight = Some(height))
208+
)
209+
210+
// Create transactions spending these fee boxes
211+
val feeTransactions = feeBoxes.map { box =>
212+
val input = Input(box.id, ProverResult.empty)
213+
val output = new ErgoBoxCandidate(box.value, feeProp, height)
214+
new ErgoTransaction(IndexedSeq(input), IndexedSeq(output))
215+
216+
val txs = CandidateGenerator.collectFees(height, feeTransactions, defaultMinerPk, emptyStateContext).toSeq
217+
218+
// check that multiple transactions were created
219+
txs.length shouldBe > (1)
220+
221+
// check that each transacton does not exceed a reasonable input limit
222+
val maxInputsPerTx = 100
223+
txs.foreach { tx =>
224+
tx.inputs.size should be <= maxInputsPerTx
225+
}
226+
227+
// Check that all fee inputs were collected
228+
val collectedInputs = txs.flatMap(_.inputs).map(_.boxId).toSet
229+
val originalInputs = feeTransactions.flatMap(_.inputs).map(_.boxId).toSet
230+
collectedInputs should equal(originalInputs)
231+
}
232+
233+
// Check that all outputs go to the miner
234+
txs.flatMap(_.outputs).foreach { output =>
235+
output.propositionBytes shouldEqual expectedRewardOutputScriptBytes(defaultMinerPk)
236+
}
237+
}
238+
199239
property("should not be able to spend recent fee boxes") {
200240

201241
val delta = 1

0 commit comments

Comments
 (0)