use of org.aion.base.AionTxExecSummary in project aion by aionnetwork.
the class ContractIntegTest method testFvmEmptyContractWith200KEnrygyBeforeUnity.
@Test
public void testFvmEmptyContractWith200KEnrygyBeforeUnity() throws IOException, VmFatalException {
String contractName = "EmptyContract";
byte[] deployCode = getDeployCode(contractName);
long nrg = 200_000;
long nrgPrice = energyPrice;
BigInteger value = BigInteger.ZERO;
BigInteger nonce = BigInteger.ZERO;
// to == null signals that this is contract creation.
AionTransaction tx = AionTransaction.create(deployerKey, nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice, txType, null);
assertTrue(tx.isContractCreationTransaction());
assertEquals(Builder.DEFAULT_BALANCE, blockchain.getRepository().getBalance(deployer));
assertEquals(BigInteger.ZERO, blockchain.getRepository().getNonce(deployer));
MiningBlock block = makeBlock(tx);
RepositoryCache repo = blockchain.getRepository().startTracking();
AionTxExecSummary summary = BulkExecutor.executeTransactionWithNoPostExecutionWork(block.getDifficulty(), block.getNumber(), block.getTimestamp(), block.getNrgLimit(), block.getCoinbase(), tx, repo, false, true, false, false, LOGGER_VM, BlockCachingContext.PENDING, block.getNumber() - 1, false, false);
if (txType == TransactionTypes.DEFAULT) {
assertEquals("OUT_OF_NRG", summary.getReceipt().getError());
checkStateOfDeployer(repo, summary, nrgPrice, value, nonce.add(BigInteger.ONE));
assertEquals(nrg, summary.getReceipt().getEnergyUsed());
} else if (txType == TransactionTypes.AVM_CREATE_CODE) {
assertEquals("Failed: invalid data", summary.getReceipt().getError());
nonce = nonce.add(BigInteger.ONE);
checkStateOfDeployer(repo, summary, nrgPrice, value, nonce);
assertEquals(nrg, summary.getReceipt().getEnergyUsed());
}
}
use of org.aion.base.AionTxExecSummary in project aion by aionnetwork.
the class ContractIntegTest method testDeployFvmContractToAnExistedAccountBefore040Fork.
@Test
public void testDeployFvmContractToAnExistedAccountBefore040Fork() throws IOException {
if (txType == TransactionTypes.AVM_CREATE_CODE) {
return;
}
blockchain.forkUtility.enable040Fork(1000);
long nrg = 1_000_000;
long nrgPrice = energyPrice;
BigInteger value = BigInteger.ONE;
AionAddress destinationAddr = TxUtil.calculateContractAddress(deployer.toByteArray(), deployerNonce);
// create a tx the sender send some balance to the account the deployer will deploy in the
// feature.
AionTransaction tx = AionTransaction.create(senderKey, senderNonce.toByteArray(), destinationAddr, value.toByteArray(), new byte[0], nrg, nrgPrice, txType, null);
assertFalse(tx.isContractCreationTransaction());
MiningBlock block = makeBlock(tx);
assertEquals(1, block.getTransactionsList().size());
Pair<ImportResult, AionBlockSummary> result = blockchain.tryToConnectAndFetchSummary(block);
assertTrue(result.getLeft().isSuccessful());
RepositoryCache repo = blockchain.getRepository().startTracking();
assertEquals(BigInteger.ONE, repo.getBalance(destinationAddr));
BigInteger txCost = BigInteger.valueOf(nrgPrice).multiply(BigInteger.valueOf(result.getRight().getReceipts().get(0).getEnergyUsed()));
assertEquals(senderBalance.subtract(BigInteger.ONE).subtract(txCost), repo.getBalance(sender));
senderNonce = senderNonce.add(BigInteger.ONE);
String contractName = "PayableConstructor";
byte[] deployCode = getDeployCode(contractName);
// to == null signals that this is contract creation.
tx = AionTransaction.create(deployerKey, deployerNonce.toByteArray(), null, BigInteger.ZERO.toByteArray(), deployCode, nrg, nrgPrice, txType, null);
assertTrue(tx.isContractCreationTransaction());
assertEquals(Builder.DEFAULT_BALANCE, blockchain.getRepository().getBalance(deployer));
assertEquals(BigInteger.ZERO, blockchain.getRepository().getNonce(deployer));
block = makeBlock(tx);
assertEquals(1, block.getTransactionsList().size());
result = blockchain.tryToConnectAndFetchSummary(block);
assertTrue(result.getLeft().isSuccessful());
repo = blockchain.getRepository().startTracking();
AionTxExecSummary summary = result.getRight().getSummaries().get(0);
if (txType == TransactionTypes.DEFAULT) {
// "" == SUCCESS
assertEquals("FAILURE", summary.getReceipt().getError());
deployerNonce = deployerNonce.add(BigInteger.ONE);
checkStateOfDeployer(repo, summary, nrgPrice, BigInteger.ZERO, deployerNonce);
}
assertEquals(1000000, summary.getReceipt().getEnergyUsed());
}
use of org.aion.base.AionTxExecSummary in project aion by aionnetwork.
the class ContractIntegTest method testDeployFvmContractToAnExistedAccountWith040Fork.
@Test
public void testDeployFvmContractToAnExistedAccountWith040Fork() throws IOException {
if (txType == TransactionTypes.AVM_CREATE_CODE) {
return;
}
blockchain.forkUtility.enable040Fork(0);
long nrg = 1_000_000;
long nrgPrice = energyPrice;
BigInteger value = BigInteger.ONE;
AionAddress destinationAddr = TxUtil.calculateContractAddress(deployer.toByteArray(), deployerNonce);
// create a tx the sender send some balance to the account the deployer will deploy in the
// feature.
AionTransaction tx = AionTransaction.create(senderKey, senderNonce.toByteArray(), destinationAddr, value.toByteArray(), new byte[0], nrg, nrgPrice, txType, null);
assertFalse(tx.isContractCreationTransaction());
MiningBlock block = makeBlock(tx);
assertEquals(1, block.getTransactionsList().size());
Pair<ImportResult, AionBlockSummary> result = blockchain.tryToConnectAndFetchSummary(block);
assertTrue(result.getLeft().isSuccessful());
RepositoryCache repo = blockchain.getRepository().startTracking();
assertEquals(BigInteger.ONE, repo.getBalance(destinationAddr));
BigInteger txCost = BigInteger.valueOf(nrgPrice).multiply(BigInteger.valueOf(result.getRight().getReceipts().get(0).getEnergyUsed()));
assertEquals(senderBalance.subtract(BigInteger.ONE).subtract(txCost), repo.getBalance(sender));
senderNonce = senderNonce.add(BigInteger.ONE);
String contractName = "PayableConstructor";
byte[] deployCode = getDeployCode(contractName);
// to == null signals that this is contract creation.
tx = AionTransaction.create(deployerKey, deployerNonce.toByteArray(), null, BigInteger.ZERO.toByteArray(), deployCode, nrg, nrgPrice, txType, null);
assertTrue(tx.isContractCreationTransaction());
assertEquals(Builder.DEFAULT_BALANCE, blockchain.getRepository().getBalance(deployer));
assertEquals(BigInteger.ZERO, blockchain.getRepository().getNonce(deployer));
block = makeBlock(tx);
assertEquals(1, block.getTransactionsList().size());
result = blockchain.tryToConnectAndFetchSummary(block);
assertTrue(result.getLeft().isSuccessful());
repo = blockchain.getRepository().startTracking();
AionTxExecSummary summary = result.getRight().getSummaries().get(0);
if (txType == TransactionTypes.DEFAULT) {
// "" == SUCCESS
assertEquals("", summary.getReceipt().getError());
AionAddress contract = TxUtil.calculateContractAddress(tx);
checkStateOfNewContract(repo, contractName, contract, summary.getResult(), FastVmResultCode.SUCCESS, value);
deployerNonce = deployerNonce.add(BigInteger.ONE);
checkStateOfDeployer(repo, summary, nrgPrice, BigInteger.ZERO, deployerNonce);
}
assertEquals(225787, summary.getReceipt().getEnergyUsed());
}
use of org.aion.base.AionTxExecSummary in project aion by aionnetwork.
the class ContractIntegTest method testContractDeployCodeIsEmpty.
@Test
public void testContractDeployCodeIsEmpty() throws Exception {
long nrg = 1_000_000;
long nrgPrice = energyPrice;
BigInteger value = BigInteger.ZERO;
BigInteger nonce = BigInteger.ZERO;
// to == null signals that this is contract creation.
AionTransaction tx = AionTransaction.create(deployerKey, nonce.toByteArray(), null, value.toByteArray(), new byte[0], nrg, nrgPrice, txType, null);
assertTrue(tx.isContractCreationTransaction());
assertEquals(Builder.DEFAULT_BALANCE, blockchain.getRepository().getBalance(deployer));
assertEquals(BigInteger.ZERO, blockchain.getRepository().getNonce(deployer));
MiningBlock block = makeBlock(tx);
RepositoryCache repo = blockchain.getRepository().startTracking();
AionTxExecSummary summary = executeTransaction(tx, block, repo);
if (txType == TransactionTypes.DEFAULT) {
// "" == SUCCESS
assertEquals("", summary.getReceipt().getError());
assertEquals(221000, summary.getReceipt().getEnergyUsed());
AionAddress contract = TxUtil.calculateContractAddress(tx);
assertArrayEquals(new byte[0], summary.getResult());
assertArrayEquals(new byte[0], repo.getCode(contract));
assertEquals(BigInteger.ZERO, repo.getBalance(contract));
assertEquals(BigInteger.ZERO, repo.getNonce(contract));
assertEquals(BigInteger.ONE, repo.getNonce(deployer));
} else if (txType == TransactionTypes.AVM_CREATE_CODE) {
assertEquals("Failed: invalid data", summary.getReceipt().getError());
nonce = nonce.add(BigInteger.ONE);
checkStateOfDeployer(repo, summary, nrgPrice, value, nonce);
}
BigInteger txCost = summary.getNrgUsed().multiply(BigInteger.valueOf(nrgPrice));
assertEquals(Builder.DEFAULT_BALANCE.subtract(txCost), repo.getBalance(deployer));
}
use of org.aion.base.AionTxExecSummary in project aion by aionnetwork.
the class ContractIntegTest method testFvmTransferValueToNonPayableConstructor.
@Test
public void testFvmTransferValueToNonPayableConstructor() throws Exception {
String contractName = "EmptyContract";
byte[] deployCode = getDeployCode(contractName);
long nrg = 1_000_000;
long nrgPrice = energyPrice;
// attempt to transfer value to new contract.
BigInteger value = BigInteger.ONE;
BigInteger nonce = BigInteger.ZERO;
// to == null signals that this is contract creation.
AionTransaction tx = AionTransaction.create(deployerKey, nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice, txType, null);
assertTrue(tx.isContractCreationTransaction());
assertEquals(Builder.DEFAULT_BALANCE, blockchain.getRepository().getBalance(deployer));
assertEquals(BigInteger.ZERO, blockchain.getRepository().getNonce(deployer));
MiningBlock block = makeBlock(tx);
RepositoryCache repo = blockchain.getRepository().startTracking();
AionTxExecSummary summary = executeTransaction(tx, block, repo);
if (txType == TransactionTypes.DEFAULT) {
assertEquals("reverted", summary.getReceipt().getError());
// all energy is not used up.
assertNotEquals(nrg, summary.getNrgUsed().longValue());
AionAddress contract = TxUtil.calculateContractAddress(tx);
checkStateOfNewContract(repo, contractName, contract, summary.getResult(), FastVmResultCode.REVERT, BigInteger.ZERO);
nonce = nonce.add(BigInteger.ONE);
} else if (txType == TransactionTypes.AVM_CREATE_CODE) {
assertEquals("Failed: invalid data", summary.getReceipt().getError());
nonce = nonce.add(BigInteger.ONE);
}
checkStateOfDeployer(repo, summary, nrgPrice, BigInteger.ZERO, nonce);
}
Aggregations