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

クローズ 初心者向け
#23 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

関連するプルリクエストがすでにマージされています。

  • #24 @tanujb03 による — マージ済み

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
82/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java

調査の方向性

2つのルールは README の "How it's supposed to work" セクションにあり、それらが説明しているコードは Blockchain.java にあります。まず mvn -B test を実行し、blocksAreMinedAndLinked と startsWithGenesisBlock がある BlockchainTest を読んでください。完了の条件は、金額ゼロの支払いが拒否されることを確認するテストと、ジェネシスブロックのハッシュが難易度に応じたゼロで始まることを確認するテストを含む新しいテストファイルが作られ、issue の表にある変異をローカルで適用したときに両方のテストが失敗することです。

索引モデルが issue の本文から書いたものです。

説明

good first issue tests

Two sentences in the README's "How it's supposed to work" section have no test that would fail if the code stopped following them.

Missing coverage

  1. The amount has to be more than 0.

    BlockchainTest.cannotMakeNegativePayment only tries -10. The boundary value 0 is never tried. The menu does reject it today ("Payment amount must be greater than zero."), but nothing would notice if it stopped.

  2. Every block's hash starts with as many zeros as the difficulty.

    blocksAreMinedAndLinked checks the zeros in a loop that starts at i = 1, and startsWithGenesisBlock only checks getPreviousHash(). The genesis block (block 0) is never checked.

Evidence

Checked on main @ 0e92205, JDK 17.0.12, Maven 3.9.16, by changing the code locally and running mvn -B test:

Local change to Blockchain.java Result
tx.amount() <= 0 changed to tx.amount() < 0 (a 0 payment is accepted) all 18 tests still pass
genesis.mine(difficulty); removed from the constructor (genesis is not mined) all 18 tests still pass

Planned change

Add one new test file with one test for each rule. Tests only, no production code changes.

I'd like to work on this.

主要言語
Java
スター
0
フォーク
3
平均マージ
2日 5時間
マージ済み PR(30日)
15

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

techcsispit/mini-chain のほかの issue

techcsispit/mini-chain の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。