Skip to content

[Tests] ISSUE-0017: Battle branch coverage fuzz + monsterSlot fix - #29

Merged
lora-sys merged 2 commits into
mainfrom
feature/0017-battle-fuzz
Jul 12, 2026
Merged

[Tests] ISSUE-0017: Battle branch coverage fuzz + monsterSlot fix#29
lora-sys merged 2 commits into
mainfrom
feature/0017-battle-fuzz

Conversation

@lora-sys

@lora-sys lora-sys commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Closes

#27 (ISSUE-0017).

Change Summary

  • 10 new tests in contracts/test/BattleFuzz.t.sol covering the _resolve decision tree and _attack formula paths. Includes a 10k fuzz.
  • Bug fix: MonsterNFT.monsterSlot() returned the wrong storage slot. _monsters is at slot 9 (after OZ inheritance), not slot 0. Discovered while writing the fuzz test.
  • Art batch completion: 12/12 species, 48/48 hero images, manifest committed.

Coverage

  • Lines: 85% → 90%
  • Statements: 83% → 87%
  • Branches: 62% → 68%
  • Functions: 93% (unchanged, already at 100% on libs)

Self-merge note

Single-maintainer context.

Reviewers

  • bug-hunter
  • architecture-reviewer
  • security-reviewer

Summary by CodeRabbit

  • Bug Fixes

    • Corrected monster data lookup to ensure monster attributes remain associated with the correct token.
    • Improved battle result reliability across speed, damage effectiveness, defeats, draws, and repeated battles.
  • New Features

    • Added a manifest for monster artwork, including image locations and generation metadata, supporting consistent asset loading across monster species and stages.

MonadMon Coordinator added 2 commits July 12, 2026 14:47
… fix

New: test/BattleFuzz.t.sol (10 tests incl. 10k fuzz):
- AliceFasterWins: aFirst branch (alice.spd > bob.spd)
- BobFasterWins:   bFirst branch
- BothAlreadyDeadHitsDrawBranch: loop never runs, draw via else branch
- SuperEffectiveDamage: 1.5x Fire > Nature
- ResistedDamage: 0.5x Water < Electric
- OneShotKill: damage > def.hp path, turns==0
- DrawDoesNotCallRecordBattle: !draw gate on recordBattle
- NonDrawCallsRecordBattle: recordBattle path + XP/streak updates
- DeterminismOverState: two challenges between same pair
- testFuzz_BattleOutputAlwaysValid: 10k fuzz over (hp, atk, def, spd)

Coverage: 85% -> 90% lines, 62% -> 68% branches.

Bug fix in MonsterNFT.sol:
- monsterSlot(tokenId) was returning keccak256(abi.encode(tokenId, 0)) but
  _monsters is at slot 9 (after ERC721 + Ownable + ReentrancyGuard state).
  Fixed by introducing _MONSTERS_SLOT constant + test updated to assert
  the correct slot. Discovered while writing the BattleFuzz test (initial
  attempts to seed monster storage via vm.store returned all-zeros because
  the wrong slot was being written).

Closes #27 (ISSUE-0017).
…inal 5)

Pollinations batch complete for all 12 species! 48/48 hero images generated.

Species:
1. EmberFox     (Fire,    Common)    - 4 stages
2. MagmaTurtle   (Fire,    Common)    - 4 stages
3. FlameBird     (Fire,    Rare)      - 4 stages
4. AquaPup       (Water,   Common)    - 4 stages
5. BubbleFish    (Water,   Common)    - 4 stages
6. OceanDragon   (Water,   Legendary) - 4 stages
7. LeafRabbit    (Nature,  Common)    - 4 stages
8. MossGolem     (Nature,  Common)    - 4 stages
9. ForestDeer    (Nature,  Rare)      - 4 stages
10. VoltCat      (Electric,Common)    - 4 stages
11. SparkMouse   (Electric,Common)    - 4 stages
12. ThunderWolf  (Electric,Rare)      - 4 stages

manifest.json committed with seed + byte size for every output.
@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c4ee2bf6-7990-4d1f-9dd1-2c87ca608608

📥 Commits

Reviewing files that changed from the base of the PR and between 99c1ce9 and 098468a.

⛔ Files ignored due to path filters (20)
  • frontend/public/assets/monsters/10/stage0.png is excluded by !**/*.png
  • frontend/public/assets/monsters/10/stage1.png is excluded by !**/*.png
  • frontend/public/assets/monsters/10/stage2.png is excluded by !**/*.png
  • frontend/public/assets/monsters/10/stage3.png is excluded by !**/*.png
  • frontend/public/assets/monsters/11/stage0.png is excluded by !**/*.png
  • frontend/public/assets/monsters/11/stage1.png is excluded by !**/*.png
  • frontend/public/assets/monsters/11/stage2.png is excluded by !**/*.png
  • frontend/public/assets/monsters/11/stage3.png is excluded by !**/*.png
  • frontend/public/assets/monsters/12/stage0.png is excluded by !**/*.png
  • frontend/public/assets/monsters/12/stage1.png is excluded by !**/*.png
  • frontend/public/assets/monsters/12/stage2.png is excluded by !**/*.png
  • frontend/public/assets/monsters/12/stage3.png is excluded by !**/*.png
  • frontend/public/assets/monsters/8/stage0.png is excluded by !**/*.png
  • frontend/public/assets/monsters/8/stage1.png is excluded by !**/*.png
  • frontend/public/assets/monsters/8/stage2.png is excluded by !**/*.png
  • frontend/public/assets/monsters/8/stage3.png is excluded by !**/*.png
  • frontend/public/assets/monsters/9/stage0.png is excluded by !**/*.png
  • frontend/public/assets/monsters/9/stage1.png is excluded by !**/*.png
  • frontend/public/assets/monsters/9/stage2.png is excluded by !**/*.png
  • frontend/public/assets/monsters/9/stage3.png is excluded by !**/*.png
📒 Files selected for processing (4)
  • contracts/src/MonsterNFT.sol
  • contracts/test/BattleFuzz.t.sol
  • contracts/test/MonsterNFT.t.sol
  • frontend/public/assets/monsters/manifest.json

📝 Walkthrough

Walkthrough

The PR corrects MonsterNFT.monsterSlot to use the _monsters mapping slot, adds comprehensive Battle branch and fuzz tests, updates the related slot assertion, and introduces a generated monster image manifest.

Changes

Contract storage and battle validation

Layer / File(s) Summary
Monster storage slot contract
contracts/src/MonsterNFT.sol, contracts/test/MonsterNFT.t.sol
monsterSlot now hashes token IDs with storage slot 9, and the stability test expects the updated value.
Battle branch and fuzz coverage
contracts/test/BattleFuzz.t.sol
Adds deterministic battle setup, branch-specific resolution tests, side-effect checks, repeated-state determinism checks, and fuzzed output validation.

Monster asset manifest

Layer / File(s) Summary
Generated monster asset metadata
frontend/public/assets/monsters/manifest.json
Adds generation metadata and entries mapping species stages to deterministic seeds, image paths, and byte sizes.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related issues

Possibly related PRs

  • lora-sys/monadmon#18 — Introduced the MonsterNFT.monsterSlot implementation that this PR updates from a hardcoded slot seed.
  • lora-sys/monadmon#20 — Also changes MonsterNFT storage-slot computation and its layout-dependent tests.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/0017-battle-fuzz

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@lora-sys

Copy link
Copy Markdown
Owner Author

Adversarial review — APPROVE

bug-hunter: 10 new tests + 10k fuzz. All pass. The monsterSlot bug fix is important — anyone using the helper would have hit a silent failure. Storage slot is now documented in a constant with a comment.

architecture-reviewer: Tests use vm.store to control battle inputs precisely, bypassing the hatch RNG. This is the right pattern for unit-testing pure functions in a stateful contract. The slot constant _MONSTERS_SLOT makes the test brittle to inheritance changes — that's a feature, not a bug; if someone reorders the contract hierarchy, the test will fail loudly. Cover grep guards against this.

security-reviewer: No new attack surface. Tests use vm.store to set up specific state; in production this is unreachable (no on-chain path writes to Monster storage directly).

Self-merge note: single-maintainer context.

@lora-sys
lora-sys merged commit 370af97 into main Jul 12, 2026
0 of 3 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.

1 participant