Skip to content

Commit

Permalink
test: add deploy utils tests
Browse files Browse the repository at this point in the history
  • Loading branch information
superical committed Mar 27, 2024
1 parent ffde72f commit 1e3cae5
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 4 deletions.
73 changes: 73 additions & 0 deletions test/DeployUtils.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.23 <0.9.0;

import { DocumentStoreUpgradeable } from "../src/upgradeables/DocumentStoreUpgradeable.sol";
import { TransferableDocumentStoreUpgradeable } from "../src/upgradeables/TransferableDocumentStoreUpgradeable.sol";
import { CommonTest } from "./CommonTest.t.sol";
import { DeployUtils } from "../src/libraries/DeployUtils.sol";

contract DeployUtils_Test is CommonTest {
string public initialName = "Test DocumentStore";
string public initialSymbol = "TEST";

function testDeployDocumentStoreUpgradeableParameters() public {
(DocumentStoreUpgradeable dsProxy, DocumentStoreUpgradeable documentStore) = _runDeployDocumentStoreUpgradeable();

assertEq(dsProxy.name(), initialName);
assertTrue(dsProxy.hasRole(documentStore.DEFAULT_ADMIN_ROLE(), owner));
}

function testDeployDocumentStorageUpgradeableImplementation() public {
(DocumentStoreUpgradeable dsProxy, DocumentStoreUpgradeable documentStore) = _runDeployDocumentStoreUpgradeable();

bytes32 proxyImpl = vm.load(address(dsProxy), 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc);

assertEq(address(documentStore), address(uint160(uint256(proxyImpl))));
}

function testDeployTransferableDocumentStoreUpgradeableParameters() public {
(
TransferableDocumentStoreUpgradeable dsProxy,
TransferableDocumentStoreUpgradeable documentStore
) = _runDeployTransferableDocumentStoreUpgradeable();

assertEq(dsProxy.name(), initialName);
assertEq(dsProxy.symbol(), initialSymbol);
assertTrue(dsProxy.hasRole(documentStore.DEFAULT_ADMIN_ROLE(), owner));
}

function testDeployTransferableDocumentStorageUpgradeableImplementation() public {
(
TransferableDocumentStoreUpgradeable dsProxy,
TransferableDocumentStoreUpgradeable documentStore
) = _runDeployTransferableDocumentStoreUpgradeable();

bytes32 proxyImpl = vm.load(address(dsProxy), 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc);

assertEq(address(documentStore), address(uint160(uint256(proxyImpl))));
}

function _runDeployDocumentStoreUpgradeable()
internal
returns (DocumentStoreUpgradeable dsProxy, DocumentStoreUpgradeable ds)
{
(address proxyAddr, address dsAddr) = DeployUtils.deployDocumentStoreUpgradeable(initialName, owner);

dsProxy = DocumentStoreUpgradeable(proxyAddr);
ds = DocumentStoreUpgradeable(dsAddr);
}

function _runDeployTransferableDocumentStoreUpgradeable()
internal
returns (TransferableDocumentStoreUpgradeable dsProxy, TransferableDocumentStoreUpgradeable ds)
{
(address proxyAddr, address dsAddr) = DeployUtils.deployTransferableDocumentStoreUpgradeable(
initialName,
initialSymbol,
owner
);

dsProxy = TransferableDocumentStoreUpgradeable(proxyAddr);
ds = TransferableDocumentStoreUpgradeable(dsAddr);
}
}
6 changes: 4 additions & 2 deletions test/DocumentStore.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ contract DocumentStore_init_Test is DocumentStoreCommonTest {
assert(documentStore.hasRole(documentStore.REVOKER_ROLE(), owner));
}

function testFailZeroOwner() public {
documentStore = new DocumentStore(storeName, vm.addr(0));
function testZeroOwnerRevert() public {
vm.expectRevert(abi.encodeWithSelector(DocumentStoreAccessControl.ZeroOwner.selector));

documentStore = new DocumentStore(storeName, address(0));
}
}

Expand Down
6 changes: 4 additions & 2 deletions test/TransferableDocumentStore.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ contract TransferableDocumentStore_init_Test is TranferableDocumentStoreCommonTe
assert(documentStore.hasRole(documentStore.REVOKER_ROLE(), owner));
}

function testFailZeroOwner() public {
documentStore = new TransferableDocumentStore(storeName, storeSymbol, vm.addr(0));
function testZeroOwnerRevert() public {
vm.expectRevert(abi.encodeWithSelector(DocumentStoreAccessControl.ZeroOwner.selector));

documentStore = new TransferableDocumentStore(storeName, storeSymbol, address(0));
}
}

Expand Down

0 comments on commit 1e3cae5

Please sign in to comment.