Repository navigation
Test #23: pin two README rules no test covers (amount 0, genesis difficulty) - #24
Merged
techcsispit merged 1 commit intoOct 16, 2026
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.").BlockchainTestis left as it is.How it works
The existing negative-amount test only tries
-10, so the checkamount <= 0could be loosened toamount < 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: withtx.amount() <= 0changed totx.amount() < 0onlycannotMakeZeroPaymentfails, and withgenesis.mine(difficulty);removed onlygenesisBlockMeetsTheDifficultyfails; the 18 old tests stay green in both cases.mvn -B clean testpasses with 20 tests.