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);
}
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);
}
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);
}
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());
}
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);
}
Aggregations