From 3945a3cdce4859751e91a6d86d813b2475070697 Mon Sep 17 00:00:00 2001 From: Seth Date: Thu, 29 Feb 2024 16:06:59 +0800 Subject: [PATCH] refactor: rename OwnableDocumentStore to TransferableDocumentStore (cherry picked from commit 893541d5fbfe85afa57d740867f79fd92a6d0318) --- package.json | 9 ++++- script/DeployBase.s.sol | 2 +- script/OwnableDocumentStore.s.sol | 29 -------------- .../OwnableDocumentStoreInitializable.s.sol | 23 ----------- script/OwnableDocumentStoreUpgradeable.s.sol | 26 ------------ script/TransferableDocumentStore.s.sol | 29 ++++++++++++++ ...ansferableDocumentStoreInitializable.s.sol | 23 +++++++++++ ...TransferableDocumentStoreUpgradeable.s.sol | 26 ++++++++++++ ...tore.sol => TransferableDocumentStore.sol} | 6 +-- ....sol => BaseTransferableDocumentStore.sol} | 21 +++++----- ...ransferableDocumentStoreInitializable.sol} | 6 +-- ...ore.sol => ITransferableDocumentStore.sol} | 2 +- ...l => ITransferableDocumentStoreErrors.sol} | 2 +- src/libraries/DeployUtils.sol | 11 +++-- ... TransferableDocumentStoreUpgradeable.sol} | 4 +- test/CommonTest.t.sol | 18 ++++----- ....t.sol => TransferableDocumentStore.t.sol} | 40 +++++++++---------- ...ransferableDocumentStoreUpgradeable.t.sol} | 24 +++++------ ...l => TransferableDocumentStoreFixture.sol} | 2 +- 19 files changed, 157 insertions(+), 146 deletions(-) delete mode 100644 script/OwnableDocumentStore.s.sol delete mode 100644 script/OwnableDocumentStoreInitializable.s.sol delete mode 100644 script/OwnableDocumentStoreUpgradeable.s.sol create mode 100644 script/TransferableDocumentStore.s.sol create mode 100644 script/TransferableDocumentStoreInitializable.s.sol create mode 100644 script/TransferableDocumentStoreUpgradeable.s.sol rename src/{OwnableDocumentStore.sol => TransferableDocumentStore.sol} (62%) rename src/base/{BaseOwnableDocumentStore.sol => BaseTransferableDocumentStore.sol} (88%) rename src/initializables/{OwnableDocumentStoreInitializable.sol => TransferableDocumentStoreInitializable.sol} (52%) rename src/interfaces/{IOwnableDocumentStore.sol => ITransferableDocumentStore.sol} (76%) rename src/interfaces/{IOwnableDocumentStoreErrors.sol => ITransferableDocumentStoreErrors.sol} (85%) rename src/upgradeables/{OwnableDocumentStoreUpgradeable.sol => TransferableDocumentStoreUpgradeable.sol} (59%) rename test/{OwnableDocumentStore.t.sol => TransferableDocumentStore.t.sol} (87%) rename test/{OwnableDocumentStoreUpgradeable.t.sol => TransferableDocumentStoreUpgradeable.t.sol} (71%) rename test/fixtures/{OwnableDocumentStoreFixture.sol => TransferableDocumentStoreFixture.sol} (90%) diff --git a/package.json b/package.json index 09d79a0..332d03e 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,14 @@ "prettier:write": "npx prettier --write \"**/*.{json,md,yml,sol}\" \"!broadcast/**/*\" --ignore-path=.prettierignore", "test": "forge test", "test:coverage": "rimraf coverage && mkdir coverage && forge coverage --report lcov && genhtml lcov.info --branch-coverage --output-dir coverage", - "test:coverage:report": "forge coverage --report lcov && genhtml lcov.info --branch-coverage --output-dir coverage" + "test:coverage:report": "forge coverage --report lcov && genhtml lcov.info --branch-coverage --output-dir coverage", + "deploy": "./deploy.sh $npm_config_network $npm_config_sender $npm_config_verify", + "deploy:ds": "npm run -s deploy script/DocumentStore.s.sol:DocumentStoreScript \"run(string,address)\" \"$npm_config_name\" \"$npm_config_admin\"", + "deploy:ds:impl": "npm run -s deploy script/DocumentStoreInitializable.s.sol:DocumentStoreInitializableScript", + "deploy:ds:upgradeable": "npm run -s deploy script/DocumentStoreUpgradeable.s.sol:DocumentStoreUpgradeableScript \"run(string,address)\" \"$npm_config_name\" \"$npm_config_admin\"", + "deploy:tds": "npm run -s deploy script/TransferableDocumentStore.s.sol:TransferableDocumentStoreScript \"run(string,string,address)\" \"$npm_config_name\" \"$npm_config_symbol\" \"$npm_config_admin\"", + "deploy:tds:impl": "npm run -s deploy script/TransferableDocumentStoreInitializable.s.sol:TransferableDocumentStoreInitializableScript", + "deploy:tds:upgradeable": "npm run -s deploy script/TransferableDocumentStoreUpgradeable.s.sol:TransferableDocumentStoreUpgradeableScript \"run(string,string,address)\" \"$npm_config_name\" \"$npm_config_symbol\" \"$npm_config_admin\"" }, "jest": { "globalSetup": "./jest/setup.ts", diff --git a/script/DeployBase.s.sol b/script/DeployBase.s.sol index 2351cb0..b38ad6a 100644 --- a/script/DeployBase.s.sol +++ b/script/DeployBase.s.sol @@ -100,7 +100,7 @@ abstract contract DocumentStoreDeployScript is DeployBaseScript { } } -abstract contract OwnableDocumentStoreDeployScript is DeployBaseScript { +abstract contract TransferableDocumentStoreDeployScript is DeployBaseScript { function _requireParams(string memory name, string memory symbol, address admin) internal pure { require(bytes(name).length > 0, "Name is required"); require(bytes(symbol).length > 0, "Symbol is required"); diff --git a/script/OwnableDocumentStore.s.sol b/script/OwnableDocumentStore.s.sol deleted file mode 100644 index cc2446d..0000000 --- a/script/OwnableDocumentStore.s.sol +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity >=0.8.23 <0.9.0; - -import { console2 } from "forge-std/console2.sol"; - -import { OwnableDocumentStoreDeployScript } from "./DeployBase.s.sol"; -import "../src/OwnableDocumentStore.sol"; - -contract OwnableDocumentStoreScript is OwnableDocumentStoreDeployScript { - function run(string memory name, string memory symbol, address admin) public returns (OwnableDocumentStore ds) { - _requireParams(name, symbol, admin); - - console2.log("OwnableDocumentStore Name: ", name); - console2.log("OwnableDocumentStore Symbol: ", symbol); - console2.log("OwnableDocumentStore Admin: ", admin); - - if (tdsImplExists()) { - bytes memory initData = abi.encodeWithSignature("initialize(string,string,address)", name, symbol, admin); - - vm.broadcast(); - address dsAddr = clone(TDS_IMPL, initData); - - ds = OwnableDocumentStore(dsAddr); - } else { - vm.broadcast(); - ds = new OwnableDocumentStore(name, symbol, admin); - } - } -} diff --git a/script/OwnableDocumentStoreInitializable.s.sol b/script/OwnableDocumentStoreInitializable.s.sol deleted file mode 100644 index 76635a3..0000000 --- a/script/OwnableDocumentStoreInitializable.s.sol +++ /dev/null @@ -1,23 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity >=0.8.23 <0.9.0; - -import { OwnableDocumentStoreDeployScript } from "./DeployBase.s.sol"; -import "../src/initializables/OwnableDocumentStoreInitializable.sol"; - -contract OwnableDocumentStoreInitializableScript is OwnableDocumentStoreDeployScript { - function run() public returns (OwnableDocumentStoreInitializable documentStore) { - require(!dsImplExists(), "OwnableDocumentStoreInitializable already exists"); - - bytes memory initCode = abi.encodePacked(type(OwnableDocumentStoreInitializable).creationCode); - - bytes32 dsSalt = getTransferableDocumentStoreSalt(); - - address computedAddr = computeAddr(dsSalt); - require(computedAddr == TDS_IMPL, "Bad deployment address"); - - vm.broadcast(); - address dsAddr = deploy(dsSalt, initCode); - - documentStore = OwnableDocumentStoreInitializable(dsAddr); - } -} diff --git a/script/OwnableDocumentStoreUpgradeable.s.sol b/script/OwnableDocumentStoreUpgradeable.s.sol deleted file mode 100644 index 3ec707f..0000000 --- a/script/OwnableDocumentStoreUpgradeable.s.sol +++ /dev/null @@ -1,26 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -pragma solidity >=0.8.23 <0.9.0; - -import { console2 } from "forge-std/console2.sol"; - -import { OwnableDocumentStoreDeployScript } from "./DeployBase.s.sol"; -import { DeployUtils } from "../src/libraries/DeployUtils.sol"; -import "../src/upgradeables/OwnableDocumentStoreUpgradeable.sol"; - -contract OwnableDocumentStoreUpgradeableScript is OwnableDocumentStoreDeployScript { - function run( - string memory name, - string memory symbol, - address admin - ) public returns (OwnableDocumentStoreUpgradeable ds) { - _requireParams(name, symbol, admin); - - console2.log("OwnableDocumentStore Name: ", name); - console2.log("OwnableDocumentStore Symbol: ", symbol); - console2.log("OwnableDocumentStore Admin: ", admin); - - vm.broadcast(); - (address pAddr, ) = DeployUtils.deployOwnableDocumentStoreUpgradeable(name, symbol, admin); - ds = OwnableDocumentStoreUpgradeable(pAddr); - } -} diff --git a/script/TransferableDocumentStore.s.sol b/script/TransferableDocumentStore.s.sol new file mode 100644 index 0000000..188f2c1 --- /dev/null +++ b/script/TransferableDocumentStore.s.sol @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity >=0.8.23 <0.9.0; + +import { console2 } from "forge-std/console2.sol"; + +import { TransferableDocumentStoreDeployScript } from "./DeployBase.s.sol"; +import "../src/TransferableDocumentStore.sol"; + +contract TransferableDocumentStoreScript is TransferableDocumentStoreDeployScript { + function run(string memory name, string memory symbol, address admin) public returns (TransferableDocumentStore ds) { + _requireParams(name, symbol, admin); + + console2.log("TransferableDocumentStore Name: ", name); + console2.log("TransferableDocumentStore Symbol: ", symbol); + console2.log("TransferableDocumentStore Admin: ", admin); + + if (tdsImplExists()) { + bytes memory initData = abi.encodeWithSignature("initialize(string,string,address)", name, symbol, admin); + + vm.broadcast(); + address dsAddr = clone(TDS_IMPL, initData); + + ds = TransferableDocumentStore(dsAddr); + } else { + vm.broadcast(); + ds = new TransferableDocumentStore(name, symbol, admin); + } + } +} diff --git a/script/TransferableDocumentStoreInitializable.s.sol b/script/TransferableDocumentStoreInitializable.s.sol new file mode 100644 index 0000000..0c3626d --- /dev/null +++ b/script/TransferableDocumentStoreInitializable.s.sol @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity >=0.8.23 <0.9.0; + +import { TransferableDocumentStoreDeployScript } from "./DeployBase.s.sol"; +import "../src/initializables/TransferableDocumentStoreInitializable.sol"; + +contract TransferableDocumentStoreInitializableScript is TransferableDocumentStoreDeployScript { + function run() public returns (TransferableDocumentStoreInitializable documentStore) { + require(!dsImplExists(), "TransferableDocumentStoreInitializable already exists"); + + bytes memory initCode = abi.encodePacked(type(TransferableDocumentStoreInitializable).creationCode); + + bytes32 dsSalt = getTransferableDocumentStoreSalt(); + + address computedAddr = computeAddr(dsSalt); + require(computedAddr == TDS_IMPL, "Bad deployment address"); + + vm.broadcast(); + address dsAddr = deploy(dsSalt, initCode); + + documentStore = TransferableDocumentStoreInitializable(dsAddr); + } +} diff --git a/script/TransferableDocumentStoreUpgradeable.s.sol b/script/TransferableDocumentStoreUpgradeable.s.sol new file mode 100644 index 0000000..5cf3106 --- /dev/null +++ b/script/TransferableDocumentStoreUpgradeable.s.sol @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity >=0.8.23 <0.9.0; + +import { console2 } from "forge-std/console2.sol"; + +import { TransferableDocumentStoreDeployScript } from "./DeployBase.s.sol"; +import { DeployUtils } from "../src/libraries/DeployUtils.sol"; +import "../src/upgradeables/TransferableDocumentStoreUpgradeable.sol"; + +contract TransferableDocumentStoreUpgradeableScript is TransferableDocumentStoreDeployScript { + function run( + string memory name, + string memory symbol, + address admin + ) public returns (TransferableDocumentStoreUpgradeable ds) { + _requireParams(name, symbol, admin); + + console2.log("TransferableDocumentStore Name: ", name); + console2.log("TransferableDocumentStore Symbol: ", symbol); + console2.log("TransferableDocumentStore Admin: ", admin); + + vm.broadcast(); + (address pAddr, ) = DeployUtils.deployTransferableDocumentStoreUpgradeable(name, symbol, admin); + ds = TransferableDocumentStoreUpgradeable(pAddr); + } +} diff --git a/src/OwnableDocumentStore.sol b/src/TransferableDocumentStore.sol similarity index 62% rename from src/OwnableDocumentStore.sol rename to src/TransferableDocumentStore.sol index d548b32..179e658 100644 --- a/src/OwnableDocumentStore.sol +++ b/src/TransferableDocumentStore.sol @@ -2,14 +2,14 @@ pragma solidity >=0.8.23 <0.9.0; -import "./base/BaseOwnableDocumentStore.sol"; +import "./base/BaseTransferableDocumentStore.sol"; -contract OwnableDocumentStore is BaseOwnableDocumentStore { +contract TransferableDocumentStore is BaseTransferableDocumentStore { constructor(string memory name_, string memory symbol_, address initAdmin) { initialize(name_, symbol_, initAdmin); } function initialize(string memory name_, string memory symbol_, address initAdmin) internal initializer { - __OwnableDocumentStore_init(name_, symbol_, initAdmin); + __TransferableDocumentStore_init(name_, symbol_, initAdmin); } } diff --git a/src/base/BaseOwnableDocumentStore.sol b/src/base/BaseTransferableDocumentStore.sol similarity index 88% rename from src/base/BaseOwnableDocumentStore.sol rename to src/base/BaseTransferableDocumentStore.sol index a9746e9..519d03c 100644 --- a/src/base/BaseOwnableDocumentStore.sol +++ b/src/base/BaseTransferableDocumentStore.sol @@ -6,31 +6,32 @@ import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol"; import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; import "../base/DocumentStoreAccessControl.sol"; -import "../interfaces/IOwnableDocumentStore.sol"; -import "../interfaces/IOwnableDocumentStoreErrors.sol"; +import "../interfaces/ITransferableDocumentStore.sol"; +import "../interfaces/ITransferableDocumentStoreErrors.sol"; import "../interfaces/IERC5192.sol"; -abstract contract BaseOwnableDocumentStore is +abstract contract BaseTransferableDocumentStore is DocumentStoreAccessControl, ERC721Upgradeable, IERC5192, - IOwnableDocumentStoreErrors, - IOwnableDocumentStore + ITransferableDocumentStoreErrors, + ITransferableDocumentStore { using Strings for uint256; - /// @custom:storage-location erc7201:openattestation.storage.OwnableDocumentStore + /// @custom:storage-location erc7201:openattestation.storage.TransferableDocumentStore struct DocumentStoreStorage { string baseURI; mapping(uint256 => bool) revoked; mapping(uint256 => bool) locked; } - // keccak256(abi.encode(uint256(keccak256("openattestation.storage.OwnableDocumentStore")) - 1)) & ~bytes32(uint256(0xff)) + // keccak256(abi.encode(uint256(keccak256("openattestation.storage.TransferableDocumentStore")) - 1)) & + // ~bytes32(uint256(0xff)) bytes32 private constant _DocumentStoreStorageSlot = - 0x5b868bb5de5c3e5f8f786d02cbc568987b1921539a10331babbe7311c24de500; + 0xe00db8ee8fc09b2a809fe10830715c77ed23b7661f93309e127fb70c1f33ef00; - function __OwnableDocumentStore_init( + function __TransferableDocumentStore_init( string memory name_, string memory symbol_, address initAdmin @@ -111,7 +112,7 @@ abstract contract BaseOwnableDocumentStore is ) public view virtual override(ERC721Upgradeable, AccessControlUpgradeable) returns (bool) { return interfaceId == type(IDocumentStore).interfaceId || - interfaceId == type(IOwnableDocumentStore).interfaceId || + interfaceId == type(ITransferableDocumentStore).interfaceId || interfaceId == type(IERC5192).interfaceId || super.supportsInterface(interfaceId); } diff --git a/src/initializables/OwnableDocumentStoreInitializable.sol b/src/initializables/TransferableDocumentStoreInitializable.sol similarity index 52% rename from src/initializables/OwnableDocumentStoreInitializable.sol rename to src/initializables/TransferableDocumentStoreInitializable.sol index 48fcd45..e780cf8 100644 --- a/src/initializables/OwnableDocumentStoreInitializable.sol +++ b/src/initializables/TransferableDocumentStoreInitializable.sol @@ -2,12 +2,12 @@ pragma solidity >=0.8.23 <0.9.0; -import "../base/BaseOwnableDocumentStore.sol"; +import "../base/BaseTransferableDocumentStore.sol"; -contract OwnableDocumentStoreInitializable is BaseOwnableDocumentStore { +contract TransferableDocumentStoreInitializable is BaseTransferableDocumentStore { constructor() initializer {} function initialize(string memory name_, string memory symbol_, address initAdmin) external initializer { - __OwnableDocumentStore_init(name_, symbol_, initAdmin); + __TransferableDocumentStore_init(name_, symbol_, initAdmin); } } diff --git a/src/interfaces/IOwnableDocumentStore.sol b/src/interfaces/ITransferableDocumentStore.sol similarity index 76% rename from src/interfaces/IOwnableDocumentStore.sol rename to src/interfaces/ITransferableDocumentStore.sol index 45bec97..fb3417d 100644 --- a/src/interfaces/IOwnableDocumentStore.sol +++ b/src/interfaces/ITransferableDocumentStore.sol @@ -3,6 +3,6 @@ pragma solidity >=0.8.23 <0.9.0; import "./IDocumentStore.sol"; -interface IOwnableDocumentStore is IDocumentStore { +interface ITransferableDocumentStore is IDocumentStore { function issue(address to, bytes32 documentRoot, bool locked) external; } diff --git a/src/interfaces/IOwnableDocumentStoreErrors.sol b/src/interfaces/ITransferableDocumentStoreErrors.sol similarity index 85% rename from src/interfaces/IOwnableDocumentStoreErrors.sol rename to src/interfaces/ITransferableDocumentStoreErrors.sol index 53616ef..e8e9e14 100644 --- a/src/interfaces/IOwnableDocumentStoreErrors.sol +++ b/src/interfaces/ITransferableDocumentStoreErrors.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity >=0.8.23 <0.9.0; -interface IOwnableDocumentStoreErrors { +interface ITransferableDocumentStoreErrors { error InactiveDocument(bytes32 document); error DocumentExists(bytes32 document); diff --git a/src/libraries/DeployUtils.sol b/src/libraries/DeployUtils.sol index 3126546..c78ed94 100644 --- a/src/libraries/DeployUtils.sol +++ b/src/libraries/DeployUtils.sol @@ -4,7 +4,7 @@ pragma solidity >=0.8.23 <0.9.0; import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; import "../upgradeables/DocumentStoreUpgradeable.sol"; -import "../upgradeables/OwnableDocumentStoreUpgradeable.sol"; +import "../upgradeables/TransferableDocumentStoreUpgradeable.sol"; library DeployUtils { function deployDocumentStoreUpgradeable(string memory name, address initAdmin) internal returns (address, address) { @@ -18,14 +18,17 @@ library DeployUtils { return (address(proxy), dsAddr); } - function deployOwnableDocumentStoreUpgradeable( + function deployTransferableDocumentStoreUpgradeable( string memory name, string memory symbol, address initAdmin ) internal returns (address, address) { - bytes memory initData = abi.encodeCall(OwnableDocumentStoreInitializable.initialize, (name, symbol, initAdmin)); + bytes memory initData = abi.encodeCall( + TransferableDocumentStoreInitializable.initialize, + (name, symbol, initAdmin) + ); - OwnableDocumentStoreUpgradeable documentStore = new OwnableDocumentStoreUpgradeable(); + TransferableDocumentStoreUpgradeable documentStore = new TransferableDocumentStoreUpgradeable(); address dsAddr = address(documentStore); ERC1967Proxy proxy = new ERC1967Proxy(dsAddr, initData); diff --git a/src/upgradeables/OwnableDocumentStoreUpgradeable.sol b/src/upgradeables/TransferableDocumentStoreUpgradeable.sol similarity index 59% rename from src/upgradeables/OwnableDocumentStoreUpgradeable.sol rename to src/upgradeables/TransferableDocumentStoreUpgradeable.sol index aac5b85..713a0dc 100644 --- a/src/upgradeables/OwnableDocumentStoreUpgradeable.sol +++ b/src/upgradeables/TransferableDocumentStoreUpgradeable.sol @@ -4,8 +4,8 @@ pragma solidity >=0.8.23 <0.9.0; import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; -import "../initializables/OwnableDocumentStoreInitializable.sol"; +import "../initializables/TransferableDocumentStoreInitializable.sol"; -contract OwnableDocumentStoreUpgradeable is UUPSUpgradeable, OwnableDocumentStoreInitializable { +contract TransferableDocumentStoreUpgradeable is UUPSUpgradeable, TransferableDocumentStoreInitializable { function _authorizeUpgrade(address) internal view virtual override onlyRole(DEFAULT_ADMIN_ROLE) {} } diff --git a/test/CommonTest.t.sol b/test/CommonTest.t.sol index bd0809c..06b0a31 100644 --- a/test/CommonTest.t.sol +++ b/test/CommonTest.t.sol @@ -5,8 +5,8 @@ import "forge-std/Test.sol"; import "../src/DocumentStore.sol"; import "./fixtures/DocumentStoreFixture.sol"; -import "../src/OwnableDocumentStore.sol"; -import "./fixtures/OwnableDocumentStoreFixture.sol"; +import "../src/TransferableDocumentStore.sol"; +import "./fixtures/TransferableDocumentStoreFixture.sol"; abstract contract CommonTest is Test { address public owner = vm.addr(1); @@ -236,31 +236,31 @@ abstract contract DocumentStore_multicall_revoke_Initializer is DocumentStore_mu } } -abstract contract OwnableDocumentStoreCommonTest is CommonTest { - OwnableDocumentStore public documentStore; +abstract contract TranferableDocumentStoreCommonTest is CommonTest { + TransferableDocumentStore public documentStore; - string public storeName = "OwnableDocumentStore Test"; + string public storeName = "TransferableDocumentStore Test"; string public storeSymbol = "XYZ"; function setUp() public virtual override { super.setUp(); vm.startPrank(owner); - documentStore = new OwnableDocumentStore(storeName, storeSymbol, owner); + documentStore = new TransferableDocumentStore(storeName, storeSymbol, owner); documentStore.grantRole(documentStore.ISSUER_ROLE(), issuer); documentStore.grantRole(documentStore.REVOKER_ROLE(), revoker); vm.stopPrank(); } } -abstract contract OwnableDocumentStore_Initializer is OwnableDocumentStoreCommonTest { - OwnableDocumentStoreFixture private _fixture; +abstract contract TransferableDocumentStore_Initializer is TranferableDocumentStoreCommonTest { + TransferableDocumentStoreFixture private _fixture; address[] public recipients; function setUp() public virtual override { super.setUp(); - _fixture = new OwnableDocumentStoreFixture(); + _fixture = new TransferableDocumentStoreFixture(); recipients = new address[](2); recipients[0] = vm.addr(4); diff --git a/test/OwnableDocumentStore.t.sol b/test/TransferableDocumentStore.t.sol similarity index 87% rename from test/OwnableDocumentStore.t.sol rename to test/TransferableDocumentStore.t.sol index a0be9bd..93295e6 100644 --- a/test/OwnableDocumentStore.t.sol +++ b/test/TransferableDocumentStore.t.sol @@ -7,7 +7,7 @@ import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; import "./CommonTest.t.sol"; -contract OwnableDocumentStore_init_Test is OwnableDocumentStoreCommonTest { +contract TransferableDocumentStore_init_Test is TranferableDocumentStoreCommonTest { function testDocumentStoreName() public { assertEq(documentStore.name(), storeName); } @@ -29,11 +29,11 @@ contract OwnableDocumentStore_init_Test is OwnableDocumentStoreCommonTest { } function testFailZeroOwner() public { - documentStore = new OwnableDocumentStore(storeName, storeSymbol, vm.addr(0)); + documentStore = new TransferableDocumentStore(storeName, storeSymbol, vm.addr(0)); } } -contract OwnableDocumentStore_issue_Test is OwnableDocumentStoreCommonTest { +contract TransferableDocumentStore_issue_Test is TranferableDocumentStoreCommonTest { address public recipient; function setUp() public override { @@ -128,7 +128,7 @@ contract OwnableDocumentStore_issue_Test is OwnableDocumentStoreCommonTest { } function testIssueToZeroDocumentRevert() public { - vm.expectRevert(abi.encodeWithSelector(IOwnableDocumentStoreErrors.ZeroDocument.selector)); + vm.expectRevert(abi.encodeWithSelector(ITransferableDocumentStoreErrors.ZeroDocument.selector)); vm.prank(issuer); documentStore.issue(recipient, bytes32(0), false); @@ -163,7 +163,7 @@ contract OwnableDocumentStore_issue_Test is OwnableDocumentStoreCommonTest { documentStore.revoke(document); vm.stopPrank(); - vm.expectRevert(abi.encodeWithSelector(IOwnableDocumentStoreErrors.DocumentIsRevoked.selector, document)); + vm.expectRevert(abi.encodeWithSelector(ITransferableDocumentStoreErrors.DocumentIsRevoked.selector, document)); vm.prank(issuer); documentStore.issue(recipient, document, false); @@ -176,14 +176,14 @@ contract OwnableDocumentStore_issue_Test is OwnableDocumentStoreCommonTest { documentStore.revoke(document); vm.stopPrank(); - vm.expectRevert(abi.encodeWithSelector(IOwnableDocumentStoreErrors.DocumentIsRevoked.selector, document)); + vm.expectRevert(abi.encodeWithSelector(ITransferableDocumentStoreErrors.DocumentIsRevoked.selector, document)); vm.prank(issuer); documentStore.issue(vm.addr(69), document, false); } } -contract OwnableDocumentStore_revoke_Test is OwnableDocumentStore_Initializer { +contract TransferableDocumentStore_revoke_Test is TransferableDocumentStore_Initializer { bytes32 public unlockedDocument; bytes32 public lockedDocument; @@ -274,7 +274,7 @@ contract OwnableDocumentStore_revoke_Test is OwnableDocumentStore_Initializer { } } -contract OwnableDocumentStore_isIssued_Test is OwnableDocumentStore_Initializer { +contract TransferableDocumentStore_isIssued_Test is TransferableDocumentStore_Initializer { function testIsIssued() public { assertTrue(documentStore.isIssued(documents()[0]), "Document should be issued"); } @@ -295,13 +295,13 @@ contract OwnableDocumentStore_isIssued_Test is OwnableDocumentStore_Initializer } function testIsIssuedZeroDocumentRevert() public { - vm.expectRevert(abi.encodeWithSelector(IOwnableDocumentStoreErrors.ZeroDocument.selector)); + vm.expectRevert(abi.encodeWithSelector(ITransferableDocumentStoreErrors.ZeroDocument.selector)); documentStore.isIssued(bytes32(0)); } } -contract OwnableDocumentStore_isRevoked_Test is OwnableDocumentStore_Initializer { +contract TransferableDocumentStore_isRevoked_Test is TransferableDocumentStore_Initializer { function setUp() public override { super.setUp(); @@ -327,13 +327,13 @@ contract OwnableDocumentStore_isRevoked_Test is OwnableDocumentStore_Initializer } function testIsRevokedZeroDocumentRevert() public { - vm.expectRevert(abi.encodeWithSelector(IOwnableDocumentStoreErrors.ZeroDocument.selector)); + vm.expectRevert(abi.encodeWithSelector(ITransferableDocumentStoreErrors.ZeroDocument.selector)); documentStore.isRevoked(bytes32(0)); } } -contract OwnableDocumentStore_isActive_Test is OwnableDocumentStore_Initializer { +contract TransferableDocumentStore_isActive_Test is TransferableDocumentStore_Initializer { function testIsActive() public { assertTrue(documentStore.isActive(documents()[0]), "Document should be active"); assertTrue(documentStore.isActive(documents()[1]), "Document should be active"); @@ -358,13 +358,13 @@ contract OwnableDocumentStore_isActive_Test is OwnableDocumentStore_Initializer } function testIsActiveZeroDocumentRevert() public { - vm.expectRevert(abi.encodeWithSelector(IOwnableDocumentStoreErrors.ZeroDocument.selector)); + vm.expectRevert(abi.encodeWithSelector(ITransferableDocumentStoreErrors.ZeroDocument.selector)); documentStore.isActive(bytes32(0)); } } -contract OwnableDocumentStore_transfer_Test is OwnableDocumentStore_Initializer { +contract TransferableDocumentStore_transfer_Test is TransferableDocumentStore_Initializer { bytes32 public unlockedDocument; bytes32 public lockedDocument; @@ -389,7 +389,7 @@ contract OwnableDocumentStore_transfer_Test is OwnableDocumentStore_Initializer } function testTransferFromLockedDocumentToNewRecipientRevert() public { - vm.expectRevert(abi.encodeWithSelector(IOwnableDocumentStoreErrors.DocumentLocked.selector, lockedDocument)); + vm.expectRevert(abi.encodeWithSelector(ITransferableDocumentStoreErrors.DocumentLocked.selector, lockedDocument)); vm.prank(recipients[1]); documentStore.transferFrom(recipients[1], recipients[0], uint256(lockedDocument)); @@ -410,7 +410,7 @@ contract OwnableDocumentStore_transfer_Test is OwnableDocumentStore_Initializer } } -contract OwnableDocumentStore_locked_Test is OwnableDocumentStoreCommonTest { +contract TransferableDocumentStore_locked_Test is TranferableDocumentStoreCommonTest { address public recipient; function setUp() public override { @@ -440,13 +440,13 @@ contract OwnableDocumentStore_locked_Test is OwnableDocumentStoreCommonTest { } function testLockedWithZeroDocument() public { - vm.expectRevert(abi.encodeWithSelector(IOwnableDocumentStoreErrors.ZeroDocument.selector)); + vm.expectRevert(abi.encodeWithSelector(ITransferableDocumentStoreErrors.ZeroDocument.selector)); documentStore.locked(uint256(bytes32(0))); } } -contract OwnableDocumentStore_setBaseURI_Test is OwnableDocumentStore_Initializer { +contract TransferableDocumentStore_setBaseURI_Test is TransferableDocumentStore_Initializer { using Strings for uint256; string public baseURI = "https://example.com/"; @@ -487,9 +487,9 @@ contract OwnableDocumentStore_setBaseURI_Test is OwnableDocumentStore_Initialize } } -contract OwnableDocumentStore_supportsInterface_Test is OwnableDocumentStoreCommonTest { +contract TransferableDocumentStore_supportsInterface_Test is TranferableDocumentStoreCommonTest { function testSupportsInterface() public { - assertTrue(documentStore.supportsInterface(type(IOwnableDocumentStore).interfaceId)); + assertTrue(documentStore.supportsInterface(type(ITransferableDocumentStore).interfaceId)); assertTrue(documentStore.supportsInterface(type(IDocumentStore).interfaceId)); assertTrue(documentStore.supportsInterface(type(IERC5192).interfaceId)); assertTrue(documentStore.supportsInterface(type(IERC721Metadata).interfaceId)); diff --git a/test/OwnableDocumentStoreUpgradeable.t.sol b/test/TransferableDocumentStoreUpgradeable.t.sol similarity index 71% rename from test/OwnableDocumentStoreUpgradeable.t.sol rename to test/TransferableDocumentStoreUpgradeable.t.sol index 3fdfb35..60fb8c9 100644 --- a/test/OwnableDocumentStoreUpgradeable.t.sol +++ b/test/TransferableDocumentStoreUpgradeable.t.sol @@ -3,27 +3,27 @@ pragma solidity >=0.8.23 <0.9.0; import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; -import "../src/upgradeables/OwnableDocumentStoreUpgradeable.sol"; +import "../src/upgradeables/TransferableDocumentStoreUpgradeable.sol"; import { CommonTest } from "./CommonTest.t.sol"; import { DeployUtils } from "../src/libraries/DeployUtils.sol"; -contract OwnableDocumentStoreUpgradeable_Test is CommonTest { - OwnableDocumentStoreUpgradeable public dsProxy; - OwnableDocumentStoreUpgradeable public documentStore; +contract TransferableDocumentStoreUpgradeable_Test is CommonTest { + TransferableDocumentStoreUpgradeable public dsProxy; + TransferableDocumentStoreUpgradeable public documentStore; - string public initialName = "OwnableDocumentStore"; + string public initialName = "TransferableDocumentStore"; string public initialSymbol = "TEST"; function setUp() public override { super.setUp(); - (address proxyAddr, address dsAddr) = DeployUtils.deployOwnableDocumentStoreUpgradeable( + (address proxyAddr, address dsAddr) = DeployUtils.deployTransferableDocumentStoreUpgradeable( initialName, initialSymbol, owner ); - dsProxy = OwnableDocumentStoreUpgradeable(proxyAddr); - documentStore = OwnableDocumentStoreUpgradeable(dsAddr); + dsProxy = TransferableDocumentStoreUpgradeable(proxyAddr); + documentStore = TransferableDocumentStoreUpgradeable(dsAddr); } function testImplInitializedValues() public { @@ -50,7 +50,7 @@ contract OwnableDocumentStoreUpgradeable_Test is CommonTest { function testUpgradeToAndCallAsNonAdmin() public { address nonAdmin = vm.addr(69); - address newImplementation = address(new OwnableDocumentStoreUpgradeable()); + address newImplementation = address(new TransferableDocumentStoreUpgradeable()); vm.expectRevert( abi.encodeWithSelector( @@ -65,7 +65,7 @@ contract OwnableDocumentStoreUpgradeable_Test is CommonTest { } function testUpgradeToAndCallAsAdmin() public { - address newImplementation = address(new OwnableDocumentStoreUpgradeable()); + address newImplementation = address(new TransferableDocumentStoreUpgradeable()); vm.prank(owner); dsProxy.upgradeToAndCall(newImplementation, ""); @@ -76,9 +76,9 @@ contract OwnableDocumentStoreUpgradeable_Test is CommonTest { } function testUpgradeToAndCallReinitialiseFail() public { - address newImplementation = address(new OwnableDocumentStoreUpgradeable()); + address newImplementation = address(new TransferableDocumentStoreUpgradeable()); bytes memory initData = abi.encodeCall( - OwnableDocumentStoreInitializable.initialize, + TransferableDocumentStoreInitializable.initialize, (initialName, initialSymbol, owner) ); diff --git a/test/fixtures/OwnableDocumentStoreFixture.sol b/test/fixtures/TransferableDocumentStoreFixture.sol similarity index 90% rename from test/fixtures/OwnableDocumentStoreFixture.sol rename to test/fixtures/TransferableDocumentStoreFixture.sol index 24a5a9e..b74860a 100644 --- a/test/fixtures/OwnableDocumentStoreFixture.sol +++ b/test/fixtures/TransferableDocumentStoreFixture.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity >=0.8.23 <0.9.0; -contract OwnableDocumentStoreFixture { +contract TransferableDocumentStoreFixture { bytes32[] internal _documents; constructor() {