Search in sources :

Example 46 with DataWord

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

the class AionRepositoryCacheTest method testGetStorageValueWithDoubleZeroKey.

@Test
public void testGetStorageValueWithDoubleZeroKey() {
    AionAddress address = getNewAddress();
    ByteArrayWrapper value = new DataWord(RandomUtils.nextBytes(DataWord.BYTES)).toWrapper();
    cache.addStorageRow(address, ZERO_WRAPPED_32, value);
    assertEquals(value, cache.getStorageValue(address, ZERO_WRAPPED_32));
    value = ByteArrayWrapper.wrap(RandomUtils.nextBytes(DOUBLE_BYTES));
    cache.addStorageRow(address, ZERO_WRAPPED_32, value);
    assertEquals(value, cache.getStorageValue(address, ZERO_WRAPPED_32));
}
Also used : AionAddress(org.aion.types.AionAddress) ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) DataWord(org.aion.util.types.DataWord) Test(org.junit.Test)

Example 47 with DataWord

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

the class AionTransactionTest method testTransactionCost2.

@Test
public void testTransactionCost2() {
    byte[] nonce = BigInteger.ONE.toByteArray();
    byte[] value = BigInteger.ONE.toByteArray();
    byte[] data = RandomUtils.nextBytes(128);
    long nrg = new DataWord(1000L).longValue();
    long nrgPrice = DataWord.ONE.longValue();
    AionTransaction tx = AionTransaction.create(key, nonce, null, value, data, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
    long expected = 200000 + 21000;
    for (byte b : data) {
        expected += (b == 0) ? 4 : 64;
    }
    assertEquals(expected, TxUtil.calculateTransactionCost(tx));
}
Also used : DataWord(org.aion.util.types.DataWord) AionTransaction(org.aion.base.AionTransaction) Test(org.junit.Test)

Example 48 with DataWord

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

the class AionTransactionTest method testTransactionCost.

@Test
public void testTransactionCost() {
    byte[] nonce = BigInteger.ONE.toByteArray();
    byte[] to = RandomUtils.nextBytes(AionAddress.LENGTH);
    byte[] value = BigInteger.ONE.toByteArray();
    byte[] data = RandomUtils.nextBytes(128);
    long nrg = new DataWord(1000L).longValue();
    long nrgPrice = DataWord.ONE.longValue();
    AionTransaction tx = AionTransaction.create(key, nonce, new AionAddress(to), value, data, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
    long expected = 21000;
    for (byte b : data) {
        expected += (b == 0) ? 4 : 64;
    }
    assertEquals(expected, TxUtil.calculateTransactionCost(tx));
}
Also used : AionAddress(org.aion.types.AionAddress) DataWord(org.aion.util.types.DataWord) AionTransaction(org.aion.base.AionTransaction) Test(org.junit.Test)

Example 49 with DataWord

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

the class TokenBridgeContractTest method testMemberCount.

@Test
public void testMemberCount() {
    // 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_MEMBER_COUNT.getSignature(), encodingList).encodeBytes();
    PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG);
    assertTrue(transferResult.getStatus().isSuccess());
    assertThat(transferResult.getReturnData()).isEqualTo(new DataWord(new BigInteger("5")).getData());
    // explicitly set the member count to 10
    this.connector.setMemberCount(10);
    // try after
    byte[] callPayload2 = new AbiEncoder(BridgeFuncSig.PURE_MEMBER_COUNT.getSignature(), encodingList).encodeBytes();
    PrecompiledTransactionResult transferResult2 = this.contract.execute(callPayload2, DEFAULT_NRG);
    assertTrue(transferResult2.getStatus().isSuccess());
    assertThat(transferResult2.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