Skip to content

Commit

Permalink
feat: added a test to check a tx with negative block height is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlen committed Dec 17, 2024
1 parent d7a0091 commit 25c1834
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 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 @@ -112,7 +112,7 @@ void whenRegisterALegacyBtcTransaction_shouldRegisterTheNewUtxoAndTransferTheRbt
co.rsk.core.Coin expectedReceiverBalance = receiverBalance.add(co.rsk.core.Coin.fromBitcoin(btcTransferred));

// Act
registerBtcTransactionAndCommit();
registerBtcTransactionAndCommit(btcBlockWithPmtHeight);

// Assert
Optional<Long> heightIfBtcTxHashIsAlreadyProcessed = bridgeStorageProvider.getHeightIfBtcTxhashIsAlreadyProcessed(bitcoinTransaction.getHash());
Expand All @@ -128,21 +128,35 @@ void whenRegisterALegacyBtcTransaction_shouldRegisterTheNewUtxoAndTransferTheRbt
@Test
void whenRegisterARepeatedLegacyBtcTransaction_shouldNotPerformAnyChange() throws Exception {
// Arrange
registerBtcTransactionAndCommit();
registerBtcTransactionAndCommit(btcBlockWithPmtHeight);

co.rsk.core.Coin expectedReceiverBalance = track.getBalance(rskReceiver);
List<UTXO> expectedFederationUTXOs = federationSupport.getActiveFederationBtcUTXOs();

// Act
registerBtcTransactionAndCommit();
registerBtcTransactionAndCommit(btcBlockWithPmtHeight);

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

private void registerBtcTransactionAndCommit() throws Exception {
bridgeSupport.registerBtcTransaction(rskTx, bitcoinTransaction.bitcoinSerialize(), btcBlockWithPmtHeight, pmtWithTransactions.bitcoinSerialize());
@Test
void whenRegisterALegacyBtcTransactionWithNegativeHeight_shouldNotPerformAnyChange() throws Exception {
// Arrange
co.rsk.core.Coin expectedReceiverBalance = track.getBalance(rskReceiver);
List<UTXO> expectedFederationUTXOs = federationSupport.getActiveFederationBtcUTXOs();

// Act
registerBtcTransactionAndCommit(-1);

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

private void registerBtcTransactionAndCommit(int heightOfBlockWithPmt) throws Exception {
bridgeSupport.registerBtcTransaction(rskTx, bitcoinTransaction.bitcoinSerialize(), heightOfBlockWithPmt, pmtWithTransactions.bitcoinSerialize());
bridgeSupport.save();
track.commit();
}
Expand Down

0 comments on commit 25c1834

Please sign in to comment.