Search in sources :

Example 56 with Account

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

the class WorldDslProcessorTest method processTransactionWithDataBuildCommand.

@Test
public void processTransactionWithDataBuildCommand() 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\ndata 01020304\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.assertArrayEquals(new byte[] { 0x01, 0x02, 0x03, 0x04 }, tx01.getData());
}
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 57 with Account

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

the class WorldDslProcessorTest method processAccountNewCommandWithBalanceAndCodeWithOtherAccountAddress.

@Test
public void processAccountNewCommandWithBalanceAndCodeWithOtherAccountAddress() throws DslProcessorException {
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    DslParser parser0 = new DslParser("account_new acc0");
    processor.processCommands(parser0);
    DslParser parser = new DslParser("account_new acc1 1000000 0102[acc0]0304");
    processor.processCommands(parser);
    Account account0 = world.getAccountByName("acc0");
    Account account = world.getAccountByName("acc1");
    Assert.assertNotNull(account);
    RepositorySnapshot repository = world.getRepositoryLocator().snapshotAt(world.getBlockChain().getBestBlock().getHeader());
    Assert.assertEquals(new BigInteger("1000000"), repository.getBalance(account.getAddress()).asBigInteger());
    byte[] code = repository.getCode(account.getAddress());
    byte[] expected = new byte[4 + 20];
    expected[0] = 0x01;
    expected[1] = 0x02;
    System.arraycopy(account0.getAddress().getBytes(), 0, expected, 2, Address.LENGTH);
    expected[22] = 0x03;
    expected[23] = 0x04;
    Assert.assertNotNull(code);
    Assert.assertArrayEquals(expected, code);
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Account(org.ethereum.core.Account) RepositorySnapshot(co.rsk.db.RepositorySnapshot) DslParser(co.rsk.test.dsl.DslParser) BigInteger(java.math.BigInteger) World(co.rsk.test.World) Test(org.junit.Test)

Example 58 with Account

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

the class WorldDslProcessorTest method processTransactionWithNonceBuildCommand.

@Test
public void processTransactionWithNonceBuildCommand() 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\nnonce 10\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("10"), tx01.getNonceAsInteger());
}
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 59 with Account

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

the class WriterMessageRecorderTest method createEthMessage.

public static Message createEthMessage() {
    Account acc1 = new AccountBuilder().name("acc1").build();
    Account acc2 = new AccountBuilder().name("acc2").build();
    Transaction tx = new co.rsk.test.builders.TransactionBuilder().sender(acc1).receiver(acc2).value(BigInteger.valueOf(1000000)).build();
    return new TransactionsMessage(config, tx);
}
Also used : Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) TransactionsMessage(org.ethereum.net.eth.message.TransactionsMessage) AccountBuilder(co.rsk.test.builders.AccountBuilder)

Example 60 with Account

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

the class TransactionPoolImplTest method addAndExecuteTwoPendingTransaction.

@Test
public void addAndExecuteTwoPendingTransaction() {
    BlockChainImpl blockchain = createBlockchain();
    Coin balance = Coin.valueOf(1000000);
    TransactionPoolImpl transactionPool = createSampleNewTransactionPoolWithAccounts(2, balance, blockchain);
    transactionPool.processBest(blockchain.getBestBlock());
    Transaction tx1 = createSampleTransaction(1, 2, 1000, 0);
    Transaction tx2 = createSampleTransaction(1, 2, 3000, 1);
    Account receiver = createAccount(2);
    transactionPool.addTransaction(tx1);
    transactionPool.addTransaction(tx2);
    Repository repository = transactionPool.getRepository();
    Assert.assertEquals(BigInteger.valueOf(1004000), 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)

Aggregations

Account (org.ethereum.core.Account)62 Test (org.junit.Test)34 Transaction (org.ethereum.core.Transaction)26 AccountBuilder (co.rsk.test.builders.AccountBuilder)22 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)16 World (co.rsk.test.World)15 DslParser (co.rsk.test.dsl.DslParser)11 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)11 BigInteger (java.math.BigInteger)10 RskAddress (co.rsk.core.RskAddress)5 RepositorySnapshot (co.rsk.db.RepositorySnapshot)5 Block (org.ethereum.core.Block)5 Repository (org.ethereum.core.Repository)5 ReceiptStore (org.ethereum.db.ReceiptStore)5 ECKey (org.ethereum.crypto.ECKey)4 Coin (co.rsk.core.Coin)3 Keccak256 (co.rsk.crypto.Keccak256)3 Trie (co.rsk.trie.Trie)3 ArrayList (java.util.ArrayList)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2