Search in sources :

Example 16 with Account

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

the class WorldDslProcessorTest method processAccountNewCommand.

@Test
public void processAccountNewCommand() throws DslProcessorException {
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    DslParser parser = new DslParser("account_new acc1");
    processor.processCommands(parser);
    Account account = world.getAccountByName("acc1");
    Assert.assertNotNull(account);
    Assert.assertEquals(BigInteger.ZERO, 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) World(co.rsk.test.World) Test(org.junit.Test)

Example 17 with Account

use of org.ethereum.core.Account 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 18 with Account

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

the class WorldDslProcessorTest method processAssertBalance.

@Test
public void processAssertBalance() throws DslProcessorException {
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    DslParser parser = new DslParser("account_new acc1 1000\nassert_balance acc1 1000\n");
    processor.processCommands(parser);
    Account account = world.getAccountByName("acc1");
    Assert.assertNotNull(account);
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Account(org.ethereum.core.Account) DslParser(co.rsk.test.dsl.DslParser) World(co.rsk.test.World) Test(org.junit.Test)

Example 19 with Account

use of org.ethereum.core.Account 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)

Example 20 with Account

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

the class EthModuleWalletEnabled method sendTransaction.

@Override
public synchronized String sendTransaction(Web3.CallArguments args) {
    Account account = this.getAccount(args.from);
    String s = null;
    try {
        if (account == null) {
            throw new JsonRpcInvalidParamException("From address private key could not be found in this node");
        }
        String toAddress = args.to != null ? Hex.toHexString(stringHexToByteArray(args.to)) : null;
        BigInteger value = args.value != null ? TypeConverter.stringNumberAsBigInt(args.value) : BigInteger.ZERO;
        BigInteger gasPrice = args.gasPrice != null ? TypeConverter.stringNumberAsBigInt(args.gasPrice) : BigInteger.ZERO;
        BigInteger gasLimit = args.gas != null ? TypeConverter.stringNumberAsBigInt(args.gas) : BigInteger.valueOf(GasCost.TRANSACTION_DEFAULT);
        if (args.data != null && args.data.startsWith("0x")) {
            args.data = args.data.substring(2);
        }
        synchronized (transactionPool) {
            BigInteger accountNonce = args.nonce != null ? TypeConverter.stringNumberAsBigInt(args.nonce) : transactionPool.getRepository().getNonce(account.getAddress());
            Transaction tx = Transaction.create(config, toAddress, value, accountNonce, gasPrice, gasLimit, args.data);
            tx.sign(account.getEcKey().getPrivKeyBytes());
            eth.submitTransaction(tx.toImmutableTransaction());
            s = tx.getHash().toJsonString();
        }
        return s;
    } finally {
        LOGGER.debug("eth_sendTransaction({}): {}", args, s);
    }
}
Also used : Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) BigInteger(java.math.BigInteger) JsonRpcInvalidParamException(org.ethereum.rpc.exception.JsonRpcInvalidParamException)

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