Search in sources :

Example 36 with Account

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

the class TransactionFactoryHelper method createSampleTransaction.

public static Transaction createSampleTransaction(int from, int to, long value, int nonce) {
    Account sender = createAccount(from);
    Account receiver = createAccount(to);
    Transaction tx = new TransactionBuilder().sender(sender).receiver(receiver).nonce(nonce).value(BigInteger.valueOf(value)).build();
    return tx;
}
Also used : Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) TransactionBuilder(co.rsk.test.builders.TransactionBuilder)

Example 37 with Account

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

the class WorldTest method saveAndGetAccount.

@Test
public void saveAndGetAccount() {
    World world = new World();
    Account account = new Account(new ECKey(Utils.getRandom()));
    world.saveAccount("acc1", account);
    Assert.assertSame(account, world.getAccountByName("acc1"));
}
Also used : Account(org.ethereum.core.Account) ECKey(org.ethereum.crypto.ECKey) Test(org.junit.Test)

Example 38 with Account

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

the class AccountBuilderTest method createAccountWithNameAsSeed.

@Test
public void createAccountWithNameAsSeed() {
    Account account = new AccountBuilder().name("acc1").build();
    Assert.assertNotNull(account);
    Assert.assertTrue(account.getEcKey().hasPrivKey());
}
Also used : Account(org.ethereum.core.Account) AccountBuilder(co.rsk.test.builders.AccountBuilder) Test(org.junit.Test)

Example 39 with Account

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

the class TransactionBuilderTest method buildTransaction.

@Test
public void buildTransaction() {
    Account sender = new AccountBuilder().name("sender").build();
    Account receiver = new AccountBuilder().name("receiver").build();
    Transaction tx = new TransactionBuilder().sender(sender).receiver(receiver).value(BigInteger.TEN).nonce(2).build();
    Assert.assertNotNull(tx);
    Assert.assertArrayEquals(sender.getAddress().getBytes(), tx.getSender().getBytes());
    Assert.assertArrayEquals(receiver.getAddress().getBytes(), tx.getReceiveAddress().getBytes());
    Assert.assertEquals(BigInteger.TEN, tx.getValue().asBigInteger());
    Assert.assertEquals(BigInteger.ONE, tx.getGasPrice().asBigInteger());
    Assert.assertEquals(BigInteger.valueOf(2), new BigInteger(1, tx.getNonce()));
    Assert.assertEquals(BigInteger.valueOf(21000), new BigInteger(1, tx.getGasLimit()));
    Assert.assertNotNull(tx.getData());
    Assert.assertEquals(0, tx.getData().length);
}
Also used : Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) TransactionBuilder(co.rsk.test.builders.TransactionBuilder) BigInteger(java.math.BigInteger) AccountBuilder(co.rsk.test.builders.AccountBuilder) Test(org.junit.Test)

Example 40 with Account

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

the class WorldDslProcessor method processAccountNewCommand.

private void processAccountNewCommand(DslCommand cmd) {
    AccountBuilder builder = new AccountBuilder(world);
    String name = cmd.getArgument(0);
    builder.name(name);
    if (cmd.getArity() > 1)
        builder.balance(new Coin(new BigInteger(cmd.getArgument(1))));
    Account account = builder.build();
    world.saveAccount(name, account);
}
Also used : Coin(co.rsk.core.Coin) Account(org.ethereum.core.Account) BigInteger(java.math.BigInteger) AccountBuilder(co.rsk.test.builders.AccountBuilder)

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