Skip to content

Conversation

@aaronmcdaid
Copy link

@aaronmcdaid aaronmcdaid commented Sep 15, 2025

Update: 2025-09-21: managed to add a few tests, by adding a secondary test mint

This is a PR to implement #671: Feature request: WALLET_MAX_FEE_PPK flag to avoid overpaying fees

This adds a --max-input-fee-ppk argument for three commands:

  • pay: adjusts the call to select_to_send such that it will raise InputFeeExceedsLimitError if the input_fee_ppk fees imposed by the mint are large.
  • send: adjusts the call to send such that it will raise InputFeeExceedsLimitError if the input_fee_ppk fees imposed by the mint are large.
  • selfpay: adjusts the call to select_to_send such that it will raise InputFeeExceedsLimitError if the input_fee_ppk fees imposed by the mint are large.

====

The most complex thing here is the tests. The standard test mint doesn't charge any fees. If I change the fee settings of that mint, then other tests break. So instead, this PR add a secondary test mint defined in conftest.py to by identical to the standard test mint but with a few overrides. I was trying lots of other things, like trying (unsuccessfully) to force the mint to create a new high-fee keyset and temporarily deactivate the original no-fee keyset, but I couldn't get it to work

===

Smaller comments/questions:

  • this is just for the input_fee_ppk which is imposed by the mint for each token. Should there be a similar limit for other kinds of fees, such as Lightning fees?
  • Should there be a persistent config option, perhaps in the .env, instead of requiring the user to put this arg on the command line?
  • ruff required some smaller cosmetic changes in lines that I didn't really touch

@aaronmcdaid
Copy link
Author

Ready for review

I'm not sure if I should tag somebody (@callebtc ?) or add a label or something to say that this is ready for review. This is my first open-source PR, so maybe I'm doing everything wrong here 😀

Comment on lines +24 to +31
# Apply override environment variables at the end
# This allows OVERRIDE_* env vars to override .env file settings
for key, value in os.environ.items():
if key.startswith("OVERRIDE_"):
# Remove OVERRIDE_ prefix and set the environment variable
actual_key = key[9:] # Remove "OVERRIDE_" (9 characters)
os.environ[actual_key] = value

Copy link
Collaborator

Choose a reason for hiding this comment

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

Was this the only way you could run a mint with fees to test the wallet?

Copy link
Author

Choose a reason for hiding this comment

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

I must admit I was hacking a lot of different things, and it's very possible that there is a simpler solution that I missed.

Was this the only way you could run a mint with fees to test the wallet?

Now that I look at bit more at the other tests, maybe I could copy a test from tests/mint/test_mint_fees.py and use that instead. For example, I guess I could make a test that uses this Wallet and Ledger approach.

I''ll try that this evening, if I have time

image

Copy link
Author

Choose a reason for hiding this comment

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

PS: Partial good news. Just a moment ago, I pushed a single commit with a simple new test. If the max_input_fee_ppk argument is too low then, as expected, it raises an Exception to complain about the fees being too high

But, when the max_input_fee_ppk argument is large enough then it should success but instead generates a strange exception: FAILED tests/wallet/test_wallet_fees.py::test_send_with_input_fee_limit - Exception: Mint Error: inputs (64) - fees (0) vs outputs (59) are not balanced. (Code: 11000)

The fees are 5 sats, so why does this error say 0 sats?

If this can be resolved, then I think the complex/ugly second mint can be removed from this PR

server.stop()


@pytest.fixture(scope="session")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was this necessary to add?

Copy link
Collaborator

@callebtc callebtc left a comment

Choose a reason for hiding this comment

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

concept ACK!

@callebtc
Copy link
Collaborator

@aaronmcdaid please excuse the delay. Thank you for this PR, and nice tests. I wonder if it is necessary to do the OVERRIDE_ and to set up a new mint in conftest for this. Maybe you can clarify that a bit.

@callebtc callebtc added question Further information is requested wallet About the Nutshell wallet tests Tests ready Reviewed, tested, ready to merge labels Sep 30, 2025
@aaronmcdaid
Copy link
Author

@aaronmcdaid please excuse the delay. Thank you for this PR, and nice tests. I wonder if it is necessary to do the OVERRIDE_ and to set up a new mint in conftest for this. Maybe you can clarify that a bit.

Thanks for the nice feedback. I'm planning to attend the e-cash hackday in Berlin tomorrow; I've registered, but I'm not sure if there is some registration confirmation that I need? Maybe we could discuss this stuff then

Although, of course, I'll try to be clearer here too. I'll respond now in-place in this PR, responding to the comments you have already made elsewhere in this PR

… mint. However, it generates a strange error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

question Further information is requested ready Reviewed, tested, ready to merge tests Tests wallet About the Nutshell wallet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants