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