Skip to content

Commit

Permalink
fix: no magic numbers, extracted them as variables
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlen committed Dec 19, 2024
1 parent 28ccc6c commit ea055ed
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions rskj-core/src/test/java/co/rsk/peg/RegisterBtcTransactionIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ void registerBtcTransaction_whenLegacyBtcTransactionWithNegativeHeight_shouldNot
List<UTXO> expectedFederationUTXOs = List.copyOf(federationSupport.getActiveFederationBtcUTXOs());

// Act
bridgeSupport.registerBtcTransaction(rskTx, bitcoinTransaction.bitcoinSerialize(), -1, pmtWithTransactions.bitcoinSerialize());
int height = -1;
bridgeSupport.registerBtcTransaction(rskTx, bitcoinTransaction.bitcoinSerialize(), height, pmtWithTransactions.bitcoinSerialize());
bridgeSupport.save();

// Assert
Expand All @@ -163,19 +164,22 @@ void registerBtcTransaction_whenLegacyBtcTransactionWithNegativeHeight_shouldNot
}

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()
);
}

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;
Expand All @@ -184,7 +188,8 @@ private BtcTransaction createPegInTransaction(Address federationAddress, Coin co
private void assertLogPegInBtc() {
Sha256Hash peginTransactionHash = bitcoinTransaction.getHash();
List<DataWord> 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);
Expand Down

0 comments on commit ea055ed

Please sign in to comment.