use of co.rsk.peg.utils.BridgeEventLoggerImpl in project rskj by rsksmart.
the class BridgeSupportTest method callUpdateCollectionsGenerateEventLog.
@Test
public void callUpdateCollectionsGenerateEventLog() throws IOException, BlockStoreException {
Repository track = new RepositoryImpl(config).startTracking();
BlockGenerator blockGenerator = new BlockGenerator();
List<Block> blocks = blockGenerator.getSimpleBlockChain(blockGenerator.getGenesisBlock(), 10);
org.ethereum.core.Block rskCurrentBlock = blocks.get(9);
List<LogInfo> eventLogs = new LinkedList<>();
BridgeEventLogger eventLogger = new BridgeEventLoggerImpl(bridgeConstants, eventLogs);
BridgeSupport bridgeSupport = new BridgeSupport(config, track, eventLogger, PrecompiledContracts.BRIDGE_ADDR, rskCurrentBlock);
Transaction tx = Transaction.create(config, TO_ADDRESS, DUST_AMOUNT, NONCE, GAS_PRICE, GAS_LIMIT, DATA);
ECKey key = new ECKey();
tx.sign(key.getPrivKeyBytes());
bridgeSupport.updateCollections(tx);
Assert.assertEquals(1, eventLogs.size());
// Assert address that made the log
LogInfo result = eventLogs.get(0);
Assert.assertArrayEquals(PrecompiledContracts.BRIDGE_ADDR.getBytes(), result.getAddress());
// Assert log topics
Assert.assertEquals(1, result.getTopics().size());
Assert.assertEquals(Bridge.UPDATE_COLLECTIONS_TOPIC, result.getTopics().get(0));
// Assert log data
Assert.assertArrayEquals(key.getAddress(), RLP.decode2(result.getData()).get(0).getRLPData());
}
use of co.rsk.peg.utils.BridgeEventLoggerImpl in project rskj by rsksmart.
the class BridgeSupportReleaseBtcTest method handmade_release_after_rskip_146_rejected_contractCaller.
@Test
public void handmade_release_after_rskip_146_rejected_contractCaller() throws IOException {
when(activationMock.isActive(ConsensusRule.RSKIP146)).thenReturn(true);
when(activationMock.isActive(ConsensusRule.RSKIP185)).thenReturn(false);
List<LogInfo> logInfo = new ArrayList<>();
BridgeEventLoggerImpl eventLogger = new BridgeEventLoggerImpl(bridgeConstants, activationMock, logInfo);
bridgeSupport = initBridgeSupport(eventLogger, activationMock);
releaseTx = buildReleaseRskTx_fromContract(Coin.COIN);
try {
bridgeSupport.releaseBtc(releaseTx);
fail();
} catch (Program.OutOfGasException e) {
assertTrue(e.getMessage().contains("Contract calling releaseBTC"));
}
}
use of co.rsk.peg.utils.BridgeEventLoggerImpl in project rskj by rsksmart.
the class BridgeSupportReleaseBtcTest method handmade_release_after_rskip_146_185.
@Test
public void handmade_release_after_rskip_146_185() throws IOException {
when(activationMock.isActive(ConsensusRule.RSKIP146)).thenReturn(true);
when(activationMock.isActive(ConsensusRule.RSKIP185)).thenReturn(true);
List<LogInfo> logInfo = new ArrayList<>();
BridgeEventLoggerImpl eventLogger = spy(new BridgeEventLoggerImpl(bridgeConstants, activationMock, logInfo));
bridgeSupport = initBridgeSupport(eventLogger, activationMock);
bridgeSupport.releaseBtc(releaseTx);
Transaction rskTx = buildUpdateTx();
rskTx.sign(SENDER.getPrivKeyBytes());
bridgeSupport.updateCollections(rskTx);
verify(repository, never()).transfer(any(), any(), any());
assertEquals(1, provider.getReleaseTransactionSet().getEntries().size());
assertEquals(0, provider.getReleaseRequestQueue().getEntries().size());
ReleaseTransactionSet.Entry entry = (ReleaseTransactionSet.Entry) provider.getReleaseTransactionSet().getEntries().toArray()[0];
assertEquals(3, logInfo.size());
verify(eventLogger, times(1)).logReleaseBtcRequested(any(byte[].class), any(BtcTransaction.class), any(Coin.class));
verify(eventLogger, times(1)).logReleaseBtcRequestReceived(any(), any(), any());
verify(eventLogger, times(1)).logUpdateCollections(any());
}
use of co.rsk.peg.utils.BridgeEventLoggerImpl in project rskj by rsksmart.
the class BridgeSupportReleaseBtcTest method release_after_rskip_219.
@Test
public void release_after_rskip_219() throws IOException {
when(activationMock.isActive(ConsensusRule.RSKIP146)).thenReturn(true);
when(activationMock.isActive(ConsensusRule.RSKIP185)).thenReturn(true);
when(activationMock.isActive(ConsensusRule.RSKIP219)).thenReturn(true);
List<LogInfo> logInfo = new ArrayList<>();
BridgeEventLoggerImpl eventLogger = spy(new BridgeEventLoggerImpl(bridgeConstants, activationMock, logInfo));
bridgeSupport = initBridgeSupport(eventLogger, activationMock);
// Get a value between old and new minimum pegout values
Coin middle = bridgeConstants.getLegacyMinimumPegoutTxValueInSatoshis().subtract(bridgeConstants.getMinimumPegoutTxValueInSatoshis()).div(2);
Coin value = bridgeConstants.getMinimumPegoutTxValueInSatoshis().add(middle);
assertTrue(value.isLessThan(bridgeConstants.getLegacyMinimumPegoutTxValueInSatoshis()));
assertTrue(value.isGreaterThan(bridgeConstants.getMinimumPegoutTxValueInSatoshis()));
bridgeSupport.releaseBtc(buildReleaseRskTx(value));
Transaction rskTx = buildUpdateTx();
rskTx.sign(SENDER.getPrivKeyBytes());
verify(repository, never()).transfer(any(), any(), any());
assertEquals(1, provider.getReleaseRequestQueue().getEntries().size());
assertEquals(1, logInfo.size());
verify(eventLogger, times(1)).logReleaseBtcRequestReceived(any(), any(), any());
}
use of co.rsk.peg.utils.BridgeEventLoggerImpl in project rskj by rsksmart.
the class BridgeSupportReleaseBtcTest method handmade_release_after_rskip_146_185_rejected_lowAmount.
@Test
public void handmade_release_after_rskip_146_185_rejected_lowAmount() throws IOException {
when(activationMock.isActive(ConsensusRule.RSKIP146)).thenReturn(true);
when(activationMock.isActive(ConsensusRule.RSKIP185)).thenReturn(true);
List<LogInfo> logInfo = new ArrayList<>();
BridgeEventLoggerImpl eventLogger = spy(new BridgeEventLoggerImpl(bridgeConstants, activationMock, logInfo));
bridgeSupport = initBridgeSupport(eventLogger, activationMock);
releaseTx = buildReleaseRskTx(Coin.ZERO);
bridgeSupport.releaseBtc(releaseTx);
Transaction rskTx = buildUpdateTx();
rskTx.sign(SENDER.getPrivKeyBytes());
bridgeSupport.updateCollections(rskTx);
verify(repository, times(1)).transfer(argThat((a) -> a.equals(PrecompiledContracts.BRIDGE_ADDR)), argThat((a) -> a.equals(new RskAddress(SENDER.getAddress()))), argThat((a) -> a.equals(co.rsk.core.Coin.fromBitcoin(Coin.ZERO))));
assertEquals(0, provider.getReleaseTransactionSet().getEntries().size());
assertEquals(0, provider.getReleaseRequestQueue().getEntries().size());
assertEquals(2, logInfo.size());
verify(eventLogger, never()).logReleaseBtcRequestReceived(any(), any(), any());
verify(eventLogger, times(1)).logReleaseBtcRequestRejected(any(), any(), any());
verify(eventLogger, times(1)).logUpdateCollections(any());
}
Aggregations