Search in sources :

Example 41 with DataWord

use of org.aion.util.types.DataWord in project aion by aionnetwork.

the class IContractDetailsTest method testPutSingleZeroValue.

@Test
public void testPutSingleZeroValue() {
    ByteArrayWrapper key = new DataWord(RandomUtils.nextBytes(DataWord.BYTES)).toWrapper();
    checkGetNonExistentPairing(cache1, key);
    checkGetNonExistentPairing(cache2, key);
    key = ByteArrayWrapper.wrap(RandomUtils.nextBytes(DOUBLE_BYTES));
    checkGetNonExistentPairing(cache1, key);
    checkGetNonExistentPairing(cache2, key);
}
Also used : ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) DataWord(org.aion.util.types.DataWord) Test(org.junit.Test)

Example 42 with DataWord

use of org.aion.util.types.DataWord in project aion by aionnetwork.

the class IContractDetailsTest method testPutDoubleZeroKey.

@Test
public void testPutDoubleZeroKey() {
    ByteArrayWrapper value = new DataWord(RandomUtils.nextBytes(DataWord.BYTES)).toWrapper();
    doPutDoubleZeroKeyTest(cache1, value);
    doPutDoubleZeroKeyTest(cache2, value);
    value = ByteArrayWrapper.wrap(RandomUtils.nextBytes(DOUBLE_BYTES));
    doPutDoubleZeroKeyTest(cache1, value);
    doPutDoubleZeroKeyTest(cache2, value);
}
Also used : ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) DataWord(org.aion.util.types.DataWord) Test(org.junit.Test)

Example 43 with DataWord

use of org.aion.util.types.DataWord in project aion by aionnetwork.

the class IContractDetailsTest method doSetZeroValueViaStorageTest.

/**
 * Sets a key-value pair with a zero value via cache.setStorage() and ensures that null is
 * returned when called on that same key.
 */
private void doSetZeroValueViaStorageTest(ContractDetails cache) {
    Map<ByteArrayWrapper, ByteArrayWrapper> storage = new HashMap<>();
    ByteArrayWrapper key = new DataWord(RandomUtils.nextBytes(DataWord.BYTES)).toWrapper();
    storage.put(key, null);
    setStorage(cache, storage);
    checkGetNonExistentPairing(cache, key);
}
Also used : ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) HashMap(java.util.HashMap) DataWord(org.aion.util.types.DataWord)

Example 44 with DataWord

use of org.aion.util.types.DataWord in project aion by aionnetwork.

the class OldTxExecutorTest method testBasicTransactionCost.

@Test
public void testBasicTransactionCost() throws Exception {
    byte[] txNonce = BigInteger.ZERO.toByteArray();
    AionAddress to = AddressUtils.wrapAddress("2222222222222222222222222222222222222222222222222222222222222222");
    byte[] value = BigInteger.ONE.toByteArray();
    byte[] data = new byte[0];
    long nrg = new DataWord(100000L).longValue();
    long nrgPrice = DataWord.ONE.longValue();
    ECKey key = ECKeyFac.inst().create();
    AionTransaction tx = AionTransaction.create(key, txNonce, to, value, data, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
    MiningBlock block = createDummyBlock();
    AionRepositoryImpl repoTop = blockchain.getRepository();
    RepositoryCache repo = repoTop.startTracking();
    repo.addBalance(tx.getSenderAddress(), BigInteger.valueOf(1_000_000_000L));
    repo.flushTo(repoTop, true);
    AionTxReceipt receipt = executeTransaction(repo, block, tx).getReceipt();
    System.out.println(receipt);
    assertEquals(TxUtil.calculateTransactionCost(tx), receipt.getEnergyUsed());
}
Also used : AionAddress(org.aion.types.AionAddress) RepositoryCache(org.aion.base.db.RepositoryCache) DataWord(org.aion.util.types.DataWord) ECKey(org.aion.crypto.ECKey) AionTransaction(org.aion.base.AionTransaction) AionRepositoryImpl(org.aion.zero.impl.db.AionRepositoryImpl) AionTxReceipt(org.aion.base.AionTxReceipt) MiningBlock(org.aion.zero.impl.types.MiningBlock) Test(org.junit.Test)

Example 45 with DataWord

use of org.aion.util.types.DataWord in project aion by aionnetwork.

the class OldTxExecutorTest method testPerformance.

@Test
public void testPerformance() 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();
    ECKey key = ECKeyFac.inst().create();
    AionTransaction tx = AionTransaction.create(key, txNonce, to, value, data, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
    MiningBlock block = createDummyBlock();
    AionRepositoryImpl repoTop = blockchain.getRepository();
    RepositoryCache repo = repoTop.startTracking();
    repo.addBalance(tx.getSenderAddress(), BigInteger.valueOf(100_000).multiply(BigInteger.valueOf(tx.getEnergyPrice())));
    repo.createAccount(to);
    repo.saveCode(to, Hex.decode(contract));
    repo.saveVmType(to, InternalVmType.FVM);
    repo.flushTo(repoTop, true);
    long t1 = System.nanoTime();
    long repeat = 1000;
    for (int i = 0; i < repeat; i++) {
        executeTransaction(repo, block, tx);
    }
    long t2 = System.nanoTime();
    System.out.println((t2 - t1) / repeat);
}
Also used : Compiler(org.aion.solidity.Compiler) AionAddress(org.aion.types.AionAddress) DataWord(org.aion.util.types.DataWord) ECKey(org.aion.crypto.ECKey) AionTransaction(org.aion.base.AionTransaction) AionRepositoryImpl(org.aion.zero.impl.db.AionRepositoryImpl) MiningBlock(org.aion.zero.impl.types.MiningBlock) RepositoryCache(org.aion.base.db.RepositoryCache) CompilationResult(org.aion.solidity.CompilationResult) Test(org.junit.Test)

Aggregations

DataWord (org.aion.util.types.DataWord)49 Test (org.junit.Test)37 AionAddress (org.aion.types.AionAddress)36 AionTransaction (org.aion.base.AionTransaction)29 BigInteger (java.math.BigInteger)23 RepositoryCache (org.aion.base.db.RepositoryCache)23 AionTxExecSummary (org.aion.base.AionTxExecSummary)18 MiningBlock (org.aion.zero.impl.types.MiningBlock)14 ByteArrayWrapper (org.aion.util.types.ByteArrayWrapper)12 BlockContext (org.aion.zero.impl.types.BlockContext)12 ECKey (org.aion.crypto.ECKey)7 AionRepositoryCache (org.aion.zero.impl.db.AionRepositoryCache)7 Log (org.aion.types.Log)4 HashMap (java.util.HashMap)3 AionTxReceipt (org.aion.base.AionTxReceipt)3 ImportResult (org.aion.zero.impl.core.ImportResult)3 Map (java.util.Map)2 InternalTransaction (org.aion.types.InternalTransaction)2 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)2 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)2