Просмотр исходного кода

Separate ERC721Mintable (#1365)

* separate part of ERC721Mintable into ERC721MetadataMintable

* remove mint and burn from 721 tests

* Fixed linter error.

* fix ERC721 mint tests

* Minor fixes.
Francisco Giordano 7 лет назад
Родитель
Сommit
744f567f40

+ 5 - 2
contracts/mocks/ERC721FullMock.sol

@@ -2,14 +2,17 @@ pragma solidity ^0.4.24;
 
 import "../token/ERC721/ERC721Full.sol";
 import "../token/ERC721/ERC721Mintable.sol";
+import "../token/ERC721/ERC721MetadataMintable.sol";
 import "../token/ERC721/ERC721Burnable.sol";
 
 /**
- * @title ERC721Mock
+ * @title ERC721FullMock
  * This mock just provides a public mint and burn functions for testing purposes,
  * and a public setter for metadata URI
  */
-contract ERC721FullMock is ERC721Full, ERC721Mintable, ERC721Burnable {
+contract ERC721FullMock
+  is ERC721Full, ERC721Mintable, ERC721MetadataMintable, ERC721Burnable {
+
   constructor(string name, string symbol) public
     ERC721Mintable()
     ERC721Full(name, symbol)

+ 2 - 1
contracts/mocks/ERC721MintableBurnableImpl.sol

@@ -2,13 +2,14 @@ pragma solidity ^0.4.24;
 
 import "../token/ERC721/ERC721Full.sol";
 import "../token/ERC721/ERC721Mintable.sol";
+import "../token/ERC721/ERC721MetadataMintable.sol";
 import "../token/ERC721/ERC721Burnable.sol";
 
 /**
  * @title ERC721MintableBurnableImpl
  */
 contract ERC721MintableBurnableImpl
-  is ERC721Full, ERC721Mintable, ERC721Burnable {
+  is ERC721Full, ERC721Mintable, ERC721MetadataMintable, ERC721Burnable {
 
   constructor()
     ERC721Mintable()

+ 32 - 0
contracts/token/ERC721/ERC721MetadataMintable.sol

@@ -0,0 +1,32 @@
+pragma solidity ^0.4.24;
+
+import "./ERC721Metadata.sol";
+import "../../access/roles/MinterRole.sol";
+
+
+/**
+ * @title ERC721MetadataMintable
+ * @dev ERC721 minting logic with metadata
+ */
+contract ERC721MetadataMintable is ERC721, ERC721Metadata, MinterRole {
+  /**
+   * @dev Function to mint tokens
+   * @param to The address that will receive the minted tokens.
+   * @param tokenId The token id to mint.
+   * @param tokenURI The token URI of the minted token.
+   * @return A boolean that indicates if the operation was successful.
+   */
+  function mintWithTokenURI(
+    address to,
+    uint256 tokenId,
+    string tokenURI
+  )
+    public
+    onlyMinter
+    returns (bool)
+  {
+    _mint(to, tokenId);
+    _setTokenURI(tokenId, tokenURI);
+    return true;
+  }
+}

+ 2 - 16
contracts/token/ERC721/ERC721Mintable.sol

@@ -1,13 +1,13 @@
 pragma solidity ^0.4.24;
 
-import "./ERC721Full.sol";
+import "./ERC721.sol";
 import "../../access/roles/MinterRole.sol";
 
 /**
  * @title ERC721Mintable
  * @dev ERC721 minting logic
  */
-contract ERC721Mintable is ERC721Full, MinterRole {
+contract ERC721Mintable is ERC721, MinterRole {
   /**
    * @dev Function to mint tokens
    * @param to The address that will receive the minted tokens.
@@ -25,18 +25,4 @@ contract ERC721Mintable is ERC721Full, MinterRole {
     _mint(to, tokenId);
     return true;
   }
-
-  function mintWithTokenURI(
-    address to,
-    uint256 tokenId,
-    string tokenURI
-  )
-    public
-    onlyMinter
-    returns (bool)
-  {
-    mint(to, tokenId);
-    _setTokenURI(tokenId, tokenURI);
-    return true;
-  }
 }

+ 0 - 2
test/token/ERC721/ERC721Full.test.js

@@ -1,6 +1,5 @@
 const { assertRevert } = require('../../helpers/assertRevert');
 const { shouldBehaveLikeERC721 } = require('./ERC721.behavior');
-const { shouldBehaveLikeMintAndBurnERC721 } = require('./ERC721MintBurn.behavior');
 const { shouldSupportInterfaces } = require('../../introspection/SupportsInterface.behavior');
 
 const BigNumber = web3.BigNumber;
@@ -221,7 +220,6 @@ contract('ERC721Full', function ([
   });
 
   shouldBehaveLikeERC721(creator, minter, accounts);
-  shouldBehaveLikeMintAndBurnERC721(creator, minter, accounts);
 
   shouldSupportInterfaces([
     'ERC165',

+ 2 - 2
test/token/ERC721/ERC721MintBurn.behavior.js

@@ -52,13 +52,13 @@ function shouldBehaveLikeMintAndBurnERC721 (
 
       describe('when the given owner address is the zero address', function () {
         it('reverts', async function () {
-          await assertRevert(this.token.mint(ZERO_ADDRESS, thirdTokenId));
+          await assertRevert(this.token.mint(ZERO_ADDRESS, thirdTokenId, { from: minter }));
         });
       });
 
       describe('when the given token ID was already tracked by this contract', function () {
         it('reverts', async function () {
-          await assertRevert(this.token.mint(owner, firstTokenId));
+          await assertRevert(this.token.mint(owner, firstTokenId, { from: minter }));
         });
       });
     });