Skip to content

Commit

Permalink
feat(btcreleaseclient): add confirmation diff logic using the receipt…
Browse files Browse the repository at this point in the history
… store for unit tests
  • Loading branch information
apancorb committed Nov 1, 2024
1 parent 3842389 commit b04c2f2
Showing 1 changed file with 44 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}

Expand All @@ -137,6 +149,8 @@ void start_whenFederationMemberNotPartOfDesiredFederation_shouldThrowException()

BtcReleaseClient btcReleaseClient = new BtcReleaseClient(
mock(Ethereum.class),
blockStore,
receiptStore,
federatorSupport,
powpegNodeSystemProperties,
mock(NodeBlockProcessor.class)
Expand All @@ -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)
Expand All @@ -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)
);
Expand Down Expand Up @@ -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)
);
Expand Down Expand Up @@ -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)
);
Expand Down Expand Up @@ -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)
);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -528,6 +544,7 @@ void onBestBlock_whenPegoutTxIsCached_shouldNotSignSamePegoutTxAgain() throws Ex
BtcReleaseClient btcReleaseClient = new BtcReleaseClient(
ethereum,
blockStore,
receiptStore,
federatorSupport,
powpegNodeSystemProperties,
mock(NodeBlockProcessor.class)
Expand Down Expand Up @@ -633,6 +650,7 @@ void onBestBlock_whenPegoutTxIsCachedWithInvalidTimestamp_shouldSignSamePegoutTx
BtcReleaseClient btcReleaseClient = new BtcReleaseClient(
ethereum,
blockStore,
receiptStore,
federatorSupport,
powpegNodeSystemProperties,
mock(NodeBlockProcessor.class)
Expand Down Expand Up @@ -745,6 +763,7 @@ void onBestBlock_whenOnlySvpSpendTxWaitingForSignaturesIsAvailable_shouldAddSign
BtcReleaseClient btcReleaseClient = new BtcReleaseClient(
ethereum,
blockStore,
receiptStore,
federatorSupport,
powpegNodeSystemProperties,
mock(NodeBlockProcessor.class)
Expand Down Expand Up @@ -835,6 +854,7 @@ void onBestBlock_whenPegoutTxIsNotReadyToBeSigned_shouldNotAddSignature() throws
BtcReleaseClient btcReleaseClient = new BtcReleaseClient(
ethereum,
blockStore,
receiptStore,
federatorSupport,
powpegNodeSystemProperties,
mock(NodeBlockProcessor.class)
Expand Down Expand Up @@ -898,6 +918,7 @@ void onBestBlock_return_when_node_is_syncing() throws BtcReleaseClientException
BtcReleaseClient btcReleaseClient = new BtcReleaseClient(
ethereum,
blockStore,
receiptStore,
federatorSupport,
powpegNodeSystemProperties,
nodeBlockProcessor
Expand Down Expand Up @@ -949,6 +970,7 @@ void onBestBlock_return_when_pegout_is_disabled() throws BtcReleaseClientExcepti
BtcReleaseClient btcReleaseClient = new BtcReleaseClient(
ethereum,
blockStore,
receiptStore,
federatorSupport,
powpegNodeSystemProperties,
nodeBlockProcessor
Expand Down Expand Up @@ -1000,6 +1022,7 @@ void onBlock_return_when_node_is_syncing() {
BtcReleaseClient btcReleaseClient = new BtcReleaseClient(
ethereum,
blockStore,
receiptStore,
federatorSupport,
powpegNodeSystemProperties,
nodeBlockProcessor
Expand Down Expand Up @@ -1047,6 +1070,7 @@ void onBlock_return_when_pegout_is_disabled() {
BtcReleaseClient btcReleaseClient = new BtcReleaseClient(
ethereum,
blockStore,
receiptStore,
federatorSupport,
powpegNodeSystemProperties,
nodeBlockProcessor
Expand Down Expand Up @@ -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)
);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1270,6 +1295,7 @@ void removeSignaturesFromTransaction() {
BtcReleaseClient client = new BtcReleaseClient(
mock(Ethereum.class),
blockStore,
receiptStore,
mock(FederatorSupport.class),
powpegNodeSystemProperties,
mock(NodeBlockProcessor.class)
Expand Down Expand Up @@ -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)
);
Expand Down Expand Up @@ -1392,6 +1418,7 @@ private void test_extractStandardRedeemScript(
BtcReleaseClient client = new BtcReleaseClient(
mock(Ethereum.class),
blockStore,
receiptStore,
mock(FederatorSupport.class),
powpegNodeSystemProperties,
mock(NodeBlockProcessor.class)
Expand Down Expand Up @@ -1528,6 +1555,7 @@ private void testUsageOfStorageWhenSigning(boolean shouldHaveDataInFile)
BtcReleaseClient btcReleaseClient = new BtcReleaseClient(
ethereumImpl,
blockStore,
receiptStore,
federatorSupport,
powpegNodeSystemProperties,
nodeBlockProcessor
Expand Down Expand Up @@ -1577,6 +1605,7 @@ private BtcReleaseClient createBtcClient() {
return new BtcReleaseClient(
mock(Ethereum.class),
blockStore,
receiptStore,
mock(FederatorSupport.class),
powpegNodeSystemProperties,
mock(NodeBlockProcessor.class)
Expand Down

0 comments on commit b04c2f2

Please sign in to comment.