Search in sources :

Example 1 with SimpleBtcTransaction

use of co.rsk.peg.bitcoin.SimpleBtcTransaction in project rskj by rsksmart.

the class BridgeStorageProviderTest method getReleaseTransactionSet_after_rskip_146_activation.

@Test
public void getReleaseTransactionSet_after_rskip_146_activation() throws IOException {
    ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class);
    when(activations.isActive(ConsensusRule.RSKIP146)).thenReturn(true);
    Set<ReleaseTransactionSet.Entry> oldEntriesSet = new HashSet<>(Collections.singletonList(new ReleaseTransactionSet.Entry(new BtcTransaction(config.getNetworkConstants().getBridgeConstants().getBtcParams()), 1L)));
    Set<ReleaseTransactionSet.Entry> newEntriesSet = new HashSet<>(Collections.singletonList(new ReleaseTransactionSet.Entry(new BtcTransaction(config.getNetworkConstants().getBridgeConstants().getBtcParams()), 1L, PegTestUtils.createHash3(0))));
    Repository repositoryMock = mock(Repository.class);
    when(repositoryMock.getStorageBytes(any(RskAddress.class), eq(DataWord.fromString("releaseTransactionSet")))).thenReturn(BridgeSerializationUtils.serializeReleaseTransactionSet(new ReleaseTransactionSet(oldEntriesSet)));
    BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activations);
    ReleaseTransactionSet releaseTransactionSet = storageProvider.getReleaseTransactionSet();
    releaseTransactionSet.add(new SimpleBtcTransaction(config.getNetworkConstants().getBridgeConstants().getBtcParams(), PegTestUtils.createHash(0)), 1L, PegTestUtils.createHash3(0));
    when(repositoryMock.getStorageBytes(any(RskAddress.class), eq(DataWord.fromString("releaseTransactionSetWithTxHash")))).then((InvocationOnMock invocation) -> BridgeSerializationUtils.serializeReleaseTransactionSetWithTxHash(new ReleaseTransactionSet(newEntriesSet)));
    ReleaseTransactionSet result = storageProvider.getReleaseTransactionSet();
    Assert.assertEquals(2, result.getEntries().size());
}
Also used : OneOffWhiteListEntry(co.rsk.peg.whitelist.OneOffWhiteListEntry) LockWhitelistEntry(co.rsk.peg.whitelist.LockWhitelistEntry) UnlimitedWhiteListEntry(co.rsk.peg.whitelist.UnlimitedWhiteListEntry) Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) SimpleBtcTransaction(co.rsk.peg.bitcoin.SimpleBtcTransaction) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SimpleBtcTransaction(co.rsk.peg.bitcoin.SimpleBtcTransaction) RskAddress(co.rsk.core.RskAddress) ForBlock(org.ethereum.config.blockchain.upgrades.ActivationConfig.ForBlock) 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 2 with SimpleBtcTransaction

use of co.rsk.peg.bitcoin.SimpleBtcTransaction in project rskj by rsksmart.

the class BridgeStorageProviderTest method saveReleaseTransactionSet_after_rskip_146_activations.

@Test
public void saveReleaseTransactionSet_after_rskip_146_activations() throws IOException {
    ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class);
    when(activations.isActive(ConsensusRule.RSKIP146)).thenReturn(true);
    Set<ReleaseTransactionSet.Entry> newEntriesSet = new HashSet<>(Collections.singletonList(new ReleaseTransactionSet.Entry(new BtcTransaction(config.getNetworkConstants().getBridgeConstants().getBtcParams()), 1L, PegTestUtils.createHash3(0))));
    Set<ReleaseTransactionSet.Entry> oldEntriesSet = new HashSet<>(Collections.singletonList(new ReleaseTransactionSet.Entry(new BtcTransaction(config.getNetworkConstants().getBridgeConstants().getBtcParams()), 1L)));
    Repository repositoryMock = mock(Repository.class);
    when(repositoryMock.getStorageBytes(any(), eq(DataWord.fromString("releaseTransactionSet")))).thenReturn(BridgeSerializationUtils.serializeReleaseTransactionSet(new ReleaseTransactionSet(oldEntriesSet)));
    BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activations);
    ReleaseTransactionSet releaseTransactionSet = storageProvider.getReleaseTransactionSet();
    releaseTransactionSet.add(new SimpleBtcTransaction(config.getNetworkConstants().getBridgeConstants().getBtcParams(), PegTestUtils.createHash(1)), 1L, PegTestUtils.createHash3(0));
    doAnswer((i) -> {
        Set<ReleaseTransactionSet.Entry> entries = BridgeSerializationUtils.deserializeReleaseTransactionSet(i.getArgument(2), networkParameters).getEntries();
        Assert.assertEquals(entries, oldEntriesSet);
        return true;
    }).when(repositoryMock).addStorageBytes(any(RskAddress.class), eq(DataWord.fromString("releaseTransactionSet")), any(byte[].class));
    doAnswer((i) -> {
        Set<ReleaseTransactionSet.Entry> entries = BridgeSerializationUtils.deserializeReleaseTransactionSet(i.getArgument(2), networkParameters, true).getEntries();
        Assert.assertEquals(entries, newEntriesSet);
        return true;
    }).when(repositoryMock).addStorageBytes(any(RskAddress.class), eq(DataWord.fromString("releaseTransactionSetWithTxHash")), any(byte[].class));
    storageProvider.saveReleaseTransactionSet();
    verify(repositoryMock, atLeastOnce()).addStorageBytes(any(RskAddress.class), eq(DataWord.fromString("releaseTransactionSet")), any(byte[].class));
    verify(repositoryMock, atLeastOnce()).addStorageBytes(any(RskAddress.class), eq(DataWord.fromString("releaseTransactionSetWithTxHash")), any(byte[].class));
    Assert.assertEquals(2, storageProvider.getReleaseTransactionSet().getEntries().size());
}
Also used : OneOffWhiteListEntry(co.rsk.peg.whitelist.OneOffWhiteListEntry) LockWhitelistEntry(co.rsk.peg.whitelist.LockWhitelistEntry) UnlimitedWhiteListEntry(co.rsk.peg.whitelist.UnlimitedWhiteListEntry) Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) SimpleBtcTransaction(co.rsk.peg.bitcoin.SimpleBtcTransaction) SimpleBtcTransaction(co.rsk.peg.bitcoin.SimpleBtcTransaction) RskAddress(co.rsk.core.RskAddress) ForBlock(org.ethereum.config.blockchain.upgrades.ActivationConfig.ForBlock) 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

RskAddress (co.rsk.core.RskAddress)2 SimpleBtcTransaction (co.rsk.peg.bitcoin.SimpleBtcTransaction)2 LockWhitelistEntry (co.rsk.peg.whitelist.LockWhitelistEntry)2 OneOffWhiteListEntry (co.rsk.peg.whitelist.OneOffWhiteListEntry)2 UnlimitedWhiteListEntry (co.rsk.peg.whitelist.UnlimitedWhiteListEntry)2 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)2 ForBlock (org.ethereum.config.blockchain.upgrades.ActivationConfig.ForBlock)2 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)2 Repository (org.ethereum.core.Repository)2 MutableRepository (org.ethereum.db.MutableRepository)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1