Skip to content

Commit

Permalink
Merge pull request #1088 from thesandboxgame/integration-tests
Browse files Browse the repository at this point in the history
Asset deployment values tests
  • Loading branch information
rishabh0x00 authored Aug 16, 2023
2 parents 0ffa0dc + c88275a commit 15877b0
Show file tree
Hide file tree
Showing 2 changed files with 379 additions and 0 deletions.
263 changes: 263 additions & 0 deletions packages/deploy/test/asset/Asset.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
import {OPERATOR_FILTER_REGISTRY} from './../../../asset/data/constants';
import {DEFAULT_BPS} from '../../deploy/400_asset/407_asset_setup';
import {expect} from 'chai';
import {deployments} from 'hardhat';
import {OperatorFilterRegistryBytecode} from '../../utils/bytecodes';
import {OperatorFilterRegistry_ABI} from '../../utils/abi';

const setupTest = deployments.createFixture(
async ({deployments, network, getNamedAccounts, ethers}) => {
const {deployer, assetAdmin, filterOperatorSubscription, sandAdmin} =
await getNamedAccounts();
await network.provider.send('hardhat_setCode', [
OPERATOR_FILTER_REGISTRY,
OperatorFilterRegistryBytecode,
]);
const OperatorFilterRegistryContract = await ethers.getContractAt(
OperatorFilterRegistry_ABI,
OPERATOR_FILTER_REGISTRY
);

await deployments.fixture([
'MockERC1155MarketPlace1',
'MockERC1155MarketPlace2',
'MockERC1155MarketPlace3',
'MockERC1155MarketPlace4',
]);

const MockERC1155MarketPlace1 = await deployments.get(
'MockERC1155MarketPlace1'
);
const MockERC1155MarketPlace2 = await deployments.get(
'MockERC1155MarketPlace2'
);
const MockERC1155MarketPlace3 = await deployments.get(
'MockERC1155MarketPlace3'
);
const MockERC1155MarketPlace4 = await deployments.get(
'MockERC1155MarketPlace4'
);

const deployerSigner = await ethers.getSigner(deployer);

const tx1 = await OperatorFilterRegistryContract.connect(
deployerSigner
).register(filterOperatorSubscription);

await tx1.wait();

await network.provider.send('hardhat_setBalance', [
'0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6',
'0xDE0B6B3A7640000',
]);
await network.provider.request({
method: 'hardhat_impersonateAccount',
params: ['0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6'],
});
const signer = await ethers.getSigner(
'0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6'
);
const tx = await OperatorFilterRegistryContract.connect(signer).register(
'0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6'
);
await tx.wait();
const MockMarketPlace1CodeHash =
await OperatorFilterRegistryContract.connect(signer).codeHashOf(
MockERC1155MarketPlace1.address
);
const MockMarketPlace2CodeHash =
await OperatorFilterRegistryContract.connect(signer).codeHashOf(
MockERC1155MarketPlace2.address
);

const subscriptionSigner = await ethers.getSigner(
filterOperatorSubscription
);
const tx2 = await OperatorFilterRegistryContract.connect(
subscriptionSigner
).updateOperators(
filterOperatorSubscription,
[MockERC1155MarketPlace1.address, MockERC1155MarketPlace2.address],
true
);
await tx2.wait();
const tx3 = await OperatorFilterRegistryContract.connect(
subscriptionSigner
).updateCodeHashes(
filterOperatorSubscription,
[MockMarketPlace1CodeHash, MockMarketPlace2CodeHash],
true
);
await tx3.wait();
await network.provider.request({
method: 'hardhat_stopImpersonatingAccount',
params: ['0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6'],
});

await deployments.fixture();
const Asset = await deployments.get('Asset');
const AssetContract = await ethers.getContractAt(Asset.abi, Asset.address);
const AssetCreate = await deployments.get('AssetCreate');
const AssetCreateContract = await ethers.getContractAt(
AssetCreate.abi,
AssetCreate.address
);

const RoyaltyManager = await deployments.get('RoyaltyManager');
const RoyaltyManagerContract = await ethers.getContractAt(
RoyaltyManager.abi,
RoyaltyManager.address
);
const TRUSTED_FORWARDER_Data = await deployments.get(
'TRUSTED_FORWARDER_V2'
);
const TRUSTED_FORWARDER = await ethers.getContractAt(
TRUSTED_FORWARDER_Data.abi,
TRUSTED_FORWARDER_Data.address
);

// grant moderator role to the assetAdmin
const adminSigner = await ethers.getSigner(assetAdmin);
const moderatorRole = await AssetContract.MODERATOR_ROLE();
await AssetContract.connect(adminSigner).grantRole(
moderatorRole,
assetAdmin
);
// set tokenURI for tokenId 1 for baseURI test
const mockMetadataHash = 'QmQ6BFzGGAU7JdkNJmvkEVjvqKC4VCGb3qoDnjAQWHexxD';
await AssetContract.connect(adminSigner).setTokenURI(1, mockMetadataHash);

return {
AssetContract,
AssetCreateContract,
RoyaltyManagerContract,
deployer,
sandAdmin,
filterOperatorSubscription,
TRUSTED_FORWARDER,
OPERATOR_FILTER_REGISTRY,
OperatorFilterRegistryContract,
mockMetadataHash,
MockERC1155MarketPlace1,
MockERC1155MarketPlace2,
MockERC1155MarketPlace3,
MockERC1155MarketPlace4,
};
}
);

describe('Asset', function () {
describe('Roles', function () {
it('Admin', async function () {
const {AssetContract, sandAdmin} = await setupTest();
const defaultAdminRole = await AssetContract.DEFAULT_ADMIN_ROLE();
expect(await AssetContract.hasRole(defaultAdminRole, sandAdmin)).to.be
.true;
});
it('Minter', async function () {
const {AssetContract, AssetCreateContract} = await setupTest();
const minterRole = await AssetContract.MINTER_ROLE();
expect(
await AssetContract.hasRole(minterRole, AssetCreateContract.address)
).to.be.true;
});
it('Burner', async function () {
// TODO Update when AssetRecycle is deployed
});
it('Moderator', async function () {
const {AssetContract, sandAdmin} = await setupTest();
const moderatorRole = await AssetContract.MODERATOR_ROLE();
expect(await AssetContract.hasRole(moderatorRole, sandAdmin)).to.be.true;
});
});
describe("Asset's Metadata", function () {
it('Asset base URI is set correctly', async function () {
const {AssetContract, mockMetadataHash} = await setupTest();
expect(await AssetContract.uri(1)).to.be.equal(
'ipfs://' + mockMetadataHash
);
});
});
describe('Royalties', function () {
it('Contract is registered on RoyaltyManager', async function () {
const {RoyaltyManagerContract, AssetContract} = await setupTest();
expect(
await RoyaltyManagerContract.getContractRoyalty(AssetContract.address)
).to.be.equal(DEFAULT_BPS);
});
});
describe('Trusted Forwarder', function () {
it('Trusted forwarder address is set correctly', async function () {
const {AssetContract, TRUSTED_FORWARDER} = await setupTest();
expect(await AssetContract.getTrustedForwarder()).to.be.equal(
TRUSTED_FORWARDER.address
);
});
});
describe('Operator Filter Registry', function () {
it('Asset contract is registered correctly', async function () {
const {OperatorFilterRegistryContract, AssetContract} = await setupTest();
expect(
await OperatorFilterRegistryContract.isRegistered(AssetContract.address)
).to.be.true;
});
it('Asset contract is subscribed to correct address', async function () {
const {
OperatorFilterRegistryContract,
AssetContract,
filterOperatorSubscription,
} = await setupTest();
expect(
await OperatorFilterRegistryContract.subscriptionOf(
AssetContract.address
)
).to.be.equal(filterOperatorSubscription);
});
it('asset contract has correct market places black listed', async function () {
const {
OperatorFilterRegistryContract,
AssetContract,
MockERC1155MarketPlace1,
MockERC1155MarketPlace2,
MockERC1155MarketPlace3,
MockERC1155MarketPlace4,
} = await setupTest();
expect(
await OperatorFilterRegistryContract.isOperatorFiltered(
AssetContract.address,
MockERC1155MarketPlace1.address
),
'MarketPlace1 should be filtered'
).to.be.equal(true);
expect(
await OperatorFilterRegistryContract.isOperatorFiltered(
AssetContract.address,
MockERC1155MarketPlace2.address
),
'MarketPlace2 should be filtered'
).to.be.equal(true);
expect(
await OperatorFilterRegistryContract.isOperatorFiltered(
AssetContract.address,
MockERC1155MarketPlace3.address
),
'MarketPlace3 should not be filtered'
).to.be.equal(false);
expect(
await OperatorFilterRegistryContract.isOperatorFiltered(
AssetContract.address,
MockERC1155MarketPlace4.address
),
'MarketPlace4 should not be filtered'
).to.be.equal(false);
});
});
describe('MultiRoyaltyDistributor', function () {
it('RoyaltyManager contract is set correctly', async function () {
const {AssetContract, RoyaltyManagerContract} = await setupTest();
expect(await AssetContract.royaltyManager()).to.be.equal(
RoyaltyManagerContract.address
);
});
});
});
116 changes: 116 additions & 0 deletions packages/deploy/test/asset/AssetCreate.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import {expect} from 'chai';
import {deployments} from 'hardhat';

const setupTest = deployments.createFixture(
async ({deployments, getNamedAccounts, ethers}) => {
const {assetAdmin, backendAuthWallet} = await getNamedAccounts();
await deployments.fixture();
const Asset = await deployments.get('Asset');
const AssetContract = await ethers.getContractAt('Asset', Asset.address);
const AssetCreate = await deployments.get('AssetCreate');
const AssetCreateContract = await ethers.getContractAt(
'AssetCreate',
AssetCreate.address
);
const Catalyst = await deployments.get('Catalyst');
const CatalystContract = await ethers.getContractAt(
'Catalyst',
Catalyst.address
);
const TRUSTED_FORWARDER = await deployments.get('TRUSTED_FORWARDER_V2');
const AuthSuperValidator = await deployments.get('AuthSuperValidator');
const AuthSuperValidatorContract = await ethers.getContractAt(
'AuthSuperValidator',
AuthSuperValidator.address
);

return {
AssetContract,
AssetCreateContract,
CatalystContract,
TRUSTED_FORWARDER,
AuthSuperValidatorContract,
assetAdmin,
backendAuthWallet,
};
}
);

describe('Asset Create', function () {
describe('Contract references', function () {
it('AuthSuperValidator', async function () {
const {AssetCreateContract, AuthSuperValidatorContract} =
await setupTest();
expect(await AssetCreateContract.getAuthValidator()).to.be.equal(
AuthSuperValidatorContract.address
);
});
it('Asset', async function () {
const {AssetCreateContract, AssetContract} = await setupTest();
expect(await AssetCreateContract.getAssetContract()).to.be.equal(
AssetContract.address
);
});
it('Catalyst', async function () {
const {AssetCreateContract, CatalystContract} = await setupTest();
expect(await AssetCreateContract.getCatalystContract()).to.be.equal(
CatalystContract.address
);
});
});
describe('Roles', function () {
it('Admin', async function () {
const {AssetCreateContract, assetAdmin} = await setupTest();
const defaultAdminRole = await AssetCreateContract.DEFAULT_ADMIN_ROLE();
expect(await AssetCreateContract.hasRole(defaultAdminRole, assetAdmin)).to
.be.true;
});
it("Asset's Minter role is granted to AssetCreate", async function () {
const {AssetCreateContract, AssetContract} = await setupTest();
const minterRole = await AssetContract.MINTER_ROLE();
expect(
await AssetContract.hasRole(minterRole, AssetCreateContract.address)
).to.be.true;
});
it("Catalyst's Burner role is granted to AssetCreate", async function () {
const {AssetCreateContract, CatalystContract} = await setupTest();
const burnerRole = await CatalystContract.BURNER_ROLE();
expect(
await CatalystContract.hasRole(burnerRole, AssetCreateContract.address)
).to.be.true;
});
it('AuthSuperValidator signer is set to backendAuthWallet', async function () {
const {
AssetCreateContract,
AuthSuperValidatorContract,
backendAuthWallet,
} = await setupTest();
expect(
await AuthSuperValidatorContract.getSigner(AssetCreateContract.address)
).to.be.equal(backendAuthWallet);
expect(
await AuthSuperValidatorContract.getSigner(AssetCreateContract.address)
).to.be.equal(backendAuthWallet);
});
});
describe('EIP712', function () {
it("name is 'Sandbox Asset Create'", async function () {
const {AssetCreateContract} = await setupTest();
const eip712Domain = await AssetCreateContract.eip712Domain();
expect(eip712Domain.name).to.be.equal('Sandbox Asset Create');
});
it("version is '1.0'", async function () {
const {AssetCreateContract} = await setupTest();
const eip712Domain = await AssetCreateContract.eip712Domain();
expect(eip712Domain.version).to.be.equal('1.0');
});
});
describe('Trusted Forwarder', function () {
it('Trusted forwarder address is set correctly', async function () {
const {AssetCreateContract, TRUSTED_FORWARDER} = await setupTest();
expect(await AssetCreateContract.getTrustedForwarder()).to.be.equal(
TRUSTED_FORWARDER.address
);
});
});
});

1 comment on commit 15877b0

@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

97.23%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/asset/contracts
   Asset.sol94.53%89.58%96.43%98.08%108, 193, 298, 298–299, 70
   AssetCreate.sol93.42%75%100%100%125, 127, 160, 266, 64
   AssetReveal.sol96.60%87.50%100%100%138, 170, 365, 406, 68
   AuthSuperValidator.sol100%100%100%100%
   Catalyst.sol94.81%91.94%95.24%98.08%133, 135, 148, 160, 231, 88
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%
packages/dependency-metatx/contracts
   ERC2771Handler.sol100%100%100%100%
   ERC2771HandlerAbstract.sol100%100%100%100%
   ERC2771HandlerUpgradeable.sol95.45%83.33%100%100%43
packages/dependency-metatx/contracts/test
   ERC2771HandlerTest.sol100%100%100%100%
   ERC2771HandlerUpgradeableTest.sol100%100%100%100%
   MockTrustedForwarder.sol0%0%0%0%15, 18–19, 19, 19–20
packages/dependency-operator-filter/contracts
   OperatorFiltererUpgradeable.sol88.64%85%100%90%14, 48–49, 58–59
   OperatorFilterSubscription.sol60%50%100%50%18–19
packages/dependency-operator-filter/contracts/interfaces
   IOperatorFilterRegistry.sol100%100%100%100%
packages/dependency-royalty-management/contracts
   MultiRoyaltyDistributor.sol88.71%62.50%100%97.44%101, 108, 41, 41, 41, 41, 70
   RoyaltyDistributor.sol90.91%50%100%100%44
   RoyaltyManager.sol96%86.36%100%100%100, 44, 94
   RoyaltySplitter.sol90.91%75%92.31%95.89%107, 147, 167, 176, 191, 228, 56, 63, 78
packages/dependency-royalty-management/contracts/interfaces
   IERC20Approve.sol100%100%100%100%
   IMultiRoyaltyDistributor.sol100%100%100%100%
   IMultiRoyaltyRecipients.sol100%100%100%100%
   IRoyaltyManager.sol100%100%100%100%
   IRoyaltyUGC.sol100%100%100%100%

Please sign in to comment.