diff --git a/src/test/java/co/rsk/federate/btcreleaseclient/BtcReleaseClientTest.java b/src/test/java/co/rsk/federate/btcreleaseclient/BtcReleaseClientTest.java index fcf91285..4d0ca704 100644 --- a/src/test/java/co/rsk/federate/btcreleaseclient/BtcReleaseClientTest.java +++ b/src/test/java/co/rsk/federate/btcreleaseclient/BtcReleaseClientTest.java @@ -62,7 +62,6 @@ import co.rsk.peg.federation.*; import co.rsk.peg.StateForFederator; import co.rsk.peg.StateForProposedFederator; - import java.lang.reflect.Field; import java.math.BigInteger; import java.time.Clock; @@ -102,6 +101,7 @@ class BtcReleaseClientTest { private static final Duration PEGOUT_SIGNED_CACHE_TTL = Duration.ofMinutes(30); private final BlockStore blockStore = mock(BlockStore.class); + private final ReceiptStore receiptStore = mock(ReceiptStore.class); private final Block bestBlock = mock(Block.class); private final NetworkParameters params = RegTestParams.get(); private final BridgeConstants bridgeConstants = Constants.regtest().bridgeConstants; @@ -115,9 +115,21 @@ class BtcReleaseClientTest { @BeforeEach void setup() { // ensure confirmation difference always passes + Keccak256 rskTxHash = createHash(1); + Keccak256 blockHash = createHash(2); + TransactionInfo transactionInfoForTxWaitingForSignatures = mock(TransactionInfo.class); Block blockWithTxWaitingForSignatures = mock(Block.class); - when(blockWithTxWaitingForSignatures.getNumber()).thenReturn(0L); - when(blockStore.getBlockByHash(any())).thenReturn(blockWithTxWaitingForSignatures); + when(transactionInfoForTxWaitingForSignatures.getBlockHash()) + .thenReturn(blockHash.getBytes()); + when(blockWithTxWaitingForSignatures.getHash()) + .thenReturn(blockHash); + when(blockWithTxWaitingForSignatures.getNumber()) + .thenReturn(0L); + + when(receiptStore.getInMainChain(rskTxHash.getBytes(), blockStore)) + .thenReturn(Optional.of(transactionInfoForTxWaitingForSignatures)); + when(blockStore.getBlockByHash(blockHash.getBytes())) + .thenReturn(blockWithTxWaitingForSignatures); when(bestBlock.getNumber()).thenReturn(5_000L); } @@ -137,6 +149,8 @@ void start_whenFederationMemberNotPartOfDesiredFederation_shouldThrowException() BtcReleaseClient btcReleaseClient = new BtcReleaseClient( mock(Ethereum.class), + blockStore, + receiptStore, federatorSupport, powpegNodeSystemProperties, mock(NodeBlockProcessor.class) @@ -157,6 +171,7 @@ void if_start_not_called_rsk_blockchain_not_listened() { new BtcReleaseClient( ethereum, blockStore, + receiptStore, mock(FederatorSupport.class), powpegNodeSystemProperties, mock(NodeBlockProcessor.class) @@ -176,9 +191,9 @@ void when_start_called_rsk_blockchain_is_listened() { BtcReleaseClient btcReleaseClient = new BtcReleaseClient( ethereum, - federatorSupport, blockStore, - mock(FederatorSupport.class), + receiptStore, + federatorSupport, powpegNodeSystemProperties, mock(NodeBlockProcessor.class) ); @@ -207,9 +222,9 @@ void if_stop_called_with_just_one_federation_rsk_blockchain_is_still_listened() BtcReleaseClient btcReleaseClient = new BtcReleaseClient( ethereum, - federatorSupport, blockStore, - mock(FederatorSupport.class), + receiptStore, + federatorSupport, powpegNodeSystemProperties, mock(NodeBlockProcessor.class) ); @@ -241,9 +256,9 @@ void if_stop_called_with_federations_rsk_blockchain_is_not_listened() { BtcReleaseClient btcReleaseClient = new BtcReleaseClient( ethereum, - federatorSupport, blockStore, - mock(FederatorSupport.class), + receiptStore, + federatorSupport, powpegNodeSystemProperties, mock(NodeBlockProcessor.class) ); @@ -305,9 +320,9 @@ void processReleases_ok() throws Exception { BtcReleaseClient client = new BtcReleaseClient( mock(Ethereum.class), - federatorSupport, blockStore, - mock(FederatorSupport.class), + receiptStore, + federatorSupport, powpegNodeSystemProperties, mock(NodeBlockProcessor.class) ); @@ -438,6 +453,7 @@ void having_two_pegouts_signs_only_one() throws Exception { BtcReleaseClient btcReleaseClient = new BtcReleaseClient( ethereum, blockStore, + receiptStore, federatorSupport, powpegNodeSystemProperties, mock(NodeBlockProcessor.class) @@ -528,6 +544,7 @@ void onBestBlock_whenPegoutTxIsCached_shouldNotSignSamePegoutTxAgain() throws Ex BtcReleaseClient btcReleaseClient = new BtcReleaseClient( ethereum, blockStore, + receiptStore, federatorSupport, powpegNodeSystemProperties, mock(NodeBlockProcessor.class) @@ -633,6 +650,7 @@ void onBestBlock_whenPegoutTxIsCachedWithInvalidTimestamp_shouldSignSamePegoutTx BtcReleaseClient btcReleaseClient = new BtcReleaseClient( ethereum, blockStore, + receiptStore, federatorSupport, powpegNodeSystemProperties, mock(NodeBlockProcessor.class) @@ -745,6 +763,7 @@ void onBestBlock_whenOnlySvpSpendTxWaitingForSignaturesIsAvailable_shouldAddSign BtcReleaseClient btcReleaseClient = new BtcReleaseClient( ethereum, blockStore, + receiptStore, federatorSupport, powpegNodeSystemProperties, mock(NodeBlockProcessor.class) @@ -835,6 +854,7 @@ void onBestBlock_whenPegoutTxIsNotReadyToBeSigned_shouldNotAddSignature() throws BtcReleaseClient btcReleaseClient = new BtcReleaseClient( ethereum, blockStore, + receiptStore, federatorSupport, powpegNodeSystemProperties, mock(NodeBlockProcessor.class) @@ -898,6 +918,7 @@ void onBestBlock_return_when_node_is_syncing() throws BtcReleaseClientException BtcReleaseClient btcReleaseClient = new BtcReleaseClient( ethereum, blockStore, + receiptStore, federatorSupport, powpegNodeSystemProperties, nodeBlockProcessor @@ -949,6 +970,7 @@ void onBestBlock_return_when_pegout_is_disabled() throws BtcReleaseClientExcepti BtcReleaseClient btcReleaseClient = new BtcReleaseClient( ethereum, blockStore, + receiptStore, federatorSupport, powpegNodeSystemProperties, nodeBlockProcessor @@ -1000,6 +1022,7 @@ void onBlock_return_when_node_is_syncing() { BtcReleaseClient btcReleaseClient = new BtcReleaseClient( ethereum, blockStore, + receiptStore, federatorSupport, powpegNodeSystemProperties, nodeBlockProcessor @@ -1047,6 +1070,7 @@ void onBlock_return_when_pegout_is_disabled() { BtcReleaseClient btcReleaseClient = new BtcReleaseClient( ethereum, blockStore, + receiptStore, federatorSupport, powpegNodeSystemProperties, nodeBlockProcessor @@ -1165,9 +1189,9 @@ void validateTxCanBeSigned_federatorAlreadySigned() throws Exception { BtcReleaseClient client = new BtcReleaseClient( mock(Ethereum.class), - federatorSupport, blockStore, - mock(FederatorSupport.class), + receiptStore, + federatorSupport, powpegNodeSystemProperties, mock(NodeBlockProcessor.class) ); @@ -1211,6 +1235,7 @@ void validateTxCanBeSigned_federationCantSign() throws Exception { BtcReleaseClient client = new BtcReleaseClient( mock(Ethereum.class), blockStore, + receiptStore, mock(FederatorSupport.class), powpegNodeSystemProperties, mock(NodeBlockProcessor.class) @@ -1270,6 +1295,7 @@ void removeSignaturesFromTransaction() { BtcReleaseClient client = new BtcReleaseClient( mock(Ethereum.class), blockStore, + receiptStore, mock(FederatorSupport.class), powpegNodeSystemProperties, mock(NodeBlockProcessor.class) @@ -1357,9 +1383,9 @@ private void test_validateTxCanBeSigned( BtcReleaseClient client = new BtcReleaseClient( mock(Ethereum.class), - federatorSupport, blockStore, - mock(FederatorSupport.class), + receiptStore, + federatorSupport, powpegNodeSystemProperties, mock(NodeBlockProcessor.class) ); @@ -1392,6 +1418,7 @@ private void test_extractStandardRedeemScript( BtcReleaseClient client = new BtcReleaseClient( mock(Ethereum.class), blockStore, + receiptStore, mock(FederatorSupport.class), powpegNodeSystemProperties, mock(NodeBlockProcessor.class) @@ -1528,6 +1555,7 @@ private void testUsageOfStorageWhenSigning(boolean shouldHaveDataInFile) BtcReleaseClient btcReleaseClient = new BtcReleaseClient( ethereumImpl, blockStore, + receiptStore, federatorSupport, powpegNodeSystemProperties, nodeBlockProcessor @@ -1577,6 +1605,7 @@ private BtcReleaseClient createBtcClient() { return new BtcReleaseClient( mock(Ethereum.class), blockStore, + receiptStore, mock(FederatorSupport.class), powpegNodeSystemProperties, mock(NodeBlockProcessor.class)