use of org.aion.base.AionTxReceipt in project aion by aionnetwork.
the class BalanceTransferConsensusTest method testBalanceTransfers.
@Test
public void testBalanceTransfers() {
BigInteger amount = BigInteger.TEN.pow(22).add(BigInteger.valueOf(123_987_156));
BigInteger initialBalance = getBalance(new AionAddress(SENDER_ADDR));
assertEquals(SENDER_BALANCE, initialBalance);
assertArrayEquals(MINER, this.blockchain.getMinerCoinbase().toByteArray());
// Get the recipients.
List<AionAddress> recipients = produceRecipients();
for (AionAddress recipient : recipients) {
assertEquals(BigInteger.ZERO, getBalance(recipient));
}
List<AionTransaction> transactions = makeBalanceTransferTransactions(recipients, amount);
// Process the transactions.
Pair<ImportResult, AionBlockSummary> results = processTransactions(transactions, transactions.size());
// Collect the consensus information from the block & receipt.
AionBlockSummary blockSummary = results.getRight();
AionTxReceipt receipt = blockSummary.getSummaries().get(0).getReceipt();
assertTrue(receipt.isSuccessful());
byte[] stateRoot = blockSummary.getBlock().getStateRoot();
byte[] blockReceiptsRoot = blockSummary.getBlock().getReceiptsRoot();
byte[] receiptTrieEncoded = receipt.getReceiptTrieEncoded();
// Verify the consensus information.
assertArrayEquals(Hex.decode(STATE_ROOT2), stateRoot);
assertArrayEquals(Hex.decode(BLOCK_RECEIPTS_ROOT2), blockReceiptsRoot);
assertArrayEquals(Hex.decode(RECEIPT_TRIE2), receiptTrieEncoded);
// Verify the sender's balance is as expected.
BigInteger expectedBalance = new BigInteger("949999998927317898701780");
assertEquals(expectedBalance, getBalance(new AionAddress(SENDER_ADDR)));
// Verify that the recipients' balances are as expected.
for (AionAddress recipient : recipients) {
assertEquals(amount, getBalance(recipient));
}
// Verify that the miner's balance is as expected.
BigInteger expectedMinerBalance = new BigInteger("750070212742838603");
assertEquals(expectedMinerBalance, getBalance(new AionAddress(MINER)));
}
use of org.aion.base.AionTxReceipt in project aion by aionnetwork.
the class BalanceTransferConsensusTest method testBalanceTransfer.
@Test
public void testBalanceTransfer() {
BigInteger amount = BigInteger.TEN.pow(23).add(BigInteger.valueOf(13_897_651));
BigInteger initialBalance = getBalance(new AionAddress(SENDER_ADDR));
assertEquals(SENDER_BALANCE, initialBalance);
assertArrayEquals(MINER, this.blockchain.getMinerCoinbase().toByteArray());
AionAddress address = new AionAddress(Hex.decode(RECIPIENT1));
assertEquals(BigInteger.ZERO, getBalance(address));
AionTransaction transaction = makeBalanceTransferTransaction(address, amount);
// Process the transaction.
Pair<ImportResult, AionBlockSummary> results = processTransactions(transaction, 1);
// Collect the consensus information from the block & receipt.
AionBlockSummary blockSummary = results.getRight();
AionTxReceipt receipt = blockSummary.getSummaries().get(0).getReceipt();
assertTrue(receipt.isSuccessful());
byte[] stateRoot = blockSummary.getBlock().getStateRoot();
byte[] blockReceiptsRoot = blockSummary.getBlock().getReceiptsRoot();
byte[] receiptTrieEncoded = receipt.getReceiptTrieEncoded();
// Verify the consensus information.
assertArrayEquals(Hex.decode(STATE_ROOT1), stateRoot);
assertArrayEquals(Hex.decode(BLOCK_RECEIPTS_ROOT1), blockReceiptsRoot);
assertArrayEquals(Hex.decode(RECEIPT_TRIE1), receiptTrieEncoded);
// Verify the sender's balance is as expected.
BigInteger expectedBalance = new BigInteger("899999999785463689829861");
assertEquals(expectedBalance, getBalance(new AionAddress(SENDER_ADDR)));
// Verify that the recipient's balance is as expected.
assertEquals(amount, getBalance(address));
// Verify that the miner's balance is as expected.
BigInteger expectedMinerBalance = new BigInteger("749212067557748651");
assertEquals(expectedMinerBalance, getBalance(new AionAddress(MINER)));
}
use of org.aion.base.AionTxReceipt in project aion by aionnetwork.
the class FvmBalanceTransferConsensusTest method testTransferUponCreationToNonPayableConstructor.
@Test
public void testTransferUponCreationToNonPayableConstructor() {
BigInteger amount = BigInteger.TEN.pow(12).add(BigInteger.valueOf(293_865));
BigInteger initialBalance = getBalance(new AionAddress(SENDER_ADDR));
assertEquals(SENDER_BALANCE, initialBalance);
assertArrayEquals(MINER, this.blockchain.getMinerCoinbase().toByteArray());
// Make the create & transfer transaction.
AionTransaction transaction = makeCreateAndTransferToFvmNonpayableConstructorContractTx(amount);
AionAddress contractAddress = TxUtil.calculateContractAddress(transaction);
assertArrayEquals(Hex.decode(CONTRACT), contractAddress.toByteArray());
// Process the transaction.
Pair<ImportResult, AionBlockSummary> results = processTransaction(transaction, 1);
// Collect the consensus information from the block & receipt.
AionBlockSummary blockSummary = results.getRight();
AionTxReceipt receipt = blockSummary.getSummaries().get(0).getReceipt();
assertFalse(receipt.isSuccessful());
byte[] stateRoot = blockSummary.getBlock().getStateRoot();
byte[] blockReceiptsRoot = blockSummary.getBlock().getReceiptsRoot();
byte[] receiptTrieEncoded = receipt.getReceiptTrieEncoded();
// Verify the consensus information.
assertArrayEquals(Hex.decode(STATE_ROOT1), stateRoot);
assertArrayEquals(Hex.decode(BLOCK_RECEIPTS_ROOT1), blockReceiptsRoot);
assertArrayEquals(Hex.decode(RECEIPT_TRIE1), receiptTrieEncoded);
// Verify that the sender has the expected balance.
BigInteger expectedBalance = new BigInteger("999999997708454321241960");
assertEquals(expectedBalance, getBalance(new AionAddress(SENDER_ADDR)));
// Verify that the contract has the expected balance.
BigInteger contractBalance = getBalance(contractAddress);
assertEquals(BigInteger.ZERO, contractBalance);
// Verify that the miner has the expected balance.
BigInteger expectedMinerBalance = new BigInteger("751289076940234203");
assertEquals(expectedMinerBalance, getBalance(new AionAddress(MINER)));
}
use of org.aion.base.AionTxReceipt in project aion by aionnetwork.
the class FvmBalanceTransferConsensusTest method testTransferToPrecompiledBlake2bContractWithData.
@Test
public void testTransferToPrecompiledBlake2bContractWithData() {
// ensure the contract is live
Properties properties = new Properties();
properties.put("fork0.3.2", "0");
CfgAion cfg = CfgAion.inst();
cfg.getFork().setProtocolUpgradeSettings(properties, null);
BigInteger amount = BigInteger.TEN.pow(12).add(BigInteger.valueOf(293_865));
BigInteger initialBalance = getBalance(new AionAddress(SENDER_ADDR));
assertThat(initialBalance).isEqualTo(SENDER_BALANCE);
assertThat(this.blockchain.getMinerCoinbase().toByteArray()).isEqualTo(MINER);
// get contract address from precompiled factory
AionAddress blake2b = ContractInfo.BLAKE_2B.contractAddress;
assertThat(ContractInfo.isPrecompiledContract(blake2b)).isTrue();
// Make balance transfer transaction to precompiled contract.
ECKey key = org.aion.crypto.ECKeyFac.inst().fromPrivate(SENDER_KEY);
AionTransaction transaction = AionTransaction.create(key, BigInteger.ZERO.toByteArray(), blake2b, amount.toByteArray(), Hex.decode("abcdef0123456789"), 2_000_000, ENERGY_PRICE, TransactionTypes.DEFAULT, null);
// Process the transaction.
Pair<ImportResult, AionBlockSummary> results = processTransaction(transaction, 1);
// Collect the consensus information from the block & receipt.
AionBlockSummary blockSummary = results.getRight();
AionTxReceipt receipt = blockSummary.getSummaries().get(0).getReceipt();
assertThat(receipt.isSuccessful()).isTrue();
assertThat(receipt.getEnergyUsed()).isEqualTo(21526);
assertThat(receipt.getTransactionOutput()).isEqualTo(Hex.decode("ac86b78afd9bdda3641a47a4aff2a7ee26acd40cc534d63655e9dfbf3f890a02"));
byte[] stateRoot = blockSummary.getBlock().getStateRoot();
byte[] blockReceiptsRoot = blockSummary.getBlock().getReceiptsRoot();
byte[] receiptTrieEncoded = receipt.getReceiptTrieEncoded();
// Verify the consensus information.
String expectedRoot = "12CB8B149B8465CE3A3BD3AF3D19EB39C3DADD528880BB7CCB4FC4ED10758E68";
String expectedReceiptsRoot = "55CB056398D1AA49328E11E97BA034C532D312CD8C4959F3E609FD25E2FC0C62";
String expectedReceiptsTrie = "f90125a0188897e00f24f83eb6a27004dcb96cb4fa4370a1e7b072f2c21c9a437146fa69b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0";
assertThat(stateRoot).isEqualTo(Hex.decode(expectedRoot));
assertThat(blockReceiptsRoot).isEqualTo(Hex.decode(expectedReceiptsRoot));
assertThat(receiptTrieEncoded).isEqualTo(Hex.decode(expectedReceiptsTrie));
// Verify that the sender has the expected balance.
BigInteger expectedBalance = new BigInteger("999999999781082468866121");
assertThat(getBalance(new AionAddress(SENDER_ADDR))).isEqualTo(expectedBalance);
// Verify that the contract has the expected balance.
BigInteger contractBalance = getBalance(blake2b);
assertThat(contractBalance).isEqualTo(amount);
// Verify that the miner has the expected balance.
BigInteger expectedMinerBalance = new BigInteger("749215448792316177");
assertThat(getBalance(new AionAddress(MINER))).isEqualTo(expectedMinerBalance);
}
use of org.aion.base.AionTxReceipt in project aion by aionnetwork.
the class FvmBalanceTransferConsensusTest method testCallToPrecompiledBlake2bContract.
@Test
public void testCallToPrecompiledBlake2bContract() {
// ensure the contract is live (after fork)
Properties properties = new Properties();
properties.put("fork0.3.2", "0");
CfgAion cfg = CfgAion.inst();
cfg.getFork().setProtocolUpgradeSettings(properties, null);
BigInteger initialBalance = getBalance(new AionAddress(SENDER_ADDR));
assertThat(initialBalance).isEqualTo(SENDER_BALANCE);
assertThat(this.blockchain.getMinerCoinbase().toByteArray()).isEqualTo(MINER);
// get contract address from precompiled factory
AionAddress blake2b = ContractInfo.BLAKE_2B.contractAddress;
assertThat(ContractInfo.isPrecompiledContract(blake2b)).isTrue();
// Make call transaction to precompiled contract.
ECKey key = org.aion.crypto.ECKeyFac.inst().fromPrivate(SENDER_KEY);
AionTransaction transaction = AionTransaction.create(key, BigInteger.ZERO.toByteArray(), blake2b, BigInteger.ZERO.toByteArray(), Hex.decode("abcdef0123456789"), 2_000_000, ENERGY_PRICE, TransactionTypes.DEFAULT, null);
// Process the transaction.
Pair<ImportResult, AionBlockSummary> results = processTransaction(transaction, 1);
// Collect the consensus information from the block & receipt.
AionBlockSummary blockSummary = results.getRight();
AionTxReceipt receipt = blockSummary.getSummaries().get(0).getReceipt();
assertThat(receipt.isSuccessful()).isTrue();
assertThat(receipt.getEnergyUsed()).isEqualTo(21526);
assertThat(receipt.getTransactionOutput()).isEqualTo(Hex.decode("ac86b78afd9bdda3641a47a4aff2a7ee26acd40cc534d63655e9dfbf3f890a02"));
byte[] stateRoot = blockSummary.getBlock().getStateRoot();
byte[] blockReceiptsRoot = blockSummary.getBlock().getReceiptsRoot();
byte[] receiptTrieEncoded = receipt.getReceiptTrieEncoded();
// Verify the consensus information.
String expectedRoot = "ABBF04753B23F36F04CC4C0AEF7969C29236A4FCD982F3A4D824CB1EDE60AF4B";
String expectedReceiptsRoot = "72C976AF0CE4627E1CA3FA1EA5EB798A0CB7118E186626E04ECA7198887AD3A1";
String expectedReceiptsTrie = "f90125a03441b15983ce33839dfd1a7b62c1fa86ca4ff9df76d263bcc7c8f1d14225dc5cb9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0";
assertThat(stateRoot).isEqualTo(Hex.decode(expectedRoot));
assertThat(blockReceiptsRoot).isEqualTo(Hex.decode(expectedReceiptsRoot));
assertThat(receiptTrieEncoded).isEqualTo(Hex.decode(expectedReceiptsTrie));
// Verify that the sender has the expected balance.
BigInteger expectedBalance = new BigInteger("999999999782082469159986");
assertThat(getBalance(new AionAddress(SENDER_ADDR))).isEqualTo(expectedBalance);
// Verify that the contract has the expected balance.
BigInteger contractBalance = getBalance(blake2b);
assertThat(contractBalance).isEqualTo(BigInteger.ZERO);
// Verify that the miner has the expected balance.
BigInteger expectedMinerBalance = new BigInteger("749215448792316177");
assertThat(getBalance(new AionAddress(MINER))).isEqualTo(expectedMinerBalance);
}
Aggregations