Search in sources :

Example 1 with AbstractJsonMockBlockDb

use of neo.rpc.client.test.util.AbstractJsonMockBlockDb 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 2 with AbstractJsonMockBlockDb

use of neo.rpc.client.test.util.AbstractJsonMockBlockDb in project neo-java by coranos.

the class TestBlockSerialization method testGetBlock.

/**
 * test reading a miner transaction.
 */
@Test
@Ignore
public void testGetBlock() {
    final BlockDb blockDb = new AbstractJsonMockBlockDb() {

        @Override
        public JSONArray getMockBlockDb() {
            return new JSONArray();
        }
    };
    try {
        final String testName = "test001TxTypeMiner1";
        final int blockIx = 1271700;
        final String expectedBlockJsonStr = IOUtils.toString(this.getClass().getResourceAsStream("/neo/rpc/client/test/TestBlockSerialization." + testName + ".json"), "UTF-8");
        final Block block = blockDb.getFullBlockFromHeight(blockIx);
        final String actualBlockHex = ModelUtil.toHexString(block.toByteArray());
        final JSONObject actualBlockJson = TestUtil.toHexJsonObject(actualBlockHex);
        final String actualBlockJsonStr = actualBlockJson.toString(2);
        Assert.assertEquals("hex encodings of blocks must match", expectedBlockJsonStr, actualBlockJsonStr);
    } catch (final Exception e) {
        throw new RuntimeException(e);
    } finally {
        blockDb.close();
    }
}
Also used : JSONObject(org.json.JSONObject) 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) ClientProtocolException(org.apache.http.client.ClientProtocolException) DecoderException(org.apache.commons.codec.DecoderException) IOException(java.io.IOException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Block (neo.model.core.Block)2 BlockDb (neo.model.db.BlockDb)2 AbstractJsonMockBlockDb (neo.rpc.client.test.util.AbstractJsonMockBlockDb)2 JSONArray (org.json.JSONArray)2 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 TreeSet (java.util.TreeSet)1 Transaction (neo.model.core.Transaction)1 TransactionType (neo.model.core.TransactionType)1 DecoderException (org.apache.commons.codec.DecoderException)1 ClientProtocolException (org.apache.http.client.ClientProtocolException)1 JSONObject (org.json.JSONObject)1