Skip to content
Open
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
17 changes: 17 additions & 0 deletions contracts/commons/ERC721Base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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
// ///
Expand Down
8 changes: 8 additions & 0 deletions contracts/core/diaspore/DebtEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions test/diaspore/TestDebtEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down