Search in sources :

Example 71 with Script

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));
}
Also used : Context(co.rsk.bitcoinj.core.Context) Coin(co.rsk.bitcoinj.core.Coin) Script(co.rsk.bitcoinj.script.Script) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) Test(org.junit.Test)

Example 72 with Script

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));
}
Also used : Context(co.rsk.bitcoinj.core.Context) Script(co.rsk.bitcoinj.script.Script) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) Test(org.junit.Test)

Example 73 with Script

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));
}
Also used : Context(co.rsk.bitcoinj.core.Context) Script(co.rsk.bitcoinj.script.Script) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) BtcECKey(co.rsk.bitcoinj.core.BtcECKey) TransactionInput(co.rsk.bitcoinj.core.TransactionInput) TransactionOutPoint(co.rsk.bitcoinj.core.TransactionOutPoint) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) Test(org.junit.Test)

Example 74 with Script

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));
}
Also used : Script(co.rsk.bitcoinj.script.Script) Address(co.rsk.bitcoinj.core.Address) RskAddress(co.rsk.core.RskAddress) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) BtcECKey(co.rsk.bitcoinj.core.BtcECKey) TransactionInput(co.rsk.bitcoinj.core.TransactionInput) TransactionOutPoint(co.rsk.bitcoinj.core.TransactionOutPoint) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) Test(org.junit.Test)

Example 75 with Script

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);
}
Also used : Context(co.rsk.bitcoinj.core.Context) Script(co.rsk.bitcoinj.script.Script) RedeemData(co.rsk.bitcoinj.wallet.RedeemData) FastBridgeFederationInformation(co.rsk.peg.fastbridge.FastBridgeFederationInformation) Test(org.junit.Test)

Aggregations

Script (co.rsk.bitcoinj.script.Script)123 Test (org.junit.Test)91 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)60 RskAddress (co.rsk.core.RskAddress)47 BtcTransaction (co.rsk.bitcoinj.core.BtcTransaction)40 Repository (org.ethereum.core.Repository)34 MutableRepository (org.ethereum.db.MutableRepository)33 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)29 BtcECKey (co.rsk.bitcoinj.core.BtcECKey)26 Block (org.ethereum.core.Block)24 Context (co.rsk.bitcoinj.core.Context)21 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)20 PeginInstructionsProvider (co.rsk.peg.pegininstructions.PeginInstructionsProvider)20 Address (co.rsk.bitcoinj.core.Address)17 TransactionOutPoint (co.rsk.bitcoinj.core.TransactionOutPoint)17 PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation (co.rsk.peg.PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation)17 PegTestUtils.createBaseRedeemScriptThatSpendsFromTheFederation (co.rsk.peg.PegTestUtils.createBaseRedeemScriptThatSpendsFromTheFederation)17 BtcLockSenderProvider (co.rsk.peg.btcLockSender.BtcLockSenderProvider)17 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)17 InternalTransaction (org.ethereum.vm.program.InternalTransaction)17