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

Fix approval assets bug plus ts tests #963

Merged
merged 7 commits into from
Nov 5, 2021

Conversation

girazoki
Copy link
Collaborator

@girazoki girazoki commented Nov 5, 2021

What does it do?

Context: in pallet-assets, approvals (when you approve someone else to spend some amount from your balance) are incremental, while in the reference ERC20 interface they are not. That is why, to match the ERC20, we need to first cancel the previous approval in pallet-assets and make a new one substituting the previous one. Now, pallet-assets does not have a public getter for approvals yet (this will come in 0.9.12 after our PR was merged) and that means we dont have an easy way of knowing whether there exists a previous approval before canceling it.

The bug came because I decided to always call cancel_approval, and match the error against the case where the approval was not present. This works well with native execution, but wasm does not allow us to format the error from the dispatchable and therefore we cannot do this error matching.

This PR fixes this by:

This PR also adds the missing typescript tests, by mocking the balance of the asset with sudo. Further, I cleaned the non-matching db write cost

What important points reviewers should know?

This is temporary until we can retrieve the allowance in 0.9.12

Is there something left for follow-up PRs?

What alternative implementations were considered?

Are there relevant PRs or issues in other repositories (Substrate, Polkadot, Frontier, Cumulus)?

What value does it bring to the blockchain users?

@girazoki girazoki added B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes A0-pleasereview Pull request needs code review. labels Nov 5, 2021
isFrozen: false,
};

async function mockAssetBalance(context, assetBalance, assetDetails, sudoAccount, assetId) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be great to move this in util for future tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I want to talk to @joelamouche for that

Copy link
Contributor

Choose a reason for hiding this comment

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

@girazoki pls create ticket

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@girazoki girazoki merged commit f88a0d7 into master Nov 5, 2021
@girazoki girazoki deleted the fix_approval_assets_bug_plus_ts_tests branch November 5, 2021 17:43
girazoki added a commit that referenced this pull request Nov 9, 2021
* pallet-assets fixing error matching

* Add erc20 instance contract

* TS tests with flag to true

* More typescript tests

* prettier

* EditorConfig

* Modify integration tests
crystalin pushed a commit that referenced this pull request Nov 10, 2021
* Fix approval assets bug plus ts tests (#963)

* pallet-assets fixing error matching

* Add erc20 instance contract

* TS tests with flag to true

* More typescript tests

* prettier

* EditorConfig

* Modify integration tests

* bump spec version

* Remove blake2 contract
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A0-pleasereview Pull request needs code review. B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants