use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class ParentNumberRuleTest method parentNumberEqualBlockNumber.
// no pass rule
@Test
public void parentNumberEqualBlockNumber() {
BlockHeader header = getHeader(100);
BlockHeader parent = getHeader(100);
assertFalse(rule.validate(header, parent));
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class ParentNumberRuleTest method parentNumberGreaterThanBlockNumber.
// no pass rule
@Test
public void parentNumberGreaterThanBlockNumber() {
BlockHeader header = getHeader(100);
BlockHeader parent = getHeader(101);
assertFalse(rule.validate(header, parent));
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class Web3ImplUnitTest method eth_getUncleCountByBlockNumber.
@Test
public void eth_getUncleCountByBlockNumber() {
String identifier = "notFoundable";
Block block = mock(Block.class);
List<BlockHeader> uncles = new LinkedList<>();
uncles.add(mock(BlockHeader.class));
uncles.add(mock(BlockHeader.class));
when(block.getUncleList()).thenReturn(uncles);
when(retriever.getBlock(eq(identifier))).thenReturn(Optional.of(block));
String result = target.eth_getUncleCountByBlockNumber(identifier);
assertEquals("0x2", result);
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class Web3ImplUnitTest method eth_getUncleCountByBlockHash.
@Test
public void eth_getUncleCountByBlockHash() {
String hash = "0x4A54";
byte[] bytesHash = TypeConverter.stringHexToByteArray(hash);
List<BlockHeader> uncles = new LinkedList<>();
uncles.add(mock(BlockHeader.class));
uncles.add(mock(BlockHeader.class));
Block block = mock(Block.class);
when(block.getUncleList()).thenReturn(uncles);
when(blockchain.getBlockByHash(eq(bytesHash))).thenReturn(block);
String result = target.eth_getUncleCountByBlockHash(hash);
assertEquals("0x2", result);
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class Web3RskImpl method ext_dumpBlockchain.
/**
* Export the blockchain tree as a tgf file to user.dir/rskblockchain.tgf
*
* @param numberOfBlocks Number of block heights to include. Eg if best block is block 2300 and numberOfBlocks is 10, the graph will include blocks in heights 2290 to 2300.
* @param includeUncles Whether to show uncle links (recommended value is false)
*/
public void ext_dumpBlockchain(long numberOfBlocks, boolean includeUncles) {
Block bestBlock = blockStore.getBestBlock();
logger.info("Dumping blockchain starting on block number {}, to best block number {}", bestBlock.getNumber() - numberOfBlocks, bestBlock.getNumber());
File graphFile = new File(System.getProperty("user.dir") + "/" + "rskblockchain.tgf");
try (PrintWriter writer = new PrintWriter(new FileWriter(graphFile))) {
List<Block> result = new LinkedList<>();
long firstBlock = bestBlock.getNumber() - numberOfBlocks;
if (firstBlock < 0) {
firstBlock = 0;
}
for (long i = firstBlock; i < bestBlock.getNumber(); i++) {
result.addAll(blockStore.getChainBlocksByNumber(i));
}
for (Block block : result) {
writer.println(HashUtil.toPrintableHash(block.getHash().getBytes()) + " " + block.getNumber() + "-" + HashUtil.toPrintableHash(block.getHash().getBytes()));
}
writer.println("#");
for (Block block : result) {
writer.println(HashUtil.toPrintableHash(block.getHash().getBytes()) + " " + HashUtil.toPrintableHash(block.getParentHash().getBytes()) + " P");
if (includeUncles) {
for (BlockHeader uncleHeader : block.getUncleList()) {
writer.println(HashUtil.toPrintableHash(block.getHash().getBytes()) + " " + HashUtil.toPrintableHash(uncleHeader.getHash().getBytes()) + " U");
}
}
}
} catch (IOException e) {
logger.error("Could nos save node graph to file", e);
}
}
Aggregations