Search in sources :

Example 91 with RepositoryCache

use of org.aion.base.db.RepositoryCache 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 92 with RepositoryCache

use of org.aion.base.db.RepositoryCache 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 93 with RepositoryCache

use of org.aion.base.db.RepositoryCache 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 94 with RepositoryCache

use of org.aion.base.db.RepositoryCache in project aion by aionnetwork.

the class SolidityTypeTest method createRepository.

private RepositoryCache createRepository(AionTransaction tx) throws IOException {
    Result r = Compiler.getInstance().compile(ContractUtils.readContract("SolidityType.sol"), Options.BIN);
    CompilationResult cr = CompilationResult.parse(r.output);
    String deployer = cr.contracts.get("SolidityType").bin;
    String contract = deployer.substring(deployer.indexOf("60506040", 1));
    AionRepositoryImpl repo = blockchain.getRepository();
    RepositoryCache track = repo.startTracking();
    track.addBalance(tx.getSenderAddress(), BigInteger.valueOf(tx.getEnergyPrice()).multiply(BigInteger.valueOf(500_000L)));
    track.createAccount(tx.getDestinationAddress());
    track.saveCode(tx.getDestinationAddress(), Hex.decode(contract));
    track.saveVmType(tx.getDestinationAddress(), InternalVmType.FVM);
    track.flushTo(repo, true);
    return track;
}
Also used : RepositoryCache(org.aion.base.db.RepositoryCache) AionRepositoryImpl(org.aion.zero.impl.db.AionRepositoryImpl) CompilationResult(org.aion.solidity.CompilationResult) Result(org.aion.solidity.Compiler.Result) CompilationResult(org.aion.solidity.CompilationResult)

Example 95 with RepositoryCache

use of org.aion.base.db.RepositoryCache 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

RepositoryCache (org.aion.base.db.RepositoryCache)120 Test (org.junit.Test)102 AionAddress (org.aion.types.AionAddress)90 AionTransaction (org.aion.base.AionTransaction)89 AionTxExecSummary (org.aion.base.AionTxExecSummary)72 BigInteger (java.math.BigInteger)43 MiningBlock (org.aion.zero.impl.types.MiningBlock)41 AccountState (org.aion.base.AccountState)38 DataWord (org.aion.util.types.DataWord)23 AionRepositoryCache (org.aion.zero.impl.db.AionRepositoryCache)23 ImportResult (org.aion.zero.impl.core.ImportResult)22 InternalTransaction (org.aion.types.InternalTransaction)18 Block (org.aion.zero.impl.types.Block)18 AionTxReceipt (org.aion.base.AionTxReceipt)17 AionBlockchainImpl.getPostExecutionWorkForGeneratePreBlock (org.aion.zero.impl.blockchain.AionBlockchainImpl.getPostExecutionWorkForGeneratePreBlock)16 BlockContext (org.aion.zero.impl.types.BlockContext)15 SolidityType (org.aion.solidity.SolidityType)10 ArrayList (java.util.ArrayList)8 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)7 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)6