use of org.ethereum.core.Account in project rskj by rsksmart.
the class WorldDslProcessor method processAssertBalanceCommand.
private void processAssertBalanceCommand(DslCommand cmd) throws DslProcessorException {
String accountName = cmd.getArgument(0);
Coin expected = new Coin(new BigInteger(cmd.getArgument(1)));
RskAddress accountAddress;
Account account = world.getAccountByName(accountName);
if (account != null)
accountAddress = account.getAddress();
else {
Transaction tx = world.getTransactionByName(accountName);
if (tx != null)
accountAddress = tx.getContractAddress();
else
accountAddress = new RskAddress(accountName);
}
Coin accountBalance = world.getRepository().getBalance(accountAddress);
if (expected.equals(accountBalance))
return;
throw new DslProcessorException(String.format("Expected account '%s' with balance '%s', but got '%s'", accountName, expected, accountBalance));
}
use of org.ethereum.core.Account in project rskj by rsksmart.
the class WorldDslProcessorTest method processAccountNewCommandWithBalance.
@Test
public void processAccountNewCommandWithBalance() throws DslProcessorException {
World world = new World();
WorldDslProcessor processor = new WorldDslProcessor(world);
DslParser parser = new DslParser("account_new acc1 1000000");
processor.processCommands(parser);
Account account = world.getAccountByName("acc1");
Assert.assertNotNull(account);
Assert.assertEquals(new BigInteger("1000000"), world.getRepository().getBalance(account.getAddress()).asBigInteger());
}
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 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 RskSystemProperties method coinbaseAddress.
@Nullable
public RskAddress coinbaseAddress() {
if (!isMinerServerEnabled()) {
return RskAddress.nullAddress();
}
// validity checks are performed by localCoinbaseAccount
Account account = localCoinbaseAccount();
if (account != null) {
return account.getAddress();
}
String coinbaseAddress = configFromFiles.getString(MINER_REWARD_ADDRESS_CONFIG);
if (coinbaseAddress.length() != Constants.getMaxAddressByteLength() * 2) {
throw new RskConfigurationException(MINER_REWARD_ADDRESS_CONFIG + " needs to be Hex encoded and 20 byte length");
}
return new RskAddress(coinbaseAddress);
}
Aggregations