Search in sources :

Example 6 with Block

use of neo.model.core.Block in project neo-java by coranos.

the class AbstractJsonMockBlockDb method getBlock.

/**
 * return the Block in the given mock block.
 *
 * @param mockBlock
 *            the mock block to use.
 * @param withTransactions
 *            if true, add transactions. If false, only return the block header.
 * @return the Block in the given mock block.
 */
private static Block getBlock(final JSONObject mockBlock, final boolean withTransactions) {
    final String blockHex = mockBlock.getString(BLOCK);
    final Block block = new Block(ByteBuffer.wrap(ModelUtil.decodeHex(blockHex)));
    if (!withTransactions) {
        block.getTransactionList().clear();
    }
    return block;
}
Also used : Block(neo.model.core.Block)

Example 7 with Block

use of neo.model.core.Block in project neo-java by coranos.

the class MockUtil method getMockBlock001.

public static Block getMockBlock001() {
    final Block block = getMockBlock000();
    final Transaction transaction = getMockTransaction000();
    transaction.inputs.add(getCoinReference000());
    transaction.outputs.add(getTransactionOutput000());
    transaction.scripts.add(getWitness000());
    block.getTransactionList().add(transaction);
    return block;
}
Also used : Transaction(neo.model.core.Transaction) Block(neo.model.core.Block)

Example 8 with Block

use of neo.model.core.Block in project neo-java by coranos.

the class MockUtil method getMockBlock002.

private static Block getMockBlock002() {
    final int minSize = (UInt32.SIZE * 3) + (UInt256.SIZE * 2) + (UInt64.SIZE) + (UInt160.SIZE) + 4;
    final byte[] ba = new byte[minSize];
    final int indexOffset = (UInt32.SIZE * 2) + (UInt256.SIZE * 2);
    final UInt32 index = new UInt32(1);
    System.arraycopy(index.getBytesCopy(), 0, ba, indexOffset, index.getByteLength());
    return new Block(ByteBuffer.wrap(ba));
}
Also used : Block(neo.model.core.Block) UInt32(neo.model.bytes.UInt32)

Example 9 with Block

use of neo.model.core.Block in project neo-java by coranos.

the class TestBlockSerialization method test00ZAllBlocks.

/**
 * pulls all the blocks (slow) to check for full coverage.
 *
 * @throws ClientProtocolException
 *             if an error occurs.
 * @throws IOException
 *             if an error occurs.
 * @throws DecoderException
 *             if an error occurs.
 * @throws InterruptedException
 *             if an error occurs.
 */
@Test
@Ignore
public void test00ZAllBlocks() throws ClientProtocolException, IOException, DecoderException, InterruptedException {
    final BlockDb blockDb = new AbstractJsonMockBlockDb() {

        @Override
        public JSONArray getMockBlockDb() {
            return new JSONArray();
        }
    };
    final long maxBlockIx = blockDb.getHeaderOfBlockWithMaxIndex().getIndexAsLong();
    final Set<TransactionType> knownTypeSet = new TreeSet<>();
    for (long blockIx = 0; blockIx <= maxBlockIx; blockIx++) {
        final Block block = blockDb.getFullBlockFromHeight(blockIx);
        for (int txIx = 0; txIx < block.getTransactionList().size(); txIx++) {
            final Transaction tx = block.getTransactionList().get(txIx);
            if (!knownTypeSet.contains(tx.type)) {
                LOG.error("getBlock {} {} tx {} {}", block.getIndexAsLong(), block.prevHash, txIx, tx.type);
                knownTypeSet.add(tx.type);
            }
        }
    }
    blockDb.close();
}
Also used : TransactionType(neo.model.core.TransactionType) Transaction(neo.model.core.Transaction) TreeSet(java.util.TreeSet) AbstractJsonMockBlockDb(neo.rpc.client.test.util.AbstractJsonMockBlockDb) JSONArray(org.json.JSONArray) Block(neo.model.core.Block) BlockDb(neo.model.db.BlockDb) AbstractJsonMockBlockDb(neo.rpc.client.test.util.AbstractJsonMockBlockDb) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with Block

use of neo.model.core.Block in project neo-java by coranos.

the class TestDBH2 method test006putAndGetTransactionWithHash.

/**
 * test put, and getTransactionWithHash.
 */
@Test
public void test006putAndGetTransactionWithHash() {
    try (TestLocalControllerNode controller = getTestLocalControllerNode()) {
        final Block block = MockUtil.getMockBlock001();
        controller.getBlockDb().put(true, block);
        final Transaction expectedTransaction = block.getTransactionList().get(0);
        final Transaction actualTransaction = controller.getBlockDb().getTransactionWithHash(expectedTransaction.getHash());
        Assert.assertEquals("transactions should match.", expectedTransaction.toJSONObject().toString(2), actualTransaction.toJSONObject().toString(2));
    }
}
Also used : Transaction(neo.model.core.Transaction) Block(neo.model.core.Block) Test(org.junit.Test)

Aggregations

Block (neo.model.core.Block)65 Test (org.junit.Test)26 Transaction (neo.model.core.Transaction)25 JSONObject (org.json.JSONObject)24 JSONArray (org.json.JSONArray)16 TransactionOutput (neo.model.core.TransactionOutput)9 BlockDb (neo.model.db.BlockDb)9 IOException (java.io.IOException)8 TreeMap (java.util.TreeMap)8 UInt256 (neo.model.bytes.UInt256)8 LocalNodeData (neo.network.model.LocalNodeData)6 Fixed8 (neo.model.bytes.Fixed8)5 Timestamp (java.sql.Timestamp)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 TreeSet (java.util.TreeSet)4 OutputStream (java.io.OutputStream)3 SQLException (java.sql.SQLException)3 UInt160 (neo.model.bytes.UInt160)3 UInt32 (neo.model.bytes.UInt32)3