use of org.aion.util.types.DataWord in project aion by aionnetwork.
the class AionRepositoryCacheTest method testOverwriteValueWithDoubleZero.
@Test
public void testOverwriteValueWithDoubleZero() {
AionAddress address = getNewAddress();
ByteArrayWrapper key = ByteArrayWrapper.wrap(RandomUtils.nextBytes(DOUBLE_BYTES));
ByteArrayWrapper value = new DataWord(RandomUtils.nextBytes(DataWord.BYTES)).toWrapper();
cache.addStorageRow(address, key, value);
assertEquals(value, cache.getStorageValue(address, key));
cache.removeStorageRow(address, key);
assertNull(cache.getStorageValue(address, key));
}
use of org.aion.util.types.DataWord 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.DataWord 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.DataWord 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.DataWord in project aion by aionnetwork.
the class TokenBridgeContractTest method testMinThreshold.
@Test
public void testMinThreshold() {
// 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_MIN_THRESH.getSignature(), encodingList).encodeBytes();
PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG);
assertTrue(transferResult.getStatus().isSuccess());
assertThat(transferResult.getReturnData()).isEqualTo(new DataWord(new BigInteger("3")).getData());
// explicitly set the min threshold to 5
this.connector.setMinThresh(5);
// try after
byte[] callPayload2 = new AbiEncoder(BridgeFuncSig.PURE_MIN_THRESH.getSignature(), encodingList).encodeBytes();
PrecompiledTransactionResult transferResult2 = this.contract.execute(callPayload2, DEFAULT_NRG);
assertTrue(transferResult2.getStatus().isSuccess());
assertThat(transferResult2.getReturnData()).isEqualTo(new DataWord(new BigInteger("5")).getData());
// try setting threshold greater than number of validator members
this.connector.setMinThresh(10);
// try after
byte[] callPayload3 = new AbiEncoder(BridgeFuncSig.PURE_MIN_THRESH.getSignature(), encodingList).encodeBytes();
PrecompiledTransactionResult transferResult3 = this.contract.execute(callPayload3, DEFAULT_NRG);
assertTrue(transferResult3.getStatus().isSuccess());
assertThat(transferResult3.getReturnData()).isEqualTo(new DataWord(new BigInteger("10")).getData());
}
Aggregations