use of org.aion.types.AionAddress in project aion by aionnetwork.
the class VMTxStateAlignTest method testDeployAndCallContractStatesAlign.
@Test
public void testDeployAndCallContractStatesAlign() throws IOException {
List<AionTransaction> txList = new ArrayList<>();
List<AionAddress> deployAddr = new ArrayList<>();
for (int i = 0; i < this.deployerKeys.size() && i < deployerNum; i++) {
ECKey senderKey = this.deployerKeys.get(i);
txList.add(makeFvmContractCreateTransaction(senderKey, BigInteger.ZERO));
deployAddr.add(TxUtil.calculateContractAddress(txList.get(i)));
}
MiningBlock deplayBlock = genNewBlock(txList, blockchainWoAVM);
tryImportNewBlock(blockchainWoAVM, deplayBlock);
txList.clear();
ECKey sender = this.deployerKeys.get(deployerKeys.size() - 1);
txList.add(makePrecompiledContractTransaction(sender, BigInteger.ZERO));
for (int i = 0; i < this.deployerKeys.size() && i < deployerNum; i++) {
ECKey senderKey = this.deployerKeys.get(i);
txList.add(makeFvmContractCallTransaction(senderKey, BigInteger.ONE, deployAddr.get(i)));
}
MiningBlock callBlock = genNewBlock(txList, blockchainWoAVM);
tryImportNewBlock(blockchainWoAVM, callBlock);
// Does not initial in the setup call due to the avmenable in the StandaloneBlockchain is a
// static variable.
StandaloneBlockchain.Bundle bundleAVM = new StandaloneBlockchain.Builder().withDefaultAccounts(deployerKeys).withAvmEnabled().withValidatorConfiguration("simple").build();
StandaloneBlockchain blockchainWithAVM = bundleAVM.bc;
tryImportNewBlock(blockchainWithAVM, deplayBlock);
tryImportNewBlock(blockchainWithAVM, callBlock);
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class VMTxStateAlignTest method setup.
@Before
public void setup() {
StandaloneBlockchain.Bundle bundle = new StandaloneBlockchain.Builder().withDefaultAccounts().withValidatorConfiguration("simple").build();
this.blockchainWoAVM = bundle.bc;
deployerKeys = bundle.privateKeys;
deployers = new ArrayList<>();
for (int i = 0; i < deployerNum && i < deployerKeys.size(); i++) {
AionAddress deployerAddr = new AionAddress(this.deployerKeys.get(i).getAddress());
deployers.add(deployerAddr);
}
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class ApiAion method createContract.
protected ApiTxResponse createContract(ArgTxCall _params) {
if (_params == null) {
return (new ApiTxResponse(TxResponse.INVALID_TX));
}
AionAddress from = _params.getFrom();
if (from == null) {
LOG.error("<create-contract msg=invalid-from-address>");
return (new ApiTxResponse(TxResponse.INVALID_FROM));
}
ECKey key = this.getAccountKey(from.toString());
if (key == null) {
LOG.debug("ApiAion.createContract - null key");
return (new ApiTxResponse(TxResponse.INVALID_ACCOUNT));
}
try {
synchronized (pendingState) {
byte[] nonce = !(_params.getNonce().equals(BigInteger.ZERO)) ? _params.getNonce().toByteArray() : pendingState.bestPendingStateNonce(new AionAddress(key.getAddress())).toByteArray();
AionTransaction tx = AionTransaction.create(key, nonce, null, _params.getValue().toByteArray(), _params.getData(), _params.getNrg(), _params.getNrgPrice(), _params.getType(), null);
TxResponse rsp = pendingState.addTransactionFromApiServer(tx);
AionAddress address = TxUtil.calculateContractAddress(tx);
return new ApiTxResponse(rsp, tx.getTransactionHash(), address);
}
} catch (Exception ex) {
LOG.error("ApiAion.createContract - exception: [{}]", ex.getMessage());
return new ApiTxResponse(TxResponse.EXCEPTION, ex);
}
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class ApiAion method estimateNrg.
protected long estimateNrg(ArgTxCall params) {
AionAddress fromAddr = (params.getFrom() == null) ? AddressUtils.ZERO_ADDRESS : params.getFrom();
AionTransaction tx = AionTransaction.createWithoutKey(params.getNonce().toByteArray(), fromAddr, params.getTo(), params.getValue().toByteArray(), params.getData(), params.getNrg(), params.getNrgPrice(), params.getType(), null);
AionTxReceipt receipt = this.ac.callConstant(tx, this.ac.getAionHub().getBlockchain().getBestBlock());
return receipt.getEnergyUsed();
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class AvmProviderTest method testBalanceTransferTransactionVersion2.
@Test
public void testBalanceTransferTransactionVersion2() throws Exception {
Assert.assertTrue(AvmProvider.tryAcquireLock(1, TimeUnit.MINUTES));
AvmProvider.enableAvmVersion(AvmVersion.VERSION_2, this.projectRootDir);
AvmProvider.startAvm(AvmVersion.VERSION_2);
// Set up the repo and give the sender account some balance.
RepositoryCache repository = newRepository();
AionAddress sender = randomAddress();
AionAddress recipient = randomAddress();
addBalance(repository, sender, BigInteger.valueOf(1_000_000));
// Run the transaction.
RepositoryCache repositoryChild = repository.startTracking();
IAvmExternalState externalState = newExternalState(AvmVersion.VERSION_2, repositoryChild, newEnergyRules());
Transaction transaction = newBalanceTransferTransaction(sender, recipient, BigInteger.TEN);
IAionVirtualMachine avm = AvmProvider.getAvm(AvmVersion.VERSION_2);
IAvmFutureResult[] futures = avm.run(externalState, new Transaction[] { transaction }, AvmExecutionType.MINING, 0);
// Assert the result and state changes we expect.
Assert.assertEquals(1, futures.length);
TransactionResult result = futures[0].getResult();
Assert.assertTrue(result.transactionStatus.isSuccess());
Assert.assertEquals(BigInteger.TEN, repositoryChild.getBalance(recipient));
AvmProvider.shutdownAvm(AvmVersion.VERSION_2);
AvmProvider.disableAvmVersion(AvmVersion.VERSION_2);
AvmProvider.releaseLock();
}
Aggregations