Skip to content

Commit

Permalink
Do not shuffle fundTx outputs order
Browse files Browse the repository at this point in the history
  • Loading branch information
julia-zack committed Jan 9, 2025
1 parent cefb90e commit e4fb4c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
1 change: 1 addition & 0 deletions rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,7 @@ private SendRequest createSvpFundTransactionSendRequest(BtcTransaction transacti
sendRequest.feePerKb = feePerKbSupport.getFeePerKb();
sendRequest.missingSigsMode = Wallet.MissingSigsMode.USE_OP_ZERO;
sendRequest.recipientsPayFees = false;
sendRequest.shuffleOutputs = false;

return sendRequest;
}
Expand Down
40 changes: 15 additions & 25 deletions rskj-core/src/test/java/co/rsk/peg/BridgeSupportSvpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,22 @@ void updateCollections_whenFundTxCanBeCreated_createsExpectedFundTxAndSavesTheHa
private void assertSvpFundTransactionHasExpectedInputsAndOutputs() {
assertInputsAreFromActiveFederation();

List<TransactionOutput> svpFundTransactionUnsignedOutputs = svpFundTransaction.getOutputs();
int svpFundTransactionUnsignedOutputsExpectedSize = 3;
assertEquals(svpFundTransactionUnsignedOutputsExpectedSize, svpFundTransactionUnsignedOutputs.size());
assertOneOutputIsChange(svpFundTransactionUnsignedOutputs);
assertOneOutputIsToProposedFederationWithExpectedAmount(svpFundTransactionUnsignedOutputs);
assertOneOutputIsToProposedFederationWithFlyoverPrefixWithExpectedAmount(svpFundTransactionUnsignedOutputs);
assertEquals(svpFundTransactionUnsignedOutputsExpectedSize, svpFundTransaction.getOutputs().size());

// assert outputs are the expected ones in the expected order
TransactionOutput outputToProposedFed = svpFundTransaction.getOutput(0);
assertEquals(outputToProposedFed.getScriptPubKey(), proposedFederation.getP2SHScript());
assertEquals(outputToProposedFed.getValue(), bridgeMainNetConstants.getMinimumPegoutTxValue());

TransactionOutput outputToFlyoverProposedFed = svpFundTransaction.getOutput(1);
Script proposedFederationWithFlyoverPrefixScriptPubKey =
PegUtils.getFlyoverScriptPubKey(bridgeMainNetConstants.getProposedFederationFlyoverPrefix(), proposedFederation.getRedeemScript());
assertEquals(outputToFlyoverProposedFed.getScriptPubKey(), proposedFederationWithFlyoverPrefixScriptPubKey);
assertEquals(outputToFlyoverProposedFed.getValue(), bridgeMainNetConstants.getMinimumPegoutTxValue());

TransactionOutput changeOutput = svpFundTransaction.getOutput(2);
assertEquals(changeOutput.getScriptPubKey(), activeFederation.getP2SHScript());
}

private void assertInputsAreFromActiveFederation() {
Expand All @@ -402,26 +412,6 @@ private void assertInputsAreFromActiveFederation() {
}
}

private void assertOneOutputIsChange(List<TransactionOutput> transactionOutputs) {
Script activeFederationScriptPubKey = activeFederation.getP2SHScript();

Optional<TransactionOutput> changeOutputOpt = searchForOutput(transactionOutputs, activeFederationScriptPubKey);
assertTrue(changeOutputOpt.isPresent());
}

private void assertOneOutputIsToProposedFederationWithExpectedAmount(List<TransactionOutput> svpFundTransactionUnsignedOutputs) {
Script proposedFederationScriptPubKey = proposedFederation.getP2SHScript();

assertOutputWasSentToExpectedScriptWithExpectedAmount(svpFundTransactionUnsignedOutputs, proposedFederationScriptPubKey, minPegoutTxValue);
}

private void assertOneOutputIsToProposedFederationWithFlyoverPrefixWithExpectedAmount(List<TransactionOutput> svpFundTransactionUnsignedOutputs) {
Script proposedFederationWithFlyoverPrefixScriptPubKey =
PegUtils.getFlyoverScriptPubKey(bridgeMainNetConstants.getProposedFederationFlyoverPrefix(), proposedFederation.getRedeemScript());

assertOutputWasSentToExpectedScriptWithExpectedAmount(svpFundTransactionUnsignedOutputs, proposedFederationWithFlyoverPrefixScriptPubKey, minPegoutTxValue);
}

@Test
void updateCollections_whenWaitingForFundTxToBeRegistered_shouldNotCreateFundTransactionAgain() throws Exception {
// arrange
Expand Down

0 comments on commit e4fb4c3

Please sign in to comment.