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