Search in sources :

Example 31 with Transaction

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());
}
Also used : BridgeEventLoggerImpl(co.rsk.peg.utils.BridgeEventLoggerImpl) LogInfo(org.ethereum.vm.LogInfo) InternalTransaction(org.ethereum.vm.program.InternalTransaction) Transaction(org.ethereum.core.Transaction) ArrayList(java.util.ArrayList) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 32 with Transaction

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());
}
Also used : BridgeEventLoggerImpl(co.rsk.peg.utils.BridgeEventLoggerImpl) LogInfo(org.ethereum.vm.LogInfo) InternalTransaction(org.ethereum.vm.program.InternalTransaction) Transaction(org.ethereum.core.Transaction) ArrayList(java.util.ArrayList) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 33 with Transaction

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());
}
Also used : BridgeEventLoggerImpl(co.rsk.peg.utils.BridgeEventLoggerImpl) RejectedPegoutReason(co.rsk.peg.utils.RejectedPegoutReason) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BtcLockSenderProvider(co.rsk.peg.btcLockSender.BtcLockSenderProvider) RskAddress(co.rsk.core.RskAddress) PeginInstructionsProvider(co.rsk.peg.pegininstructions.PeginInstructionsProvider) BridgeEventLoggerImpl(co.rsk.peg.utils.BridgeEventLoggerImpl) Hex(org.bouncycastle.util.encoders.Hex) Block(org.ethereum.core.Block) ArrayList(java.util.ArrayList) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) MutableTrieCache(co.rsk.db.MutableTrieCache) ArgumentCaptor(org.mockito.ArgumentCaptor) BridgeConstants(co.rsk.config.BridgeConstants) co.rsk.bitcoinj.core(co.rsk.bitcoinj.core) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) BigInteger(java.math.BigInteger) BridgeRegTestConstants(co.rsk.config.BridgeRegTestConstants) Before(org.junit.Before) LogInfo(org.ethereum.vm.LogInfo) HashUtil(org.ethereum.crypto.HashUtil) DataWord(org.ethereum.vm.DataWord) Test(org.junit.Test) IOException(java.io.IOException) MutableTrieImpl(co.rsk.db.MutableTrieImpl) Instant(java.time.Instant) Repository(org.ethereum.core.Repository) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) MutableRepository(org.ethereum.db.MutableRepository) Program(org.ethereum.vm.program.Program) Mockito(org.mockito.Mockito) List(java.util.List) InternalTransaction(org.ethereum.vm.program.InternalTransaction) BridgeEventLogger(co.rsk.peg.utils.BridgeEventLogger) Transaction(org.ethereum.core.Transaction) Assert(org.junit.Assert) Trie(co.rsk.trie.Trie) ConsensusRule(org.ethereum.config.blockchain.upgrades.ConsensusRule) Constants(org.ethereum.config.Constants) ECKey(org.ethereum.crypto.ECKey) LogInfo(org.ethereum.vm.LogInfo) InternalTransaction(org.ethereum.vm.program.InternalTransaction) Transaction(org.ethereum.core.Transaction) ArrayList(java.util.ArrayList) RskAddress(co.rsk.core.RskAddress) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 34 with Transaction

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));
}
Also used : Transaction(org.ethereum.core.Transaction) RskAddress(co.rsk.core.RskAddress) Test(org.junit.Test)

Example 35 with Transaction

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);
}
Also used : ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Transaction(org.ethereum.core.Transaction) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DslParser(co.rsk.test.dsl.DslParser) JsonNode(com.fasterxml.jackson.databind.JsonNode) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) ReceiptStore(org.ethereum.db.ReceiptStore) Test(org.junit.Test)

Aggregations

Transaction (org.ethereum.core.Transaction)257 Test (org.junit.Test)166 Block (org.ethereum.core.Block)73 RskAddress (co.rsk.core.RskAddress)69 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)57 InternalTransaction (org.ethereum.vm.program.InternalTransaction)57 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)39 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)39 BigInteger (java.math.BigInteger)38 ArrayList (java.util.ArrayList)38 Repository (org.ethereum.core.Repository)35 JsonNode (com.fasterxml.jackson.databind.JsonNode)32 ECKey (org.ethereum.crypto.ECKey)30 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)29 Keccak256 (co.rsk.crypto.Keccak256)28 Account (org.ethereum.core.Account)26 World (co.rsk.test.World)23 DslParser (co.rsk.test.dsl.DslParser)23 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)23 MutableRepository (org.ethereum.db.MutableRepository)22