use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.
the class FvmBalanceTransferConsensusTest method testCallToPrecompiledContract.
@Test
public void testCallToPrecompiledContract() {
BigInteger initialBalance = getBalance(new AionAddress(SENDER_ADDR));
assertThat(initialBalance).isEqualTo(SENDER_BALANCE);
assertThat(this.blockchain.getMinerCoinbase().toByteArray()).isEqualTo(MINER);
// ensure bridge is viewed as precompiled contract
AionAddress bridge = AddressUtils.wrapAddress("0000000000000000000000000000000000000000000000000000000000000200");
assertThat(ContractInfo.isPrecompiledContract(bridge)).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(), bridge, BigInteger.ZERO.toByteArray(), Hex.decode("a6f9dae1a048613dd3cb89685cb3f9cfa410ecf606c7ec7320e721edacd194050828c6b0"), 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(23304);
byte[] stateRoot = blockSummary.getBlock().getStateRoot();
byte[] blockReceiptsRoot = blockSummary.getBlock().getReceiptsRoot();
byte[] receiptTrieEncoded = receipt.getReceiptTrieEncoded();
// Verify the consensus information.
String expectedRoot = "7D91DD44FC7AABC0291BB6FD9CBCD70BEB3859FDD10E0F2356D2B5947EBC55D7";
String expectedReceiptsRoot = "E897C7EB2531B5CC45293AE3EC0CC156B0FACEAEF3046D671A08D6C91BA88827";
String expectedReceiptsTrie = "f90125a06ed1cbe0a46be351c90404aaeb7d12d9737d4c8a070e8c63dc1cfc0d7441fbdbb9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0";
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("999999999764082962989144");
assertThat(getBalance(new AionAddress(SENDER_ADDR))).isEqualTo(expectedBalance);
// Verify that the contract has the expected balance.
BigInteger contractBalance = getBalance(bridge);
assertThat(contractBalance).isEqualTo(BigInteger.ZERO);
// Verify that the miner has the expected balance.
BigInteger expectedMinerBalance = new BigInteger("749233448298487019");
assertThat(getBalance(new AionAddress(MINER))).isEqualTo(expectedMinerBalance);
}
use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.
the class FvmBalanceTransferConsensusTest method testTransferAfterCreatingToNonPayableFallbackFunction.
@Test
public void testTransferAfterCreatingToNonPayableFallbackFunction() {
BigInteger amount = BigInteger.TEN.pow(17).add(BigInteger.valueOf(38_193));
BigInteger initialBalance = getBalance(new AionAddress(SENDER_ADDR));
assertEquals(SENDER_BALANCE, initialBalance);
assertArrayEquals(MINER, this.blockchain.getMinerCoinbase().toByteArray());
// Make the create transaction.
AionTransaction transaction = makeCreateNonpayableFallbackContractTx();
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();
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_ROOT6), stateRoot);
assertArrayEquals(Hex.decode(BLOCK_RECEIPTS_ROOT6), blockReceiptsRoot);
assertArrayEquals(Hex.decode(RECEIPT_TRIE6), receiptTrieEncoded);
// Make the balance transfer transaction.
transaction = makeCallFallbackFunctionTx(contractAddress, amount);
// Process the transaction.
results = processTransaction(transaction, 1);
// Collect the consensus information from the block & receipt.
blockSummary = results.getRight();
receipt = blockSummary.getSummaries().get(0).getReceipt();
assertFalse(receipt.isSuccessful());
stateRoot = blockSummary.getBlock().getStateRoot();
blockReceiptsRoot = blockSummary.getBlock().getReceiptsRoot();
receiptTrieEncoded = receipt.getReceiptTrieEncoded();
// Verify the consensus information.
assertArrayEquals(Hex.decode(STATE_ROOT7), stateRoot);
assertArrayEquals(Hex.decode(BLOCK_RECEIPTS_ROOT7), blockReceiptsRoot);
assertArrayEquals(Hex.decode(RECEIPT_TRIE7), receiptTrieEncoded);
// Verify the sender's balance is as expected.
BigInteger expectedBalance = new BigInteger("999999997488350123735522");
assertEquals(expectedBalance, getBalance(new AionAddress(SENDER_ADDR)));
// Verify that the contract has the expected balance.
assertEquals(BigInteger.ZERO, getBalance(contractAddress));
// Verify that the miner has the expected balance.
BigInteger expectedMinerBalance = new BigInteger("1500509602039037875");
assertEquals(expectedMinerBalance, getBalance(new AionAddress(MINER)));
}
use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.
the class FvmBalanceTransferConsensusTest method testTransferUponCreationToPayableConstructor.
@Test
public void testTransferUponCreationToPayableConstructor() {
BigInteger amount = BigInteger.TEN.pow(11).add(BigInteger.valueOf(1_234_578));
BigInteger initialBalance = getBalance(new AionAddress(SENDER_ADDR));
assertEquals(SENDER_BALANCE, initialBalance);
assertArrayEquals(MINER, this.blockchain.getMinerCoinbase().toByteArray());
// Make the create & transfer transaction.
AionTransaction transaction = makeCreateAndTransferToFvmPayableConstructorContractTx(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();
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);
BigInteger expectedBalance = new BigInteger("999999997714155060747479");
assertEquals(expectedBalance, getBalance(new AionAddress(SENDER_ADDR)));
// Verify that the contract has the expected balance.
BigInteger contractBalance = getBalance(contractAddress);
assertEquals(amount, contractBalance);
// Verify that the miner has the expected balance.
BigInteger expectedMinerBalance = new BigInteger("751283276199494106");
assertEquals(expectedMinerBalance, getBalance(new AionAddress(MINER)));
}
use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.
the class FvmBalanceTransferConsensusTest method testTransferToPrecompiledBlake2bContractWithoutData.
@Test
public void testTransferToPrecompiledBlake2bContractWithoutData() {
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(), new byte[] {}, 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()).isFalse();
assertThat(receipt.getEnergyUsed()).isEqualTo(21010);
byte[] stateRoot = blockSummary.getBlock().getStateRoot();
byte[] blockReceiptsRoot = blockSummary.getBlock().getReceiptsRoot();
byte[] receiptTrieEncoded = receipt.getReceiptTrieEncoded();
// Verify the consensus information.
String expectedRoot = "37C62813178F694DA9A82398F63CBD7CFFD913B6CE6B2080A8B9374E688EF37E";
String expectedReceiptsRoot = "BE3697A1A56274D8378EE9EF40C308BFBFC8BE48AD5250E1EDCF04A26E11F021";
String expectedReceiptsTrie = "f90125a0619b938d5971660fd2a83cf7c2718653bb5f9b8e78b3b5e7a361e66635c32fd1b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0";
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("999999979753086422000000");
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("749210225088613053");
assertThat(getBalance(new AionAddress(MINER))).isEqualTo(expectedMinerBalance);
}
use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.
the class FvmBalanceTransferConsensusTest method testTransferAfterCreatingToPayableFallbackFunction.
@Test
public void testTransferAfterCreatingToPayableFallbackFunction() {
BigInteger amount = BigInteger.TEN.pow(17).add(BigInteger.valueOf(38_193));
BigInteger initialBalance = getBalance(new AionAddress(SENDER_ADDR));
assertEquals(SENDER_BALANCE, initialBalance);
assertArrayEquals(MINER, this.blockchain.getMinerCoinbase().toByteArray());
// Make the create transaction.
AionTransaction transaction = makeCreatePayableFallbackContractTx();
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();
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_ROOT8), stateRoot);
assertArrayEquals(Hex.decode(BLOCK_RECEIPTS_ROOT8), blockReceiptsRoot);
assertArrayEquals(Hex.decode(RECEIPT_TRIE8), receiptTrieEncoded);
// Make the balance transfer transaction.
transaction = makeCallFallbackFunctionTx(contractAddress, amount);
// Process the transaction.
results = processTransaction(transaction, 1);
// Collect the consensus information from the block & receipt.
blockSummary = results.getRight();
receipt = blockSummary.getSummaries().get(0).getReceipt();
assertTrue(receipt.isSuccessful());
stateRoot = blockSummary.getBlock().getStateRoot();
blockReceiptsRoot = blockSummary.getBlock().getReceiptsRoot();
receiptTrieEncoded = receipt.getReceiptTrieEncoded();
// Verify the consensus information.
assertArrayEquals(Hex.decode(STATE_ROOT9), stateRoot);
assertArrayEquals(Hex.decode(BLOCK_RECEIPTS_ROOT9), blockReceiptsRoot);
assertArrayEquals(Hex.decode(RECEIPT_TRIE9), receiptTrieEncoded);
// Verify the sender's balance is as expected.
BigInteger expectedBalance = new BigInteger("999999897494333086659628");
assertEquals(expectedBalance, getBalance(new AionAddress(SENDER_ADDR)));
// Verify that the contract has the expected balance.
assertEquals(amount, getBalance(contractAddress));
// Verify that the miner has the expected balance.
BigInteger expectedMinerBalance = new BigInteger("1500503619076075576");
assertEquals(expectedMinerBalance, getBalance(new AionAddress(MINER)));
}
Aggregations