Search in sources :

Example 1 with Transaction

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()));
}
Also used : Transaction(org.ethereum.core.Transaction) BigInteger(java.math.BigInteger) SimpleEthereum(org.ethereum.rpc.Simples.SimpleEthereum) Test(org.junit.Test)

Example 2 with Transaction

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()));
}
Also used : Transaction(org.ethereum.core.Transaction) TransactionsMessage(org.ethereum.net.eth.message.TransactionsMessage) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with Transaction

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()));
}
Also used : Transaction(org.ethereum.core.Transaction) TransactionsMessage(org.ethereum.net.eth.message.TransactionsMessage) BigInteger(java.math.BigInteger) ECKey(org.ethereum.crypto.ECKey) Test(org.junit.Test)

Example 4 with Transaction

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

Example 5 with Transaction

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]}");
}
Also used : LogFilterElement(org.ethereum.rpc.LogFilterElement) LogInfo(org.ethereum.vm.LogInfo) Transaction(org.ethereum.core.Transaction) ArrayList(java.util.ArrayList) Block(org.ethereum.core.Block) DataWord(org.ethereum.vm.DataWord) Keccak256(co.rsk.crypto.Keccak256) 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