use of org.aion.types.AionAddress in project aion by aionnetwork.
the class AvmLogAndInternalTransactionTest method testLogAndInternalTransactionsOnFailure.
@Test
public void testLogAndInternalTransactionsOnFailure() {
AvmVersion version = AvmVersion.VERSION_1;
AionAddress contract = deployContract(version, BigInteger.ZERO);
AionAddress other = deployContract(version, BigInteger.ONE);
Pair<ImportResult, AionBlockSummary> connectResult = callFireLogs(version, BigInteger.TWO, contract, other, "fireLogsAndFail");
AionBlockSummary summary = connectResult.getRight();
assertThat(connectResult.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
AionTxReceipt receipt = summary.getReceipts().get(0);
assertFalse(receipt.isSuccessful());
List<InternalTransaction> internalTransactions = summary.getSummaries().get(0).getInternalTransactions();
List<Log> logs = receipt.getLogInfoList();
assertEquals(0, logs.size());
assertEquals(1, internalTransactions.size());
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class AvmProviderTest method testBalanceTransferTransactionVersion2WithCoinbaseLock.
@Test
public void testBalanceTransferTransactionVersion2WithCoinbaseLock() throws Exception {
Assert.assertTrue(AvmProvider.tryAcquireLock(1, TimeUnit.MINUTES));
AvmProvider.enableAvmVersion(AvmVersion.VERSION_2, this.projectRootDir);
AvmProvider.startAvm(AvmVersion.VERSION_2, true);
// 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();
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class AccountManager method createAccount.
@Override
public AionAddress createAccount(String password) {
String address = Keystore.create(password);
ECKey key = Keystore.getKey(address, password);
logger.debug("<create-success addr={}>", address);
AionAddress aionAddress = new AionAddress(key.getAddress());
this.accounts.put(aionAddress, new Account(key, 0));
return aionAddress;
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class SolidityTypeTest 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.types.AionAddress in project aion by aionnetwork.
the class TotalCurrencyContract method executeUpdateTotalBalance.
private PrecompiledTransactionResult executeUpdateTotalBalance(byte[] input, long nrg) {
// update total portion
if (nrg < COST) {
return new PrecompiledTransactionResult(TransactionStatus.nonRevertedFailure("OUT_OF_NRG"), 0);
}
if (input.length < 114) {
return new PrecompiledTransactionResult(TransactionStatus.nonRevertedFailure("FAILURE"), 0);
}
// process input data
int offset = 0;
PrecompiledDataWord chainId = PrecompiledDataWord.fromInt(input[0]);
offset++;
byte signum = input[1];
offset++;
byte[] amount = new byte[16];
byte[] sign = new byte[96];
System.arraycopy(input, offset, amount, 0, 16);
offset += 16;
System.arraycopy(input, offset, sign, 0, 96);
IExternalCapabilitiesForPrecompiled capabilities = CapabilitiesProvider.getExternalCapabilities();
byte[] payload = new byte[18];
System.arraycopy(input, 0, payload, 0, 18);
boolean b = capabilities.verifyEd25519Signature(payload, sign);
if (!b) {
return new PrecompiledTransactionResult(TransactionStatus.nonRevertedFailure("FAILURE"), 0);
}
// verify public key matches owner
if (!this.ownerAddress.equals(new AionAddress(capabilities.getEd25519Address(sign)))) {
return new PrecompiledTransactionResult(TransactionStatus.nonRevertedFailure("FAILURE"), 0);
}
// payload processing
IPrecompiledDataWord totalCurr = this.externalState.getStorageValue(this.address, chainId);
BigInteger totalCurrBI = totalCurr == null ? BigInteger.ZERO : BIUtil.toBI(totalCurr.copyOfData());
BigInteger value = BIUtil.toBI(amount);
if (signum != 0x0 && signum != 0x1) {
return new PrecompiledTransactionResult(TransactionStatus.nonRevertedFailure("FAILURE"), 0);
}
BigInteger finalValue;
if (signum == 0x0) {
// addition
finalValue = totalCurrBI.add(value);
} else {
// subtraction
if (value.compareTo(totalCurrBI) > 0) {
return new PrecompiledTransactionResult(TransactionStatus.nonRevertedFailure("FAILURE"), 0);
}
finalValue = totalCurrBI.subtract(value);
}
// store result and successful exit
this.externalState.addStorageValue(this.address, chainId, PrecompiledDataWord.fromBytes(finalValue.toByteArray()));
return new PrecompiledTransactionResult(TransactionStatus.successful(), nrg - COST);
}
Aggregations