use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.
the class BlockchainIntegrationTest method testSimpleOneTokenBalanceTransfer.
@Test
public void testSimpleOneTokenBalanceTransfer() {
// generate a recipient
final Address receiverAddress = Address.wrap(ByteUtil.hexStringToBytes("CAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE"));
StandaloneBlockchain.Bundle bundle = (new StandaloneBlockchain.Builder()).withValidatorConfiguration("simple").withDefaultAccounts().build();
StandaloneBlockchain bc = bundle.bc;
final ECKey sender = bundle.privateKeys.get(0);
final BigInteger senderInitialBalance = bc.getRepository().getBalance(Address.wrap(sender.getAddress()));
AionTransaction tx = new AionTransaction(BigInteger.valueOf(0).toByteArray(), receiverAddress, BigInteger.valueOf(100).toByteArray(), ByteUtil.EMPTY_BYTE_ARRAY, 21000L, 1L);
tx.sign(sender);
AionBlock block = bc.createNewBlock(bc.getBestBlock(), Collections.singletonList(tx), true);
assertThat(block.getTransactionsList().size()).isEqualTo(1);
assertThat(block.getTransactionsList().get(0)).isEqualTo(tx);
ImportResult connection = bc.tryToConnect(block);
assertThat(connection).isEqualTo(ImportResult.IMPORTED_BEST);
// to be sure, perform some DB tests
IRepository repo = bc.getRepository();
assertThat(repo.getBalance(receiverAddress)).isEqualTo(BigInteger.valueOf(100));
assertThat(repo.getBalance(Address.wrap(sender.getAddress()))).isEqualTo(senderInitialBalance.subtract(BigInteger.valueOf(21000)).subtract(BigInteger.valueOf(100)));
}
use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.
the class BlockchainIntegrationTest method testPruningEnabledBalanceTransfer.
@Ignore
@Test
public void testPruningEnabledBalanceTransfer() {
// generate a recipient
final Address receiverAddress = Address.wrap(ByteUtil.hexStringToBytes("CAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE"));
// generate bc bundle with pruning enabled
StandaloneBlockchain.Bundle bundle = (new StandaloneBlockchain.Builder()).withBlockPruningEnabled().withValidatorConfiguration("simple").withDefaultAccounts().build();
StandaloneBlockchain bc = bundle.bc;
// desginate the first account in our list of private keys as the sender
// (each key in the bundle is preloaded with balance)
final ECKey sender = bundle.privateKeys.get(0);
// generate transaction that transfers 100 tokens from sender to receiver
// pk[0] -> receiverAddress
AionTransaction tx = new AionTransaction(BigInteger.valueOf(0).toByteArray(), receiverAddress, BigInteger.valueOf(100).toByteArray(), ByteUtil.EMPTY_BYTE_ARRAY, 21000L, 1L);
tx.sign(sender);
// create a new block containing a single transaction (tx)
AionBlock block = bc.createNewBlock(bc.getBestBlock(), Collections.singletonList(tx), true);
// import the block to our blockchain
ImportResult connection = bc.tryToConnect(block);
assertThat(connection).isEqualTo(ImportResult.IMPORTED_BEST);
}
use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.
the class PendingTxCacheTest method flushTest1.
@Test
public void flushTest1() {
PendingTxCache cache = new PendingTxCache(1);
List<AionTransaction> txn = getMockTransaction(0, 10, 0);
List<AionTransaction> newCache = new ArrayList<>();
for (ITransaction tx : txn) {
newCache.add(cache.addCacheTx((AionTransaction) tx).get(0));
}
assertTrue(newCache.size() == 10);
Map<Address, BigInteger> map = new HashMap<>();
map.put(Address.wrap(key.get(0).getAddress()), BigInteger.TWO);
newCache = cache.flush(map);
assertTrue(newCache.size() == 1);
Map<BigInteger, AionTransaction> cacheMap = cache.geCacheTx(Address.wrap(key.get(0).getAddress()));
assertTrue(cacheMap.size() == 8);
}
use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.
the class PendingTxCacheTest method getMockBigTransaction.
private List<AionTransaction> getMockBigTransaction(int startNonce, int num, int keyIndex, int size) {
List<AionTransaction> txn = new ArrayList<>();
String data = "";
for (int i = 0; i < size; i++) {
data += "1";
}
for (int i = startNonce; i < startNonce + num; i++) {
AionTransaction tx = new AionTransaction(BigInteger.valueOf(i).toByteArray(), Address.wrap(key.get(keyIndex).getAddress()), Address.wrap("0000000000000000000000000000000000000000000000000000000000000001"), ByteUtils.fromHexString("1"), ByteUtils.fromHexString(data), 10000L, 1L);
tx.sign(key.get(keyIndex));
txn.add(tx);
}
return txn;
}
use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.
the class PendingTxCacheTest method addCacheTxTest4.
@Test
public void addCacheTxTest4() {
PendingTxCache cache = new PendingTxCache(1);
List<AionTransaction> txn = getMockTransaction(0, 10, 0);
txn.addAll(getMockTransaction(5, 10, 0));
List<AionTransaction> newCache = new ArrayList<>();
for (ITransaction tx : txn) {
newCache.add(cache.addCacheTx((AionTransaction) tx).get(0));
}
assertTrue(newCache.size() == 20);
Map<BigInteger, AionTransaction> cacheMap = cache.geCacheTx(Address.wrap(key.get(0).getAddress()));
assertTrue(cacheMap.size() == 15);
}
Aggregations