Skip to content

Commit 8dd92fd

Browse files
nventurofrangio
authored andcommitted
Add ERC20 _setTokenURI (#1618)
* Add _setTokenURI internal. * Rename TokenMetadata to ERC20Metadata. * Add changelog entry for ERC20Metadata. * Fix linter error. * Add breaking change changelog notice.
1 parent 1fd993b commit 8dd92fd

File tree

6 files changed

+46
-32
lines changed

6 files changed

+46
-32
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### New features:
66
* `ERC20`: added internal `_approve(address owner, address spender, uint256 value)`, allowing derived contracts to set the allowance of arbitrary accounts.
7+
* `ERC20Metadata`: added internal `_setTokenURI(string memory tokenURI)`.
78

89
### Improvements:
910
* Upgraded the minimum compiler version to v0.5.2: this removes many Solidity warnings that were false positives.
@@ -14,6 +15,7 @@
1415
### Bugfixes:
1516

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

1820
## 2.1.2 (2019-17-01)
1921
* Removed most of the test suite from the npm package, except `PublicRole.behavior.js`, which may be useful to users testing their own `Roles`.

contracts/drafts/ERC1046/TokenMetadata.sol renamed to contracts/drafts/ERC1046/ERC20Metadata.sol

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ import "../../token/ERC20/IERC20.sol";
77
* @dev See https://eips.ethereum.org/EIPS/eip-1046
88
* @dev tokenURI must respond with a URI that implements https://eips.ethereum.org/EIPS/eip-1047
99
*/
10-
contract ERC20TokenMetadata is IERC20 {
11-
function tokenURI() external view returns (string memory);
12-
}
13-
14-
contract ERC20WithMetadata is ERC20TokenMetadata {
10+
contract ERC20Metadata {
1511
string private _tokenURI;
1612

17-
constructor (string memory tokenURI) public {
18-
_tokenURI = tokenURI;
13+
constructor (string memory tokenURI_) public {
14+
_setTokenURI(tokenURI_);
1915
}
2016

2117
function tokenURI() external view returns (string memory) {
2218
return _tokenURI;
2319
}
20+
21+
function _setTokenURI(string memory tokenURI_) internal {
22+
_tokenURI = tokenURI_;
23+
}
2424
}

contracts/mocks/ERC20MetadataMock.sol

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pragma solidity ^0.5.2;
2+
3+
import "../token/ERC20/ERC20.sol";
4+
import "../drafts/ERC1046/ERC20Metadata.sol";
5+
6+
contract ERC20MetadataMock is ERC20, ERC20Metadata {
7+
constructor (string memory tokenURI) public ERC20Metadata(tokenURI) {
8+
// solhint-disable-previous-line no-empty-blocks
9+
}
10+
11+
function setTokenURI(string memory tokenURI) public {
12+
_setTokenURI(tokenURI);
13+
}
14+
}

contracts/mocks/ERC20WithMetadataMock.sol

-10
This file was deleted.
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require('openzeppelin-test-helpers');
2+
3+
const ERC20MetadataMock = artifacts.require('ERC20MetadataMock');
4+
5+
const metadataURI = 'https://example.com';
6+
7+
describe('ERC20Metadata', function () {
8+
beforeEach(async function () {
9+
this.token = await ERC20MetadataMock.new(metadataURI);
10+
});
11+
12+
it('responds with the metadata', async function () {
13+
(await this.token.tokenURI()).should.equal(metadataURI);
14+
});
15+
16+
describe('setTokenURI', function () {
17+
it('changes the original URI', async function () {
18+
const newMetadataURI = 'https://betterexample.com';
19+
await this.token.setTokenURI(newMetadataURI);
20+
(await this.token.tokenURI()).should.equal(newMetadataURI);
21+
});
22+
});
23+
});

test/drafts/ERC1046/TokenMetadata.test.js

-15
This file was deleted.

0 commit comments

Comments
 (0)