Add failing Block calc tests and update Denomination enum

This commit is contained in:
nicksavers 2014-06-07 15:49:34 +02:00
parent cae6fecab7
commit c1b8cd3bf9
4 changed files with 29 additions and 16 deletions

View File

@ -66,9 +66,6 @@ public class Block {
this.parsed = true;
}
// [parent_hash, uncles_hash, coinbase, state_root, tx_trie_root,
// difficulty, number, minGasPrice, gasLimit, gasUsed, timestamp,
// extradata, nonce]
private void parseRLP() {
RLPList params = (RLPList) RLP.decode2(rlpEncoded);
@ -294,15 +291,15 @@ public class Block {
* likely next period. Conversely, if the period is too large, the difficulty,
* and expected time to the next block, is reduced.
*/
private boolean isValid() {
boolean isValid = false;
public boolean isValid() {
boolean isValid = true;
// verify difficulty meets requirements
isValid = this.getDifficulty() == this.calcDifficulty();
//isValid = this.getDifficulty() == this.calcDifficulty();
// verify gasLimit meets requirements
isValid = this.getGasLimit() == this.calcGasLimit();
//isValid = this.getGasLimit() == this.calcGasLimit();
// verify timestamp meets requirements
isValid = this.getTimestamp() > this.getParent().getTimestamp();
// isValid = this.getTimestamp() > this.getParent().getTimestamp();
return isValid;
}

View File

@ -83,11 +83,13 @@ public class Blockchain extends ArrayList<Block> {
}
private void addBlock(Block block) {
this.wallet.processBlock(block);
this.gasPrice = block.getMinGasPrice();
if(lastBlock == null || block.getNumber() > lastBlock.getNumber())
this.lastBlock = block;
this.add(block);
if(block.isValid()) {
this.wallet.processBlock(block);
this.gasPrice = block.getMinGasPrice();
if(lastBlock == null || block.getNumber() > lastBlock.getNumber())
this.lastBlock = block;
this.add(block);
}
}
public long getGasPrice() {

View File

@ -10,15 +10,17 @@ public enum Denomination {
SHANNON(newBigInt(9)),
SZABO(newBigInt(12)),
FINNY(newBigInt(15)),
ETHER(newBigInt(18));
ETHER(newBigInt(18)),
EINSTEIN(newBigInt(21)),
DOUGLAS(newBigInt(42));
private BigInteger amount;
private Denomination(BigInteger value) {
this.amount = value;
}
public BigInteger getDenomination() {
public BigInteger value() {
return amount;
}

View File

@ -86,4 +86,16 @@ public class BlockTest {
BlocksMessage blockData = new BlocksMessage(rlpList);
System.out.println(blockData.toString());
}
@Test
public void testCalcDifficulty() {
// Block.calcDifficulty()
fail("Yet to be implemented.");
}
@Test
public void testCalcGasLimit() {
// Block.calcGasLimit()
fail("Yet to be implemented.");
}
}