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