use of neo.model.core.Block in project neo-java by coranos.
the class TestDBMapDb method test004getHeaderOfBlockWithMaxIndex.
/**
* test getHeaderOfBlockWithMaxIndex.
*/
@Test
public void test004getHeaderOfBlockWithMaxIndex() {
try (TestLocalControllerNode controller = getTestLocalControllerNode()) {
final Block actual = controller.getBlockDb().getHeaderOfBlockWithMaxIndex();
Assert.assertEquals("getHeaderOfBlockWithMaxIndex should return null with empty db.", null, actual);
}
}
use of neo.model.core.Block in project neo-java by coranos.
the class TestDBMapDb method test011putAndGetHeaderOfBlockFromHash.
/**
* test put, and getHeaderOfBlockFromHash.
*/
@Test
public void test011putAndGetHeaderOfBlockFromHash() {
try (TestLocalControllerNode controller = getTestLocalControllerNode()) {
final Block expectedBlock = MockUtil.getMockBlock003();
controller.getBlockDb().put(true, GenesisBlockUtil.GENESIS_BLOCK);
controller.getBlockDb().put(true, expectedBlock);
expectedBlock.getTransactionList().clear();
final Block actualBlock = controller.getBlockDb().getHeaderOfBlockFromHash(expectedBlock.hash);
Assert.assertEquals("blocks should match.", expectedBlock.toString(), actualBlock.toString());
}
}
use of neo.model.core.Block in project neo-java by coranos.
the class TestDBMapDb method test010putAndGetHeaderOfBlockFromHeight.
/**
* test put, and getHeaderOfBlockFromHeight.
*/
@Test
public void test010putAndGetHeaderOfBlockFromHeight() {
try (TestLocalControllerNode controller = getTestLocalControllerNode()) {
final Block expectedBlock = MockUtil.getMockBlock003();
controller.getBlockDb().put(true, GenesisBlockUtil.GENESIS_BLOCK);
controller.getBlockDb().put(true, expectedBlock);
expectedBlock.getTransactionList().clear();
final Block actualBlock = controller.getBlockDb().getHeaderOfBlockFromHeight(1);
Assert.assertEquals("blocks should match.", expectedBlock.toString(), actualBlock.toString());
}
}
use of neo.model.core.Block in project neo-java by coranos.
the class TestDBMapDb method test007putAndGetFullBlockFromHash.
/**
* test put, and getFullBlockFromHash.
*/
@Test
public void test007putAndGetFullBlockFromHash() {
try (TestLocalControllerNode controller = getTestLocalControllerNode()) {
final Block expectedBlock = MockUtil.getMockBlock003();
controller.getBlockDb().put(true, GenesisBlockUtil.GENESIS_BLOCK);
controller.getBlockDb().put(true, expectedBlock);
final Block actualBlock = controller.getBlockDb().getFullBlockFromHash(expectedBlock.hash);
Assert.assertEquals("blocks should match.", expectedBlock.toString(), actualBlock.toString());
}
}
use of neo.model.core.Block in project neo-java by coranos.
the class Message method createPayload.
/**
* creates a payload.
*
* @param cl
* the payload class.
* @param <T>
* the payload type.
* @return the payload.
*/
@SuppressWarnings("unchecked")
private <T extends Payload> T createPayload(final Class<T> cl) {
if (LOG.isTraceEnabled()) {
LOG.trace("initPayload payloadBa {}", Hex.encodeHexString(payloadBa));
}
final Payload payload;
switch(command) {
case "version":
payload = new VersionPayload(ByteBuffer.wrap(payloadBa));
break;
case "inv":
payload = new InvPayload(ByteBuffer.wrap(payloadBa));
break;
case "addr":
payload = new AddrPayload(ByteBuffer.wrap(payloadBa));
break;
case "headers":
payload = new HeadersPayload(ByteBuffer.wrap(payloadBa));
break;
case "verack":
payload = null;
break;
case "getaddr":
payload = null;
break;
case "getdata":
payload = null;
break;
case "getblocks":
payload = null;
break;
case "mempool":
payload = null;
break;
case "":
payload = null;
break;
case "getheaders":
payload = null;
break;
case "consensus":
payload = null;
break;
case "block":
payload = new Block(ByteBuffer.wrap(payloadBa));
break;
case "tx":
payload = new Transaction(ByteBuffer.wrap(payloadBa));
break;
default:
if (!command.matches(LOWERCASE_ALPHABET)) {
LOG.debug("unknown payload type for non alphabetic command \"{}\"", command);
payload = null;
} else {
LOG.error("unknown payload type for command \"{}\"", command);
payload = null;
}
}
return (T) payload;
}
Aggregations