Skip to content

Commit

Permalink
Add test for getTxHashWithoutSigs using a real pegout. Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
julia-zack committed Nov 21, 2024
1 parent 007ffad commit 29bc369
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,10 @@ private void updateSvpFundTransactionValues(BtcTransaction transaction) {

private boolean isTheSvpSpendTransaction(BtcTransaction transaction) {
return provider.getSvpSpendTxHashUnsigned()
.map(svpSpendTransactionHashUnsigned ->
.filter(svpSpendTransactionHashUnsigned ->
getMultiSigTransactionHashWithoutSignatures(networkParameters, transaction).equals(svpSpendTransactionHashUnsigned)
)
.orElse(false);
.isPresent();
}

private void registerSvpSpendTransaction(BtcTransaction svpSpendTx) throws IOException {
Expand Down
16 changes: 16 additions & 0 deletions rskj-core/src/test/java/co/rsk/peg/bitcoin/BitcoinUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,22 @@ void getTransactionHashWithoutSignatures_whenTransactionIsLegacyAndInputsHaveP2s
assertEquals(transactionHashBeforeSigning, transactionHashWithoutSignatures);
}

@Test
void getTransactionHashWithoutSignatures_forRealPegout() {
// arrange
// getting the btc raw tx from a real release_btc event
byte[] btcRawTxFromReleaseBtcEvent = Hex.decode("0200000001de890a3fcdf7391f8f66d0b04e26d8ef05c342c4ad5b5feb64e24b525aa1721001000000fd3a0300483045022100ba4f30ded162d3203c89c73c03e8c6001255ab62fb7e258a92b112f7cefe2e8e0220683d7e552b0e812257be4fb41f9d2a0b99a91e2cd8bc5e9eb2305a0ddf6b833c01483045022100c8705daac34ec164ef1a441a24f9f9661ecf5bd271d2d6d85d4bd11d444d65e7022065599fc87a8d335f0ddee2a93ed442fae55e08d514f16ba087d4442f3cb2fca001483045022100a85719ee3b3e8bc3716900575b059fd40b1f3852d4de58efa6de1185d6ed5bda022052beda3d8597f4071918136c2cfd8f80aede4aaf6e8710585d2e5fbe988fd0ce0147304402205e90f4c98d2187a1021d7200f40b11623d4e6d3e99d5481b70bedadda10be759022071a3bac20aa917abd46bdedd52d97033050cb8da28f9b93507c93af69ffe67f201483045022100eb2fc5dd75c210311bbb0a0f9eacbd0675e61d413a2b227422232735fd95238602204f92e268e55b113c732b4351ba2049ff48b6347ba6e9a4efe9da70fb97f321e601004dc901645521020ace50bab1230f8002a0bfe619482af74b338cc9e4c956add228df47e6adae1c21025093f439fb8006fd29ab56605ffec9cdc840d16d2361004e1337a2f86d8bd2db210275d473555de2733c47125f9702b0f870df1d817379f5587f09b6c40ed2c6c9492102a95f095d0ce8cb3b9bf70cc837e3ebe1d107959b1fa3f9b2d8f33446f9c8cbdb2103250c11be0561b1d7ae168b1f59e39cbc1fd1ba3cf4d2140c1a365b2723a2bf9321034851379ec6b8a701bd3eef8a0e2b119abb4bdde7532a3d6bcbff291b0daf3f25210350179f143a632ce4e6ac9a755b82f7f4266cfebb116a42cadb104c2c2a3350f92103b04fbd87ef5e2c0946a684c8c93950301a45943bbe56d979602038698facf9032103b58a5da144f5abab2e03e414ad044b732300de52fa25c672a7f7b3588877190659ae670350cd00b275532102370a9838e4d15708ad14a104ee5606b36caaaaf739d833e67770ce9fd9b3ec80210257c293086c4d4fe8943deda5f890a37d11bebd140e220faa76258a41d077b4d42103c2660a46aa73078ee6016dee953488566426cf55fc8011edd0085634d75395f92103cd3e383ec6e12719a6c69515e5559bcbe037d0aa24c187e1e26ce932e22ad7b354ae68ffffffff0258369b02000000001976a91481769a94a036ceba700a71467f6cef39652acfd688ac33aa0c9d0000000017a914d3530b561910c250f58fbd572d2f7a7d847354ef8700000000");
BtcTransaction btcTxFromReleaseBtcEvent = new BtcTransaction(btcMainnetParams, btcRawTxFromReleaseBtcEvent);

// act
Sha256Hash btcTxHashWithoutSigs = getMultiSigTransactionHashWithoutSignatures(btcMainnetParams, btcTxFromReleaseBtcEvent);

// assert
// the tx hash emitted in the release_requested event does not have the signatures
Sha256Hash hashFromReleaseRequestedEvent = Sha256Hash.wrap("7fba184a41c4ca22e2b806bdd961c4e52b1bd2a1d2552bbe61cbba4d56c00fae");
assertEquals(hashFromReleaseRequestedEvent, btcTxHashWithoutSigs);
}

@Test
void addInputFromOutputSentToScript_withNoMatchingOutputScript_shouldNotAddInput() {
// arrange
Expand Down

0 comments on commit 29bc369

Please sign in to comment.