use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class ValidGasUsedValidatorTest method blockWithInvalidGasUsedBiggerThanGasLimit.
@Test
public void blockWithInvalidGasUsedBiggerThanGasLimit() {
BlockHeader blockHeader = Mockito.mock(BlockHeader.class);
Mockito.when(blockHeader.getGasUsed()).thenReturn(120L);
Mockito.when(blockHeader.getGasLimit()).thenReturn(BigInteger.valueOf(107L).toByteArray());
Block block = new Block(blockHeader);
ValidGasUsedRule gasUsedRule = new ValidGasUsedRule();
Assert.assertFalse(gasUsedRule.isValid(block));
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class ValidGasUsedValidatorTest method blockWithInvalidGasUsedLessThanZero.
@Test
public void blockWithInvalidGasUsedLessThanZero() {
BlockHeader blockHeader = Mockito.mock(BlockHeader.class);
Mockito.when(blockHeader.getGasUsed()).thenReturn(-120L);
Mockito.when(blockHeader.getGasLimit()).thenReturn(BigInteger.valueOf(107L).toByteArray());
Block block = new Block(blockHeader);
ValidGasUsedRule gasUsedRule = new ValidGasUsedRule();
Assert.assertFalse(gasUsedRule.isValid(block));
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class ValidGasUsedValidatorTest method blockWithValidGasUsed.
@Test
public void blockWithValidGasUsed() {
BlockHeader blockHeader = Mockito.mock(BlockHeader.class);
Mockito.when(blockHeader.getGasUsed()).thenReturn(20L);
Mockito.when(blockHeader.getGasLimit()).thenReturn(BigInteger.valueOf(107L).toByteArray());
Block block = new Block(blockHeader);
ValidGasUsedRule gasUsedRule = new ValidGasUsedRule();
Assert.assertTrue(gasUsedRule.isValid(block));
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class GitHubBasicTest method runDifficultyFrontierTest.
@Test
public void runDifficultyFrontierTest() throws IOException, ParseException {
config.setBlockchainConfig(new MainNetConfig());
String json = JSONReader.loadJSONFromCommit("BasicTests/difficultyFrontier.json", shacommit);
DifficultyTestSuite testSuite = new DifficultyTestSuite(json);
for (DifficultyTestCase testCase : testSuite.getTestCases()) {
logger.info("Running {}\n", testCase.getName());
BlockHeader current = testCase.getCurrent();
BlockHeader parent = testCase.getParent();
assertEquals(testCase.getExpectedDifficulty(), DIFFICULTY_CALCULATOR.calcDifficulty(current, parent));
}
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class BlockBuilder method build.
public static Block build(BlockHeaderTck header, List<TransactionTck> transactionsTck, List<BlockHeaderTck> unclesTck) {
if (header == null)
return null;
List<BlockHeader> uncles = new ArrayList<>();
if (unclesTck != null)
for (BlockHeaderTck uncle : unclesTck) uncles.add(BlockHeaderBuilder.build(uncle));
List<Transaction> transactions = new ArrayList<>();
if (transactionsTck != null)
for (TransactionTck tx : transactionsTck) transactions.add(TransactionBuilder.build(tx));
BlockHeader blockHeader = BlockHeaderBuilder.build(header);
Block block = new Block(blockHeader, transactions, uncles);
return block;
}
Aggregations