Add ERC20 _setTokenURI (#1618)
* Add _setTokenURI internal. * Rename TokenMetadata to ERC20Metadata. * Add changelog entry for ERC20Metadata. * Fix linter error. * Add breaking change changelog notice.
This commit is contained in:
committed by
Francisco Giordano
parent
1fd993bc01
commit
8dd92fd6ca
@ -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.
|
||||
@ -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`.
|
||||
|
||||
@ -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
contracts/mocks/ERC20MetadataMock.sol
Normal file
14
contracts/mocks/ERC20MetadataMock.sol
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
pragma solidity ^0.5.2;
|
||||
|
||||
import "../token/ERC20/ERC20.sol";
|
||||
import "../drafts/ERC1046/TokenMetadata.sol";
|
||||
|
||||
contract ERC20WithMetadataMock is ERC20, ERC20WithMetadata {
|
||||
constructor (string memory tokenURI) public ERC20WithMetadata(tokenURI) {
|
||||
// solhint-disable-previous-line no-empty-blocks
|
||||
}
|
||||
}
|
||||
23
test/drafts/ERC1046/ERC20Metadata.test.js
Normal file
23
test/drafts/ERC1046/ERC20Metadata.test.js
Normal file
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,15 +0,0 @@
|
||||
require('openzeppelin-test-helpers');
|
||||
|
||||
const ERC20WithMetadataMock = artifacts.require('ERC20WithMetadataMock');
|
||||
|
||||
const metadataURI = 'https://example.com';
|
||||
|
||||
describe('ERC20WithMetadata', function () {
|
||||
beforeEach(async function () {
|
||||
this.token = await ERC20WithMetadataMock.new(metadataURI);
|
||||
});
|
||||
|
||||
it('responds with the metadata', async function () {
|
||||
(await this.token.tokenURI()).should.equal(metadataURI);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user