From b30aaa6b3e63c1426474aeb8a73e094f0778122a Mon Sep 17 00:00:00 2001 From: Julian Len Date: Thu, 26 Dec 2024 15:59:31 -0300 Subject: [PATCH] feat: test a tx with multiple outputs below the minimum peg in value s.t. the total value is above the minimum --- .../co/rsk/peg/RegisterBtcTransactionIT.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/rskj-core/src/test/java/co/rsk/peg/RegisterBtcTransactionIT.java b/rskj-core/src/test/java/co/rsk/peg/RegisterBtcTransactionIT.java index 4a24e8c649..4229b0acb8 100644 --- a/rskj-core/src/test/java/co/rsk/peg/RegisterBtcTransactionIT.java +++ b/rskj-core/src/test/java/co/rsk/peg/RegisterBtcTransactionIT.java @@ -163,6 +163,33 @@ void registerBtcTransaction_forMultipleLegacyBtcTransaction_shouldRegisterTheNew assertLogPegInBtc(bitcoinTransaction, minimumPeginValue.getValue() * numberOfOutputs); } + @Test + void registerBtcTransaction_forMultipleLegacyBtcTransactionBelowMinimumWithSumAboveMinimum_shouldNotPerformAnyPegIn() throws Exception { + // Arrange + short numberOfOutputs = 2; + Coin partOfMinimumValue = Coin.valueOf(minimumPeginValue.getValue() / numberOfOutputs); + BtcTransaction bitcoinTransaction = createTransactionWithMultiplePegIns(federationSupport.getActiveFederation().getAddress(), btcPublicKey, partOfMinimumValue, numberOfOutputs); + assertTrue((partOfMinimumValue.getValue() * numberOfOutputs) >= minimumPeginValue.getValue()); + + setupChainWithBtcTransaction(bitcoinTransaction); + bridgeStorageProvider.save(); + + co.rsk.core.Coin expectedReceiverBalance = repository.getBalance(rskReceiver); + List expectedFederationUTXOs = List.copyOf(federationSupport.getActiveFederationBtcUTXOs()); + + // Act + bridgeSupport.registerBtcTransaction(rskTx, bitcoinTransaction.bitcoinSerialize(), btcBlockWithPmtHeight, pmtWithTransactions.bitcoinSerialize()); + bridgeSupport.save(); + + // Assert + assertEquals(expectedFederationUTXOs, federationSupport.getActiveFederationBtcUTXOs()); + assertEquals(expectedReceiverBalance, repository.getBalance(rskReceiver)); + + assertRejectedPeginTransaction(bitcoinTransaction, BridgeEvents.UNREFUNDABLE_PEGIN.getEvent(), RejectedPeginReason.INVALID_AMOUNT.getValue()); + Optional heightIfBtcTxHashIsAlreadyProcessed = bridgeStorageProvider.getHeightIfBtcTxhashIsAlreadyProcessed(bitcoinTransaction.getHash()); + assertFalse(heightIfBtcTxHashIsAlreadyProcessed.isPresent()); + } + @Test void registerBtcTransaction_forARepeatedLegacyBtcTransaction_shouldNotPerformAnyChange() throws Exception { // Arrange