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