use of org.aion.zero.impl.types.MiningBlock 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.zero.impl.types.MiningBlock in project aion by aionnetwork.
the class OldTxExecutorTest method testCallTransaction.
@Test
public void testCallTransaction() throws Exception {
Compiler.Result r = Compiler.getInstance().compile(ContractUtils.readContract("Ticker.sol"), Options.ABI, Options.BIN);
CompilationResult cr = CompilationResult.parse(r.output);
// deployer
String deployer = cr.contracts.get("Ticker").bin;
// contract
String contract = deployer.substring(deployer.indexOf("60506040", 1));
byte[] txNonce = BigInteger.ZERO.toByteArray();
AionAddress to = AddressUtils.wrapAddress("2222222222222222222222222222222222222222222222222222222222222222");
byte[] value = BigInteger.ZERO.toByteArray();
byte[] data = Hex.decode("c0004213");
long nrg = new DataWord(100000L).longValue();
long nrgPrice = DataWord.ONE.longValue();
AionTransaction tx = AionTransaction.create(deployerKey, txNonce, to, value, data, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
MiningBlock block = createDummyBlock();
AionRepositoryImpl repo = blockchain.getRepository();
RepositoryCache cache = repo.startTracking();
cache.addBalance(tx.getSenderAddress(), BigInteger.valueOf(100_000).multiply(BigInteger.valueOf(tx.getEnergyPrice())));
cache.createAccount(to);
cache.saveCode(to, Hex.decode(contract));
cache.saveVmType(to, InternalVmType.FVM);
cache.flushTo(repo, true);
AionTxReceipt receipt = executeTransaction(repo, block, tx).getReceipt();
System.out.println(receipt);
assertArrayEquals(Hex.decode("00000000000000000000000000000000"), receipt.getTransactionOutput());
}
use of org.aion.zero.impl.types.MiningBlock in project aion by aionnetwork.
the class OldTxExecutorTest method createDummyBlock.
private static MiningBlock createDummyBlock() {
byte[] parentHash = new byte[32];
byte[] coinbase = RandomUtils.nextBytes(AionAddress.LENGTH);
byte[] logsBloom = new byte[256];
byte[] difficulty = new DataWord(0x1000000L).getData();
long number = 1;
long timestamp = System.currentTimeMillis() / 1000;
byte[] extraData = new byte[0];
byte[] nonce = new byte[32];
byte[] receiptsRoot = new byte[32];
byte[] transactionsRoot = new byte[32];
byte[] stateRoot = new byte[32];
List<AionTransaction> transactionsList = Collections.emptyList();
byte[] solutions = new byte[1408];
// TODO: set a dummy limit of 5000000 for now
return new MiningBlock(parentHash, new AionAddress(coinbase), logsBloom, difficulty, number, timestamp, extraData, nonce, receiptsRoot, transactionsRoot, stateRoot, transactionsList, solutions, 0, 5000000);
}
use of org.aion.zero.impl.types.MiningBlock in project aion by aionnetwork.
the class StatefulnessTest method sendTransactions.
private AionTxReceipt sendTransactions(AionTransaction... transactions) {
Block parentBlock = this.blockchain.getBestBlock();
MiningBlock block = this.blockchain.createBlock(parentBlock, Arrays.asList(transactions), false, parentBlock.getTimestamp());
Pair<ImportResult, AionBlockSummary> connectResult = this.blockchain.tryToConnectAndFetchSummary(block);
assertEquals(ImportResult.IMPORTED_BEST, connectResult.getLeft());
return connectResult.getRight().getReceipts().get(0);
}
use of org.aion.zero.impl.types.MiningBlock in project aion by aionnetwork.
the class FvmBulkTransactionTest method sendTransactionsInBulkInSingleBlock.
private AionBlockSummary sendTransactionsInBulkInSingleBlock(List<AionTransaction> transactions) {
Block parentBlock = this.blockchain.getBestBlock();
MiningBlock block = this.blockchain.createBlock(parentBlock, transactions, false, parentBlock.getTimestamp());
Pair<ImportResult, AionBlockSummary> connectResult = this.blockchain.tryToConnectAndFetchSummary(block);
assertEquals(ImportResult.IMPORTED_BEST, connectResult.getLeft());
return connectResult.getRight();
}
Aggregations