use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.
the class AionBlock method toString.
@Override
public String toString() {
StringBuilder toStringBuff = new StringBuilder();
parseRLP();
toStringBuff.setLength(0);
toStringBuff.append(Hex.toHexString(this.getEncoded())).append("\n");
toStringBuff.append("BlockData [ ");
toStringBuff.append("hash=").append(ByteUtil.toHexString(this.getHash())).append("\n");
toStringBuff.append(header.toString());
if (!getTransactionsList().isEmpty()) {
toStringBuff.append("Txs [\n");
for (AionTransaction tx : getTransactionsList()) {
toStringBuff.append(tx);
toStringBuff.append("\n");
}
toStringBuff.append("]\n");
} else {
toStringBuff.append("Txs []\n");
}
toStringBuff.append("]");
return toStringBuff.toString();
}
use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.
the class AionBlock method toFlatString.
public String toFlatString() {
StringBuilder toStringBuff = new StringBuilder();
parseRLP();
toStringBuff.setLength(0);
toStringBuff.append("BlockData [");
toStringBuff.append("hash=").append(ByteUtil.toHexString(this.getHash()));
toStringBuff.append(header.toFlatString());
for (AionTransaction tx : getTransactionsList()) {
toStringBuff.append("\n");
toStringBuff.append(tx.toString());
}
toStringBuff.append("]");
return toStringBuff.toString();
}
use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.
the class BlockchainConcurrencyTest method testPublishBestBlockSafely.
@Test
public void testPublishBestBlockSafely() {
ExecutorService blockCreationService = Executors.newSingleThreadExecutor();
ExecutorService getBlockService = Executors.newSingleThreadExecutor();
StandaloneBlockchain.Bundle bundle = new StandaloneBlockchain.Builder().withDefaultAccounts().withValidatorConfiguration("simple").build();
StandaloneBlockchain bc = bundle.bc;
final int MAX_COUNT = 100000;
final CountDownLatch endLatch = new CountDownLatch(2);
// this will not definitively prove
try {
blockCreationService.submit(() -> {
int count = 0;
List<AionTransaction> txList = Collections.emptyList();
AionBlock block = bc.createNewBlock(bc.genesis, Collections.emptyList(), false);
while (!Thread.currentThread().isInterrupted() && count < MAX_COUNT) {
block = bc.createNewBlock(block, txList, false);
count++;
}
System.out.println("completed block creation");
endLatch.countDown();
});
getBlockService.submit(() -> {
int count = 0;
long prevNumber = bc.getBestBlock().getNumber();
while (!Thread.currentThread().isInterrupted() && count < MAX_COUNT) {
// all three of these methods use {@link AionBlockchainImpl#pubBestBlock}
assertThat(bc.getBestBlockHash()).isNotNull();
bc.getSize();
AionBlock block = bc.getBestBlock();
assertThat(block).isNotNull();
assertThat(block.getNumber()).isAtLeast(prevNumber);
prevNumber = block.getNumber();
count++;
}
endLatch.countDown();
});
} finally {
blockCreationService.shutdown();
getBlockService.shutdown();
}
}
use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.
the class BlockchainIntegrationTest method testSimpleFailedTransactionInsufficientBalance.
@Test
public void testSimpleFailedTransactionInsufficientBalance() {
// 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;
// (byte[] nonce, byte[] from, byte[] to, byte[] value, byte[] data)
AionTransaction tx = new AionTransaction(BigInteger.valueOf(1).toByteArray(), receiverAddress, BigInteger.valueOf(100).toByteArray(), ByteUtil.EMPTY_BYTE_ARRAY, 1L, 1L);
tx.sign(bundle.privateKeys.get(0));
AionBlock block = bc.createNewBlock(bc.getBestBlock(), Collections.singletonList(tx), true);
assertThat(block.getTransactionsList()).isEmpty();
assertThat(block.getTxTrieRoot()).isEqualTo(HashUtil.EMPTY_TRIE_HASH);
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 AionTxExecSummaryTest method testRLPEncoding.
@Test
public void testRLPEncoding() {
AionTransaction mockTx = new AionTransaction(BigInteger.ONE.toByteArray(), defaultAddress, defaultAddress, BigInteger.ONE.toByteArray(), HashUtil.EMPTY_DATA_HASH, 1L, 1L);
AionTxReceipt txReceipt = new AionTxReceipt(HashUtil.EMPTY_TRIE_HASH, new Bloom(), Collections.EMPTY_LIST);
txReceipt.setNrgUsed(1);
txReceipt.setTransaction(mockTx);
AionTxExecSummary.Builder builder = AionTxExecSummary.builderFor(txReceipt);
builder.markAsFailed().result(new byte[0]);
AionTxExecSummary summary = builder.build();
byte[] encodedSummary = summary.getEncoded();
AionTxExecSummary newSummary = new AionTxExecSummary(encodedSummary);
newSummary.getReceipt().setTransaction(mockTx);
assertThat(newSummary.getFee()).isEqualTo(BigInteger.ONE);
}
Aggregations