Fix canColonyMintNativeToken
resover to work with all tokens
#3273
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current implementation of this resolver assumes that all tokens have the
authority()
function built in their contract, but this is rather of our doing, so only Colony Contract created tokens do have it. Others might not (most likely will not)Due to this, if a colony will have been created using an external token (in this case the actual
metacolony
), the dapp will actually crash as we don't handle this case.Even worse, tokens might be able to be minted, even if they don't have the
authority
method, as themint
function is somewhat standard on most, and the user creating the colony might actually be the owner of said token, so we need to check for that as well.For this I've chosen to go the "estimate route", by estimating gas on the call to mint, and if it succeeds assume the user can mint, and if it fails, they can't.
This approach should cover most cases
Testing
This is quite tricky to test (it's actually easier on QA), but I'll try to do my best to explain how to.
1. Start the
truffle
consoleInside the
src/lib/colonyNetwork
folder, runyarn truffle console
(or./node_modules/.bin/truffle console
)2. Deploy a new "non-standard" token. We'll use
ERC20PresetMinterPauser
since it's available to us already.Inside the truffle console, run:
then
3. Create a new colony via the Dapp and use the above address as an external token (don't create a new token)
Once created, if the colony loads, and doesn't show the "Mint" and "Unlock" menu entries in the "Actions" menu, then this fix worked.
Changes
canColonyMintNativeToken
resolver in thecolony
resolvers file