Skip to content

test(splitter): balance returns 0 for unknown split or token (#99) - #378

Merged
Spagero763 merged 1 commit into
tributary-protocol:mainfrom
jadonamite:test/issue-99-balance-unknown-zero
Jul 27, 2026
Merged

test(splitter): balance returns 0 for unknown split or token (#99)#378
Spagero763 merged 1 commit into
tributary-protocol:mainfrom
jadonamite:test/issue-99-balance-unknown-zero

Conversation

@jadonamite

Copy link
Copy Markdown
Contributor

Summary

Adds a test asserting that Splitter::balance returns 0 for a non-existent key, documenting the intended read-of-missing behaviour. Closes #99.

balance(env, id, token) reads DataKey::Balance(id, token) from persistent storage and falls back to .unwrap_or(0), so an unknown split id or an unknown token yields 0 rather than an error. This test pins that contract.

Test

balance_returns_zero_for_unknown_split_or_token in contracts/splitter/src/test.rs:

  • Unknown split id — queries balance for an id that was never created and asserts 0.
  • Known split, unknown token — creates a split, deposits token X, then asserts balance for a never-deposited token Y is 0, while token X still reads back its real balance (proving the zero is specific to the unknown key, not a blanket default).

Acceptance criteria

  • Test asserts 0 for unknown id and unknown token.

No contract code changed — no_std and typed errors are untouched. cargo fmt --check clean; test added under the existing suite.

balance() reads DataKey::Balance(id, token) with unwrap_or(0), so a
non-existent key yields 0 rather than an error. Pin that behaviour with a
test covering both an unknown split id and an unknown token for a known id.

Closes tributary-protocol#99
@jadonamite
jadonamite requested a review from Spagero763 as a code owner July 23, 2026 18:08
@Spagero763
Spagero763 merged commit 2c2b124 into tributary-protocol:main Jul 27, 2026
5 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.

Test balance returns 0 for an unknown split or token

2 participants