use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class TxBuilderTest method createBasicTransaction.
@Test
public void createBasicTransaction() {
SimpleEthereum rsk = new SimpleEthereum();
TxBuilder builder = new TxBuilder(config, rsk, null, (Repository) rsk.repository);
BigInteger gasPrice = BigInteger.ONE;
BigInteger gasLimit = BigInteger.valueOf(21000);
BigInteger nonce = BigInteger.TEN;
Transaction tx = builder.createNewTransaction(gasPrice, gasLimit, nonce);
Assert.assertEquals(gasLimit, new BigInteger(1, tx.getGasLimit()));
Assert.assertEquals(gasPrice, tx.getGasPrice().asBigInteger());
Assert.assertEquals(nonce, new BigInteger(1, tx.getNonce()));
}
use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class TransactionsMessageTest method test_1.
/* TRANSACTIONS */
@Ignore
@Test
public /* Transactions message 1 */
void test_1() {
String txsPacketRaw = "f86e12f86b04648609184e72a00094cd2a3d9f938e13cd947ec05abc7fe734df8dd826" + "881bc16d674ec80000801ba05c89ebf2b77eeab88251e553f6f9d53badc1d800" + "bbac02d830801c2aa94a4c9fa00b7907532b1f29c79942b75fff98822293bf5f" + "daa3653a8d9f424c6a3265f06c";
byte[] payload = Hex.decode(txsPacketRaw);
TransactionsMessage transactionsMessage = new TransactionsMessage(config, payload);
System.out.println(transactionsMessage);
assertEquals(EthMessageCodes.TRANSACTIONS, transactionsMessage.getCommand());
assertEquals(1, transactionsMessage.getTransactions().size());
Transaction tx = transactionsMessage.getTransactions().iterator().next();
assertEquals("5d2aee0490a9228024158433d650335116b4af5a30b8abb10e9b7f9f7e090fd8", tx.getHash().toHexString());
assertEquals("04", Hex.toHexString(tx.getNonce()));
assertEquals("1bc16d674ec80000", Hex.toHexString(tx.getValue().getBytes()));
assertEquals("cd2a3d9f938e13cd947ec05abc7fe734df8dd826", tx.getReceiveAddress().toString());
assertEquals("64", Hex.toHexString(tx.getGasPrice().getBytes()));
assertEquals("09184e72a000", Hex.toHexString(tx.getGasLimit()));
assertEquals("", ByteUtil.toHexString(tx.getData()));
assertEquals("1b", Hex.toHexString(new byte[] { tx.getSignature().v }));
assertEquals("5c89ebf2b77eeab88251e553f6f9d53badc1d800bbac02d830801c2aa94a4c9f", Hex.toHexString(tx.getSignature().r.toByteArray()));
assertEquals("0b7907532b1f29c79942b75fff98822293bf5fdaa3653a8d9f424c6a3265f06c", Hex.toHexString(tx.getSignature().s.toByteArray()));
}
use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class TransactionsMessageTest method test_3.
@Test
public /* Transactions msg encode */
void test_3() throws Exception {
String expected = "f872f870808609184e72a0008242559479b08ad8787060333663d19704909ee7b1903e588b00d3c21bcecceda1000000801ca07c3f47d609d453737ddcf7c403190f67432c41e1f26051296b24e4e10a837083a0375fdb6d3b82dae7e1e78aa7d7413d0bfefeb05341058361d2b5a53d9c8783d6";
BigInteger value = new BigInteger("1000000000000000000000000");
byte[] privKey = HashUtil.keccak256("cat".getBytes());
ECKey ecKey = ECKey.fromPrivate(privKey);
byte[] gasPrice = Hex.decode("09184e72a000");
byte[] gasLimit = Hex.decode("4255");
Transaction tx = new Transaction(null, gasPrice, gasLimit, ecKey.getAddress(), value.toByteArray(), null);
tx.sign(privKey);
tx.getEncoded();
TransactionsMessage transactionsMessage = new TransactionsMessage(config, Collections.singletonList(tx));
assertEquals(expected, Hex.toHexString(transactionsMessage.getEncoded()));
}
use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class TransactionPoolImplTest method rejectTransactionPoolTransaction.
@Test
public void rejectTransactionPoolTransaction() {
BlockChainImpl blockchain = createBlockchain();
Coin balance = Coin.valueOf(1000000);
TransactionPoolImpl transactionPool = createSampleNewTransactionPoolWithAccounts(2, balance, blockchain);
transactionPool.processBest(blockchain.getBestBlock());
Transaction tx = createSampleTransaction(1, 2, 1000, 0);
tx.setGasLimit(BigInteger.valueOf(3000001).toByteArray());
Account receiver = createAccount(2);
transactionPool.addTransaction(tx);
Repository repository = transactionPool.getRepository();
Assert.assertEquals(BigInteger.valueOf(1000000), repository.getBalance(receiver.getAddress()).asBigInteger());
}
use of org.ethereum.core.Transaction in project rskj by rsksmart.
the class Web3RskImplTest method web3_LogFilterElement_toString.
@Test
public void web3_LogFilterElement_toString() {
LogInfo logInfo = Mockito.mock(LogInfo.class);
byte[] valueToTest = HashUtil.keccak256(new byte[] { 1 });
Mockito.when(logInfo.getData()).thenReturn(valueToTest);
List<DataWord> topics = new ArrayList<>();
topics.add(new DataWord("c1"));
topics.add(new DataWord("c2"));
Mockito.when(logInfo.getTopics()).thenReturn(topics);
Block block = Mockito.mock(Block.class);
Mockito.when(block.getHash()).thenReturn(new Keccak256(valueToTest));
Mockito.when(block.getNumber()).thenReturn(1L);
int txIndex = 1;
Transaction tx = Mockito.mock(Transaction.class);
byte[] bytes = new byte[32];
bytes[0] = 2;
Mockito.when(tx.getHash()).thenReturn(new Keccak256(bytes));
int logIdx = 5;
LogFilterElement logFilterElement = new LogFilterElement(logInfo, block, txIndex, tx, logIdx);
Assert.assertEquals(logFilterElement.toString(), "LogFilterElement{logIndex='0x5', blockNumber='0x1', blockHash='0x5fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd2', transactionHash='0x0200000000000000000000000000000000000000000000000000000000000000', transactionIndex='0x1', address='0x00', data='0x5fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd2', topics=[0x00000000000000000000000000000000000000000000000000000000000000c1, 0x00000000000000000000000000000000000000000000000000000000000000c2]}");
}
Aggregations