Search in sources :

Example 1 with Bytes32Type

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

the class SolidityTypeTest method testFixedBytes1.

@Test
public void testFixedBytes1() throws Exception {
    byte[] x = Hex.decode("1122334455");
    SolidityType type = new Bytes32Type("bytes5");
    byte[] params = type.encode(x);
    System.out.println(Hex.toHexString(params));
    AionTransaction tx = createTransaction(ByteUtil.merge(Hex.decode("faa068d1"), 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)

Example 2 with Bytes32Type

use of org.aion.solidity.SolidityType.Bytes32Type 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)2 AionTxReceipt (org.aion.base.AionTxReceipt)2 RepositoryCache (org.aion.base.db.RepositoryCache)2 SolidityType (org.aion.solidity.SolidityType)2 Bytes32Type (org.aion.solidity.SolidityType.Bytes32Type)2 MiningBlock (org.aion.zero.impl.types.MiningBlock)2 Test (org.junit.Test)2