Skip to content

Commit

Permalink
Merge pull request #2195 from rsksmart/adds-more-tests-for-evaluatePegin
Browse files Browse the repository at this point in the history
Adds tests to evaluatePegin for pegout and migration
  • Loading branch information
marcos-iov authored Dec 1, 2023
2 parents 2e1f9e5 + 71e699a commit 1cfdc9c
Showing 1 changed file with 60 additions and 6 deletions.
66 changes: 60 additions & 6 deletions rskj-core/src/test/java/co/rsk/peg/PegUtilsEvaluatePeginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import co.rsk.bitcoinj.core.Address;
import co.rsk.bitcoinj.core.BtcECKey;
import co.rsk.bitcoinj.core.BtcTransaction;
import co.rsk.bitcoinj.core.Coin;
import co.rsk.bitcoinj.core.Context;
import co.rsk.bitcoinj.core.NetworkParameters;
import co.rsk.bitcoinj.core.*;
import co.rsk.bitcoinj.script.ScriptBuilder;
import co.rsk.bitcoinj.wallet.Wallet;
import co.rsk.config.BridgeConstants;
import co.rsk.config.BridgeMainNetConstants;
Expand Down Expand Up @@ -239,4 +235,62 @@ void evaluatePegin_validPeginInformationWithInvalidProtocolVersion_throwsExcepti

assertEquals(expectedErrorMessage, thrownException.getMessage());
}

@Test
void evaluatePegin_pegout_peginProcessActionCanBeRegistered() {
PeginInformation peginInformation = mock(PeginInformation.class);
when(peginInformation.getProtocolVersion()).thenReturn(1);

BtcTransaction btcTx = new BtcTransaction(networkParameters);

Address randomAddress = BitcoinTestUtils.createP2PKHAddress(networkParameters, "add1");

btcTx.addInput(
BitcoinTestUtils.createHash(1),
0,
ScriptBuilder.createP2SHMultiSigInputScript(null, activeFederation.getRedeemScript())
); // Fed spending utxo

btcTx.addOutput(minimumPegInTxValue, randomAddress); // Output to random address
btcTx.addOutput(minimumPegInTxValue, activeFederation.getAddress()); // "change" output to fed

PeginEvaluationResult peginEvaluationResult = PegUtils.evaluatePegin(
btcTx,
peginInformation,
minimumPegInTxValue,
activeFedWallet,
activations
);

assertEquals(PeginProcessAction.CAN_BE_REGISTERED, peginEvaluationResult.getPeginProcessAction());
}

@Test
void evaluatePegin_migration_peginProcessActionCanBeRegistered() {
PeginInformation peginInformation = mock(PeginInformation.class);
when(peginInformation.getProtocolVersion()).thenReturn(1);

BtcTransaction btcTx = new BtcTransaction(networkParameters);

Address randomAddress = BitcoinTestUtils.createP2PKHAddress(networkParameters, "add1");

btcTx.addInput(
BitcoinTestUtils.createHash(1),
0,
ScriptBuilder.createP2SHMultiSigInputScript(null, activeFederation.getRedeemScript())
); // Fed spending utxo

btcTx.addOutput(minimumPegInTxValue, activeFederation.getAddress());

PeginEvaluationResult peginEvaluationResult = PegUtils.evaluatePegin(
btcTx,
peginInformation,
minimumPegInTxValue,
activeFedWallet,
activations
);

assertEquals(PeginProcessAction.CAN_BE_REGISTERED, peginEvaluationResult.getPeginProcessAction());
}

}

0 comments on commit 1cfdc9c

Please sign in to comment.