|
1 | 1 | package org.ergoplatform.nodeView.mempool
|
2 | 2 |
|
3 |
| -import org.ergoplatform.modifiers.mempool.{ErgoTransaction, UnconfirmedTransaction} |
| 3 | +import org.ergoplatform.{ErgoBoxCandidate, Input} |
4 | 4 | import org.ergoplatform.nodeView.mempool.ErgoMemPoolUtils.{ProcessingOutcome, SortingOption}
|
| 5 | +import org.ergoplatform.modifiers.mempool.{ErgoTransaction, UnconfirmedTransaction} |
5 | 6 | import org.ergoplatform.nodeView.state.wrapped.WrappedUtxoState
|
6 | 7 | import org.ergoplatform.settings.ErgoSettings
|
7 |
| -import org.ergoplatform.utils.ErgoTestHelpers |
8 |
| -import org.ergoplatform.{ErgoBoxCandidate, Input} |
| 8 | +import org.ergoplatform.utils.{ErgoTestHelpers, RandomWrapper} |
9 | 9 | import org.scalatest.flatspec.AnyFlatSpec
|
10 | 10 | import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks
|
11 | 11 | import sigma.ast.ErgoTree.ZeroHeader
|
@@ -299,11 +299,41 @@ class ErgoMemPoolSpec extends AnyFlatSpec
|
299 | 299 | }
|
300 | 300 | pool.size shouldBe (family_depth + 1) * txs.size
|
301 | 301 | allTxs.foreach { tx =>
|
302 |
| - pool = pool.remove(tx.transaction) |
| 302 | + pool = pool.removeTxAndDoubleSpends(tx.transaction) |
303 | 303 | }
|
304 | 304 | pool.size shouldBe 0
|
305 | 305 | }
|
306 | 306 |
|
| 307 | + it should "correctly remove doublespents of a transaction from pool" in { |
| 308 | + val (us, bh) = createUtxoState(settings) |
| 309 | + val genesis = validFullBlock(None, us, bh) |
| 310 | + val wus = WrappedUtxoState(us, bh, settings, parameters).applyModifier(genesis)(_ => ()).get |
| 311 | + val boxes = wus.takeBoxes(4) |
| 312 | + |
| 313 | + val limit = 10000 |
| 314 | + |
| 315 | + val tx1 = validTransactionsFromBoxes(limit, boxes.take(1), new RandomWrapper) |
| 316 | + ._1.map(tx => UnconfirmedTransaction(tx, None)).head |
| 317 | + |
| 318 | + val tx2 = validTransactionsFromBoxes(limit, boxes.takeRight(2), new RandomWrapper) |
| 319 | + ._1.map(tx => UnconfirmedTransaction(tx, None)).head |
| 320 | + |
| 321 | + val tx3 = validTransactionsFromBoxes(limit, boxes.take(1), new RandomWrapper) |
| 322 | + ._1.map(tx => UnconfirmedTransaction(tx, None)).head |
| 323 | + |
| 324 | + tx1.transaction.inputs.head.boxId shouldBe tx3.transaction.inputs.head.boxId |
| 325 | + |
| 326 | + var pool = ErgoMemPool.empty(settings) |
| 327 | + Seq(tx2, tx3).foreach { tx => |
| 328 | + pool = pool.put(tx) |
| 329 | + } |
| 330 | + |
| 331 | + pool = pool.removeTxAndDoubleSpends(tx1.transaction) |
| 332 | + pool.contains(tx1.transaction) shouldBe false |
| 333 | + pool.contains(tx2.transaction) shouldBe true |
| 334 | + pool.contains(tx3.transaction) shouldBe false |
| 335 | + } |
| 336 | + |
307 | 337 | it should "return results take / getAll / getAllPrioritized sorted by priority" in {
|
308 | 338 | val feeProp = settings.chainSettings.monetary.feeProposition
|
309 | 339 |
|
@@ -378,7 +408,7 @@ class ErgoMemPoolSpec extends AnyFlatSpec
|
378 | 408 | pool.stats.snapTakenTxns shouldBe MemPoolStatistics(System.currentTimeMillis(),0,System.currentTimeMillis()).snapTakenTxns
|
379 | 409 |
|
380 | 410 | allTxs.foreach { tx =>
|
381 |
| - pool = pool.remove(tx.transaction) |
| 411 | + pool = pool.removeTxAndDoubleSpends(tx.transaction) |
382 | 412 | }
|
383 | 413 | pool.size shouldBe 0
|
384 | 414 | pool.stats.takenTxns shouldBe (family_depth + 1) * txs.size
|
|
0 commit comments