Skip to content

Commit

Permalink
Add tests to deploy package
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciech-turek committed Dec 11, 2023
1 parent f9475b0 commit 7356236
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
27 changes: 26 additions & 1 deletion packages/deploy/test/asset/Asset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,14 @@ const setupTest = deployments.createFixture(
const mockMetadataHash = 'QmQ6BFzGGAU7JdkNJmvkEVjvqKC4VCGb3qoDnjAQWHexxD';
await AssetContract.connect(adminSigner).setTokenURI(1, mockMetadataHash);

const deployeSigner = await ethers.getSigner(deployer);

return {
AssetContract,
AssetCreateContract,
RoyaltyManagerContract,
deployer,
deployer: deployeSigner,
adminSigner,
sandAdmin,
OperatorFilterAssetSubscription,
TRUSTED_FORWARDER,
Expand All @@ -146,6 +149,28 @@ const setupTest = deployments.createFixture(
);

describe('Asset', function () {
describe('Owner', function () {
it('allows DEFAULT_ADMIN_ROLE to transfer the ownership', async function () {
const {AssetContract, adminSigner, deployer} = await setupTest();
await AssetContract.connect(adminSigner).transferOwnership(
deployer.address
);
expect(await AssetContract.owner()).to.be.equals(deployer.address);
});
it('does not allow non-DEFAULT_ADMIN_ROLE account to transfer the ownership', async function () {
const {AssetContract, deployer} = await setupTest();
await expect(
AssetContract.connect(deployer).transferOwnership(deployer.address)
).to.be.revertedWith('Asset: Unauthorized');
});
it('emits OwnershipTransferred event when DEFAULT_ADMIN_ROLE transfers the ownership', async function () {
const {AssetContract, adminSigner, deployer} = await setupTest();
const tx = await AssetContract.connect(adminSigner).transferOwnership(
deployer.address
);
await expect(tx).to.emit(AssetContract, 'OwnershipTransferred');
});
});
describe('Roles', function () {
it('Admin', async function () {
const {AssetContract, sandAdmin} = await setupTest();
Expand Down
33 changes: 30 additions & 3 deletions packages/deploy/test/catalyst/catalyst.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {deployments} from 'hardhat';

const setupTest = deployments.createFixture(
async ({deployments, network, getNamedAccounts, ethers}) => {
const {catalystAdmin, catalystMinter, sandAdmin} = await getNamedAccounts();
const {deployer, catalystAdmin, catalystMinter, sandAdmin} =
await getNamedAccounts();

await network.provider.send('hardhat_setCode', [
OPERATOR_FILTER_REGISTRY,
Expand Down Expand Up @@ -121,11 +122,15 @@ const setupTest = deployments.createFixture(
TRUSTED_FORWARDER_Data.address
);

const deployeSigner = await ethers.getSigner(deployer);
const catalystAdminSigner = await ethers.getSigner(catalystAdmin);

return {
CatalystContract,
OperatorFilterCatalystSubscription,
RoyaltyManagerContract,
catalystAdmin,
deployer: deployeSigner,
catalystAdmin: catalystAdminSigner,
TRUSTED_FORWARDER,
OPERATOR_FILTER_REGISTRY,
OperatorFilterRegistryContract,
Expand All @@ -139,12 +144,34 @@ const setupTest = deployments.createFixture(
);

describe('Catalyst', function () {
describe('Owner', function () {
it('allows DEFAULT_ADMIN_ROLE to transfer the ownership', async function () {
const {CatalystContract, catalystAdmin, deployer} = await setupTest();
await CatalystContract.connect(catalystAdmin).transferOwnership(
deployer.address
);
expect(await CatalystContract.owner()).to.be.equals(deployer.address);
});
it('does not allow non-DEFAULT_ADMIN_ROLE account to transfer the ownership', async function () {
const {CatalystContract, deployer} = await setupTest();
await expect(
CatalystContract.connect(deployer).transferOwnership(deployer.address)
).to.be.revertedWith('Asset: Unauthorized');
});
it('emits OwnershipTransferred event when DEFAULT_ADMIN_ROLE transfers the ownership', async function () {
const {CatalystContract, catalystAdmin, deployer} = await setupTest();
const tx = await CatalystContract.connect(
catalystAdmin
).transferOwnership(deployer.address);
await expect(tx).to.emit(CatalystContract, 'OwnershipTransferred');
});
});
describe('check roles', function () {
it('admin', async function () {
const {CatalystContract, catalystAdmin} = await setupTest();
const defaultAdminRole = await CatalystContract.DEFAULT_ADMIN_ROLE();
expect(
await CatalystContract.hasRole(defaultAdminRole, catalystAdmin)
await CatalystContract.hasRole(defaultAdminRole, catalystAdmin.address)
).to.be.equals(true);
});
it('minter', async function () {
Expand Down

1 comment on commit 7356236

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage for this commit

98.65%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/asset/contracts
   Asset.sol95%90%96.88%98.28%118, 209, 311, 311–312, 78
   AssetCreate.sol94.64%84.21%100%100%140, 142, 200, 216, 333, 74
   AssetReveal.sol94.35%86.21%96.55%98.89%143, 147, 181, 376, 416, 424, 441, 75, 98
   AuthSuperValidator.sol90%83.33%100%88.89%51–52
   Catalyst.sol95.39%92.19%96.15%98.39%125, 127, 140, 152, 224, 80
packages/asset/contracts/interfaces
   IAsset.sol100%100%100%100%
   IAssetCreate.sol100%100%100%100%
   IAssetReveal.sol100%100%100%100%
   ICatalyst.sol100%100%100%100%
   ITokenUtils.sol100%100%100%100%
packages/asset/contracts/libraries
   TokenIdUtils.sol100%100%100%100%

Please sign in to comment.