Search in sources :

Example 1 with DataWord

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));
}
Also used : AionAddress(org.aion.types.AionAddress) ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) DataWord(org.aion.util.types.DataWord) Test(org.junit.Test)

Example 2 with DataWord

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);
}
Also used : ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) DataWord(org.aion.util.types.DataWord) Test(org.junit.Test)

Example 3 with DataWord

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);
}
Also used : ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) DataWord(org.aion.util.types.DataWord) Test(org.junit.Test)

Example 4 with DataWord

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);
}
Also used : ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) DataWord(org.aion.util.types.DataWord) Test(org.junit.Test)

Example 5 with DataWord

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());
}
Also used : PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) TokenBridgeContract(org.aion.precompiled.contracts.ATB.TokenBridgeContract) AddressFVM(org.aion.zero.impl.precompiled.encoding.AddressFVM) AbiEncoder(org.aion.zero.impl.precompiled.encoding.AbiEncoder) BigInteger(java.math.BigInteger) ECKey(org.aion.crypto.ECKey) DataWord(org.aion.util.types.DataWord) ListFVM(org.aion.zero.impl.precompiled.encoding.ListFVM) 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