From 1259bb6be12774a91cbf4e668a628a87cd26388f Mon Sep 17 00:00:00 2001 From: Agustin Aguilar Date: Mon, 16 Sep 2019 16:17:10 +0200 Subject: [PATCH 1/2] Add setName and setSymbol methods on DebtEngine --- contracts/commons/ERC721Base.sol | 17 +++++++++++++++++ contracts/core/diaspore/DebtEngine.sol | 8 ++++++++ test/diaspore/TestDebtEngine.js | 20 ++++++++++++++++++++ 3 files changed, 45 insertions(+) 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..7e7e0601 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 () { + 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 () { + 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 () { + 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 () { + 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(); From 3ff73e2bf13bb881a5b7be6b7560fee432bda24a Mon Sep 17 00:00:00 2001 From: Agustin Aguilar Date: Mon, 16 Sep 2019 16:29:57 +0200 Subject: [PATCH 2/2] Fix tests update NFT metadata --- test/diaspore/TestDebtEngine.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/diaspore/TestDebtEngine.js b/test/diaspore/TestDebtEngine.js index 7e7e0601..5b081ede 100644 --- a/test/diaspore/TestDebtEngine.js +++ b/test/diaspore/TestDebtEngine.js @@ -64,21 +64,21 @@ contract('Test DebtEngine Diaspore', function (accounts) { }); describe('Update name and symbol', function () { it('Should update name of NFT', async function () { - debtEngine = await DebtEngine.new(rcn.address, { from: accounts[2] }); + 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 () { - debtEngine = await DebtEngine.new(rcn.address, { from: accounts[2] }); + 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 () { - debtEngine = await DebtEngine.new(rcn.address, { from: accounts[2] }); + 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 () { - debtEngine = await DebtEngine.new(rcn.address, { from: accounts[2] }); + 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'); }); });