From e4fb4c382b3111923d5c7a184516d9d947884921 Mon Sep 17 00:00:00 2001 From: julia-zack Date: Wed, 8 Jan 2025 19:42:19 -0300 Subject: [PATCH] Do not shuffle fundTx outputs order --- .../main/java/co/rsk/peg/BridgeSupport.java | 1 + .../java/co/rsk/peg/BridgeSupportSvpTest.java | 40 +++++++------------ 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java b/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java index 79da301ab5..132d814bd8 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java @@ -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; } diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportSvpTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportSvpTest.java index a71dabb7f3..870d6913b6 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportSvpTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportSvpTest.java @@ -385,12 +385,22 @@ void updateCollections_whenFundTxCanBeCreated_createsExpectedFundTxAndSavesTheHa private void assertSvpFundTransactionHasExpectedInputsAndOutputs() { assertInputsAreFromActiveFederation(); - List 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() { @@ -402,26 +412,6 @@ private void assertInputsAreFromActiveFederation() { } } - private void assertOneOutputIsChange(List transactionOutputs) { - Script activeFederationScriptPubKey = activeFederation.getP2SHScript(); - - Optional changeOutputOpt = searchForOutput(transactionOutputs, activeFederationScriptPubKey); - assertTrue(changeOutputOpt.isPresent()); - } - - private void assertOneOutputIsToProposedFederationWithExpectedAmount(List svpFundTransactionUnsignedOutputs) { - Script proposedFederationScriptPubKey = proposedFederation.getP2SHScript(); - - assertOutputWasSentToExpectedScriptWithExpectedAmount(svpFundTransactionUnsignedOutputs, proposedFederationScriptPubKey, minPegoutTxValue); - } - - private void assertOneOutputIsToProposedFederationWithFlyoverPrefixWithExpectedAmount(List svpFundTransactionUnsignedOutputs) { - Script proposedFederationWithFlyoverPrefixScriptPubKey = - PegUtils.getFlyoverScriptPubKey(bridgeMainNetConstants.getProposedFederationFlyoverPrefix(), proposedFederation.getRedeemScript()); - - assertOutputWasSentToExpectedScriptWithExpectedAmount(svpFundTransactionUnsignedOutputs, proposedFederationWithFlyoverPrefixScriptPubKey, minPegoutTxValue); - } - @Test void updateCollections_whenWaitingForFundTxToBeRegistered_shouldNotCreateFundTransactionAgain() throws Exception { // arrange