Search in sources :

Example 41 with Account

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));
}
Also used : Coin(co.rsk.core.Coin) Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger)

Example 42 with Account

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());
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Account(org.ethereum.core.Account) DslParser(co.rsk.test.dsl.DslParser) BigInteger(java.math.BigInteger) World(co.rsk.test.World) Test(org.junit.Test)

Example 43 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 44 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 45 with Account

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);
}
Also used : Account(org.ethereum.core.Account) RskAddress(co.rsk.core.RskAddress) Nullable(javax.annotation.Nullable)

Aggregations

Account (org.ethereum.core.Account)49 Test (org.junit.Test)29 Transaction (org.ethereum.core.Transaction)20 AccountBuilder (co.rsk.test.builders.AccountBuilder)14 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)10 BigInteger (java.math.BigInteger)9 World (co.rsk.test.World)8 Coin (co.rsk.core.Coin)7 DslParser (co.rsk.test.dsl.DslParser)7 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)7 Repository (org.ethereum.core.Repository)7 RskAddress (co.rsk.core.RskAddress)5 ECKey (org.ethereum.crypto.ECKey)4 Block (org.ethereum.core.Block)2 BlockDifficulty (co.rsk.core.BlockDifficulty)1 Nullable (javax.annotation.Nullable)1 Bloom (org.ethereum.core.Bloom)1 ImmutableTransaction (org.ethereum.core.ImmutableTransaction)1 TransactionsMessage (org.ethereum.net.eth.message.TransactionsMessage)1 JsonRpcInvalidParamException (org.ethereum.rpc.exception.JsonRpcInvalidParamException)1