Skip to content

feat: allow zero to be recorded in configured stream#157

Merged
MicBun merged 6 commits into
mainfrom
allowZeros
May 1, 2026
Merged

feat: allow zero to be recorded in configured stream#157
MicBun merged 6 commits into
mainfrom
allowZeros

Conversation

@MicBun
Copy link
Copy Markdown
Contributor

@MicBun MicBun commented May 1, 2026

resolves: https://github.com/truflation/website/issues/3757

Summary by CodeRabbit

  • New Features

    • deployStream gains optional flags: allowZeros (persist zero-value inserts) and synchronous (wait until confirmed).
    • Owner-gated per-stream allowZeros setter and a getter; default false and existing history unchanged.
  • Documentation

    • API reference updated with new flags, actions, and usage guidance (including waiting for tx confirmation).
  • Tests

    • Added allowZeros tests and updated integration tests for bridge/history scenarios; deprecated test removed.
  • Chores

    • CI image retagging and more robust service health retries.

@MicBun MicBun requested a review from pr-time-tracker May 1, 2026 03:04
@MicBun MicBun self-assigned this May 1, 2026
@MicBun MicBun added the enhancement New feature or request label May 1, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 1, 2026

Warning

Rate limit exceeded

@MicBun has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 32 minutes and 21 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d5fab729-3cd4-461d-9433-1ad4fbe1c3d8

📥 Commits

Reviewing files that changed from the base of the PR and between 933aba7 and 7523270.

📒 Files selected for processing (2)
  • .github/workflows/ci.yaml
  • tests/integration/history.test.ts
📝 Walkthrough

Walkthrough

Adds an owner-gated per-stream allow_zeros metadata flag, documents deployStream to accept synchronous and allowZeros, adds actions setAllowZeros/getAllowZeros, threads allowZeros through deploy logic, and enforces runtime reserved-key guards preventing generic writes to allow_zeros.

Changes

Cohort / File(s) Summary
Documentation
docs/api-reference.md
Updated client.deployStream signature to synchronous? and allowZeros?; added guidance to use client.waitForTx(tx_hash) and new action.setAllowZeros / action.getAllowZeros docs.
Client SDK
src/client/client.ts
BaseTNClient.deployStream(..., synchronous?, allowZeros?) signature updated; allowZeros forwarded to deploy call.
Deploy Stream
src/contracts-api/deployStream.ts
DeployStreamInput gains allowZeros?: boolean; deployStream conditionally includes $allow_zeros: true in execute params only when enabled.
Metadata & Contract Values
src/contracts-api/contractValues.ts
Added MetadataKey.AllowZerosKey, registered its value type as bool, exported RESERVED_METADATA_KEYS, ReservedMetadataKey, MutableMetadataKey, and isReservedMetadataKey type guard.
Contract Actions
src/contracts-api/action.ts
Added ReservedMetadataKeyError; restricted setMetadata to MutableMetadataKey with runtime reserved-key guard; added setAllowZeros(stream, value) and getAllowZeros(stream): Promise<boolean> (defaults to false when no row).
Contract Action Tests
src/contracts-api/action.test.ts
Added tests for allow_zeros wiring: metadata registration, setAllowZeros action params, getAllowZeros boolean mapping, and negative test ensuring setMetadata rejects reserved key via ReservedMetadataKeyError.
Integration tests
tests/integration/...
Updated integration tests: changed chain id to eth_truf in erc20Bridge tests, removed deprecated listWalletRewards test, refactored history tests to use external NodeTNClient (no local TN/Postgres bootstrap), and adjusted timeouts.
CI / Devops
.github/workflows/ci.yaml
Retags local built tn-db image as ghcr.io/trufnetwork/node:latest after local build to ensure integration tests pull the freshly built image.
Test utilities
tests/integration/trufnetwork.setup.ts
waitForTnHealth increased retries (10→30) and added per-request timeout via AbortController to avoid stalled fetches.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client SDK
    participant Gateway as Gateway / Node
    participant Contract as Contract Actions
    participant Postgres as Postgres

    Client->>Gateway: deployStream(streamId, type, allowZeros=true, synchronous?)
    Gateway->>Contract: execute deploy_stream({ $stream_id, $stream_type, $allow_zeros: true })
    Contract->>Postgres: insert stream + metadata (allow_zeros = true)
    Contract-->>Gateway: tx receipt / status
    Gateway-->>Client: GenericResponse { status, data?.tx_hash }

    Client->>Gateway: action.setAllowZeros(stream, true)
    Gateway->>Contract: invoke set_allow_zeros($stream_id, $value)
    Contract->>Postgres: insert/update allow_zeros metadata row
    Contract-->>Gateway: tx receipt
    Gateway-->>Client: GenericResponse { status, data?.tx_hash }

    Client->>Gateway: action.getAllowZeros(stream)
    Gateway->>Contract: query get_allow_zeros($stream_id)
    alt row exists
        Contract->>Postgres: return allow_zeros row
        Contract-->>Gateway: { allow_zeros: true/false }
    else no row
        Contract-->>Gateway: empty -> default false
    end
    Gateway-->>Client: boolean
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • pr-time-tracker
  • outerlook
  • williamrusdyputra

Poem

"I nibble bytes and hop through code,
I guard the keys along the road.
Zeros once dropped may now remain,
Small flags planted in the stream's domain. 🐰"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately reflects the main feature: adding the ability to configure streams to allow zero values to be recorded, which is the primary change across all modified files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch allowZeros

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
Review rate limit: 0/1 reviews remaining, refill in 32 minutes and 21 seconds.

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

@holdex
Copy link
Copy Markdown

holdex Bot commented May 1, 2026

Time Submission Status

Member Status Time Action Last Update
MicBun ✅ Submitted 4h Update time May 1, 2026, 2:30 PM

You can submit time with the command. Example:

@holdex pr submit-time 15m

See available commands to help comply with our Guidelines.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/api-reference.md`:
- Around line 69-70: The `allowZeros` description ends with a sentence fragment;
change the fragment to a full sentence such as "This setting can be toggled
later via `action.setAllowZeros`." Update the `allowZeros?: boolean` doc string
so it reads smoothly and includes the complete sentence referencing `allowZeros`
and `action.setAllowZeros`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cfac12c8-64d4-4368-8d61-d084f266b4ec

📥 Commits

Reviewing files that changed from the base of the PR and between dda810d and 96ab85f.

📒 Files selected for processing (6)
  • docs/api-reference.md
  • src/client/client.ts
  • src/contracts-api/action.test.ts
  • src/contracts-api/action.ts
  • src/contracts-api/contractValues.ts
  • src/contracts-api/deployStream.ts

Comment thread docs/api-reference.md Outdated
@MicBun
Copy link
Copy Markdown
Contributor Author

MicBun commented May 1, 2026

@holdex pr submit-time 4h

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/api-reference.md`:
- Line 63: The docs show client.deployStream returning Promise<DeploymentResult>
but the implementation of deployStream returns
Promise<Types.GenericResponse<Types.TxReceipt>>; update the API reference to
match the actual contract by changing the documented return type to
Promise<Types.GenericResponse<Types.TxReceipt>> (or document both if
DeploymentResult is an alias) and ensure the text around deployStream explains
the GenericResponse wrapper and TxReceipt payload so consumers know how to
access the tx receipt from the response.

In `@tests/integration/history.test.ts`:
- Around line 12-29: The test currently falls back to hardcoded
endpoint/chainId/privateKey, which can hit mainnet silently; in beforeAll update
the logic so that endpoint and chainId are required from env (throw or fail the
test if they are missing) and handle privateKey by either requiring it as well
or, if the suite is intended to be read-only, generate a fresh wallet per run by
calling new Wallet() without a seed; update the NodeTNClient creation to use the
validated endpoint/chainId and the generated or provided Wallet (refer to
variables endpoint, chainId, privateKey, Wallet, NodeTNClient and the beforeAll
block) so tests fail fast on misconfiguration or use a non-deterministic wallet.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 857aa165-d7d7-48d4-b996-ebfc72e358c9

📥 Commits

Reviewing files that changed from the base of the PR and between 96ab85f and 36a6353.

📒 Files selected for processing (3)
  • docs/api-reference.md
  • tests/integration/erc20Bridge.test.ts
  • tests/integration/history.test.ts
✅ Files skipped from review due to trivial changes (1)
  • tests/integration/erc20Bridge.test.ts

Comment thread docs/api-reference.md Outdated
Comment thread tests/integration/history.test.ts Outdated
@MicBun MicBun merged commit c599e1c into main May 1, 2026
4 checks passed
@MicBun MicBun deleted the allowZeros branch May 1, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant