use of org.aion.base.AionTxExecSummary in project aion by aionnetwork.
the class ContractIntegTest method testRedeployContractAtExistentContractAddress.
@Test
public void testRedeployContractAtExistentContractAddress() throws Exception {
String contractName = "MultiFeatureContract";
byte[] deployCode = getDeployCode(contractName);
long nrg = 1_000_000;
long nrgPrice = energyPrice;
BigInteger value = BigInteger.ZERO;
BigInteger nonce = BigInteger.ZERO;
AionTransaction tx = AionTransaction.create(deployerKey, nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice, txType, null);
// Mock up the repo so that the contract address already exists.
AionRepositoryCache repo = mock(AionRepositoryCache.class);
when(repo.hasAccountState(Mockito.any(AionAddress.class))).thenReturn(true);
when(repo.getNonce(Mockito.any(AionAddress.class))).thenReturn(nonce);
when(repo.getBalance(Mockito.any(AionAddress.class))).thenReturn(Builder.DEFAULT_BALANCE);
when(repo.getCode(Mockito.any(AionAddress.class))).thenReturn(new byte[1]);
when(repo.startTracking()).thenReturn(repo);
assertTrue(tx.isContractCreationTransaction());
assertEquals(Builder.DEFAULT_BALANCE, blockchain.getRepository().getBalance(deployer));
assertEquals(BigInteger.ZERO, blockchain.getRepository().getNonce(deployer));
MiningBlock block = makeBlock(tx);
AionTxExecSummary summary = executeTransaction(tx, block, repo);
if (txType == TransactionTypes.DEFAULT) {
assertEquals("FAILURE", summary.getReceipt().getError());
assertEquals(nrg, summary.getNrgUsed().longValue());
} else if (txType == TransactionTypes.AVM_CREATE_CODE) {
assertEquals("Failed: invalid data", summary.getReceipt().getError());
assertEquals(nrg, summary.getNrgUsed().longValue());
}
}
use of org.aion.base.AionTxExecSummary in project aion by aionnetwork.
the class ContractIntegTest method testContractDeployCodeIsNonsensical.
@Test
public void testContractDeployCodeIsNonsensical() throws Exception {
byte[] deployCode = new byte[1];
deployCode[0] = 0x1;
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(), 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("OUT_OF_NRG", summary.getReceipt().getError());
assertEquals(nrg, summary.getNrgUsed().longValue());
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 testFvmEmptyContractWith226160EnergyAfterUnity.
@Test
public void testFvmEmptyContractWith226160EnergyAfterUnity() throws IOException, VmFatalException {
long unityForkBlock = 2;
blockchain.forkUtility.enableUnityFork(unityForkBlock);
ECKey stakingRegistryOwner = accounts.get(1);
List<ECKey> stakers = new ArrayList<>(accounts);
stakers.remove(deployerKey);
stakers.remove(stakingRegistryOwner);
assertThat(stakers.size()).isEqualTo(8);
// the default configuration does not apply to this test case
AvmTestConfig.clearConfigurations();
AvmTestConfig.supportBothAvmVersions(0, unityForkBlock, 0);
// populating the chain to be above the Unity for point
BlockchainTestUtils.generateRandomUnityChain(blockchain, resourceProvider, unityForkBlock + 1, 1, stakers, stakingRegistryOwner, 10);
String contractName = "EmptyContract";
byte[] deployCode = getDeployCode(contractName);
long nrg = 226160;
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));
// The transaction has invalid energylimit settings
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 OpcodeIntegTest method testCallcodeActors.
@Test
public void testCallcodeActors() throws Exception {
RepositoryCache repo = blockchain.getRepository().startTracking();
AionAddress D = deployContract(repo, "D", "D.sol", BigInteger.ZERO);
AionAddress E = deployContract(repo, "E", "D.sol", BigInteger.ZERO);
// Deployer calls contract D which performs CALLCODE to call contract E. From the
// perspective
// of the internal transaction, however, it looks like D calls D.
long nrg = 1_000_000;
long nrgPrice = 1;
BigInteger nonce = BigInteger.TWO;
byte[] input = // use CALLCODE on E.
ByteUtil.merge(Hex.decode("5cce9fc2"), E.toByteArray());
// pass in 'n' also.
input = ByteUtil.merge(input, new DataWord(0).getData());
AionTransaction tx = AionTransaction.create(deployerKey, nonce.toByteArray(), D, BigInteger.ZERO.toByteArray(), input, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
assertEquals(deployer, tx.getSenderAddress());
assertEquals(D, tx.getDestinationAddress());
BlockContext context = blockchain.createNewMiningBlockContext(blockchain.getBestBlock(), Collections.singletonList(tx), false);
AionTxExecSummary summary = executeTransaction(tx, context.block, repo);
assertEquals("", summary.getReceipt().getError());
assertEquals(summary.getNrgUsed().longValue(), summary.getNrgUsed().longValue());
// We expect that the internal transaction is sent from D to D.
List<InternalTransaction> internalTxs = summary.getInternalTransactions();
assertEquals(1, internalTxs.size());
assertEquals(D, internalTxs.get(0).sender);
assertEquals(D, internalTxs.get(0).destination);
}
use of org.aion.base.AionTxExecSummary in project aion by aionnetwork.
the class OpcodeIntegTest method testNoRevert.
// ====================== test repo & track flushing over multiple levels ======================
@Test
public void testNoRevert() throws Exception {
RepositoryCache repo = blockchain.getRepository().startTracking();
AionAddress D = deployContract(repo, "F", "F.sol", BigInteger.ZERO);
long nrg = 1_000_000;
long nrgPrice = 1;
BigInteger nonce = BigInteger.ONE;
byte[] input = ByteUtil.merge(Hex.decode("f854bb89"), new DataWord(6).getData());
AionTransaction tx = AionTransaction.create(deployerKey, nonce.toByteArray(), D, BigInteger.ZERO.toByteArray(), input, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
BlockContext context = blockchain.createNewMiningBlockContext(blockchain.getBestBlock(), Collections.singletonList(tx), false);
AionTxExecSummary summary = executeTransaction(tx, context.block, repo);
assertEquals("", summary.getReceipt().getError());
assertEquals(summary.getNrgUsed().longValue(), summary.getNrgUsed().longValue());
// Check that the logs from our internal transactions are as we expect.
List<Log> logs = summary.getReceipt().getLogInfoList();
assertEquals(12, logs.size());
assertArrayEquals(new DataWord(0).getData(), logs.get(0).copyOfData());
assertArrayEquals(new DataWord(6).getData(), logs.get(1).copyOfData());
assertArrayEquals(new DataWord(5).getData(), logs.get(2).copyOfData());
assertArrayEquals(new DataWord(4).getData(), logs.get(3).copyOfData());
assertArrayEquals(new DataWord(3).getData(), logs.get(4).copyOfData());
assertArrayEquals(new DataWord(2).getData(), logs.get(5).copyOfData());
assertArrayEquals(new DataWord(1).getData(), logs.get(6).copyOfData());
assertArrayEquals(new DataWord(1).getData(), logs.get(7).copyOfData());
assertArrayEquals(new DataWord(1).getData(), logs.get(8).copyOfData());
assertArrayEquals(new DataWord(1).getData(), logs.get(9).copyOfData());
assertArrayEquals(new DataWord(1).getData(), logs.get(10).copyOfData());
assertArrayEquals(new DataWord(1).getData(), logs.get(11).copyOfData());
}
Aggregations