Search in sources :

Example 46 with Transaction

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

the class TransactionResultDTOTest method remascAddressSerialization.

@Test
public void remascAddressSerialization() {
    Block b = mock(Block.class);
    Integer index = 42;
    Transaction tx = mock(Transaction.class);
    when(tx.getHash()).thenReturn(new Keccak256(TestUtils.randomBytes(32)));
    when(tx.getSender()).thenReturn(RemascTransaction.REMASC_ADDRESS);
    when(tx.getReceiveAddress()).thenReturn(TestUtils.randomAddress());
    when(tx.getGasPrice()).thenReturn(Coin.valueOf(42));
    when(tx.getValue()).thenReturn(Coin.ZERO);
    when(tx.getData()).thenReturn(TestUtils.randomBytes(2));
    TransactionResultDTO dto = new TransactionResultDTO(b, index, tx);
    assertThat(dto.from, is("0x0000000000000000000000000000000000000000"));
}
Also used : RemascTransaction(co.rsk.remasc.RemascTransaction) Transaction(org.ethereum.core.Transaction) Block(org.ethereum.core.Block) Keccak256(co.rsk.crypto.Keccak256) Test(org.junit.Test)

Example 47 with Transaction

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

the class TransactionFactoryHelper method createSampleTransactionWithData.

public static Transaction createSampleTransactionWithData(int from, int nonce, String data) {
    Account sender = createAccount(from);
    Transaction tx = new TransactionBuilder().sender(sender).receiverAddress(new byte[0]).nonce(nonce).data(data).gasLimit(BigInteger.valueOf(1000000)).build();
    return tx;
}
Also used : Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) TransactionBuilder(co.rsk.test.builders.TransactionBuilder)

Example 48 with Transaction

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

the class DslFilesTest method runCreate01Resource.

@Test
public void runCreate01Resource() throws FileNotFoundException, DslProcessorException {
    DslParser parser = DslParser.fromResource("dsl/create01.txt");
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    processor.processCommands(parser);
    Transaction transaction = world.getTransactionByName("tx01");
    Assert.assertNotNull(transaction);
    TransactionInfo txinfo = world.getBlockChain().getTransactionInfo(transaction.getHash().getBytes());
    Assert.assertNotNull(txinfo);
    BigInteger gasUsed = BigIntegers.fromUnsignedByteArray(txinfo.getReceipt().getGasUsed());
    Assert.assertNotEquals(BigInteger.ZERO, gasUsed);
    // According to TestRPC and geth, the gas used is 0x010c2d
    Assert.assertEquals(BigIntegers.fromUnsignedByteArray(Hex.decode("010c2d")), gasUsed);
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Transaction(org.ethereum.core.Transaction) DslParser(co.rsk.test.dsl.DslParser) TransactionInfo(org.ethereum.db.TransactionInfo) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 49 with Transaction

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

the class WorldDslProcessorTest method processTransactionBuildCommand.

@Test
public void processTransactionBuildCommand() throws DslProcessorException {
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    DslParser parser = new DslParser("account_new acc1\naccount_new acc2\ntransaction_build tx01\nsender acc1\nreceiver acc2\nvalue 1000\nbuild");
    processor.processCommands(parser);
    Account acc1 = world.getAccountByName("acc1");
    Account acc2 = world.getAccountByName("acc2");
    Assert.assertNotNull(acc1);
    Assert.assertNotNull(acc2);
    Transaction tx01 = world.getTransactionByName("tx01");
    Assert.assertNotNull(tx01);
    Assert.assertArrayEquals(acc1.getAddress().getBytes(), tx01.getSender().getBytes());
    Assert.assertArrayEquals(acc2.getAddress().getBytes(), tx01.getReceiveAddress().getBytes());
    Assert.assertEquals(new BigInteger("1000"), tx01.getValue().asBigInteger());
    Assert.assertNotNull(tx01.getData());
    Assert.assertEquals(0, tx01.getData().length);
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) DslParser(co.rsk.test.dsl.DslParser) BigInteger(java.math.BigInteger) World(co.rsk.test.World) Test(org.junit.Test)

Example 50 with Transaction

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

the class WorldDslProcessorTest method processTransactionWithGasAndGasPriceBuildCommand.

@Test
public void processTransactionWithGasAndGasPriceBuildCommand() throws DslProcessorException {
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    DslParser parser = new DslParser("account_new acc1\naccount_new acc2\ntransaction_build tx01\nsender acc1\nreceiver acc2\nvalue 1000\ngas 1200000\ngasPrice 2\nbuild");
    processor.processCommands(parser);
    Account acc1 = world.getAccountByName("acc1");
    Account acc2 = world.getAccountByName("acc2");
    Assert.assertNotNull(acc1);
    Assert.assertNotNull(acc2);
    Transaction tx01 = world.getTransactionByName("tx01");
    Assert.assertNotNull(tx01);
    Assert.assertArrayEquals(acc1.getAddress().getBytes(), tx01.getSender().getBytes());
    Assert.assertArrayEquals(acc2.getAddress().getBytes(), tx01.getReceiveAddress().getBytes());
    Assert.assertEquals(new BigInteger("1000"), tx01.getValue().asBigInteger());
    Assert.assertNotNull(tx01.getData());
    Assert.assertEquals(0, tx01.getData().length);
    Assert.assertEquals(new BigInteger("2"), tx01.getGasPrice().asBigInteger());
    Assert.assertEquals(new BigInteger("1200000"), tx01.getGasLimitAsInteger());
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) DslParser(co.rsk.test.dsl.DslParser) BigInteger(java.math.BigInteger) World(co.rsk.test.World) Test(org.junit.Test)

Aggregations

Transaction (org.ethereum.core.Transaction)131 Test (org.junit.Test)82 BigInteger (java.math.BigInteger)33 Coin (co.rsk.core.Coin)23 Account (org.ethereum.core.Account)20 ArrayList (java.util.ArrayList)17 Block (org.ethereum.core.Block)17 RskAddress (co.rsk.core.RskAddress)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Repository (org.ethereum.core.Repository)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 AccountState (org.ethereum.core.AccountState)10 RemascTransaction (co.rsk.remasc.RemascTransaction)9 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)9 ImmutableTransaction (org.ethereum.core.ImmutableTransaction)8 ECKey (org.ethereum.crypto.ECKey)8 Keccak256 (co.rsk.crypto.Keccak256)7 AccountBuilder (co.rsk.test.builders.AccountBuilder)7 DslParser (co.rsk.test.dsl.DslParser)6 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)6