use of org.aion.util.types.DataWord in project aion by aionnetwork.
the class Benchmark method verifyState.
private static void verifyState() throws VmFatalException {
long ownerNonce = repo.getNonce(owner).longValue();
for (int i = 0; i < recipients.size(); i++) {
byte[] nonce = BigInteger.valueOf(ownerNonce + i).toByteArray();
AionAddress to = contract;
byte[] value = BigInteger.ZERO.toByteArray();
byte[] data = ByteUtil.merge(Hex.decode("70a08231" + "000000000000000000000000"), recipients.get(i));
long nrg = 1_000_000L;
long nrgPrice = 10_000_000_000L;
AionTransaction tx = AionTransaction.create(key, nonce, to, value, data, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
AionTxExecSummary summary = executeTransaction(tx);
assertFalse(summary.isFailed());
assertEquals(1, new DataWord(summary.getReceipt().getTransactionOutput()).longValue());
}
}
use of org.aion.util.types.DataWord in project aion by aionnetwork.
the class AionRepositoryImpl method buildGenesis.
/**
* Saves the genesis block data inside the repository.
*
* @param genesis the genesis block to be flushed into the repository
*/
public void buildGenesis(AionGenesis genesis) {
// initialization section for network balance contract
RepositoryCache track = startTracking();
AionAddress networkBalanceAddress = ContractInfo.TOTAL_CURRENCY.contractAddress;
track.createAccount(networkBalanceAddress);
// saving FVM type for networkBalance contract
track.saveVmType(networkBalanceAddress, InternalVmType.FVM);
for (Map.Entry<Integer, BigInteger> addr : genesis.getNetworkBalances().entrySet()) {
// assumes only additions are performed in the genesis
track.addStorageRow(networkBalanceAddress, new DataWord(addr.getKey()).toWrapper(), wrapValueForPut(new DataWord(addr.getValue())));
}
for (AionAddress addr : genesis.getPremine().keySet()) {
track.createAccount(addr);
track.addBalance(addr, genesis.getPremine().get(addr).getBalance());
}
track.flushTo(this, true);
commitBlock(genesis.getHashWrapper(), genesis.getNumber(), genesis.getStateRoot());
blockStore.saveBlock(genesis, genesis.getDifficultyBI(), true);
}
use of org.aion.util.types.DataWord in project aion by aionnetwork.
the class TokenBridgeContractTest method testMemberCount.
@Test
public void testMemberCount() {
// override defaults
this.contract = new TokenBridgeContract(context(OWNER_ADDR, CONTRACT_ADDR), ExternalStateForTests.usingRepository(this.repository), OWNER_ADDR, CONTRACT_ADDR);
this.connector = this.contract.getConnector();
ListFVM encodingList = new ListFVM();
for (ECKey k : members) {
encodingList.add(new AddressFVM(k.getAddress()));
}
byte[] payload = new AbiEncoder(BridgeFuncSig.SIG_RING_INITIALIZE.getSignature(), encodingList).encodeBytes();
PrecompiledTransactionResult result = this.contract.execute(payload, DEFAULT_NRG);
assertTrue(result.getStatus().isSuccess());
// try before
byte[] callPayload = new AbiEncoder(BridgeFuncSig.PURE_MEMBER_COUNT.getSignature(), encodingList).encodeBytes();
PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG);
assertTrue(transferResult.getStatus().isSuccess());
assertThat(transferResult.getReturnData()).isEqualTo(new DataWord(new BigInteger("5")).getData());
// explicitly set the member count to 10
this.connector.setMemberCount(10);
// try after
byte[] callPayload2 = new AbiEncoder(BridgeFuncSig.PURE_MEMBER_COUNT.getSignature(), encodingList).encodeBytes();
PrecompiledTransactionResult transferResult2 = this.contract.execute(callPayload2, DEFAULT_NRG);
assertTrue(transferResult2.getStatus().isSuccess());
assertThat(transferResult2.getReturnData()).isEqualTo(new DataWord(new BigInteger("10")).getData());
}
use of org.aion.util.types.DataWord in project aion by aionnetwork.
the class InternalTransactionTest method testRecursiveCall.
/*
pragma solidity ^0.4.0;
contract A {
function f(int n) {
if (n > 0) {
this.f(n - 1);
}
}
}
*/
@Test
public void testRecursiveCall() throws Exception {
String contractA = "0x605060405234156100105760006000fd5b610015565b60e9806100236000396000f30060506040526000356c01000000000000000000000000900463ffffffff168063ec77996414603157602b565b60006000fd5b3415603c5760006000fd5b605060048080359060100190919050506052565b005b600081131560b9573063ec779964600184036040518263ffffffff166c01000000000000000000000000028152600401808281526010019150506000604051808303816000888881813b151560a75760006000fd5b5af1151560b45760006000fd5b505050505b5b505600a165627a7a7230582033f76d593b80b3468bfb0f873882bc00903a790a9b996cb8ca3bac51295994cd0029";
StandaloneBlockchain.Bundle bundle = (new StandaloneBlockchain.Builder()).withValidatorConfiguration("simple").withDefaultAccounts().build();
StandaloneBlockchain bc = bundle.bc;
ECKey deployerAccount = bundle.privateKeys.get(0);
// ======================
// DEPLOY
// ======================
BigInteger nonce = BigInteger.ZERO;
AionTransaction tx1 = AionTransaction.create(deployerAccount, nonce.toByteArray(), null, new byte[0], ByteUtil.hexStringToBytes(contractA), 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
BlockContext context = bc.createNewMiningBlockContext(bc.getBestBlock(), List.of(tx1), false);
ImportResult result = bc.tryToConnect(context.block);
assertThat(result).isEqualTo(ImportResult.IMPORTED_BEST);
AionAddress addressA = TxUtil.calculateContractAddress(tx1);
System.out.println("contract A = " + addressA);
Thread.sleep(1000);
// ======================
// CALL
// ======================
nonce = nonce.add(BigInteger.ONE);
AionTransaction tx2 = AionTransaction.create(deployerAccount, nonce.toByteArray(), addressA, new byte[0], ByteUtil.merge(ByteUtil.hexStringToBytes("0xec779964"), new DataWord(2).getData()), 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
context = bc.createNewMiningBlockContext(bc.getBestBlock(), List.of(tx2), false);
AionTxExecSummary summary = executeTransaction(bc, context, tx2);
assertEquals(2, summary.getInternalTransactions().size());
}
use of org.aion.util.types.DataWord in project aion by aionnetwork.
the class AionTransactionTest method testTransactionCost2.
@Test
public void testTransactionCost2() {
byte[] nonce = BigInteger.ONE.toByteArray();
byte[] value = BigInteger.ONE.toByteArray();
byte[] data = RandomUtils.nextBytes(128);
long nrg = new DataWord(1000L).longValue();
long nrgPrice = DataWord.ONE.longValue();
AionTransaction tx = AionTransaction.create(key, nonce, null, value, data, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
long expected = 200000 + 21000;
for (byte b : data) {
expected += (b == 0) ? 4 : 64;
}
assertEquals(expected, TxUtil.calculateTransactionCost(tx));
}
Aggregations