Search in sources :

Example 21 with FastBridgeFederationInformation

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

the class BridgeStorageProviderTest method getFastBridgeFederationInformation_nullParameter_returnEmpty.

@Test
public void getFastBridgeFederationInformation_nullParameter_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(null);
    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 22 with FastBridgeFederationInformation

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

the class BridgeSupportTest method createFastBridgeFederationInformation_OK.

@Test
public void createFastBridgeFederationInformation_OK() {
    ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class);
    when(activations.isActive(ConsensusRule.RSKIP176)).thenReturn(true);
    Federation fed = bridgeConstants.getGenesisFederation();
    FederationSupport federationSupport = mock(FederationSupport.class);
    when(federationSupport.getActiveFederation()).thenReturn(fed);
    BridgeSupport bridgeSupport = new BridgeSupport(bridgeConstants, mock(BridgeStorageProvider.class), mock(BridgeEventLogger.class), new BtcLockSenderProvider(), new PeginInstructionsProvider(), mock(Repository.class), mock(Block.class), mock(Context.class), federationSupport, mock(BtcBlockStoreWithCache.Factory.class), activations);
    Script fastBridgeRedeemScript = FastBridgeRedeemScriptParser.createMultiSigFastBridgeRedeemScript(bridgeConstants.getGenesisFederation().getRedeemScript(), PegTestUtils.createHash(1));
    Script fastBridgeP2SH = ScriptBuilder.createP2SHOutputScript(fastBridgeRedeemScript);
    Keccak256 derivationHash = PegTestUtils.createHash3(1);
    FastBridgeFederationInformation expectedFastBridgeFederationInformation = new FastBridgeFederationInformation(derivationHash, fed.getP2SHScript().getPubKeyHash(), fastBridgeP2SH.getPubKeyHash());
    FastBridgeFederationInformation obtainedFastBridgeFedInfo = bridgeSupport.createFastBridgeFederationInformation(derivationHash);
    Assert.assertEquals(expectedFastBridgeFederationInformation.getFastBridgeFederationAddress(bridgeConstants.getBtcParams()), obtainedFastBridgeFedInfo.getFastBridgeFederationAddress(bridgeConstants.getBtcParams()));
}
Also used : Script(co.rsk.bitcoinj.script.Script) PeginInstructionsProvider(co.rsk.peg.pegininstructions.PeginInstructionsProvider) 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)

Example 23 with FastBridgeFederationInformation

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

the class FastBridgeCompatibleBtcWalletWithStorageTest method findRedeemDataFromScriptHash_with_fastBridgeInformation_in_storage_and_erp_fed.

@Test
public void findRedeemDataFromScriptHash_with_fastBridgeInformation_in_storage_and_erp_fed() {
    BridgeStorageProvider provider = mock(BridgeStorageProvider.class);
    Keccak256 derivationArgumentsHash = PegTestUtils.createHash3(1);
    Script fastBridgeRedeemScript = FastBridgeErpRedeemScriptParser.createFastBridgeErpRedeemScript(erpFederation.getRedeemScript(), Sha256Hash.wrap(derivationArgumentsHash.getBytes()));
    Script p2SHOutputScript = ScriptBuilder.createP2SHOutputScript(fastBridgeRedeemScript);
    byte[] fastBridgeFederationP2SH = p2SHOutputScript.getPubKeyHash();
    FastBridgeFederationInformation fastBridgeFederationInformation = new FastBridgeFederationInformation(derivationArgumentsHash, erpFederation.getP2SHScript().getPubKeyHash(), fastBridgeFederationP2SH);
    when(provider.getFastBridgeFederationInformation(fastBridgeFederationP2SH)).thenReturn(Optional.of(fastBridgeFederationInformation));
    FastBridgeCompatibleBtcWalletWithStorage fastBridgeCompatibleBtcWalletWithStorage = new FastBridgeCompatibleBtcWalletWithStorage(mock(Context.class), erpFederationList, 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 24 with FastBridgeFederationInformation

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

the class FastBridgeCompatibleBtcWalletWithStorageTest method getFastBridgeFederationInformation_data_on_storage.

@Test
public void getFastBridgeFederationInformation_data_on_storage() {
    byte[] fastBridgeScriptHash = new byte[1];
    FastBridgeFederationInformation fastBridgeFederationInformation = new FastBridgeFederationInformation(PegTestUtils.createHash3(2), new byte[0], fastBridgeScriptHash);
    BridgeStorageProvider provider = mock(BridgeStorageProvider.class);
    when(provider.getFastBridgeFederationInformation(any(byte[].class))).thenReturn(Optional.of(fastBridgeFederationInformation));
    FastBridgeCompatibleBtcWalletWithStorage fastBridgeCompatibleBtcWalletWithStorage = new FastBridgeCompatibleBtcWalletWithStorage(mock(Context.class), federationList, provider);
    Optional<FastBridgeFederationInformation> result = fastBridgeCompatibleBtcWalletWithStorage.getFastBridgeFederationInformation(fastBridgeScriptHash);
    Assert.assertTrue(result.isPresent());
    Assert.assertEquals(fastBridgeFederationInformation, result.get());
}
Also used : Context(co.rsk.bitcoinj.core.Context) FastBridgeFederationInformation(co.rsk.peg.fastbridge.FastBridgeFederationInformation) Test(org.junit.Test)

Example 25 with FastBridgeFederationInformation

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

the class FastBridgeCompatibleBtcWalletWithStorageTest method findRedeemDataFromScriptHash_null_destination_federation.

@Test
public void findRedeemDataFromScriptHash_null_destination_federation() {
    Keccak256 derivationArgumentsHash = PegTestUtils.createHash3(2);
    FastBridgeFederationInformation fastBridgeFederationInformation = new FastBridgeFederationInformation(derivationArgumentsHash, new byte[0], new byte[1]);
    BridgeStorageProvider provider = mock(BridgeStorageProvider.class);
    when(provider.getFastBridgeFederationInformation(any(byte[].class))).thenReturn(Optional.of(fastBridgeFederationInformation));
    FastBridgeCompatibleBtcWalletWithStorage fastBridgeCompatibleBtcWalletWithStorage = new FastBridgeCompatibleBtcWalletWithStorage(mock(Context.class), federationList, provider);
    Assert.assertNull(fastBridgeCompatibleBtcWalletWithStorage.findRedeemDataFromScriptHash(new byte[] { 1 }));
}
Also used : Context(co.rsk.bitcoinj.core.Context) Keccak256(co.rsk.crypto.Keccak256) 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