Skip to content

Commit

Permalink
feat: test a tx with multiple outputs below the minimum peg in value …
Browse files Browse the repository at this point in the history
…s.t. the total value is above the minimum
  • Loading branch information
julianlen committed Dec 26, 2024
1 parent f0bdcaf commit b30aaa6
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions rskj-core/src/test/java/co/rsk/peg/RegisterBtcTransactionIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<UTXO> 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<Long> heightIfBtcTxHashIsAlreadyProcessed = bridgeStorageProvider.getHeightIfBtcTxhashIsAlreadyProcessed(bitcoinTransaction.getHash());
assertFalse(heightIfBtcTxHashIsAlreadyProcessed.isPresent());
}

@Test
void registerBtcTransaction_forARepeatedLegacyBtcTransaction_shouldNotPerformAnyChange() throws Exception {
// Arrange
Expand Down

0 comments on commit b30aaa6

Please sign in to comment.