Search in sources :

Example 61 with Script

use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.

the class PeginInstructionsProviderTest method buildPeginInstructions_v1_dataLengthSmallerThanExpected.

@Test(expected = PeginInstructionsException.class)
public void buildPeginInstructions_v1_dataLengthSmallerThanExpected() throws Exception {
    // Arrange
    int protocolVersion = 1;
    BtcTransaction btcTransaction = new BtcTransaction(params);
    Script opReturnScript = PegTestUtils.createOpReturnScriptForRskWithCustomPayload(protocolVersion, new byte[5]);
    btcTransaction.addOutput(Coin.ZERO, opReturnScript);
    // Act
    PeginInstructionsProvider peginInstructionsProvider = new PeginInstructionsProvider();
    peginInstructionsProvider.buildPeginInstructions(btcTransaction);
}
Also used : Script(co.rsk.bitcoinj.script.Script) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) Test(org.junit.Test)

Example 62 with Script

use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.

the class PeginInstructionsProviderTest method extractOpReturnData_twoOpReturnOutputsForRsk.

@Test(expected = PeginInstructionsException.class)
public void extractOpReturnData_twoOpReturnOutputsForRsk() throws PeginInstructionsException {
    // Arrange
    Script opReturnScript = PegTestUtils.createOpReturnScriptForRsk(1, new RskAddress(new byte[20]), Optional.empty());
    BtcTransaction btcTransaction = new BtcTransaction(params);
    btcTransaction.addOutput(Coin.ZERO, opReturnScript);
    btcTransaction.addOutput(Coin.ZERO, opReturnScript);
    // Act
    PeginInstructionsProvider.extractOpReturnData(btcTransaction);
}
Also used : Script(co.rsk.bitcoinj.script.Script) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) RskAddress(co.rsk.core.RskAddress) Test(org.junit.Test)

Example 63 with Script

use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.

the class PeginInstructionsProviderTest method buildPeginInstructions_invalidProtocolVersion.

@Test(expected = PeginInstructionsException.class)
public void buildPeginInstructions_invalidProtocolVersion() throws Exception {
    // Arrange
    int invalidProtocolVersion = 0;
    BtcTransaction btcTransaction = new BtcTransaction(params);
    Script opReturnScript = PegTestUtils.createOpReturnScriptForRsk(invalidProtocolVersion, new RskAddress(new byte[20]), Optional.empty());
    btcTransaction.addOutput(Coin.ZERO, opReturnScript);
    // Act
    PeginInstructionsProvider peginInstructionsProvider = new PeginInstructionsProvider();
    peginInstructionsProvider.buildPeginInstructions(btcTransaction);
}
Also used : Script(co.rsk.bitcoinj.script.Script) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) RskAddress(co.rsk.core.RskAddress) Test(org.junit.Test)

Example 64 with Script

use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.

the class BridgeUtilsTest method testIsValidPegInTx_hasChangeUtxoFromFastBridgeErpFederation_beforeRskip201_isPegin.

@Test
public void testIsValidPegInTx_hasChangeUtxoFromFastBridgeErpFederation_beforeRskip201_isPegin() {
    Context btcContext = new Context(networkParameters);
    when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(false);
    Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation();
    List<BtcECKey> erpFederationKeys = Arrays.asList(BtcECKey.fromPrivate(Hex.decode("fa01")), BtcECKey.fromPrivate(Hex.decode("fa02")));
    erpFederationKeys.sort(BtcECKey.PUBKEY_COMPARATOR);
    Federation erpFederation = new Federation(FederationTestUtils.getFederationMembersWithBtcKeys(erpFederationKeys), Instant.ofEpochMilli(1000L), 0L, networkParameters);
    Script fastBridgeErpRedeemScript = FastBridgeErpRedeemScriptParser.createFastBridgeErpRedeemScript(activeFederation.getRedeemScript(), erpFederation.getRedeemScript(), 500L, Sha256Hash.of(PegTestUtils.createHash(1).getBytes()));
    // Create a tx from the fast bridge erp fed to the active fed
    BtcTransaction tx = new BtcTransaction(networkParameters);
    tx.addOutput(Coin.COIN, activeFederation.getAddress());
    tx.addInput(Sha256Hash.ZERO_HASH, 0, fastBridgeErpRedeemScript);
    Assert.assertTrue(BridgeUtils.isValidPegInTx(tx, activeFederation, 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) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) Test(org.junit.Test)

Example 65 with Script

use of co.rsk.bitcoinj.script.Script in project rskj by rsksmart.

the class BridgeUtilsTest method testIsValidPegInTx_hasChangeUtxoFromFastBridgeFederation_afterRskip201_notPegin.

@Test
public void testIsValidPegInTx_hasChangeUtxoFromFastBridgeFederation_afterRskip201_notPegin() {
    Context btcContext = new Context(networkParameters);
    when(activations.isActive(ConsensusRule.RSKIP201)).thenReturn(true);
    Federation activeFederation = bridgeConstantsRegtest.getGenesisFederation();
    Script fastBridgeRedeemScript = FastBridgeRedeemScriptParser.createMultiSigFastBridgeRedeemScript(activeFederation.getRedeemScript(), Sha256Hash.of(PegTestUtils.createHash(1).getBytes()));
    // Create a tx from the fast bridge fed to the active fed
    BtcTransaction tx = new BtcTransaction(networkParameters);
    tx.addOutput(Coin.COIN, activeFederation.getAddress());
    tx.addInput(Sha256Hash.ZERO_HASH, 0, fastBridgeRedeemScript);
    Assert.assertFalse(BridgeUtils.isValidPegInTx(tx, activeFederation, 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)

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