Skip to content

Commit 655a9ca

Browse files
Oba-Oneclaude
andcommitted
fix(contracts): delegate purpose validation to CookieJarValidation library
CookieJar._validateWithdrawalConstraints had an inline bytes(purpose).length check that duplicated and diverged from CookieJarValidation.validatePurpose. Now delegates to the library which uses countUnicodeCodePoints, matching client-side unicodeCodePointLength semantics for multi-byte characters. Also replace remaining bun test references in README with bun run test. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3873392 commit 655a9ca

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ cookie-jar/
116116

117117
**Contracts**: Edit in `contracts/src/` → Auto-recompile → Auto-redeploy → Regen types
118118
**Client**: `localhost:3000` with hot reload on Chain ID 31337
119-
**Testing**: `bun test` (both contracts + client)
119+
**Testing**: `bun run test` (both contracts + client)
120120

121121
```bash
122-
bun test:contracts # Smart contract tests
123-
bun test:client # Frontend tests
122+
bun run test:contracts # Smart contract tests
123+
bun run test:client # Frontend tests
124124
bun deploy:local # Manual deployment
125125
bun seed:demo # Refresh demo data
126126
```
@@ -151,7 +151,7 @@ bun seed:demo # Refresh demo data
151151
```bash
152152
# Essential
153153
bun dev # Start local development
154-
bun test # Run all tests
154+
bun run test # Run all tests
155155
bun build # Build contracts + client
156156

157157
# Development variants
@@ -479,7 +479,7 @@ Just clone, install, and develop!
479479

480480
1. Fork the repository
481481
2. Create a feature branch: `git checkout -b feature/amazing-feature`
482-
3. Make your changes and test: `bun test`
482+
3. Make your changes and test: `bun run test`
483483
4. Commit with conventional commits: `git commit -m "feat: add amazing feature"`
484484
5. Push and create a Pull Request
485485

contracts/src/CookieJar.sol

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";
1010
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
1111

1212
import {CookieJarLib} from "./libraries/CookieJarLib.sol";
13+
import {CookieJarValidation} from "./libraries/CookieJarValidation.sol";
1314
import {UniversalSwapAdapter} from "./libraries/UniversalSwapAdapter.sol";
1415
import {Streaming} from "./libraries/Streaming.sol";
1516
import {ISuperfluid, IConstantFlowAgreementV1} from "@superfluid-finance/ethereum-contracts/interfaces/superfluid/ISuperfluid.sol";
@@ -461,10 +462,8 @@ contract CookieJar is AccessControl, Pausable, ReentrancyGuard {
461462
if (amount == 0) revert CookieJarLib.ZeroAmount();
462463
if (currencyHeldByJar < amount) revert CookieJarLib.InsufficientBalance();
463464

464-
// Validate purpose requirement
465-
if (STRICT_PURPOSE && bytes(purpose).length < 27) {
466-
revert CookieJarLib.InvalidPurpose();
467-
}
465+
// Validate purpose requirement (uses Unicode code-point counting)
466+
CookieJarValidation.validatePurpose(STRICT_PURPOSE, purpose);
468467

469468
// Validate withdrawal amount
470469
if (WITHDRAWAL_OPTION == CookieJarLib.WithdrawalTypeOptions.Fixed) {

0 commit comments

Comments
 (0)