Search in sources :

Example 16 with ByteArrayWrapper

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

the class IContractDetailsTest method testPutKeyValueThenOverwriteValueWithZero.

@Test
public void testPutKeyValueThenOverwriteValueWithZero() {
    // single-single
    ByteArrayWrapper key = new DataWord(RandomUtils.nextBytes(DataWord.BYTES)).toWrapper();
    ByteArrayWrapper value = new DataWord(RandomUtils.nextBytes(DataWord.BYTES)).toWrapper();
    doPutKeyValueThenOverwriteValueWithZero(cache1, key, value);
    doPutKeyValueThenOverwriteValueWithZero(cache2, key, value);
    // single-double
    value = ByteArrayWrapper.wrap(sixteenToThirtyTwo(RandomUtils.nextBytes(SINGLE_BYTES)));
    doPutKeyValueThenOverwriteValueWithZero(cache1, key, value);
    doPutKeyValueThenOverwriteValueWithZero(cache2, key, value);
    // double-single
    key = ByteArrayWrapper.wrap(sixteenToThirtyTwo(RandomUtils.nextBytes(SINGLE_BYTES)));
    value = new DataWord(RandomUtils.nextBytes(DataWord.BYTES)).toWrapper();
    doPutKeyValueThenOverwriteValueWithZero(cache1, key, value);
    doPutKeyValueThenOverwriteValueWithZero(cache2, key, value);
    // double-double
    key = ByteArrayWrapper.wrap(sixteenToThirtyTwo(RandomUtils.nextBytes(SINGLE_BYTES)));
    value = ByteArrayWrapper.wrap(sixteenToThirtyTwo(RandomUtils.nextBytes(SINGLE_BYTES)));
    doPutKeyValueThenOverwriteValueWithZero(cache1, key, value);
    doPutKeyValueThenOverwriteValueWithZero(cache2, key, value);
}
Also used : ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) DataWord(org.aion.util.types.DataWord) Test(org.junit.Test)

Example 17 with ByteArrayWrapper

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

the class IContractDetailsTest method testPutSingleZeroKey.

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

Example 18 with ByteArrayWrapper

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

the class IContractDetailsTest method checkAllPairs.

/**
 * Checks that cache contains all key-value pairs in keys and values, where it is assumed every
 * n'th pair was deleted.
 */
private void checkAllPairs(ContractDetails cache, List<ByteArrayWrapper> keys, List<ByteArrayWrapper> values, int n) {
    int size = keys.size();
    assertEquals(size, values.size());
    int count = 1;
    for (ByteArrayWrapper key : keys) {
        if (count % n == 0) {
            checkGetNonExistentPairing(cache, key);
        } else {
            assertEquals(values.get(count - 1), cache.get(key));
        }
        count++;
    }
}
Also used : ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper)

Example 19 with ByteArrayWrapper

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

the class IContractDetailsTest method testPutDoubleZeroValue.

@Test
public void testPutDoubleZeroValue() {
    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 20 with ByteArrayWrapper

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

the class IContractDetailsTest method massPutIntoCache.

/**
 * Puts all of the key-value pairs in keys and values into cache.
 */
private void massPutIntoCache(ContractDetails cache, List<ByteArrayWrapper> keys, List<ByteArrayWrapper> values) {
    int size = keys.size();
    assertEquals(size, values.size());
    for (int i = 0; i < size; i++) {
        ByteArrayWrapper value = values.get(i);
        if (value == null || value.isZero()) {
            cache.delete(keys.get(i));
        } else {
            cache.put(keys.get(i), values.get(i));
        }
    }
}
Also used : ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper)

Aggregations

ByteArrayWrapper (org.aion.util.types.ByteArrayWrapper)130 Test (org.junit.Test)51 HashMap (java.util.HashMap)39 ArrayList (java.util.ArrayList)33 AionAddress (org.aion.types.AionAddress)26 Block (org.aion.zero.impl.types.Block)24 Map (java.util.Map)20 BigInteger (java.math.BigInteger)14 MiningBlock (org.aion.zero.impl.types.MiningBlock)14 IOException (java.io.IOException)13 MockDB (org.aion.db.impl.mockdb.MockDB)13 DataWord (org.aion.util.types.DataWord)13 PooledTransaction (org.aion.base.PooledTransaction)11 List (java.util.List)10 AionTransaction (org.aion.base.AionTransaction)10 Properties (java.util.Properties)8 HashSet (java.util.HashSet)5 Optional (java.util.Optional)5 ECKey (org.aion.crypto.ECKey)5 RLPElement (org.aion.rlp.RLPElement)5