From 568762cc78ea3b91cfec39927f4f34f782aadda2 Mon Sep 17 00:00:00 2001 From: Julian Len Date: Wed, 18 Dec 2024 12:07:29 -0300 Subject: [PATCH] fix: style code changes --- .../java/co/rsk/peg/BridgeSupportSvpTest.java | 6 +- .../co/rsk/peg/BridgeSupportTestUtil.java | 4 +- .../co/rsk/peg/RegisterBtcTransactionIT.java | 70 +++++++++---------- 3 files changed, 36 insertions(+), 44 deletions(-) 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 6acd217b8f..e273991e5a 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportSvpTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportSvpTest.java @@ -93,11 +93,7 @@ void setUp() { // rsk execution block long rskExecutionBlockNumber = 1000L; long rskExecutionBlockTimestamp = 10L; - BlockHeader blockHeader = new BlockHeaderBuilder(mock(ActivationConfig.class)) - .setNumber(rskExecutionBlockNumber) - .setTimestamp(rskExecutionBlockTimestamp) - .build(); - rskExecutionBlock = Block.createBlockFromHeader(blockHeader, true); + rskExecutionBlock = getRskExecutionBlock(rskExecutionBlockNumber, rskExecutionBlockTimestamp); Keccak256 rskTxHash = PegTestUtils.createHash3(1); rskTx = mock(Transaction.class); diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTestUtil.java b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTestUtil.java index d501cdbbe8..f4c04238db 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTestUtil.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTestUtil.java @@ -95,9 +95,7 @@ public static FederationStorageProvider createFederationStorageProvider(Reposito return new FederationStorageProviderImpl(bridgeStorageAccessor); } - public static Block getRskExecutionBlock() { - long rskExecutionBlockNumber = 1000L; - long rskExecutionBlockTimestamp = 10L; + public static Block getRskExecutionBlock(long rskExecutionBlockNumber, long rskExecutionBlockTimestamp) { BlockHeader blockHeader = new BlockHeaderBuilder(ActivationConfigsForTest.all()) .setNumber(rskExecutionBlockNumber) .setTimestamp(rskExecutionBlockTimestamp) diff --git a/rskj-core/src/test/java/co/rsk/peg/RegisterBtcTransactionIT.java b/rskj-core/src/test/java/co/rsk/peg/RegisterBtcTransactionIT.java index 857b99a3cf..dab40ce610 100644 --- a/rskj-core/src/test/java/co/rsk/peg/RegisterBtcTransactionIT.java +++ b/rskj-core/src/test/java/co/rsk/peg/RegisterBtcTransactionIT.java @@ -34,13 +34,15 @@ import java.util.*; class RegisterBtcTransactionIT { + public static final long RSK_EXECUTION_BLOCK_NUMBER = 1000L; + public static final long RSK_EXECUTION_BLOCK_TIMESTAMP = 10L; private final BridgeConstants bridgeConstants = BridgeMainNetConstants.getInstance(); private final NetworkParameters btcNetworkParams = bridgeConstants.getBtcParams(); private final BridgeSupportBuilder bridgeSupportBuilder = BridgeSupportBuilder.builder(); private final ActivationConfig.ForBlock activations = ActivationConfigsForTest.all().forBlock(0); private final Transaction rskTx = TransactionUtils.createTransaction(); private final Coin minimumPeginValue = bridgeConstants.getMinimumPeginTxValue(activations); - private final Block rskExecutionBlock = getRskExecutionBlock(); + private final Block rskExecutionBlock = getRskExecutionBlock(RSK_EXECUTION_BLOCK_NUMBER, RSK_EXECUTION_BLOCK_TIMESTAMP); private Repository repository; private FederationSupport federationSupport; private BridgeStorageProvider bridgeStorageProvider; @@ -60,20 +62,17 @@ void setUp() throws Exception{ StorageAccessor bridgeStorageAccessor = new BridgeStorageAccessorImpl(repository); FeePerKbStorageProvider feePerKbStorageProvider = new FeePerKbStorageProviderImpl(bridgeStorageAccessor); - FeePerKbSupport feePerKbSupport = new FeePerKbSupportImpl( - bridgeConstants.getFeePerKbConstants(), - feePerKbStorageProvider - ); + FeePerKbSupport feePerKbSupport = new FeePerKbSupportImpl(bridgeConstants.getFeePerKbConstants(), feePerKbStorageProvider); + FederationStorageProvider federationStorageProvider = new FederationStorageProviderImpl(bridgeStorageAccessor); Federation federation = P2shErpFederationBuilder.builder().build(); - FederationStorageProvider federationStorageProvider = createFederationStorageProvider(repository); federationStorageProvider.setNewFederation(federation); FederationConstants federationConstants = bridgeConstants.getFederationConstants(); federationSupport = FederationSupportBuilder.builder() - .withFederationConstants(federationConstants) - .withFederationStorageProvider(federationStorageProvider) - .withActivations(activations) - .build(); + .withFederationConstants(federationConstants) + .withFederationStorageProvider(federationStorageProvider) + .withActivations(activations) + .build(); bridgeStorageProvider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, btcNetworkParams, activations); BtcBlockStoreWithCache.Factory btcBlockStoreFactory = new RepositoryBtcBlockStoreWithCache.Factory(btcNetworkParams, 100, 100); @@ -93,29 +92,23 @@ void setUp() throws Exception{ recreateChainFromPmt(btcBlockStoreWithCache, chainHeight, pmtWithTransactions, btcBlockWithPmtHeight, btcNetworkParams); bridgeStorageProvider.save(); + bridgeSupport = bridgeSupportBuilder - .withBridgeConstants(bridgeConstants) - .withProvider(bridgeStorageProvider) - .withActivations(activations) - .withEventLogger(bridgeEventLogger) - .withFederationSupport(federationSupport) - .withFeePerKbSupport(feePerKbSupport) - .withExecutionBlock(rskExecutionBlock) - .withBtcBlockStoreFactory(btcBlockStoreFactory) - .withRepository(repository) - .withBtcLockSenderProvider(btcLockSenderProvider) - .build(); + .withBridgeConstants(bridgeConstants) + .withProvider(bridgeStorageProvider) + .withActivations(activations) + .withEventLogger(bridgeEventLogger) + .withFederationSupport(federationSupport) + .withFeePerKbSupport(feePerKbSupport) + .withExecutionBlock(rskExecutionBlock) + .withBtcBlockStoreFactory(btcBlockStoreFactory) + .withRepository(repository) + .withBtcLockSenderProvider(btcLockSenderProvider) + .build(); } @Test void registerBtcTransaction_forALegacyBtcTransaction_shouldRegisterTheNewUtxoAndTransferTheRbtcBalance() throws Exception { - // Arrange - TransactionOutput output = bitcoinTransaction.getOutput(0); - List expectedFederationUtxos = Collections.singletonList(utxoOf(bitcoinTransaction, output)); - - co.rsk.core.Coin receiverBalance = repository.getBalance(rskReceiver); - co.rsk.core.Coin expectedReceiverBalance = receiverBalance.add(co.rsk.core.Coin.fromBitcoin(minimumPeginValue)); - // Act bridgeSupport.registerBtcTransaction(rskTx, bitcoinTransaction.bitcoinSerialize(), btcBlockWithPmtHeight, pmtWithTransactions.bitcoinSerialize()); bridgeSupport.save(); @@ -123,12 +116,17 @@ void registerBtcTransaction_forALegacyBtcTransaction_shouldRegisterTheNewUtxoAnd // Assert Optional heightIfBtcTxHashIsAlreadyProcessed = bridgeStorageProvider.getHeightIfBtcTxhashIsAlreadyProcessed(bitcoinTransaction.getHash()); assertTrue(heightIfBtcTxHashIsAlreadyProcessed.isPresent()); - assertEquals(rskExecutionBlock.getNumber(), heightIfBtcTxHashIsAlreadyProcessed.get()); + assertEquals(RSK_EXECUTION_BLOCK_NUMBER, heightIfBtcTxHashIsAlreadyProcessed.get()); + + int outputIndex = 0; + TransactionOutput output = bitcoinTransaction.getOutput(outputIndex); + List expectedFederationUtxos = Collections.singletonList(utxoOf(bitcoinTransaction, output)); assertEquals(expectedFederationUtxos, federationSupport.getActiveFederationBtcUTXOs()); + + co.rsk.core.Coin expectedReceiverBalance = co.rsk.core.Coin.fromBitcoin(output.getValue()); assertEquals(expectedReceiverBalance, repository.getBalance(rskReceiver)); assertLogPegInBtc(); - } @Test @@ -151,12 +149,12 @@ void registerBtc_forARepeatedLegacyBtcTransaction_shouldNotPerformAnyChange() th private static UTXO utxoOf(BtcTransaction bitcoinTransaction, TransactionOutput output) { return new UTXO( - bitcoinTransaction.getHash(), - output.getIndex(), - output.getValue(), - 0, - bitcoinTransaction.isCoinBase(), - output.getScriptPubKey() + bitcoinTransaction.getHash(), + output.getIndex(), + output.getValue(), + 0, + bitcoinTransaction.isCoinBase(), + output.getScriptPubKey() ); }