Commit 8dd92fd6 by Nicolás Venturo Committed by Francisco Giordano

Add ERC20 _setTokenURI (#1618)

* Add _setTokenURI internal.

* Rename TokenMetadata to ERC20Metadata.

* Add changelog entry for ERC20Metadata.

* Fix linter error.

* Add breaking change changelog notice.
parent 1fd993bc
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
### New features: ### New features:
* `ERC20`: added internal `_approve(address owner, address spender, uint256 value)`, allowing derived contracts to set the allowance of arbitrary accounts. * `ERC20`: added internal `_approve(address owner, address spender, uint256 value)`, allowing derived contracts to set the allowance of arbitrary accounts.
* `ERC20Metadata`: added internal `_setTokenURI(string memory tokenURI)`.
### Improvements: ### Improvements:
* Upgraded the minimum compiler version to v0.5.2: this removes many Solidity warnings that were false positives. * Upgraded the minimum compiler version to v0.5.2: this removes many Solidity warnings that were false positives.
...@@ -14,6 +15,7 @@ ...@@ -14,6 +15,7 @@
### Bugfixes: ### Bugfixes:
### Breaking changes: ### Breaking changes:
* `TokenMetadata` (in drafts) has been renamed to `ERC20Metadata`.
## 2.1.2 (2019-17-01) ## 2.1.2 (2019-17-01)
* Removed most of the test suite from the npm package, except `PublicRole.behavior.js`, which may be useful to users testing their own `Roles`. * Removed most of the test suite from the npm package, except `PublicRole.behavior.js`, which may be useful to users testing their own `Roles`.
......
...@@ -7,18 +7,18 @@ import "../../token/ERC20/IERC20.sol"; ...@@ -7,18 +7,18 @@ import "../../token/ERC20/IERC20.sol";
* @dev See https://eips.ethereum.org/EIPS/eip-1046 * @dev See https://eips.ethereum.org/EIPS/eip-1046
* @dev tokenURI must respond with a URI that implements https://eips.ethereum.org/EIPS/eip-1047 * @dev tokenURI must respond with a URI that implements https://eips.ethereum.org/EIPS/eip-1047
*/ */
contract ERC20TokenMetadata is IERC20 { contract ERC20Metadata {
function tokenURI() external view returns (string memory);
}
contract ERC20WithMetadata is ERC20TokenMetadata {
string private _tokenURI; string private _tokenURI;
constructor (string memory tokenURI) public { constructor (string memory tokenURI_) public {
_tokenURI = tokenURI; _setTokenURI(tokenURI_);
} }
function tokenURI() external view returns (string memory) { function tokenURI() external view returns (string memory) {
return _tokenURI; return _tokenURI;
} }
function _setTokenURI(string memory tokenURI_) internal {
_tokenURI = tokenURI_;
}
} }
pragma solidity ^0.5.2; pragma solidity ^0.5.2;
import "../token/ERC20/ERC20.sol"; import "../token/ERC20/ERC20.sol";
import "../drafts/ERC1046/TokenMetadata.sol"; import "../drafts/ERC1046/ERC20Metadata.sol";
contract ERC20WithMetadataMock is ERC20, ERC20WithMetadata { contract ERC20MetadataMock is ERC20, ERC20Metadata {
constructor (string memory tokenURI) public ERC20WithMetadata(tokenURI) { constructor (string memory tokenURI) public ERC20Metadata(tokenURI) {
// solhint-disable-previous-line no-empty-blocks // solhint-disable-previous-line no-empty-blocks
} }
function setTokenURI(string memory tokenURI) public {
_setTokenURI(tokenURI);
}
} }
require('openzeppelin-test-helpers'); require('openzeppelin-test-helpers');
const ERC20WithMetadataMock = artifacts.require('ERC20WithMetadataMock'); const ERC20MetadataMock = artifacts.require('ERC20MetadataMock');
const metadataURI = 'https://example.com'; const metadataURI = 'https://example.com';
describe('ERC20WithMetadata', function () { describe('ERC20Metadata', function () {
beforeEach(async function () { beforeEach(async function () {
this.token = await ERC20WithMetadataMock.new(metadataURI); this.token = await ERC20MetadataMock.new(metadataURI);
}); });
it('responds with the metadata', async function () { it('responds with the metadata', async function () {
(await this.token.tokenURI()).should.equal(metadataURI); (await this.token.tokenURI()).should.equal(metadataURI);
}); });
describe('setTokenURI', function () {
it('changes the original URI', async function () {
const newMetadataURI = 'https://betterexample.com';
await this.token.setTokenURI(newMetadataURI);
(await this.token.tokenURI()).should.equal(newMetadataURI);
});
});
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment