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