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;
}
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;
}
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));
}
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();
}
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));
}
}
Aggregations