Skip to content

Commit

Permalink
Add ERC20 _setTokenURI (#1618)
Browse files Browse the repository at this point in the history
* Add _setTokenURI internal.

* Rename TokenMetadata to ERC20Metadata.

* Add changelog entry for ERC20Metadata.

* Fix linter error.

* Add breaking change changelog notice.
  • Loading branch information
nventuro authored and frangio committed Jan 25, 2019
1 parent 1fd993b commit 8dd92fd
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 32 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### New features:
* `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:
* Upgraded the minimum compiler version to v0.5.2: this removes many Solidity warnings that were false positives.
Expand All @@ -14,6 +15,7 @@
### Bugfixes:

### Breaking changes:
* `TokenMetadata` (in drafts) has been renamed to `ERC20Metadata`.

## 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`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import "../../token/ERC20/IERC20.sol";
* @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
*/
contract ERC20TokenMetadata is IERC20 {
function tokenURI() external view returns (string memory);
}

contract ERC20WithMetadata is ERC20TokenMetadata {
contract ERC20Metadata {
string private _tokenURI;

constructor (string memory tokenURI) public {
_tokenURI = tokenURI;
constructor (string memory tokenURI_) public {
_setTokenURI(tokenURI_);
}

function tokenURI() external view returns (string memory) {
return _tokenURI;
}

function _setTokenURI(string memory tokenURI_) internal {
_tokenURI = tokenURI_;
}
}
14 changes: 14 additions & 0 deletions contracts/mocks/ERC20MetadataMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pragma solidity ^0.5.2;

import "../token/ERC20/ERC20.sol";
import "../drafts/ERC1046/ERC20Metadata.sol";

contract ERC20MetadataMock is ERC20, ERC20Metadata {
constructor (string memory tokenURI) public ERC20Metadata(tokenURI) {
// solhint-disable-previous-line no-empty-blocks
}

function setTokenURI(string memory tokenURI) public {
_setTokenURI(tokenURI);
}
}
10 changes: 0 additions & 10 deletions contracts/mocks/ERC20WithMetadataMock.sol

This file was deleted.

23 changes: 23 additions & 0 deletions test/drafts/ERC1046/ERC20Metadata.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require('openzeppelin-test-helpers');

const ERC20MetadataMock = artifacts.require('ERC20MetadataMock');

const metadataURI = 'https://example.com';

describe('ERC20Metadata', function () {
beforeEach(async function () {
this.token = await ERC20MetadataMock.new(metadataURI);
});

it('responds with the metadata', async function () {
(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);
});
});
});
15 changes: 0 additions & 15 deletions test/drafts/ERC1046/TokenMetadata.test.js

This file was deleted.

0 comments on commit 8dd92fd

Please sign in to comment.