Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ERC20 _setTokenURI #1618

Merged
merged 5 commits into from
Jan 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
nventuro marked this conversation as resolved.
Show resolved Hide resolved
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.