Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed transaction imbalance when burning assets from the same policy #376

Merged
merged 9 commits into from
Sep 22, 2024

Conversation

xxAVOGADROxx
Copy link
Contributor

@xxAVOGADROxx xxAVOGADROxx commented Sep 20, 2024

Problem

The logic did not properly handle cases where assets under one policy were burned. This led to incorrect outputs in the multi_asset structure, causing transaction outputs to be improperly computed.

Solution

A fix was applied to ensure proper handling of burning assets under the same policy.

  • Unite test:
    Assets that are burned under a given policy ID (policy_id_1) are properly removed from the multi_asset map.

Changes

  • In the _calc_change method of txbuilder.py.

Additional information

Tested on preproduction.

@xxAVOGADROxx xxAVOGADROxx changed the title Fixed tx imbalance when burning multiple tokens Fixed tx imbalance when burning multiple assets Sep 20, 2024
@cffls
Copy link
Collaborator

cffls commented Sep 21, 2024

Amazing! Thanks for the fix. Could you add a unit test to cover the new code being added?

@xxAVOGADROxx
Copy link
Contributor Author

@cffls Please let me know if any changes are needed. Thanks!

@nielstron
Copy link
Contributor

I had hoped that my changes to the multi asset/asset class would disallow empty/ zero assets (see the normalization methods). I am wondering if there is an oversight in the implementation that introduces this need for a fix inside the tx builder? Do we need to run normalization after init as well?

@nielstron
Copy link
Contributor

nielstron commented Sep 21, 2024

In fact @xxAVOGADROxx I reverted your changes to the txbuilder class and the test case you added still passes. Please make sure that the test case fails before your applied change, otherwise it is not clear what exactly is the change introduced.

I have enabled workflows for this PR so you can directly see if any added unit test increases coverage.

Copy link

codecov bot commented Sep 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.22%. Comparing base (388ab97) to head (66ef7d5).
Report is 4 commits behind head on chang.

Additional details and impacted files
@@            Coverage Diff             @@
##            chang     #376      +/-   ##
==========================================
- Coverage   85.24%   85.22%   -0.02%     
==========================================
  Files          32       32              
  Lines        4209     4211       +2     
  Branches     1059     1059              
==========================================
+ Hits         3588     3589       +1     
  Misses        435      435              
- Partials      186      187       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@xxAVOGADROxx xxAVOGADROxx changed the title Fixed tx imbalance when burning multiple assets Fixed tx imbalance when burning multiple assets under one policy while preserving assets under another. Sep 22, 2024
@xxAVOGADROxx xxAVOGADROxx changed the title Fixed tx imbalance when burning multiple assets under one policy while preserving assets under another. Fixed transaction imbalance when burning assets from a single policy Sep 22, 2024
@xxAVOGADROxx
Copy link
Contributor Author

xxAVOGADROxx commented Sep 22, 2024

Hello @nielstron, I've added the correct unit test (verifying that it solves the issue). Additionally, I realized the logic for filtering empty/zero assets wasn't necessary, so I've removed that part.

@xxAVOGADROxx xxAVOGADROxx changed the title Fixed transaction imbalance when burning assets from a single policy Fixed transaction imbalance when burning assets from the same policy Sep 22, 2024
@cffls
Copy link
Collaborator

cffls commented Sep 22, 2024

Thanks @xxAVOGADROxx for adding the test. I realized that this error originated from __iadd__ in Asset and MultiAsset. In the previous implementation, __iadd__ will only update assets whose value has changed, but it won't update if the key is deleted. I pushed a fix to this behavior and we won't need to change txbuilder now :D

@cffls cffls merged commit ba73b10 into Python-Cardano:chang Sep 22, 2024
11 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.

3 participants