`invoice_count()` returns the next invoice id, not the number of invoices

Aperta
#55 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
rust

Direzione di ricerca

Start in contracts/invoice/src/lib.rs at invoice_count, which returns the stored NextId, and at the test invoice_count_returns_next_id in contracts/invoice/src/test.rs, which currently asserts that behaviour. Confirm the intended semantics with a maintainer first, since the issue asks for either NextId - 1 or a rename to a next-id function. Done means the count matches the chosen semantics, the doc comment and contracts/invoice/README.md agree, and cargo test, cargo fmt --check and clippy pass.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug contract difficulty: beginner needs-discussion

Difficulty: Beginner

Problem

invoice_count returns the stored NextId, which is 1 when no invoice exists. The unit test invoice_count_returns_next_id codifies this, and the doc comment says "total number of invoices ever created (the next invoice id)", which contradicts itself. A client that loops 1..=count would be off by one.

Why it matters

The function exists to replace the id-by-id scan. An off-by-one in a newly merged public function is cheapest to fix before the contract is redeployed (the live testnet contract does not have it yet).

Scope of work

Make the function return the real count (NextId - 1, saturating) or rename it to match its behaviour, update its doc comment, test and the contract README, and state the choice in the PR.

Acceptance criteria

  • No invoices gives 0; after N creations it gives N (or the function is renamed and documented as "next id").
  • Test and README updated.
  • cargo fmt --check, clippy and tests pass.

Relevant files

  • contracts/invoice/src/lib.rs
  • contracts/invoice/src/test.rs
  • contracts/invoice/README.md

Dependencies

Related to #27, #28 and #29, which also touch lib.rs; coordinate to avoid conflicts.

Maintainer discussion needed?

Yes, briefly: confirm the intended semantics. The function is not deployed yet, so there is no compatibility concern.

Lingua principale
TypeScript
Stelle
0
Fork
4
Merge medio
54m
PR unite (30g)
6

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Yormee-103/PayLoop

Tutte le issue di Yormee-103/PayLoop

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.