Add failing Block calc tests and update Denomination enum
This commit is contained in:
parent
cae6fecab7
commit
c1b8cd3bf9
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -10,7 +10,9 @@ 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;
|
||||
|
||||
|
@ -18,7 +20,7 @@ public enum Denomination {
|
|||
this.amount = value;
|
||||
}
|
||||
|
||||
public BigInteger getDenomination() {
|
||||
public BigInteger value() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue