Add failing Block calc tests and update Denomination enum

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

View File

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

View File

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

View File

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

View File

@ -86,4 +86,16 @@ public class BlockTest {
BlocksMessage blockData = new BlocksMessage(rlpList); BlocksMessage blockData = new BlocksMessage(rlpList);
System.out.println(blockData.toString()); 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.");
}
} }