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;
}
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();
}
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;
}
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;
}
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()));
}
Aggregations