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());
}
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()));
}
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);
}
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());
}
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 }));
}
Aggregations