Search in sources :

Example 31 with Account

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

the class WalletTest method addAccountWithPassphraseAndTwoAccountsWithSeed.

@Test
public void addAccountWithPassphraseAndTwoAccountsWithSeed() {
    Wallet wallet = WalletFactory.createWallet();
    RskAddress addr1 = wallet.addAccount("passphrase");
    Assert.assertNotNull(addr1);
    byte[] address2 = wallet.addAccountWithSeed("seed");
    Assert.assertNotNull(address2);
    byte[] address3 = wallet.addAccountWithSeed("seed2");
    Assert.assertNotNull(address3);
    List<byte[]> addresses = wallet.getAccountAddresses();
    Assert.assertNotNull(addresses);
    Assert.assertFalse(addresses.isEmpty());
    Assert.assertEquals(3, addresses.size());
    byte[] addr = addresses.get(0);
    Assert.assertNotNull(addr);
    Assert.assertArrayEquals(address2, addr);
    addr = addresses.get(1);
    Assert.assertNotNull(addr);
    Assert.assertArrayEquals(address3, addr);
    addr = addresses.get(2);
    Assert.assertNotNull(addr);
    Assert.assertArrayEquals(addr1.getBytes(), addr);
    Account account = wallet.getAccount(addr1, "passphrase");
    Assert.assertNotNull(account);
    Assert.assertEquals(addr1, account.getAddress());
}
Also used : Account(org.ethereum.core.Account) Test(org.junit.Test)

Example 32 with Account

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

the class WalletTest method unlockAccountWithPassphrase.

@Test
public void unlockAccountWithPassphrase() {
    Wallet wallet = WalletFactory.createWallet();
    byte[] address = wallet.addAccount("passphrase").getBytes();
    Assert.assertNotNull(address);
    List<byte[]> addresses = wallet.getAccountAddresses();
    Assert.assertNotNull(addresses);
    Assert.assertFalse(addresses.isEmpty());
    Assert.assertEquals(1, addresses.size());
    byte[] addr = addresses.get(0);
    Assert.assertNotNull(addr);
    Assert.assertArrayEquals(address, addr);
    Account account0 = wallet.getAccount(new RskAddress(address));
    Assert.assertNull(account0);
    Assert.assertTrue(wallet.unlockAccount(new RskAddress(address), "passphrase"));
    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 33 with Account

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

the class WalletTest method addAccountWithPassphraseAndWithSeed.

@Test
public void addAccountWithPassphraseAndWithSeed() {
    Wallet wallet = WalletFactory.createWallet();
    RskAddress addr1 = wallet.addAccount("passphrase");
    Assert.assertNotNull(addr1);
    byte[] address2 = wallet.addAccountWithSeed("seed");
    Assert.assertNotNull(address2);
    List<byte[]> addresses = wallet.getAccountAddresses();
    Assert.assertNotNull(addresses);
    Assert.assertFalse(addresses.isEmpty());
    Assert.assertEquals(2, addresses.size());
    byte[] addr = addresses.get(0);
    Assert.assertNotNull(addr);
    Assert.assertArrayEquals(address2, addr);
    addr = addresses.get(1);
    Assert.assertNotNull(addr);
    Assert.assertArrayEquals(addr1.getBytes(), addr);
    Account account = wallet.getAccount(addr1, "passphrase");
    Assert.assertNotNull(account);
    Assert.assertEquals(addr1, account.getAddress());
}
Also used : Account(org.ethereum.core.Account) Test(org.junit.Test)

Example 34 with Account

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

the class TxPoolModuleImplTest method createSampleTransaction.

private Transaction createSampleTransaction(int from, int to, long value, int nonce) {
    Account sender = getAccount(from);
    Account receiver = getAccount(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 35 with Account

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

the class TransactionFactoryHelper method createSampleTransaction.

public static Transaction createSampleTransaction(long nonce) {
    Account sender = new AccountBuilder().name("sender").build();
    Account receiver = new AccountBuilder().name("receiver").build();
    Transaction tx = new TransactionBuilder().nonce(nonce).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)

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