Skip to content

Test #23: pin two README rules no test covers (amount 0, genesis difficulty) - #24

Merged
techcsispit merged 1 commit into
techcsispit:mainfrom
tanujb03:test/23-readme-rules-coverage
Oct 16, 2026
Merged

techcsispit merged 1 commit into
techcsispit:mainfrom
tanujb03:test/23-readme-rules-coverage

Conversation

@tanujb03

Copy link
Copy Markdown
Contributor

Closes #23

What I changed

Added src/test/java/minichain/ReadmeRulesTest.java (a new file; tests only, no production code changed) with one test for each README rule that nothing was checking:

  • cannotMakeZeroPayment: a payment of 0 is rejected and nothing is queued or moved ("The amount has to be more than 0.").
  • genesisBlockMeetsTheDifficulty: block 0 of a new chain starts with as many zeros as the difficulty and its hash matches its contents ("Every block's hash starts with as many zeros as the difficulty.").

BlockchainTest is left as it is.

How it works

The existing negative-amount test only tries -10, so the check amount <= 0 could be loosened to amount < 0 (letting a 0 payment through) and every test would still pass. The existing difficulty check loops from block 1, so the genesis block could skip mining and every test would still pass. The two new tests close those gaps. I checked that each one really guards its rule by changing the code locally: with tx.amount() <= 0 changed to tx.amount() < 0 only cannotMakeZeroPayment fails, and with genesis.mine(difficulty); removed only genesisBlockMeetsTheDifficulty fails; the 18 old tests stay green in both cases. mvn -B clean test passes with 20 tests.

… 0, genesis difficulty)

cannotMakeZeroPayment checks that a payment of 0 is rejected ("The amount has to be more than 0."); the existing test only tries a negative amount. genesisBlockMeetsTheDifficulty checks that block 0 starts with the required zeros ("Every block's hash starts with as many zeros as the difficulty."); the existing loop starts at block 1. Tests only, no production code changed.
@techcsispit
techcsispit merged commit 49adc5b into techcsispit:main Oct 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tests: no test covers a payment of 0 or the genesis block meeting the difficulty

2 participants