Skip to content

Validate FFI primitive inputs + refresh bindings/tests#1263

Merged
benalleng merged 4 commits intopayjoin:masterfrom
chavic:chavic/primitives-validation
Feb 17, 2026
Merged

Validate FFI primitive inputs + refresh bindings/tests#1263
benalleng merged 4 commits intopayjoin:masterfrom
chavic:chavic/primitives-validation

Conversation

@chavic
Copy link
Collaborator

@chavic chavic commented Jan 10, 2026

This PR addresses #1262 and hardens the FFI boundary by validating primitive inputs and surfacing explicit errors. Updates integration tests/bindings to match the new error shapes and removes silent acceptance of invalid fee rates/amounts.

Follow-ups

Decide final script/witness size caps and document rationale.
Add Dart integration fix for large fee rate parsing (separate PR).

@coveralls
Copy link
Collaborator

coveralls commented Jan 10, 2026

Pull Request Test Coverage Report for Build 22112284749

Details

  • 3 of 5 (60.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.01%) to 83.169%

Changes Missing Coverage Covered Lines Changed/Added Lines %
payjoin/src/core/psbt/mod.rs 0 2 0.0%
Totals Coverage Status
Change from base Build 22022393890: -0.01%
Covered Lines: 10219
Relevant Lines: 12287

💛 - Coveralls

@benalleng benalleng mentioned this pull request Jan 13, 2026
9 tasks
@chavic chavic force-pushed the chavic/primitives-validation branch 2 times, most recently from cd3391a to a44a282 Compare January 19, 2026 17:40
@chavic chavic force-pushed the chavic/primitives-validation branch 2 times, most recently from 59affc6 to 93bc4e8 Compare January 27, 2026 11:10
@chavic chavic force-pushed the chavic/primitives-validation branch 5 times, most recently from 055a2bb to 53db1cb Compare February 3, 2026 17:13
@chavic chavic marked this pull request as ready for review February 4, 2026 09:52
Copy link
Collaborator

@benalleng benalleng left a comment

Choose a reason for hiding this comment

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

Instead of updating the msrv for dart I think we can simply use cargo install --locked wasm-bindgen-cli on the js workflow to prevent the install step from trying to update the deps

@chavic
Copy link
Collaborator Author

chavic commented Feb 4, 2026

Instead of updating the msrv for dart I think we can simply use cargo install --locked wasm-bindgen-cli on the js workflow to prevent the install step from trying to update the

Thanks... applying that now

@chavic chavic force-pushed the chavic/primitives-validation branch from 759be1b to 10ee724 Compare February 4, 2026 14:35
@chavic chavic requested a review from benalleng February 4, 2026 14:38
@chavic chavic force-pushed the chavic/primitives-validation branch 8 times, most recently from 732c40a to f331ef3 Compare February 4, 2026 17:21
Copy link
Collaborator

@benalleng benalleng left a comment

Choose a reason for hiding this comment

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

CACK f331ef3 got the commits nicely reviewable again thanks for that.

@chavic chavic force-pushed the chavic/primitives-validation branch 4 times, most recently from 8b3625e to 20d3670 Compare February 11, 2026 08:30
@chavic chavic removed the request for review from spacebear21 February 11, 2026 11:11
Copy link
Collaborator

@benalleng benalleng left a comment

Choose a reason for hiding this comment

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

I think you may have misunderstood my comments on the review, the psbt consts can be simply imported and not set as strings in the tests. I appreciate seeing the test_utils.dart but it was not really my intention to need to add this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

you've kind of reversed what you did here that you did in the dart file

Copy link
Collaborator Author

@chavic chavic Feb 12, 2026

Choose a reason for hiding this comment

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

This fell back during the rebase; I had a backup branch, so I'll bring it back. Side note, I've noticed only the Python test fails if the poll approach isn't used... will try to find out why (not the top task)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sidenote, should we consider asserting a failure when attempts exceed 3, unless the intent is explicitly “smoke test only”

Copy link
Collaborator

@benalleng benalleng Feb 11, 2026

Choose a reason for hiding this comment

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

The can actually just be

final psbt = test_utils.originalPsbt();

you will need to add it to the test_utils.dart import though

Copy link
Collaborator

Choose a reason for hiding this comment

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

Related note (but not a blocker for this PR), we should really not expose test utils in the main payjoin namespace for language bindings. This test_utils approach is a nice helper but the test utils are still exposed in the main namespace. I tried my hand at this briefly and couldn't find a good approach #1199 (comment)

@chavic chavic force-pushed the chavic/primitives-validation branch 4 times, most recently from 5771b7a to c1c3600 Compare February 12, 2026 15:18
@chavic chavic force-pushed the chavic/primitives-validation branch 2 times, most recently from 51d9f8b to 3f78b70 Compare February 16, 2026 12:52
Copy link
Collaborator

@benalleng benalleng left a comment

Choose a reason for hiding this comment

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

TACK 777f16b Sorry it took so long, I know we got a bit caught up in rebase hell but lets try to keep focus when we are this close for so long before moving on to other stuff

@spacebear21 spacebear21 force-pushed the chavic/primitives-validation branch from 777f16b to 2b8e63e Compare February 17, 2026 17:31
Copy link
Collaborator

@spacebear21 spacebear21 left a comment

Choose a reason for hiding this comment

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

utACK. I rebased to squash Ben's commit into the relevant 2nd commit, and added an additional commit that renames PrimitiveError to the more descriptive FfiValidationError

pub struct SerdeJsonError(#[from] serde_json::Error);

#[derive(Debug, thiserror::Error, uniffi::Error)]
pub enum PrimitiveError {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this type (and the PrimitiveError variants on specific error types) could be more descriptive as e.g. ValidationError or TypeCastError.

@spacebear21 spacebear21 force-pushed the chavic/primitives-validation branch from 2b8e63e to edbe432 Compare February 17, 2026 17:56
Comment on lines 216 to 221
/// Amount exceeds allowed maximum.
#[error("Amount out of range: {amount_sat} sats (max {max_sat})")]
AmountOutOfRange { amount_sat: u64, max_sat: u64 },
/// Weight must be positive and no more than a block.
#[error("Weight out of range: {weight_units} wu (max {max_wu})")]
WeightOutOfRange { weight_units: u64, max_wu: u64 },
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems these should just be part of the FfiValidation variant?

@spacebear21 spacebear21 force-pushed the chavic/primitives-validation branch from edbe432 to b4a64e4 Compare February 17, 2026 18:16
Copy link
Collaborator

@spacebear21 spacebear21 left a comment

Choose a reason for hiding this comment

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

re-ACK b4a64e4

Rename error type and variants for clarity
@spacebear21 spacebear21 force-pushed the chavic/primitives-validation branch from b4a64e4 to 0679a8c Compare February 17, 2026 19:18
Copy link
Collaborator

@spacebear21 spacebear21 left a comment

Choose a reason for hiding this comment

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

re-re-ACK 0679a8c

I cleaned up the python checks which were false negatives before

Copy link
Collaborator

@benalleng benalleng left a comment

Choose a reason for hiding this comment

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

Re-ACK 0679a8c spacebear corrected a silent failure in the python integration test. This silent failure seems to be a common occurrence in python. we should explore how to better handle errors and warnings in python

@benalleng benalleng merged commit a27e1b7 into payjoin:master Feb 17, 2026
20 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.

4 participants