Search in sources :

Example 1 with DynamicArrayType

use of org.aion.solidity.SolidityType.DynamicArrayType in project aion by aionnetwork.

the class SolidityTypeTest method testDynamicArray1.

@Test
public void testDynamicArray1() throws Exception {
    List<BigInteger> x = new ArrayList<>();
    x.add(BigInteger.valueOf(1L));
    x.add(BigInteger.valueOf(2L));
    x.add(BigInteger.valueOf(3L));
    SolidityType type = new DynamicArrayType("uint16[]");
    byte[] params = ByteUtil.merge(Hex.decode("00000000000000000000000000000010"), type.encode(x));
    System.out.println(Hex.toHexString(params));
    AionTransaction tx = createTransaction(ByteUtil.merge(Hex.decode("8c0c5523"), params));
    MiningBlock block = createDummyBlock();
    RepositoryCache repo = createRepository(tx);
    AionTxReceipt receipt = executeTransaction(tx, block, repo).getReceipt();
    System.out.println(receipt);
    assertArrayEquals(params, receipt.getTransactionOutput());
    Object[] decoded = (Object[]) type.decode(receipt.getTransactionOutput(), 16);
    for (Object d : decoded) {
        System.out.println(d);
    }
}
Also used : DynamicArrayType(org.aion.solidity.SolidityType.DynamicArrayType) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) RepositoryCache(org.aion.base.db.RepositoryCache) AionTransaction(org.aion.base.AionTransaction) SolidityType(org.aion.solidity.SolidityType) AionTxReceipt(org.aion.base.AionTxReceipt) MiningBlock(org.aion.zero.impl.types.MiningBlock) Test(org.junit.Test)

Example 2 with DynamicArrayType

use of org.aion.solidity.SolidityType.DynamicArrayType in project aion by aionnetwork.

the class SolidityTypeTest method testDynamicArray2.

@Test
public void testDynamicArray2() throws Exception {
    List<byte[]> x = new ArrayList<>();
    x.add(Hex.decode("1122334455667788112233445566778811223344"));
    x.add(Hex.decode("2122334455667788112233445566778811223344"));
    x.add(Hex.decode("3122334455667788112233445566778811223344"));
    SolidityType type = new DynamicArrayType("bytes20[]");
    byte[] params = ByteUtil.merge(Hex.decode("00000000000000000000000000000010"), type.encode(x));
    System.out.println(Hex.toHexString(params));
    AionTransaction tx = createTransaction(ByteUtil.merge(Hex.decode("97c3b2db"), params));
    MiningBlock block = createDummyBlock();
    RepositoryCache repo = createRepository(tx);
    AionTxReceipt receipt = executeTransaction(tx, block, repo).getReceipt();
    System.out.println(receipt);
    assertArrayEquals(params, receipt.getTransactionOutput());
    Object[] decoded = (Object[]) type.decode(receipt.getTransactionOutput(), 16);
    for (Object d : decoded) {
        System.out.println(d);
    }
}
Also used : DynamicArrayType(org.aion.solidity.SolidityType.DynamicArrayType) ArrayList(java.util.ArrayList) RepositoryCache(org.aion.base.db.RepositoryCache) AionTransaction(org.aion.base.AionTransaction) SolidityType(org.aion.solidity.SolidityType) AionTxReceipt(org.aion.base.AionTxReceipt) MiningBlock(org.aion.zero.impl.types.MiningBlock) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 AionTransaction (org.aion.base.AionTransaction)2 AionTxReceipt (org.aion.base.AionTxReceipt)2 RepositoryCache (org.aion.base.db.RepositoryCache)2 SolidityType (org.aion.solidity.SolidityType)2 DynamicArrayType (org.aion.solidity.SolidityType.DynamicArrayType)2 MiningBlock (org.aion.zero.impl.types.MiningBlock)2 Test (org.junit.Test)2 BigInteger (java.math.BigInteger)1