use of org.aion.avm.stub.AvmVersion in project aion by aionnetwork.
the class AvmInternalTxTest method testDeployAndCallContract.
@Test
public void testDeployAndCallContract() {
AvmVersion version = AvmVersion.VERSION_1;
TransactionTypeRule.allowAVMContractTransaction();
// Deploy the contract.
byte[] jar = getJarBytes(version);
AionTransaction transaction = AionTransaction.create(deployerKey, new byte[0], null, new byte[0], jar, 5_000_000, minEnergyPrice, TransactionTypes.AVM_CREATE_CODE, null);
MiningBlock block = this.blockchain.createNewMiningBlock(this.blockchain.getBestBlock(), Collections.singletonList(transaction), false);
Pair<ImportResult, AionBlockSummary> connectResult = this.blockchain.tryToConnectAndFetchSummary(block);
AionTxReceipt receipt = connectResult.getRight().getReceipts().get(0);
// Check the block was imported, the contract has the Avm prefix, and deployment succeeded.
assertThat(connectResult.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
assertThat(receipt.getTransactionOutput()[0]).isEqualTo(AddressSpecs.A0_IDENTIFIER);
assertThat(receipt.isSuccessful()).isTrue();
AionAddress contract = new AionAddress(receipt.getTransactionOutput());
// verify that the output is indeed the contract address
assertThat(TxUtil.calculateContractAddress(transaction)).isEqualTo(contract);
IAvmResourceFactory factory = (version == AvmVersion.VERSION_1) ? resourceProvider.factoryForVersion1 : resourceProvider.factoryForVersion2;
byte[] call = factory.newStreamingEncoder().encodeOneString("recursivelyGetValue").getEncoding();
makeCall(BigInteger.ONE, contract, call);
}
use of org.aion.avm.stub.AvmVersion in project aion by aionnetwork.
the class AvmTransactionExecutor method updateAvmsAndGetVersionToUse.
/**
* Updates the state of the avm versions depending on the current block number.
*
* This method will ensure that any avm versions that are enabled but which are prohibited to
* be enabled at this block number will be shutdown and disabled.
*
* It will also ensure that the avm version that is considered the canonical version at this
* block number is enabled and that its avm is started.
*
* @implNote The projectRootPath is the path to the root directory of the aion project. This is
* required so that we can find the resources to load.
*
* @param projectRootPath The path of the project root directory.
* @param currentBlockNumber The current block number.
* @param enableCoinbaseAddressLocking The flag to enable the coinbase addresslock
* @return the version of the avm to use for the given block number.
*/
public static AvmVersion updateAvmsAndGetVersionToUse(String projectRootPath, long currentBlockNumber, boolean enableCoinbaseAddressLocking) throws IOException, IllegalAccessException, ClassNotFoundException, InstantiationException {
AvmVersionSchedule schedule = AvmConfigurations.getAvmVersionSchedule();
AvmVersion versionToUse = schedule.whichVersionToRunWith(currentBlockNumber);
if (versionToUse == null) {
throw new IllegalStateException("Attempted to invoke the avm at a block that has no avm support!");
}
if (versionToUse == AvmVersion.VERSION_1) {
disableVersionIfEnabledAndProhibited(schedule, AvmVersion.VERSION_2, currentBlockNumber);
ensureVersionIsEnabledAndStarted(AvmVersion.VERSION_1, projectRootPath);
} else if (versionToUse == AvmVersion.VERSION_2) {
disableVersionIfEnabledAndProhibited(schedule, AvmVersion.VERSION_1, currentBlockNumber);
if (AvmConfigurations.isCoinbaseAddressLockingEnabled() != enableCoinbaseAddressLocking || // AKI-636 workaround
currentBlockNumber == 4820587) {
if (AvmProvider.isAvmRunning(versionToUse)) {
AvmProvider.shutdownAvm(versionToUse);
}
boolean enable = (currentBlockNumber == 4820587) || enableCoinbaseAddressLocking;
AionLoggerFactory.getLogger(LogEnum.VM.toString()).info("Set the CoinbaseAddressLocking to {}, block#{}", enable, currentBlockNumber);
AvmConfigurations.setEnableCoinbaseAddressLocking(enable);
}
ensureVersionIsEnabledAndStarted(AvmVersion.VERSION_2, projectRootPath);
} else {
throw new IllegalStateException("Unknown avm version: " + versionToUse);
}
return versionToUse;
}
Aggregations