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 1f7ed3484c..38dbf100d2 100644 --- a/rskj-core/src/test/java/co/rsk/peg/RegisterBtcTransactionIT.java +++ b/rskj-core/src/test/java/co/rsk/peg/RegisterBtcTransactionIT.java @@ -120,7 +120,7 @@ void registerBtcTransaction_forALegacyBtcTransaction_shouldRegisterTheNewUtxoAnd int outputIndex = 0; TransactionOutput output = bitcoinTransaction.getOutput(outputIndex); - List expectedFederationUtxos = Collections.singletonList(utxoOf(bitcoinTransaction, output)); + List expectedFederationUtxos = List.of(utxoOf(bitcoinTransaction, output)); assertEquals(expectedFederationUtxos, federationSupport.getActiveFederationBtcUTXOs()); co.rsk.core.Coin expectedReceiverBalance = co.rsk.core.Coin.fromBitcoin(output.getValue()); @@ -136,7 +136,7 @@ void registerBtcTransaction_forARepeatedLegacyBtcTransaction_shouldNotPerformAny bridgeSupport.save(); co.rsk.core.Coin expectedReceiverBalance = repository.getBalance(rskReceiver); - List expectedFederationUTXOs = federationSupport.getActiveFederationBtcUTXOs(); + List expectedFederationUTXOs = List.copyOf(federationSupport.getActiveFederationBtcUTXOs()); // Act bridgeSupport.registerBtcTransaction(rskTx, bitcoinTransaction.bitcoinSerialize(), btcBlockWithPmtHeight, pmtWithTransactions.bitcoinSerialize()); @@ -147,12 +147,29 @@ void registerBtcTransaction_forARepeatedLegacyBtcTransaction_shouldNotPerformAny assertEquals(expectedReceiverBalance, repository.getBalance(rskReceiver)); } + @Test + void registerBtcTransaction_whenLegacyBtcTransactionWithNegativeHeight_shouldNotPerformAnyChange() throws Exception { + // Arrange + co.rsk.core.Coin expectedReceiverBalance = repository.getBalance(rskReceiver); + List expectedFederationUTXOs = List.copyOf(federationSupport.getActiveFederationBtcUTXOs()); + + // Act + int height = -1; + bridgeSupport.registerBtcTransaction(rskTx, bitcoinTransaction.bitcoinSerialize(), height, pmtWithTransactions.bitcoinSerialize()); + bridgeSupport.save(); + + // Assert + assertEquals(expectedFederationUTXOs, federationSupport.getActiveFederationBtcUTXOs()); + assertEquals(expectedReceiverBalance, repository.getBalance(rskReceiver)); + } + private static UTXO utxoOf(BtcTransaction bitcoinTransaction, TransactionOutput output) { + int height = 0; return new UTXO( bitcoinTransaction.getHash(), output.getIndex(), output.getValue(), - 0, + height, bitcoinTransaction.isCoinBase(), output.getScriptPubKey() ); @@ -160,7 +177,9 @@ private static UTXO utxoOf(BtcTransaction bitcoinTransaction, TransactionOutput private BtcTransaction createPegInTransaction(Address federationAddress, Coin coin, BtcECKey pubKey) { BtcTransaction btcTx = new BtcTransaction(btcNetworkParams); - btcTx.addInput(BitcoinTestUtils.createHash(0), 0, ScriptBuilder.createInputScript(null, pubKey)); + int outputIndex = 0; + int nHash = 0; + btcTx.addInput(BitcoinTestUtils.createHash(nHash), outputIndex, ScriptBuilder.createInputScript(null, pubKey)); btcTx.addOutput(new TransactionOutput(btcNetworkParams, btcTx, coin, federationAddress)); return btcTx; @@ -169,7 +188,8 @@ private BtcTransaction createPegInTransaction(Address federationAddress, Coin co private void assertLogPegInBtc() { Sha256Hash peginTransactionHash = bitcoinTransaction.getHash(); List encodedTopics = getEncodedTopics(BridgeEvents.PEGIN_BTC.getEvent(), rskReceiver.toString(), peginTransactionHash.getBytes()); - byte[] encodedData = getEncodedData(BridgeEvents.PEGIN_BTC.getEvent(), minimumPeginValue.getValue(), 0); + int protocolVersion = 0; + byte[] encodedData = getEncodedData(BridgeEvents.PEGIN_BTC.getEvent(), minimumPeginValue.getValue(), protocolVersion); assertEventWasEmittedWithExpectedTopics(encodedTopics, logs); assertEventWasEmittedWithExpectedData(encodedData, logs);