Created
October 11, 2024 20:35
-
-
Save kushti/5793c40b7615ad99916a4de125b0e149 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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 | |
| new ErgoBoxCandidate(value, feeProp, height) | |
| } | |
| // Create transactions spending these fee boxes | |
| val feeTransactions = feeBoxes.map { box => | |
| val input = Input(box.toBox(bytesToId(Array.fill(32)(0.toByte)), 0.toShort).id, ProverResult.empty) | |
| val output = new ErgoBoxCandidate(box.value, feeProp, height) | |
| new ErgoTransaction(IndexedSeq(input), IndexedSeq.empty, 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) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
`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(1L, 100L).sample.get
new ErgoBoxCandidate(value, feeProp, height)
}
// Create transactions spending these fee boxes
val feeTransactions = feeBoxes.map { box =>
val input = Input(box.toBox(bytesToId(Array.fill(32)(0.toByte)), 0.toShort).id, ProverResult.empty)
val output = new ErgoBoxCandidate(box.value, feeProp, height)
new ErgoTransaction(IndexedSeq(input), IndexedSeq.empty, IndexedSeq(output))
}
val txs = CandidateGenerator.collectFees(height, feeTransactions, defaultMinerPk, emptyStateContext).toSeq
// Check that multiple transactions were created
txs.length should be > 1
// Check that each transaction 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)
}
// Check that the total collected fee is correct
val totalCollectedFee = txs.flatMap(.outputs).map(.value).sum
val expectedTotalFee = feeTransactions.flatMap(.outputs).map(.value).sum
totalCollectedFee shouldEqual expectedTotalFee
}`