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