Search in sources :

Example 56 with Script

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

the class PeginInstructionsProviderTest method extractOpReturnData_oneOpReturnForRskWithValue.

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

Example 57 with Script

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

the class PeginInstructionsProviderTest method extractOpReturnData_oneOpReturnForRsk.

@Test
public void extractOpReturnData_oneOpReturnForRsk() 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);
    // Act
    byte[] data = PeginInstructionsProvider.extractOpReturnData(btcTransaction);
    // Assert
    Assert.assertArrayEquals(opReturnScript.getChunks().get(1).data, data);
}
Also used : Script(co.rsk.bitcoinj.script.Script) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) RskAddress(co.rsk.core.RskAddress) Test(org.junit.Test)

Example 58 with Script

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

the class PeginInstructionsProviderTest method buildPeginInstructions_nullOpReturnData.

@Test
public void buildPeginInstructions_nullOpReturnData() throws Exception {
    // Arrange
    BtcTransaction btcTransaction = new BtcTransaction(params);
    // Add OP_RETURN output with empty data
    btcTransaction.addOutput(Coin.ZERO, new Script(new byte[] { ScriptOpCodes.OP_RETURN }));
    // Act
    PeginInstructionsProvider peginInstructionsProvider = new PeginInstructionsProvider();
    Optional<PeginInstructions> peginInstructionsOptional = peginInstructionsProvider.buildPeginInstructions(btcTransaction);
    // Assert
    Assert.assertFalse(peginInstructionsOptional.isPresent());
}
Also used : Script(co.rsk.bitcoinj.script.Script) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) Test(org.junit.Test)

Example 59 with Script

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

the class PeginInstructionsProviderTest method buildPeginInstructions_v1_dataLengthDifferentThanSupported.

@Test(expected = PeginInstructionsParseException.class)
public void buildPeginInstructions_v1_dataLengthDifferentThanSupported() throws Exception {
    // Arrange
    int protocolVersion = 1;
    BtcTransaction btcTransaction = new BtcTransaction(params);
    Script opReturnScript = PegTestUtils.createOpReturnScriptForRskWithCustomPayload(protocolVersion, new byte[30]);
    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 60 with Script

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

the class PeginInstructionsProviderTest method extractOpReturnData_noOpReturnForRsk.

@Test(expected = NoOpReturnException.class)
public void extractOpReturnData_noOpReturnForRsk() throws PeginInstructionsException {
    // Arrange
    Script opReturnScript = ScriptBuilder.createOpReturnScript("some-payload".getBytes());
    BtcTransaction btcTransaction = new BtcTransaction(params);
    btcTransaction.addOutput(Coin.ZERO, opReturnScript);
    // Act
    PeginInstructionsProvider.extractOpReturnData(btcTransaction);
}
Also used : Script(co.rsk.bitcoinj.script.Script) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) 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