Search in sources :

Example 6 with SolidityType

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

the class SolidityTypeTest method testBytes2.

@Test
public void testBytes2() throws Exception {
    byte[] x = Hex.decode("11223344556677881122334455667788112233445566778811223344556677881122334455667788");
    SolidityType type = new BytesType();
    byte[] params = ByteUtil.merge(Hex.decode("00000000000000000000000000000010"), type.encode(x));
    System.out.println(Hex.toHexString(params));
    AionTransaction tx = createTransaction(ByteUtil.merge(Hex.decode("61cb5a01"), params));
    MiningBlock block = createDummyBlock();
    RepositoryCache repo = createRepository(tx);
    AionTxReceipt receipt = executeTransaction(tx, block, repo).getReceipt();
    System.out.println(receipt);
    assertArrayEquals(params, receipt.getTransactionOutput());
    assertArrayEquals(x, (byte[]) type.decode(receipt.getTransactionOutput(), 16));
}
Also used : 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) BytesType(org.aion.solidity.SolidityType.BytesType) Test(org.junit.Test)

Example 7 with SolidityType

use of org.aion.solidity.SolidityType 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)

Example 8 with SolidityType

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

the class SolidityTypeTest method testString2.

@Test
public void testString2() throws Exception {
    String x = "hello, world!hello, world!hello, world!hello, world!hello, world!hello, world!";
    SolidityType type = new StringType();
    byte[] params = ByteUtil.merge(Hex.decode("00000000000000000000000000000010"), type.encode(x));
    System.out.println(Hex.toHexString(params));
    AionTransaction tx = createTransaction(ByteUtil.merge(Hex.decode("61cb5a01"), params));
    MiningBlock block = createDummyBlock();
    RepositoryCache repo = createRepository(tx);
    AionTxReceipt receipt = executeTransaction(tx, block, repo).getReceipt();
    System.out.println(receipt);
    assertArrayEquals(params, receipt.getTransactionOutput());
    assertEquals(x, type.decode(receipt.getTransactionOutput(), 16));
}
Also used : StringType(org.aion.solidity.SolidityType.StringType) 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 9 with SolidityType

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

the class SolidityTypeTest method testString1.

@Test
public void testString1() throws Exception {
    String x = "hello, world!";
    SolidityType type = new StringType();
    byte[] params = ByteUtil.merge(Hex.decode("00000000000000000000000000000010"), type.encode(x));
    System.out.println(Hex.toHexString(params));
    AionTransaction tx = createTransaction(ByteUtil.merge(Hex.decode("61cb5a01"), params));
    MiningBlock block = createDummyBlock();
    RepositoryCache repo = createRepository(tx);
    AionTxReceipt receipt = executeTransaction(tx, block, repo).getReceipt();
    System.out.println(receipt);
    assertArrayEquals(params, receipt.getTransactionOutput());
    assertEquals(x, type.decode(receipt.getTransactionOutput(), 16));
}
Also used : StringType(org.aion.solidity.SolidityType.StringType) 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 10 with SolidityType

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

the class SolidityTypeTest method testFixedBytes2.

@Test
public void testFixedBytes2() throws Exception {
    byte[] x = Hex.decode("1122334455667788112233445566778811223344");
    SolidityType type = new Bytes32Type("bytes20");
    byte[] params = type.encode(x);
    System.out.println(Hex.toHexString(params));
    AionTransaction tx = createTransaction(ByteUtil.merge(Hex.decode("877b277f"), params));
    MiningBlock block = createDummyBlock();
    RepositoryCache repo = createRepository(tx);
    AionTxReceipt receipt = executeTransaction(tx, block, repo).getReceipt();
    System.out.println(receipt);
    assertArrayEquals(params, receipt.getTransactionOutput());
    assertArrayEquals(x, (byte[]) type.decode(receipt.getTransactionOutput()));
}
Also used : Bytes32Type(org.aion.solidity.SolidityType.Bytes32Type) 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

AionTransaction (org.aion.base.AionTransaction)10 AionTxReceipt (org.aion.base.AionTxReceipt)10 RepositoryCache (org.aion.base.db.RepositoryCache)10 SolidityType (org.aion.solidity.SolidityType)10 MiningBlock (org.aion.zero.impl.types.MiningBlock)10 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)4 BigInteger (java.math.BigInteger)2 Bytes32Type (org.aion.solidity.SolidityType.Bytes32Type)2 BytesType (org.aion.solidity.SolidityType.BytesType)2 DynamicArrayType (org.aion.solidity.SolidityType.DynamicArrayType)2 StaticArrayType (org.aion.solidity.SolidityType.StaticArrayType)2 StringType (org.aion.solidity.SolidityType.StringType)2