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