From b751f1c7435735f27443f7e23cd1a0dfadafdb46 Mon Sep 17 00:00:00 2001 From: Julian Len Date: Tue, 17 Dec 2024 15:13:58 -0300 Subject: [PATCH] fix: deleted boilerplate code like getters --- .../co/rsk/peg/RegisterBtcTransactionIT.java | 52 +++++++------------ 1 file changed, 20 insertions(+), 32 deletions(-) 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 778e3d1f6a..0017b760bb 100644 --- a/rskj-core/src/test/java/co/rsk/peg/RegisterBtcTransactionIT.java +++ b/rskj-core/src/test/java/co/rsk/peg/RegisterBtcTransactionIT.java @@ -59,10 +59,17 @@ void setUp() throws Exception{ track = repository.startTracking(); BtcLockSenderProvider btcLockSenderProvider = new BtcLockSenderProvider(); - FeePerKbSupport feePerKbSupport = getFeePerKbSupport(repository, bridgeConstants); + StorageAccessor bridgeStorageAccessor = new BridgeStorageAccessorImpl(repository); + + FeePerKbStorageProvider feePerKbStorageProvider = new FeePerKbStorageProviderImpl(bridgeStorageAccessor); + FeePerKbSupport feePerKbSupport = new FeePerKbSupportImpl( + bridgeConstants.getFeePerKbConstants(), + feePerKbStorageProvider + ); Federation federation = P2shErpFederationBuilder.builder().build(); - FederationStorageProvider federationStorageProvider = getFederationStorageProvider(track, federation); + FederationStorageProvider federationStorageProvider = createFederationStorageProvider(track); + federationStorageProvider.setNewFederation(federation); FederationConstants federationConstants = bridgeConstants.getFederationConstants(); federationSupport = FederationSupportBuilder.builder() .withFederationConstants(federationConstants) @@ -75,7 +82,8 @@ void setUp() throws Exception{ BtcBlockStoreWithCache btcBlockStoreWithCache = btcBlockStoreFactory.newInstance(track, bridgeConstants, bridgeStorageProvider, activations); BtcECKey btcPublicKey = BitcoinTestUtils.getBtcEcKeyFromSeed("seed"); - rskReceiver = getRskReceiver(btcPublicKey); + ECKey ecKey = ECKey.fromPublicOnly(btcPublicKey.getPubKey()); + rskReceiver = new RskAddress(ecKey.getAddress()); bitcoinTransaction = createPegInTransaction(federationSupport.getActiveFederation().getAddress(), minimumPeginValue, btcPublicKey); pmtWithTransactions = createValidPmtForTransactions(List.of(bitcoinTransaction.getHash()), bridgeConstants.getBtcParams()); @@ -110,7 +118,9 @@ void whenRegisterALegacyBtcTransaction_shouldRegisterTheNewUtxoAndTransferTheRbt co.rsk.core.Coin expectedReceiverBalance = receiverBalance.add(co.rsk.core.Coin.fromBitcoin(minimumPeginValue)); // Act - registerBtcTransactionAndCommit(); + bridgeSupport.registerBtcTransaction(rskTx, bitcoinTransaction.bitcoinSerialize(), btcBlockWithPmtHeight, pmtWithTransactions.bitcoinSerialize()); + bridgeSupport.save(); + track.commit(); // Assert Optional heightIfBtcTxHashIsAlreadyProcessed = bridgeStorageProvider.getHeightIfBtcTxhashIsAlreadyProcessed(bitcoinTransaction.getHash()); @@ -126,25 +136,23 @@ void whenRegisterALegacyBtcTransaction_shouldRegisterTheNewUtxoAndTransferTheRbt @Test void whenRegisterARepeatedLegacyBtcTransaction_shouldNotPerformAnyChange() throws Exception { // Arrange - registerBtcTransactionAndCommit(); + bridgeSupport.registerBtcTransaction(rskTx, bitcoinTransaction.bitcoinSerialize(), btcBlockWithPmtHeight, pmtWithTransactions.bitcoinSerialize()); + bridgeSupport.save(); + track.commit(); co.rsk.core.Coin expectedReceiverBalance = track.getBalance(rskReceiver); List expectedFederationUTXOs = federationSupport.getActiveFederationBtcUTXOs(); // Act - registerBtcTransactionAndCommit(); + bridgeSupport.registerBtcTransaction(rskTx, bitcoinTransaction.bitcoinSerialize(), btcBlockWithPmtHeight, pmtWithTransactions.bitcoinSerialize()); + bridgeSupport.save(); + track.commit(); // Assert assertEquals(expectedFederationUTXOs, federationSupport.getActiveFederationBtcUTXOs()); assertEquals(expectedReceiverBalance, repository.getBalance(rskReceiver)); } - private void registerBtcTransactionAndCommit() throws Exception { - bridgeSupport.registerBtcTransaction(rskTx, bitcoinTransaction.bitcoinSerialize(), btcBlockWithPmtHeight, pmtWithTransactions.bitcoinSerialize()); - bridgeSupport.save(); - track.commit(); - } - private static UTXO utxoOf(BtcTransaction bitcoinTransaction, TransactionOutput output) { return new UTXO( bitcoinTransaction.getHash(), @@ -156,26 +164,6 @@ private static UTXO utxoOf(BtcTransaction bitcoinTransaction, TransactionOutput ); } - private RskAddress getRskReceiver(BtcECKey btcPublicKey) { - ECKey ecKey = ECKey.fromPublicOnly(btcPublicKey.getPubKey()); - return new RskAddress(ecKey.getAddress()); - } - - private FederationStorageProvider getFederationStorageProvider(Repository track, Federation federation) { - FederationStorageProvider federationStorageProvider = createFederationStorageProvider(track); - federationStorageProvider.setNewFederation(federation); - return federationStorageProvider; - } - - private static FeePerKbSupport getFeePerKbSupport(Repository repository, BridgeConstants bridgeConstants) { - StorageAccessor bridgeStorageAccessor = new BridgeStorageAccessorImpl(repository); - FeePerKbStorageProvider feePerKbStorageProvider = new FeePerKbStorageProviderImpl(bridgeStorageAccessor); - return new FeePerKbSupportImpl( - bridgeConstants.getFeePerKbConstants(), - feePerKbStorageProvider - ); - } - private BtcTransaction createPegInTransaction(Address federationAddress, Coin coin, BtcECKey pubKey) { BtcTransaction btcTx = new BtcTransaction(btcParams); btcTx.addInput(BitcoinTestUtils.createHash(0), 0, ScriptBuilder.createInputScript(null, pubKey));