Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
feat(PTP-466): Added renounce method
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpavelicconsensys committed Jun 7, 2022
1 parent 0aa9f5f commit 561c30d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/ContractTemplates/ERC721Mintable/ERC721Mintable.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,25 @@ export default class ERC721Mintable {
throw new Error(`[ERC721Mintable.approveTransfer] An error occured: ${error}`);
}
}

/*
* Renouncing ownership of the smart contract (will leave the contract without an owner).
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
* @returns {bool} Success or fail of the operation
*/
async renounceOwnership() {
if (!this.contractAddress && !this.#contractDeployed) {
throw new Error('[ERC721Mintable.renounceOwnership] Contract needs to be deployed');
}

try {
return await this.#contractDeployed.renounceOwnership();
} catch (error) {
throw new Error(`[ERC721Mintable.renounceOwnership] An error occured: ${error}`);
}
}
}
14 changes: 14 additions & 0 deletions test/ERC721Mintable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('SDK', () => {
approve: jest.fn(),
setRoyalties: jest.fn(),
royaltyInfo: jest.fn(),
renounceOwnership: jest.fn(),
}),
}));

Expand Down Expand Up @@ -689,4 +690,17 @@ describe('SDK', () => {
);
});
});
describe('renounceOwnership', () => {
it('[renounceOwnership] - should throw when args are missing (contractAddress)', async () => {
const contract = new ERC721Mintable(signer);
contract.contractAddress = null;

await expect(() => contract.renounceOwnership()).rejects.toThrow(
'[ERC721Mintable.renounceOwnership] Contract needs to be deployed',
);
});
it('[renounceOwnership] - should throw if contract not deployed', async () => {});

it('[renounceOwnership] - should call renounce ownership', async () => {});
});
});

0 comments on commit 561c30d

Please sign in to comment.