Search in sources :

Example 26 with Transaction

use of org.ethereum.core.Transaction in project rskj by rsksmart.

the class DslFilesTest method runCodeSizeAfterSuicide.

@Test
public void runCodeSizeAfterSuicide() throws FileNotFoundException, DslProcessorException {
    DslParser parser = DslParser.fromResource("dsl/codeSizeAfterSuicide.txt");
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    processor.processCommands(parser);
    Transaction transaction = world.getTransactionByName("callCodeSizeChecker");
    Assert.assertNotNull(transaction);
    TransactionInfo txinfo = world.getBlockChain().getTransactionInfo(transaction.getHash().getBytes());
    Assert.assertNotNull(txinfo);
    long gasUsed = BigIntegers.fromUnsignedByteArray(txinfo.getReceipt().getGasUsed()).longValue();
    // Gas consumed SHOULD NOT be all there is available
    Assert.assertNotEquals(200000, gasUsed);
    Assert.assertFalse("Transaction should be reverted", txinfo.getReceipt().isSuccessful());
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Transaction(org.ethereum.core.Transaction) DslParser(co.rsk.test.dsl.DslParser) TransactionInfo(org.ethereum.db.TransactionInfo) Test(org.junit.Test)

Example 27 with Transaction

use of org.ethereum.core.Transaction in project rskj by rsksmart.

the class Secp256k1ServiceTest method testSignatureToKey_from_Tx.

@Test
public void testSignatureToKey_from_Tx() throws SignatureException {
    byte[] messageHash = HashUtil.keccak256(exampleMessage.getBytes());
    byte[] pk = this.privateKey.toByteArray();
    String receiver = "CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826";
    ECKey fromPrivate = ECKey.fromPrivate(pk);
    ECKey fromPrivateDecompress = fromPrivate.decompress();
    String pubKeyExpected = Hex.toHexString(fromPrivateDecompress.getPubKey());
    String addressExpected = Hex.toHexString(fromPrivateDecompress.getAddress());
    // Create tx and sign, then recover from serialized.
    Transaction newTx = Transaction.builder().nonce(BigInteger.valueOf(2L)).gasPrice(BigInteger.valueOf(2L)).gasLimit(BigInteger.valueOf(2L)).destination(Hex.decode(receiver)).data(messageHash).value(BigInteger.valueOf(2L)).build();
    newTx.sign(pk);
    ImmutableTransaction recoveredTx = new ImmutableTransaction(newTx.getEncoded());
    // Recover Pub Key from recovered tx
    ECKey actualKey = this.getSecp256k1().signatureToKey(HashUtil.keccak256(recoveredTx.getEncodedRaw()), recoveredTx.getSignature());
    // Recover PK and Address.
    String pubKeyActual = Hex.toHexString(actualKey.getPubKey());
    logger.debug("Signature public key\t: {}", pubKeyActual);
    assertEquals(pubKeyExpected, pubKeyActual);
    assertEquals(pubString, pubKeyActual);
    assertArrayEquals(pubKey, actualKey.getPubKey());
    String addressActual = Hex.toHexString(actualKey.getAddress());
    logger.debug("Sender is\t\t: {}", addressActual);
    assertEquals(addressExpected, addressActual);
}
Also used : ImmutableTransaction(org.ethereum.core.ImmutableTransaction) Transaction(org.ethereum.core.Transaction) ImmutableTransaction(org.ethereum.core.ImmutableTransaction) ECKey(org.ethereum.crypto.ECKey) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 28 with Transaction

use of org.ethereum.core.Transaction in project rskj by rsksmart.

the class MessageVisitor method apply.

public void apply(TransactionsMessage message) {
    if (blockProcessor.hasBetterBlockToSync()) {
        loggerMessageProcess.debug("Message[{}] not processed.", message.getMessageType());
        return;
    }
    long start = System.nanoTime();
    loggerMessageProcess.debug("Tx message about to be process: {}", message.getMessageContentInfo());
    List<Transaction> messageTxs = message.getTransactions();
    List<Transaction> txs = new LinkedList<>();
    for (Transaction tx : messageTxs) {
        if (!tx.acceptTransactionSignature(config.getNetworkConstants().getChainId())) {
            recordEventForPeerScoring(sender, EventType.INVALID_TRANSACTION);
        } else {
            txs.add(tx);
            recordEventForPeerScoring(sender, EventType.VALID_TRANSACTION);
        }
    }
    transactionGateway.receiveTransactionsFrom(txs, Collections.singleton(sender.getPeerNodeID()));
    if (loggerMessageProcess.isDebugEnabled()) {
        loggerMessageProcess.debug("Tx message process finished after [{}] seconds.", FormatUtils.formatNanosecondsToSeconds(System.nanoTime() - start));
    }
}
Also used : Transaction(org.ethereum.core.Transaction)

Example 29 with Transaction

use of org.ethereum.core.Transaction in project rskj by rsksmart.

the class TxsPerAccount method readyToBeSent.

List<Transaction> readyToBeSent(BigInteger accountNonce) {
    if (nextNonce == null || nextNonce.compareTo(accountNonce) < 0) {
        nextNonce = accountNonce;
    }
    List<Transaction> ret = new LinkedList<>();
    for (Transaction tx : txs) {
        BigInteger nonce = new BigInteger(1, tx.getNonce());
        if (nextNonce.compareTo(nonce) == 0) {
            nextNonce = nonce.add(BigInteger.valueOf(1));
            ret.add(tx);
        }
    }
    return ret;
}
Also used : Transaction(org.ethereum.core.Transaction) BigInteger(java.math.BigInteger) LinkedList(java.util.LinkedList)

Example 30 with Transaction

use of org.ethereum.core.Transaction in project rskj by rsksmart.

the class BlockHashesHelperTest method calculateReceiptsTrieRootForDifferentTxHash.

@Test
public void calculateReceiptsTrieRootForDifferentTxHash() {
    World world = new World();
    // Creation of transactions
    Account acc1 = new AccountBuilder(world).name("acc1").balance(Coin.valueOf(2000000)).build();
    Account acc2 = new AccountBuilder().name("acc2").build();
    Transaction tx1 = new TransactionBuilder().sender(acc1).receiver(acc2).value(BigInteger.valueOf(1000000)).build();
    Account acc3 = new AccountBuilder(world).name("acc3").balance(Coin.valueOf(2000000)).build();
    Account acc4 = new AccountBuilder().name("acc4").build();
    Transaction tx2 = new TransactionBuilder().sender(acc3).receiver(acc4).value(BigInteger.valueOf(500000)).build();
    Account acc5 = new AccountBuilder(world).name("acc5").balance(Coin.valueOf(2000000)).build();
    Account acc6 = new AccountBuilder().name("acc6").build();
    Transaction tx3 = new TransactionBuilder().sender(acc5).receiver(acc6).value(BigInteger.valueOf(800000)).build();
    List<Transaction> txs = new ArrayList<>();
    txs.add(tx1);
    txs.add(tx2);
    Block block = mock(Block.class);
    when(block.getTransactionsList()).thenReturn(txs);
    when(block.getHash()).thenReturn(new Keccak256(Hex.decode("0246c165ac839255aab76c1bc3df7842673ee3673e20dd908bba60862cf41326")));
    ReceiptStore receiptStore = mock(ReceiptStore.class);
    byte[] rskBlockHash = new byte[] { 0x2 };
    when(receiptStore.get(tx1.getHash().getBytes(), block.getHash().getBytes())).thenReturn(Optional.of(new TransactionInfo(new TransactionReceipt(), rskBlockHash, 0)));
    when(receiptStore.get(tx2.getHash().getBytes(), block.getHash().getBytes())).thenReturn(Optional.of(new TransactionInfo(new TransactionReceipt(), rskBlockHash, 0)));
    when(receiptStore.get(tx3.getHash().getBytes(), block.getHash().getBytes())).thenReturn(Optional.of(new TransactionInfo(new TransactionReceipt(), rskBlockHash, 0)));
    // Tx3 is not part of the transaction list of the block
    List<Trie> trie = BlockHashesHelper.calculateReceiptsTrieRootFor(block, receiptStore, tx3.getHash());
    assertNull(trie);
}
Also used : Account(org.ethereum.core.Account) ArrayList(java.util.ArrayList) TransactionReceipt(org.ethereum.core.TransactionReceipt) TransactionBuilder(co.rsk.test.builders.TransactionBuilder) Keccak256(co.rsk.crypto.Keccak256) World(co.rsk.test.World) Transaction(org.ethereum.core.Transaction) Block(org.ethereum.core.Block) TransactionInfo(org.ethereum.db.TransactionInfo) AccountBuilder(co.rsk.test.builders.AccountBuilder) Trie(co.rsk.trie.Trie) 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