Search in sources :

Example 11 with FastBridgeFederationInformation

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

the class BridgeSupportTest method saveFastBridgeDataInStorage_OK.

@Test
public void saveFastBridgeDataInStorage_OK() throws IOException {
    Repository repository = createRepository();
    BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, bridgeConstants, activationsAfterForks);
    BridgeSupport bridgeSupport = bridgeSupportBuilder.withBridgeConstants(bridgeConstants).withProvider(provider).withActivations(activationsAfterForks).build();
    Sha256Hash btcTxHash = PegTestUtils.createHash(1);
    Keccak256 derivationHash = PegTestUtils.createHash3(1);
    byte[] fastBridgeScriptHash = new byte[] { 0x1 };
    FastBridgeFederationInformation fastBridgeFederationInformation = new FastBridgeFederationInformation(PegTestUtils.createHash3(2), new byte[] { 0x1 }, fastBridgeScriptHash);
    List<UTXO> utxos = new ArrayList<>();
    Sha256Hash utxoHash = PegTestUtils.createHash(1);
    UTXO utxo = new UTXO(utxoHash, 0, Coin.COIN.multiply(2), 0, false, new Script(new byte[] {}));
    utxos.add(utxo);
    Assert.assertEquals(0, provider.getNewFederationBtcUTXOs().size());
    bridgeSupport.saveFastBridgeDataInStorage(btcTxHash, derivationHash, fastBridgeFederationInformation, utxos);
    bridgeSupport.save();
    Assert.assertEquals(1, provider.getNewFederationBtcUTXOs().size());
    assertEquals(utxo, provider.getNewFederationBtcUTXOs().get(0));
    Assert.assertTrue(provider.isFastBridgeFederationDerivationHashUsed(btcTxHash, derivationHash));
    Optional<FastBridgeFederationInformation> optionalFastBridgeFederationInformation = provider.getFastBridgeFederationInformation(fastBridgeScriptHash);
    Assert.assertTrue(optionalFastBridgeFederationInformation.isPresent());
    FastBridgeFederationInformation obtainedFastBridgeFederationInformation = optionalFastBridgeFederationInformation.get();
    Assert.assertEquals(fastBridgeFederationInformation.getDerivationHash(), obtainedFastBridgeFederationInformation.getDerivationHash());
    Assert.assertArrayEquals(fastBridgeFederationInformation.getFederationRedeemScriptHash(), obtainedFastBridgeFederationInformation.getFederationRedeemScriptHash());
}
Also used : Script(co.rsk.bitcoinj.script.Script) Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) Keccak256(co.rsk.crypto.Keccak256) FastBridgeFederationInformation(co.rsk.peg.fastbridge.FastBridgeFederationInformation) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) Test(org.junit.Test)

Example 12 with FastBridgeFederationInformation

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

the class BridgeStorageProviderTest method saveFastBridgeFederationInformation_afterRSKIP176_ok.

@Test
public void saveFastBridgeFederationInformation_afterRSKIP176_ok() throws IOException {
    Repository repository = mock(Repository.class);
    Keccak256 derivationHash = PegTestUtils.createHash3(2);
    byte[] federationRedeemScriptHash = new byte[] { (byte) 0xaa };
    byte[] fastBridgeFederationRedeemScriptHash = new byte[] { (byte) 0x22 };
    FastBridgeFederationInformation fastBridgeFederationInformation = new FastBridgeFederationInformation(derivationHash, federationRedeemScriptHash, fastBridgeFederationRedeemScriptHash);
    ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class);
    when(activations.isActive(ConsensusRule.RSKIP176)).thenReturn(true);
    BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, config.getNetworkConstants().getBridgeConstants(), activations);
    provider.setFastBridgeFederationInformation(fastBridgeFederationInformation);
    provider.save();
    verify(repository, times(1)).addStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromLongString("fastBridgeFederationInformation-" + Hex.toHexString(fastBridgeFederationRedeemScriptHash)), BridgeSerializationUtils.serializeFastBridgeFederationInformation(fastBridgeFederationInformation));
}
Also used : Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) Keccak256(co.rsk.crypto.Keccak256) ForBlock(org.ethereum.config.blockchain.upgrades.ActivationConfig.ForBlock) FastBridgeFederationInformation(co.rsk.peg.fastbridge.FastBridgeFederationInformation) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with FastBridgeFederationInformation

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

the class BridgeStorageProviderTest method getFastBridgeFederationInformation_arrayEmpty_returnEmpty.

@Test
public void getFastBridgeFederationInformation_arrayEmpty_returnEmpty() {
    Repository repository = mock(Repository.class);
    ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class);
    when(activations.isActive(ConsensusRule.RSKIP176)).thenReturn(true);
    BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, config.getNetworkConstants().getBridgeConstants(), activations);
    Optional<FastBridgeFederationInformation> result = provider.getFastBridgeFederationInformation(new byte[] {});
    Assert.assertFalse(result.isPresent());
}
Also used : Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) ForBlock(org.ethereum.config.blockchain.upgrades.ActivationConfig.ForBlock) FastBridgeFederationInformation(co.rsk.peg.fastbridge.FastBridgeFederationInformation) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with FastBridgeFederationInformation

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

the class BridgeStorageProviderTest method saveFastBridgeFederationInformation_beforeRSKIP176_ok.

@Test
public void saveFastBridgeFederationInformation_beforeRSKIP176_ok() throws IOException {
    Repository repository = mock(Repository.class);
    Keccak256 derivationHash = PegTestUtils.createHash3(2);
    byte[] federationRedeemScriptHash = new byte[] { (byte) 0xaa };
    byte[] fastBridgeFederationRedeemScriptHash = new byte[] { (byte) 0x22 };
    FastBridgeFederationInformation fastBridgeFederationInformation = new FastBridgeFederationInformation(derivationHash, federationRedeemScriptHash, fastBridgeFederationRedeemScriptHash);
    ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class);
    when(activations.isActive(ConsensusRule.RSKIP176)).thenReturn(false);
    BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, config.getNetworkConstants().getBridgeConstants(), activations);
    provider.setFastBridgeFederationInformation(fastBridgeFederationInformation);
    provider.save();
    verify(repository, never()).addStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromLongString("fastBridgeFederationInformation-" + Hex.toHexString(fastBridgeFederationRedeemScriptHash)), BridgeSerializationUtils.serializeFastBridgeFederationInformation(fastBridgeFederationInformation));
}
Also used : Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) Keccak256(co.rsk.crypto.Keccak256) ForBlock(org.ethereum.config.blockchain.upgrades.ActivationConfig.ForBlock) FastBridgeFederationInformation(co.rsk.peg.fastbridge.FastBridgeFederationInformation) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with FastBridgeFederationInformation

use of co.rsk.peg.fastbridge.FastBridgeFederationInformation 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

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