Search in sources :

Example 31 with MiningBlock

use of org.aion.zero.impl.types.MiningBlock in project aion by aionnetwork.

the class SolidityTypeTest method createDummyBlock.

private static MiningBlock createDummyBlock() {
    byte[] parentHash = new byte[32];
    byte[] coinbase = RandomUtils.nextBytes(AionAddress.LENGTH);
    byte[] logsBloom = new byte[256];
    byte[] difficulty = new DataWord(0x1000000L).getData();
    long number = 1;
    long timestamp = System.currentTimeMillis() / 1000;
    byte[] extraData = new byte[0];
    byte[] nonce = new byte[32];
    byte[] receiptsRoot = new byte[32];
    byte[] transactionsRoot = new byte[32];
    byte[] stateRoot = new byte[32];
    List<AionTransaction> transactionsList = Collections.emptyList();
    byte[] solutions = new byte[1408];
    // TODO: set a dummy limit of 5000000 for now
    return new MiningBlock(parentHash, new AionAddress(coinbase), logsBloom, difficulty, number, timestamp, extraData, nonce, receiptsRoot, transactionsRoot, stateRoot, transactionsList, solutions, 0, 5000000);
}
Also used : AionAddress(org.aion.types.AionAddress) DataWord(org.aion.util.types.DataWord) AionTransaction(org.aion.base.AionTransaction) MiningBlock(org.aion.zero.impl.types.MiningBlock)

Example 32 with MiningBlock

use of org.aion.zero.impl.types.MiningBlock in project aion by aionnetwork.

the class SolidityTypeTest method testBytes1.

@Test
public void testBytes1() throws Exception {
    byte[] x = Hex.decode("1122334455667788");
    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 33 with MiningBlock

use of org.aion.zero.impl.types.MiningBlock 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 34 with MiningBlock

use of org.aion.zero.impl.types.MiningBlock in project aion by aionnetwork.

the class SolidityTypeTest method testStaticArray1.

@Test
public void testStaticArray1() 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 StaticArrayType("uint16[3]");
    byte[] params = type.encode(x);
    System.out.println(Hex.toHexString(params));
    AionTransaction tx = createTransaction(ByteUtil.merge(Hex.decode("97e934e2"), 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());
    for (Object d : decoded) {
        System.out.println(d);
    }
}
Also used : ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) RepositoryCache(org.aion.base.db.RepositoryCache) StaticArrayType(org.aion.solidity.SolidityType.StaticArrayType) 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 35 with MiningBlock

use of org.aion.zero.impl.types.MiningBlock 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)

Aggregations

MiningBlock (org.aion.zero.impl.types.MiningBlock)185 Test (org.junit.Test)136 AionTransaction (org.aion.base.AionTransaction)128 ImportResult (org.aion.zero.impl.core.ImportResult)81 AionAddress (org.aion.types.AionAddress)79 BigInteger (java.math.BigInteger)64 Block (org.aion.zero.impl.types.Block)63 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)59 RepositoryCache (org.aion.base.db.RepositoryCache)41 AionTxReceipt (org.aion.base.AionTxReceipt)37 ArrayList (java.util.ArrayList)36 ECKey (org.aion.crypto.ECKey)27 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)27 AionTxExecSummary (org.aion.base.AionTxExecSummary)25 AionRepositoryCache (org.aion.zero.impl.db.AionRepositoryCache)24 MiningBlockHeader (org.aion.zero.impl.types.MiningBlockHeader)22 BlockContext (org.aion.zero.impl.types.BlockContext)18 DataWord (org.aion.util.types.DataWord)13 MockDB (org.aion.db.impl.mockdb.MockDB)12 StakingBlock (org.aion.zero.impl.types.StakingBlock)11