Search in sources :

Example 51 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 52 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 53 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 54 with Account

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

the class TransactionBuilder method buildRandomTransaction.

/**
 * Generates a random transaction
 */
public Transaction buildRandomTransaction() {
    int i = new Random().nextInt();
    BigInteger randomPositiveVal = i > 0 ? BigInteger.valueOf(i) : BigInteger.valueOf(i * -1);
    Account receiver = new AccountBuilder().name("account" + randomPositiveVal).build();
    String to = receiver.getAddress().toHexString();
    BigInteger nonce = randomPositiveVal;
    BigInteger gasLimit = randomPositiveVal;
    BigInteger gasPrice = randomPositiveVal;
    // should be a random valid one
    byte chainId = Constants.REGTEST_CHAIN_ID;
    byte[] data = randomPositiveVal.toByteArray();
    BigInteger value = randomPositiveVal;
    byte[] privateKey = ECKey.fromPrivate(randomPositiveVal).getPrivKeyBytes();
    return build(to, nonce, gasLimit, gasPrice, chainId, data, value, privateKey, false);
}
Also used : Account(org.ethereum.core.Account) Random(java.util.Random) BigInteger(java.math.BigInteger)

Example 55 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);
    RepositorySnapshot repository = world.getRepositoryLocator().snapshotAt(world.getBlockChain().getBestBlock().getHeader());
    Assert.assertEquals(new BigInteger("1000000"), repository.getBalance(account.getAddress()).asBigInteger());
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Account(org.ethereum.core.Account) RepositorySnapshot(co.rsk.db.RepositorySnapshot) DslParser(co.rsk.test.dsl.DslParser) BigInteger(java.math.BigInteger) World(co.rsk.test.World) Test(org.junit.Test)

Aggregations

Account (org.ethereum.core.Account)62 Test (org.junit.Test)34 Transaction (org.ethereum.core.Transaction)26 AccountBuilder (co.rsk.test.builders.AccountBuilder)22 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)16 World (co.rsk.test.World)15 DslParser (co.rsk.test.dsl.DslParser)11 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)11 BigInteger (java.math.BigInteger)10 RskAddress (co.rsk.core.RskAddress)5 RepositorySnapshot (co.rsk.db.RepositorySnapshot)5 Block (org.ethereum.core.Block)5 Repository (org.ethereum.core.Repository)5 ReceiptStore (org.ethereum.db.ReceiptStore)5 ECKey (org.ethereum.crypto.ECKey)4 Coin (co.rsk.core.Coin)3 Keccak256 (co.rsk.crypto.Keccak256)3 Trie (co.rsk.trie.Trie)3 ArrayList (java.util.ArrayList)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2