Skip to content

Commit

Permalink
feat: added a test to assert that the registration of a btc transacti…
Browse files Browse the repository at this point in the history
…on with negative height should not perform any modification in the state
  • Loading branch information
julianlen committed Dec 11, 2024
1 parent a017be8 commit de4c30f
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions rskj-core/src/test/java/co/rsk/peg/RegisterBtcTransactionIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void whenRegisterALegacyBtcTransaction_shouldRegisterTheNewUtxoAndTransferTheRbt
co.rsk.core.Coin expectedReceiverBalance = receiverBalance.add(co.rsk.core.Coin.fromBitcoin(BTC_TRANSFERRED));

// Act
registerBtcTransactionOrFail();
registerBtcTransactionOrFail(btcBlockWithPmtHeight);

// Assert
try {
Expand All @@ -121,23 +121,38 @@ void whenRegisterALegacyBtcTransaction_shouldRegisterTheNewUtxoAndTransferTheRbt
@Test
void whenRegisterARepeatedLegacyBtcTransaction_shouldNotPerformAnyChange() {
// Arrange
registerBtcTransactionOrFail();
registerBtcTransactionOrFail(btcBlockWithPmtHeight);

RskAddress receiverBalance = new RskAddress(ecKey.getAddress());
co.rsk.core.Coin expectedReceiverBalance = track.getBalance(receiverBalance);
List<UTXO> expectedFederationUTXOs = federationSupport.getActiveFederationBtcUTXOs();

// Act
registerBtcTransactionOrFail();
registerBtcTransactionOrFail(btcBlockWithPmtHeight);

// Assert
assertEquals(expectedFederationUTXOs, federationSupport.getActiveFederationBtcUTXOs());
assertEquals(expectedReceiverBalance, repository.getBalance(receiverBalance));
}

private void registerBtcTransactionOrFail() {
@Test
void whenRegisterALegacyBtcTransactionWithNegativeHeight_shouldNotPerformAnyChange() {
// Arrange
RskAddress receiverBalance = new RskAddress(ecKey.getAddress());
co.rsk.core.Coin expectedReceiverBalance = track.getBalance(receiverBalance);
List<UTXO> expectedFederationUTXOs = federationSupport.getActiveFederationBtcUTXOs();

// Act
registerBtcTransactionOrFail(-1);

// Assert
assertEquals(expectedFederationUTXOs, federationSupport.getActiveFederationBtcUTXOs());
assertEquals(expectedReceiverBalance, repository.getBalance(receiverBalance));
}

private void registerBtcTransactionOrFail(int blockWithPmtHeight) {
try {
bridgeSupport.registerBtcTransaction(rskTx, bitcoinTransaction.bitcoinSerialize(), btcBlockWithPmtHeight, pmtWithTransactions.bitcoinSerialize());
bridgeSupport.registerBtcTransaction(rskTx, bitcoinTransaction.bitcoinSerialize(), blockWithPmtHeight, pmtWithTransactions.bitcoinSerialize());
} catch (Exception e) {
fail(e.getMessage());
}
Expand Down

0 comments on commit de4c30f

Please sign in to comment.