use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.
the class BridgeUtilsTest method testIsValidPegInTx_value_between_old_and_new_after_iris.
@Test
public void testIsValidPegInTx_value_between_old_and_new_after_iris() {
// Tx sending btc between old and new value, it is a peg-in after iris
Context btcContext = new Context(networkParameters);
Federation federation = this.getGenesisFederationForTest(bridgeConstantsRegtest, btcContext);
when(activations.isActive(ConsensusRule.RSKIP219)).thenReturn(true);
BtcTransaction tx = new BtcTransaction(networkParameters);
// Get a value in between pre and post iris minimum
Coin minimumPegInValueBeforeIris = bridgeConstantsRegtest.getLegacyMinimumPeginTxValueInSatoshis();
Coin minimumPegInValueAfterIris = bridgeConstantsRegtest.getMinimumPeginTxValueInSatoshis();
Coin valueLock = minimumPegInValueAfterIris.plus((minimumPegInValueBeforeIris.subtract(minimumPegInValueAfterIris)).div(2));
assertTrue(valueLock.isGreaterThan(minimumPegInValueAfterIris));
assertTrue(valueLock.isLessThan(minimumPegInValueBeforeIris));
tx.addOutput(valueLock, federation.getAddress());
tx.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[] {}));
assertTrue(BridgeUtils.isValidPegInTx(tx, federation, btcContext, bridgeConstantsRegtest, activations));
}
use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.
the class BridgeUtilsTest method testIsValidPegInTx_sending_50_btc_after_iris.
@Test
public void testIsValidPegInTx_sending_50_btc_after_iris() {
// Tx sending 50 btc to the federation, is a peg-in tx
Context btcContext = new Context(networkParameters);
Federation federation = this.getGenesisFederationForTest(bridgeConstantsRegtest, btcContext);
when(activations.isActive(ConsensusRule.RSKIP219)).thenReturn(true);
BtcTransaction tx = new BtcTransaction(networkParameters);
tx.addOutput(Coin.FIFTY_COINS, federation.getAddress());
tx.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[] {}));
assertTrue(BridgeUtils.isValidPegInTx(tx, federation, btcContext, bridgeConstantsRegtest, activations));
}
use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.
the class BridgeUtilsTest method testIsValidPegInTx_hasChangeUtxoFromFastBridgeErpRetiredFederation_beforeRskip201_isPegin.
@Test
public void testIsValidPegInTx_hasChangeUtxoFromFastBridgeErpRetiredFederation_beforeRskip201_isPegin() {
Context btcContext = new Context(networkParameters);
Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation();
when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(false);
when(activations.isActive(ConsensusRule.RSKIP284)).thenReturn(true);
List<BtcECKey> retiredFederationKeys = Arrays.asList(BtcECKey.fromPrivate(Hex.decode("fa01")), BtcECKey.fromPrivate(Hex.decode("fa02")));
retiredFederationKeys.sort(BtcECKey.PUBKEY_COMPARATOR);
Federation retiredFederation = new Federation(FederationTestUtils.getFederationMembersWithBtcKeys(retiredFederationKeys), Instant.ofEpochMilli(1000L), 0L, networkParameters);
List<BtcECKey> erpFederationPublicKeys = Arrays.asList(BtcECKey.fromPrivate(Hex.decode("fa03")), BtcECKey.fromPrivate(Hex.decode("fa04")));
erpFederationPublicKeys.sort(BtcECKey.PUBKEY_COMPARATOR);
Federation erpFederation = new ErpFederation(FederationTestUtils.getFederationMembersWithBtcKeys(retiredFederationKeys), Instant.ofEpochMilli(1000L), 0L, networkParameters, erpFederationPublicKeys, 500L, activations);
// Create a tx from the retired fast bridge fed to the active fed
BtcTransaction tx = new BtcTransaction(networkParameters);
tx.addOutput(Coin.COIN, activeFederation.getAddress());
TransactionInput txInput = new TransactionInput(networkParameters, tx, new byte[0], new TransactionOutPoint(networkParameters, 0, Sha256Hash.ZERO_HASH));
tx.addInput(txInput);
Script fastBridgeErpRedeemScript = FastBridgeErpRedeemScriptParser.createFastBridgeErpRedeemScript(erpFederation.getRedeemScript(), PegTestUtils.createHash(2));
signWithNecessaryKeys(erpFederation, fastBridgeErpRedeemScript, retiredFederationKeys, txInput, tx);
assertTrue(BridgeUtils.isValidPegInTx(tx, Collections.singletonList(activeFederation), retiredFederation.getP2SHScript(), btcContext, bridgeConstantsRegtest, activations));
}
use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.
the class BridgeUtilsTest method testIsPegOutTx_invalidRedeemScript.
@Test
public void testIsPegOutTx_invalidRedeemScript() {
Federation federation = bridgeConstantsRegtest.getGenesisFederation();
Address randomAddress = PegTestUtils.createRandomBtcAddress();
Script invalidRedeemScript = ScriptBuilder.createRedeemScript(2, Arrays.asList(new BtcECKey(), new BtcECKey()));
BtcTransaction pegOutTx1 = new BtcTransaction(networkParameters);
pegOutTx1.addOutput(Coin.COIN, randomAddress);
TransactionInput pegOutInput1 = new TransactionInput(networkParameters, pegOutTx1, invalidRedeemScript.getProgram(), new TransactionOutPoint(networkParameters, 0, Sha256Hash.ZERO_HASH));
pegOutTx1.addInput(pegOutInput1);
assertFalse(BridgeUtils.isPegOutTx(pegOutTx1, Collections.singletonList(federation), activations));
}
use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.
the class FastBridgeCompatibleBtcWalletWithSingleScriptTest method findRedeemDataFromScriptHash_with_fastBridgeInformation_and_erp_federation.
@Test
public void findRedeemDataFromScriptHash_with_fastBridgeInformation_and_erp_federation() {
byte[] fastBridgeScriptHash = new byte[] { (byte) 0x22 };
FastBridgeFederationInformation fastBridgeFederationInformation = new FastBridgeFederationInformation(PegTestUtils.createHash3(2), erpFederation.getP2SHScript().getPubKeyHash(), fastBridgeScriptHash);
FastBridgeCompatibleBtcWalletWithSingleScript fastBridgeCompatibleBtcWalletWithSingleScript = new FastBridgeCompatibleBtcWalletWithSingleScript(mock(Context.class), erpFederationList, fastBridgeFederationInformation);
RedeemData redeemData = fastBridgeCompatibleBtcWalletWithSingleScript.findRedeemDataFromScriptHash(erpFederation.getP2SHScript().getPubKeyHash());
Script fastBridgeRedeemScript = FastBridgeErpRedeemScriptParser.createFastBridgeErpRedeemScript(erpFederation.getRedeemScript(), Sha256Hash.wrap(fastBridgeFederationInformation.getDerivationHash().getBytes()));
Assert.assertNotNull(redeemData);
Assert.assertEquals(fastBridgeRedeemScript, redeemData.redeemScript);
}
Aggregations