Skip to content

Commit

Permalink
fix: style code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlen committed Dec 18, 2024
1 parent c3770fe commit 568762c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 44 deletions.
6 changes: 1 addition & 5 deletions rskj-core/src/test/java/co/rsk/peg/BridgeSupportSvpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
70 changes: 34 additions & 36 deletions rskj-core/src/test/java/co/rsk/peg/RegisterBtcTransactionIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -93,42 +92,41 @@ 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<UTXO> 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();

// Assert
Optional<Long> 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<UTXO> 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
Expand All @@ -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()
);
}

Expand Down

0 comments on commit 568762c

Please sign in to comment.