Search in sources :

Example 26 with Account

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

the class WalletTest method addAccountWithRandomPrivateKey.

@Test
public void addAccountWithRandomPrivateKey() {
    Wallet wallet = WalletFactory.createWallet();
    byte[] address = wallet.addAccount().getBytes();
    Assert.assertNotNull(address);
    Account account = wallet.getAccount(new RskAddress(address));
    Assert.assertNotNull(account);
    Assert.assertArrayEquals(address, account.getAddress().getBytes());
}
Also used : Account(org.ethereum.core.Account) Test(org.junit.Test)

Example 27 with Account

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

the class Wallet method addAccount.

public RskAddress addAccount() {
    Account account = new Account(new ECKey());
    saveAccount(account);
    return account.getAddress();
}
Also used : Account(org.ethereum.core.Account) ECKey(org.ethereum.crypto.ECKey)

Example 28 with Account

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

the class WriterMessageRecorderTest method createEthMessage.

public static Message createEthMessage() {
    Account acc1 = new AccountBuilder().name("acc1").build();
    Account acc2 = new AccountBuilder().name("acc2").build();
    Transaction tx = new co.rsk.test.builders.TransactionBuilder().sender(acc1).receiver(acc2).value(BigInteger.valueOf(1000000)).build();
    return new TransactionsMessage(config, tx);
}
Also used : Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) TransactionsMessage(org.ethereum.net.eth.message.TransactionsMessage) AccountBuilder(co.rsk.test.builders.AccountBuilder)

Example 29 with Account

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

the class TransactionPoolImplTest method addAndExecuteTwoPendingTransaction.

@Test
public void addAndExecuteTwoPendingTransaction() {
    BlockChainImpl blockchain = createBlockchain();
    Coin balance = Coin.valueOf(1000000);
    TransactionPoolImpl transactionPool = createSampleNewTransactionPoolWithAccounts(2, balance, blockchain);
    transactionPool.processBest(blockchain.getBestBlock());
    Transaction tx1 = createSampleTransaction(1, 2, 1000, 0);
    Transaction tx2 = createSampleTransaction(1, 2, 3000, 1);
    Account receiver = createAccount(2);
    transactionPool.addTransaction(tx1);
    transactionPool.addTransaction(tx2);
    Repository repository = transactionPool.getRepository();
    Assert.assertEquals(BigInteger.valueOf(1004000), repository.getBalance(receiver.getAddress()).asBigInteger());
}
Also used : Coin(co.rsk.core.Coin) Account(org.ethereum.core.Account) Repository(org.ethereum.core.Repository) Transaction(org.ethereum.core.Transaction) Test(org.junit.Test)

Example 30 with Account

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

the class TransactionPoolImplTest method createSampleNewTransactionPoolWithAccounts.

private static TransactionPoolImpl createSampleNewTransactionPoolWithAccounts(int naccounts, Coin balance, BlockChainImpl blockChain) {
    Block best = blockChain.getStatus().getBestBlock();
    Repository repository = blockChain.getRepository();
    Repository track = repository.startTracking();
    for (int k = 1; k <= naccounts; k++) {
        Account account = createAccount(k);
        track.createAccount(account.getAddress());
        track.addBalance(account.getAddress(), balance);
    }
    track.commit();
    best.setStateRoot(repository.getRoot());
    best.flushRLP();
    TransactionPoolImpl transactionPool = new TransactionPoolImpl(config, blockChain.getRepository(), blockChain.getBlockStore(), null, new ProgramInvokeFactoryImpl(), new BlockExecutorTest.SimpleEthereumListener(), 10, 100);
    blockChain.setTransactionPool(transactionPool);
    return transactionPool;
}
Also used : Account(org.ethereum.core.Account) Repository(org.ethereum.core.Repository) Block(org.ethereum.core.Block) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)

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