Skip to content

Commit

Permalink
Remove assert methods that do not return void
Browse files Browse the repository at this point in the history
  • Loading branch information
julia-zack committed Jan 9, 2025
1 parent e4fb4c3 commit 94912ba
Showing 1 changed file with 19 additions and 30 deletions.
49 changes: 19 additions & 30 deletions rskj-core/src/test/java/co/rsk/peg/BridgeSupportSvpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,12 @@ void updateCollections_whenFundTxCanBeCreated_createsExpectedFundTxAndSavesTheHa
bridgeStorageProvider.save();

// assert
Sha256Hash svpFundTxHashUnsigned = assertSvpFundTxHashUnsignedIsInStorage();
assertSvpFundTxReleaseWasSettled(svpFundTxHashUnsigned);
Optional<Sha256Hash> svpFundTxHashUnsigned = bridgeStorageProvider.getSvpFundTxHashUnsigned();
assertTrue(svpFundTxHashUnsigned.isPresent());
assertSvpFundTxReleaseWasSettled(svpFundTxHashUnsigned.get());

assertActiveFederationUtxosSize(activeFederationUtxosSizeBeforeCreatingFundTx - 1);

assertSvpFundTransactionHasExpectedInputsAndOutputs();
}

Expand Down Expand Up @@ -416,7 +419,6 @@ private void assertInputsAreFromActiveFederation() {
void updateCollections_whenWaitingForFundTxToBeRegistered_shouldNotCreateFundTransactionAgain() throws Exception {
// arrange
arrangeSvpFundTransactionUnsigned();
assertSvpFundTxHashUnsignedIsInStorage();

// act
bridgeSupport.updateCollections(rskTx);
Expand Down Expand Up @@ -469,7 +471,10 @@ private void assertJustUpdateCollectionsWasLogged() {
private void arrangeSvpFundTransactionUnsigned() {
recreateSvpFundTransactionUnsigned();
addOutputChange(svpFundTransaction);

saveSvpFundTransactionUnsigned();
Optional<Sha256Hash> svpFundTransactionHashUnsigned = bridgeStorageProvider.getSvpFundTxHashUnsigned();
assertTrue(svpFundTransactionHashUnsigned.isPresent());
}

private void saveSvpFundTransactionUnsigned() {
Expand All @@ -487,12 +492,6 @@ private void saveSvpFundTransactionHashUnsigned(Sha256Hash svpFundTransactionHas
bridgeSupport.save();
}

private Sha256Hash assertSvpFundTxHashUnsignedIsInStorage() {
Optional<Sha256Hash> svpFundTransactionHashUnsigned = bridgeStorageProvider.getSvpFundTxHashUnsigned();
assertTrue(svpFundTransactionHashUnsigned.isPresent());

return svpFundTransactionHashUnsigned.get();
}

private void assertSvpFundTxReleaseWasSettled(Sha256Hash svpFundTransactionHashUnsigned) throws IOException {
PegoutsWaitingForConfirmations pegoutsWaitingForConfirmations = bridgeStorageProvider.getPegoutsWaitingForConfirmations();
Expand Down Expand Up @@ -702,15 +701,22 @@ void updateCollections_whenSpendTxCanBeCreated_createsExpectedSpendTxAndSavesThe
bridgeStorageProvider.save();

// assert
Sha256Hash svpSpendTransactionHashUnsigned = assertSvpSpendTxHashUnsignedIsInStorage();
svpSpendTransaction = assertSvpSpendTxIsWaitingForSignatures();
Optional<Sha256Hash> svpSpendTransactionHashUnsigned = bridgeStorageProvider.getSvpSpendTxHashUnsigned();
assertTrue(svpSpendTransactionHashUnsigned.isPresent());

Optional<Map.Entry<Keccak256, BtcTransaction>> svpSpendTxWaitingForSignaturesOpt = bridgeStorageProvider.getSvpSpendTxWaitingForSignatures();
assertTrue(svpSpendTxWaitingForSignaturesOpt.isPresent());
Map.Entry<Keccak256, BtcTransaction> svpSpendTxWaitingForSignatures = svpSpendTxWaitingForSignaturesOpt.get();
svpSpendTransaction = svpSpendTxWaitingForSignatures.getValue();

assertSvpSpendTxHasExpectedInputsAndOutputs();

assertSvpFundTxSignedWasRemovedFromStorage();

assertLogPegoutTransactionCreated(svpSpendTransaction);

TransactionOutput outputToActiveFed = svpSpendTransaction.getOutput(0);
assertLogReleaseRequested(rskTx.getHash(), svpSpendTransactionHashUnsigned, outputToActiveFed.getValue());
assertLogReleaseRequested(rskTx.getHash(), svpSpendTransactionHashUnsigned.get(), outputToActiveFed.getValue());
}

private void assertSvpFundTxSignedWasRemovedFromStorage() {
Expand Down Expand Up @@ -766,26 +772,9 @@ private void assertInputHasExpectedScriptSig(TransactionInput input, Script rede
}
}

private Sha256Hash assertSvpSpendTxHashUnsignedIsInStorage() {
private void assertSvpSpendTxHashUnsignedIsInStorage() {
Optional<Sha256Hash> svpSpendTransactionHashUnsignedOpt = bridgeStorageProvider.getSvpSpendTxHashUnsigned();
assertTrue(svpSpendTransactionHashUnsignedOpt.isPresent());

return svpSpendTransactionHashUnsignedOpt.get();
}

private BtcTransaction assertSvpSpendTxIsWaitingForSignatures() {
Optional<Map.Entry<Keccak256, BtcTransaction>> svpSpendTxWaitingForSignaturesOpt = bridgeStorageProvider.getSvpSpendTxWaitingForSignatures();
assertTrue(svpSpendTxWaitingForSignaturesOpt.isPresent());
Map.Entry<Keccak256, BtcTransaction> svpSpendTxWaitingForSignatures = svpSpendTxWaitingForSignaturesOpt.get();

Keccak256 svpSpendTxWaitingForSignaturesRskTxHash = svpSpendTxWaitingForSignatures.getKey();
assertEquals(rskTx.getHash(), svpSpendTxWaitingForSignaturesRskTxHash);

BtcTransaction svpSpendTxWaitingForSignaturesSpendTx = svpSpendTxWaitingForSignatures.getValue();
Sha256Hash svpSpendTransactionHashUnsigned = assertSvpSpendTxHashUnsignedIsInStorage();
assertEquals(svpSpendTransactionHashUnsigned, svpSpendTxWaitingForSignaturesSpendTx.getHash());

return svpSpendTxWaitingForSignaturesSpendTx;
}

@Nested
Expand Down

0 comments on commit 94912ba

Please sign in to comment.