diff --git a/contracts/commons/ERC721Base.sol b/contracts/commons/ERC721Base.sol index 5e7e7e68..e304e742 100644 --- a/contracts/commons/ERC721Base.sol +++ b/contracts/commons/ERC721Base.sol @@ -42,6 +42,9 @@ contract ERC721Base is ERC165 { _name = name; _symbol = symbol; + emit SetName(name); + emit SetSymbol(symbol); + _registerInterface(ERC_721_INTERFACE); _registerInterface(ERC_721_METADATA_INTERFACE); _registerInterface(ERC_721_ENUMERATION_INTERFACE); @@ -56,6 +59,8 @@ contract ERC721Base is ERC165 { /// Note: the ERC-165 identifier for this interface is 0x5b5e139f. event SetURIProvider(address _uriProvider); + event SetName(string _name); + event SetSymbol(string _symbol); string private _name; string private _symbol; @@ -90,6 +95,18 @@ contract ERC721Base is ERC165 { return true; } + // @notice Updates the descriptive name for a collection of NFTs in this contract + function _setName(string memory _newName) internal { + emit SetName(_newName); + _name = _newName; + } + + // @notice Updates the abbreviated name for NFTs in this contract + function _setSymbol(string memory _newSymbol) internal { + emit SetSymbol(_newSymbol); + _symbol = _newSymbol; + } + // /// // ERC721 Enumeration // /// diff --git a/contracts/core/diaspore/DebtEngine.sol b/contracts/core/diaspore/DebtEngine.sol index 272488ee..9683914d 100644 --- a/contracts/core/diaspore/DebtEngine.sol +++ b/contracts/core/diaspore/DebtEngine.sol @@ -109,6 +109,14 @@ contract DebtEngine is ERC721Base, Ownable { _setURIProvider(_provider); } + function setName(string calldata _name) external onlyOwner { + _setName(_name); + } + + function setSymbol(string calldata _symbol) external onlyOwner { + _setSymbol(_symbol); + } + function create( Model _model, address _owner, diff --git a/test/diaspore/TestDebtEngine.js b/test/diaspore/TestDebtEngine.js index 0981251f..5b081ede 100644 --- a/test/diaspore/TestDebtEngine.js +++ b/test/diaspore/TestDebtEngine.js @@ -62,6 +62,26 @@ contract('Test DebtEngine Diaspore', function (accounts) { ); }); }); + describe('Update name and symbol', function () { + it('Should update name of NFT', async function () { + const debtEngine = await DebtEngine.new(rcn.address, { from: accounts[2] }); + await debtEngine.setName('New name for NFT', { from: accounts[2] }); + expect(await debtEngine.name()).to.be.equal('New name for NFT'); + }); + it('Should update symbol of NFT', async function () { + const debtEngine = await DebtEngine.new(rcn.address, { from: accounts[2] }); + await debtEngine.setSymbol('SYM2', { from: accounts[2] }); + expect(await debtEngine.symbol()).to.be.equal('SYM2'); + }); + it('Should fail update name of NFT if callers is not the owner', async function () { + const debtEngine = await DebtEngine.new(rcn.address, { from: accounts[2] }); + await Helper.tryCatchRevert(debtEngine.setName('New name for NFT', { from: accounts[1] }), 'The owner should be the sender'); + }); + it('Should fail update symbol of NFT if callers is not the owner', async function () { + const debtEngine = await DebtEngine.new(rcn.address, { from: accounts[2] }); + await Helper.tryCatchRevert(debtEngine.setSymbol('New name for NFT', { from: accounts[1] }), 'The owner should be the sender'); + }); + }); describe('Function setURIProvider', function () { it('Should set the URI provider', async function () { const URIProvider = await TestURIProvider.new();