use of org.ethereum.core.Transaction 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 org.ethereum.core.Transaction 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 org.ethereum.core.Transaction 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());
}
use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class AddressBasedAuthorizerTest method isAuthorized.
@Test
public void isAuthorized() {
AddressBasedAuthorizer auth = new AddressBasedAuthorizer(Arrays.asList(ECKey.fromPrivate(BigInteger.valueOf(100L)), ECKey.fromPrivate(BigInteger.valueOf(101L)), ECKey.fromPrivate(BigInteger.valueOf(102L))), AddressBasedAuthorizer.MinimumRequiredCalculation.MAJORITY);
for (long n = 100L; n <= 102L; n++) {
Transaction mockedTx = mock(Transaction.class);
when(mockedTx.getSender()).thenReturn(new RskAddress(ECKey.fromPrivate(BigInteger.valueOf(n)).getAddress()));
Assert.assertTrue(auth.isAuthorized(new RskAddress(ECKey.fromPrivate(BigInteger.valueOf(n)).getAddress())));
Assert.assertTrue(auth.isAuthorized(mockedTx));
}
Assert.assertFalse(auth.isAuthorized(new RskAddress(ECKey.fromPrivate(BigInteger.valueOf(50L)).getAddress())));
Transaction mockedTx = mock(Transaction.class);
when(mockedTx.getSender()).thenReturn(new RskAddress(ECKey.fromPrivate(BigInteger.valueOf(50L)).getAddress()));
Assert.assertFalse(auth.isAuthorized(mockedTx));
}
use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class DebugModuleImplTest method debug_traceTransaction_retrieveSimpleContractCreationTrace.
@Test
public void debug_traceTransaction_retrieveSimpleContractCreationTrace() throws Exception {
DslParser parser = DslParser.fromResource("dsl/contracts01.txt");
ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
World world = new World(receiptStore);
WorldDslProcessor processor = new WorldDslProcessor(world);
processor.processCommands(parser);
Transaction transaction = world.getTransactionByName("tx01");
DebugModuleImpl debugModule = new DebugModuleImpl(world.getBlockStore(), receiptStore, messageHandler, world.getBlockExecutor());
JsonNode result = debugModule.traceTransaction(transaction.getHash().toJsonString(), null);
Assert.assertNotNull(result);
Assert.assertTrue(result.isObject());
ObjectNode oResult = (ObjectNode) result;
Assert.assertTrue(oResult.get("error").textValue().isEmpty());
Assert.assertTrue(oResult.get("result").isTextual());
JsonNode structLogs = oResult.get("structLogs");
Assert.assertTrue(structLogs.isArray());
Assert.assertTrue(structLogs.size() > 0);
}
Aggregations