Search in sources :

Example 16 with FastBridgeFederationInformation

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

the class BridgeSerializationUtilsTest method deserializeFastBridgeFederationInformation_null_data.

@Test
public void deserializeFastBridgeFederationInformation_null_data() {
    FastBridgeFederationInformation result = BridgeSerializationUtils.deserializeFastBridgeFederationInformation(null, null);
    Assert.assertNull(result);
}
Also used : FastBridgeFederationInformation(co.rsk.peg.fastbridge.FastBridgeFederationInformation) Test(org.junit.Test)

Example 17 with FastBridgeFederationInformation

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

the class BridgeSerializationUtilsTest method serializeFastBridgeFederationInformation_Ok.

@Test
public void serializeFastBridgeFederationInformation_Ok() {
    byte[] fastBridgeFederationRedeemScriptHash = new byte[] { (byte) 0x23 };
    FastBridgeFederationInformation fastBridgeFederationInformation = new FastBridgeFederationInformation(PegTestUtils.createHash3(2), new byte[] { (byte) 0x22 }, fastBridgeFederationRedeemScriptHash);
    FastBridgeFederationInformation result = BridgeSerializationUtils.deserializeFastBridgeFederationInformation(BridgeSerializationUtils.serializeFastBridgeFederationInformation(fastBridgeFederationInformation), fastBridgeFederationRedeemScriptHash);
    Assert.assertArrayEquals(fastBridgeFederationInformation.getDerivationHash().getBytes(), result.getDerivationHash().getBytes());
    Assert.assertArrayEquals(fastBridgeFederationInformation.getFederationRedeemScriptHash(), result.getFederationRedeemScriptHash());
    Assert.assertArrayEquals(fastBridgeFederationInformation.getFastBridgeFederationRedeemScriptHash(), result.getFastBridgeFederationRedeemScriptHash());
}
Also used : FastBridgeFederationInformation(co.rsk.peg.fastbridge.FastBridgeFederationInformation) Test(org.junit.Test)

Example 18 with FastBridgeFederationInformation

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

the class BridgeStorageProviderTest method getFastBridgeFederationInformation_beforeRSKIP176_ok.

@Test
public void getFastBridgeFederationInformation_beforeRSKIP176_ok() {
    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);
    when(repository.getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromLongString("fastBridgeFederationInformation-" + Hex.toHexString(fastBridgeFederationRedeemScriptHash)))).thenReturn(BridgeSerializationUtils.serializeFastBridgeFederationInformation(fastBridgeFederationInformation));
    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);
    Optional<FastBridgeFederationInformation> result = provider.getFastBridgeFederationInformation(fastBridgeFederationRedeemScriptHash);
    Assert.assertFalse(result.isPresent());
}
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 19 with FastBridgeFederationInformation

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

the class BridgeStorageProviderTest method saveFastBridgeFederationInformation_alreadySet_dont_set_again.

@Test
public void saveFastBridgeFederationInformation_alreadySet_dont_set_again() 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);
    // Set again
    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 20 with FastBridgeFederationInformation

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

the class BridgeStorageProviderTest method getFastBridgeFederationInformation_afterRSKIP176_ok.

@Test
public void getFastBridgeFederationInformation_afterRSKIP176_ok() {
    Repository repository = mock(Repository.class);
    byte[] fastBridgeFederationRedeemScriptHash = new byte[] { (byte) 0xbb };
    Keccak256 derivationHash = PegTestUtils.createHash3(1);
    byte[] federationRedeemScriptHash = new byte[] { (byte) 0xaa };
    FastBridgeFederationInformation fastBridgeFederationInformation = new FastBridgeFederationInformation(derivationHash, federationRedeemScriptHash, fastBridgeFederationRedeemScriptHash);
    when(repository.getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromLongString("fastBridgeFederationInformation-" + Hex.toHexString(fastBridgeFederationRedeemScriptHash)))).thenReturn(BridgeSerializationUtils.serializeFastBridgeFederationInformation(fastBridgeFederationInformation));
    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(fastBridgeFederationRedeemScriptHash);
    Assert.assertTrue((result.isPresent()));
    Assert.assertArrayEquals(federationRedeemScriptHash, result.get().getFederationRedeemScriptHash());
    Assert.assertArrayEquals(derivationHash.getBytes(), result.get().getDerivationHash().getBytes());
    Assert.assertArrayEquals(fastBridgeFederationRedeemScriptHash, result.get().getFastBridgeFederationRedeemScriptHash());
}
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)

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