Search in sources :

Example 11 with Account

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

the class TxPoolModuleImplTest method createSampleTransaction.

private Transaction createSampleTransaction() {
    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).build();
    return tx;
}
Also used : Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) TransactionBuilder(co.rsk.test.builders.TransactionBuilder) AccountBuilder(co.rsk.test.builders.AccountBuilder)

Example 12 with Account

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

the class BodyResponseMessageTest method createTransaction.

private static Transaction createTransaction(int number) {
    AccountBuilder acbuilder = new AccountBuilder();
    acbuilder.name("sender" + number);
    Account sender = acbuilder.build();
    acbuilder.name("receiver" + number);
    Account receiver = acbuilder.build();
    TransactionBuilder txbuilder = new TransactionBuilder();
    return txbuilder.sender(sender).receiver(receiver).value(BigInteger.valueOf(number * 1000 + 1000)).build();
}
Also used : Account(org.ethereum.core.Account) TransactionBuilder(co.rsk.test.builders.TransactionBuilder) AccountBuilder(co.rsk.test.builders.AccountBuilder)

Example 13 with Account

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

the class TransactionFactoryHelper method createSampleTransactionWithData.

public static Transaction createSampleTransactionWithData(int from, int nonce, String data) {
    Account sender = createAccount(from);
    Transaction tx = new TransactionBuilder().sender(sender).receiverAddress(new byte[0]).nonce(nonce).data(data).gasLimit(BigInteger.valueOf(1000000)).build();
    return tx;
}
Also used : Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) TransactionBuilder(co.rsk.test.builders.TransactionBuilder)

Example 14 with Account

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

the class AccountBuilder method build.

public Account build() {
    byte[] privateKeyBytes = HashUtil.keccak256(name.getBytes());
    ECKey key = ECKey.fromPrivate(privateKeyBytes);
    Account account = new Account(key);
    if (blockChain != null) {
        Block best = blockChain.getStatus().getBestBlock();
        BlockDifficulty td = blockChain.getStatus().getTotalDifficulty();
        Repository repository = blockChain.getRepository();
        Repository track = repository.startTracking();
        track.createAccount(account.getAddress());
        if (this.balance != null)
            track.addBalance(account.getAddress(), this.balance);
        if (this.code != null)
            track.saveCode(account.getAddress(), this.code);
        track.commit();
        best.setStateRoot(repository.getRoot());
        best.flushRLP();
        blockChain.getBlockStore().saveBlock(best, td, true);
    }
    return account;
}
Also used : Account(org.ethereum.core.Account) BlockDifficulty(co.rsk.core.BlockDifficulty) Repository(org.ethereum.core.Repository) Block(org.ethereum.core.Block) ECKey(org.ethereum.crypto.ECKey)

Example 15 with Account

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

the class AccountBuilderTest method createAccountWithBalanceAndCode.

@Test
public void createAccountWithBalanceAndCode() {
    World world = new World();
    byte[] code = new byte[] { 0x01, 0x02, 0x03 };
    Coin balance = Coin.valueOf(10);
    Account account = new AccountBuilder(world).name("acc1").balance(balance).code(code).build();
    Assert.assertNotNull(account);
    Assert.assertTrue(account.getEcKey().hasPrivKey());
    Assert.assertEquals(balance, world.getRepository().getBalance(account.getAddress()));
    Assert.assertArrayEquals(code, world.getRepository().getCode(account.getAddress()));
}
Also used : Coin(co.rsk.core.Coin) Account(org.ethereum.core.Account) AccountBuilder(co.rsk.test.builders.AccountBuilder) World(co.rsk.test.World) Test(org.junit.Test)

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