Search in sources :

Example 6 with FastBridgeFederationInformation

use of co.rsk.peg.fastbridge.FastBridgeFederationInformation in project rskj by rsksmart.

the class BridgeSerializationUtilsTest method deserializeFastBridgeFederationInformation_ok.

@Test
public void deserializeFastBridgeFederationInformation_ok() {
    byte[][] rlpElements = new byte[2][];
    rlpElements[0] = RLP.encodeElement(Sha256Hash.wrap("0000000000000000000000000000000000000000000000000000000000000002").getBytes());
    rlpElements[1] = RLP.encodeElement(new byte[] { (byte) 0x22 });
    FastBridgeFederationInformation result = BridgeSerializationUtils.deserializeFastBridgeFederationInformation(RLP.encodeList(rlpElements), new byte[] { (byte) 0x23 });
    Assert.assertNotNull(result);
    Assert.assertArrayEquals(Sha256Hash.wrap("0000000000000000000000000000000000000000000000000000000000000002").getBytes(), result.getDerivationHash().getBytes());
    Assert.assertArrayEquals(new byte[] { (byte) 0x22 }, result.getFederationRedeemScriptHash());
    Assert.assertArrayEquals(new byte[] { (byte) 0x23 }, result.getFastBridgeFederationRedeemScriptHash());
}
Also used : FastBridgeFederationInformation(co.rsk.peg.fastbridge.FastBridgeFederationInformation) Test(org.junit.Test)

Example 7 with FastBridgeFederationInformation

use of co.rsk.peg.fastbridge.FastBridgeFederationInformation in project rskj by rsksmart.

the class FastBridgeCompatibleBtcWalletWithStorageTest method findRedeemDataFromScriptHash_with_fastBridgeInformation_in_storage.

@Test
public void findRedeemDataFromScriptHash_with_fastBridgeInformation_in_storage() {
    BridgeStorageProvider provider = mock(BridgeStorageProvider.class);
    Keccak256 derivationArgumentsHash = PegTestUtils.createHash3(1);
    Script fastBridgeRedeemScript = FastBridgeRedeemScriptParser.createMultiSigFastBridgeRedeemScript(federation.getRedeemScript(), Sha256Hash.wrap(derivationArgumentsHash.getBytes()));
    Script p2SHOutputScript = ScriptBuilder.createP2SHOutputScript(fastBridgeRedeemScript);
    byte[] fastBridgeFederationP2SH = p2SHOutputScript.getPubKeyHash();
    FastBridgeFederationInformation fastBridgeFederationInformation = new FastBridgeFederationInformation(derivationArgumentsHash, federation.getP2SHScript().getPubKeyHash(), fastBridgeFederationP2SH);
    when(provider.getFastBridgeFederationInformation(fastBridgeFederationP2SH)).thenReturn(Optional.of(fastBridgeFederationInformation));
    FastBridgeCompatibleBtcWalletWithStorage fastBridgeCompatibleBtcWalletWithStorage = new FastBridgeCompatibleBtcWalletWithStorage(mock(Context.class), federationList, provider);
    RedeemData redeemData = fastBridgeCompatibleBtcWalletWithStorage.findRedeemDataFromScriptHash(fastBridgeFederationP2SH);
    Assert.assertNotNull(redeemData);
    Assert.assertEquals(fastBridgeRedeemScript, redeemData.redeemScript);
}
Also used : Context(co.rsk.bitcoinj.core.Context) Script(co.rsk.bitcoinj.script.Script) Keccak256(co.rsk.crypto.Keccak256) RedeemData(co.rsk.bitcoinj.wallet.RedeemData) FastBridgeFederationInformation(co.rsk.peg.fastbridge.FastBridgeFederationInformation) Test(org.junit.Test)

Example 8 with FastBridgeFederationInformation

use of co.rsk.peg.fastbridge.FastBridgeFederationInformation in project rskj by rsksmart.

the class FastBridgeCompatibleBtcWalletWithSingleScriptTest method findRedeemDataFromScriptHash_with_fastBridgeInformation.

@Test
public void findRedeemDataFromScriptHash_with_fastBridgeInformation() {
    byte[] fastBridgeScriptHash = new byte[] { (byte) 0x22 };
    FastBridgeFederationInformation fastBridgeFederationInformation = new FastBridgeFederationInformation(PegTestUtils.createHash3(2), federation.getP2SHScript().getPubKeyHash(), fastBridgeScriptHash);
    FastBridgeCompatibleBtcWalletWithSingleScript fastBridgeCompatibleBtcWalletWithSingleScript = new FastBridgeCompatibleBtcWalletWithSingleScript(mock(Context.class), federationList, fastBridgeFederationInformation);
    RedeemData redeemData = fastBridgeCompatibleBtcWalletWithSingleScript.findRedeemDataFromScriptHash(federation.getP2SHScript().getPubKeyHash());
    Script fastBridgeRedeemScript = FastBridgeRedeemScriptParser.createMultiSigFastBridgeRedeemScript(federation.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)

Example 9 with FastBridgeFederationInformation

use of co.rsk.peg.fastbridge.FastBridgeFederationInformation in project rskj by rsksmart.

the class FastBridgeCompatibleBtcWalletWithSingleScriptTest method findRedeemDataFromScriptHash_null_destination_federation.

@Test
public void findRedeemDataFromScriptHash_null_destination_federation() {
    FastBridgeFederationInformation fastBridgeFederationInformation = new FastBridgeFederationInformation(null, new byte[0], new byte[0]);
    FastBridgeCompatibleBtcWalletWithSingleScript fastBridgeCompatibleBtcWalletWithSingleScript = new FastBridgeCompatibleBtcWalletWithSingleScript(mock(Context.class), federationList, fastBridgeFederationInformation);
    Assert.assertNull(fastBridgeCompatibleBtcWalletWithSingleScript.findRedeemDataFromScriptHash(federation.getP2SHScript().getPubKeyHash()));
}
Also used : Context(co.rsk.bitcoinj.core.Context) FastBridgeFederationInformation(co.rsk.peg.fastbridge.FastBridgeFederationInformation) Test(org.junit.Test)

Example 10 with FastBridgeFederationInformation

use of co.rsk.peg.fastbridge.FastBridgeFederationInformation in project rskj by rsksmart.

the class BridgeSupportTest method getFastBridgeWallet_ok.

@Test
public void getFastBridgeWallet_ok() {
    ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class);
    when(activations.isActive(ConsensusRule.RSKIP176)).thenReturn(true);
    Context btcContext = mock(Context.class);
    when(btcContext.getParams()).thenReturn(bridgeConstants.getBtcParams());
    BridgeSupport bridgeSupport = new BridgeSupport(bridgeConstants, mock(BridgeStorageProvider.class), mock(BridgeEventLogger.class), new BtcLockSenderProvider(), new PeginInstructionsProvider(), mock(Repository.class), mock(Block.class), btcContext, mock(FederationSupport.class), mock(BtcBlockStoreWithCache.Factory.class), activations);
    Federation fed = bridgeConstants.getGenesisFederation();
    Keccak256 derivationHash = PegTestUtils.createHash3(1);
    Script fastBridgeRedeemScript = FastBridgeRedeemScriptParser.createMultiSigFastBridgeRedeemScript(fed.getRedeemScript(), Sha256Hash.wrap(derivationHash.getBytes()));
    Script fastBridgeP2SH = ScriptBuilder.createP2SHOutputScript(fastBridgeRedeemScript);
    FastBridgeFederationInformation fastBridgeFederationInformation = new FastBridgeFederationInformation(derivationHash, fed.getP2SHScript().getPubKeyHash(), fastBridgeP2SH.getPubKeyHash());
    BtcTransaction tx = new BtcTransaction(bridgeConstants.getBtcParams());
    tx.addOutput(Coin.COIN, fastBridgeFederationInformation.getFastBridgeFederationAddress(bridgeConstants.getBtcParams()));
    List<UTXO> utxoList = new ArrayList<>();
    UTXO utxo = new UTXO(tx.getHash(), 0, Coin.COIN, 0, false, fastBridgeP2SH);
    utxoList.add(utxo);
    Wallet obtainedWallet = bridgeSupport.getFastBridgeWallet(btcContext, utxoList, fastBridgeFederationInformation);
    Assert.assertEquals(Coin.COIN, obtainedWallet.getBalance());
}
Also used : Script(co.rsk.bitcoinj.script.Script) PeginInstructionsProvider(co.rsk.peg.pegininstructions.PeginInstructionsProvider) Wallet(co.rsk.bitcoinj.wallet.Wallet) Keccak256(co.rsk.crypto.Keccak256) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) BtcLockSenderProvider(co.rsk.peg.btcLockSender.BtcLockSenderProvider) Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation(co.rsk.peg.PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation) PegTestUtils.createBaseRedeemScriptThatSpendsFromTheFederation(co.rsk.peg.PegTestUtils.createBaseRedeemScriptThatSpendsFromTheFederation) Block(org.ethereum.core.Block) FastBridgeFederationInformation(co.rsk.peg.fastbridge.FastBridgeFederationInformation) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) Test(org.junit.Test)

Aggregations

FastBridgeFederationInformation (co.rsk.peg.fastbridge.FastBridgeFederationInformation)26 Test (org.junit.Test)22 Keccak256 (co.rsk.crypto.Keccak256)13 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)11 Repository (org.ethereum.core.Repository)11 MutableRepository (org.ethereum.db.MutableRepository)11 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)10 Script (co.rsk.bitcoinj.script.Script)9 ForBlock (org.ethereum.config.blockchain.upgrades.ActivationConfig.ForBlock)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 Context (co.rsk.bitcoinj.core.Context)7 RedeemData (co.rsk.bitcoinj.wallet.RedeemData)4 PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation (co.rsk.peg.PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation)2 PegTestUtils.createBaseRedeemScriptThatSpendsFromTheFederation (co.rsk.peg.PegTestUtils.createBaseRedeemScriptThatSpendsFromTheFederation)2 BtcLockSenderProvider (co.rsk.peg.btcLockSender.BtcLockSenderProvider)2 PeginInstructionsProvider (co.rsk.peg.pegininstructions.PeginInstructionsProvider)2 Block (org.ethereum.core.Block)2 Address (co.rsk.bitcoinj.core.Address)1 BtcTransaction (co.rsk.bitcoinj.core.BtcTransaction)1 Coin (co.rsk.bitcoinj.core.Coin)1