-
Notifications
You must be signed in to change notification settings - Fork 335
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
Conversation
isFrozen: false, | ||
}; | ||
|
||
async function mockAssetBalance(context, assetBalance, assetDetails, sudoAccount, assetId) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@girazoki pls create ticket
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* pallet-assets fixing error matching * Add erc20 instance contract * TS tests with flag to true * More typescript tests * prettier * EditorConfig * Modify integration tests
* 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
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:
Calling cancel_approval instead of force_cancel_approval. This way we make sure that the preliminary checks that we pass in cancel_approval are the same as those in approve_transfer, except for the "does an approval exist already" check. See https://github.com/paritytech/substrate/blob/bf43f7420a8548f10a010e61ffab52dabadb4272/frame/assets/src/lib.rs#L1139 and https://github.com/paritytech/substrate/blob/bf43f7420a8548f10a010e61ffab52dabadb4272/frame/assets/src/lib.rs#L1189.
Continue the execution of the precompile with approve_transfer if the error is of the type OtherError after calling cancel_approval. We know this error only returns if the dispatchable failed. If the dispatchable failed because of any of the reasons that are not "does an approval exist already", we know approve_transfer will fail anyway. If it failed because of the check "does an approval exist already", we know we should continue with approve_transfer execution.
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?