Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
channing-magiceden committed Feb 24, 2024
1 parent b4a9b46 commit c02e471
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions test/ERC721CMRoyalties.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ const WALLET_1 = '0x0764844ac95ABCa4F6306E592c7D9C9f3615f590';
const WALLET_2 = '0xef59F379B48f2E92aBD94ADcBf714D170967925D';

describe('ERC721CMRoyalties', function () {
let contract: ERC721CMRoyalties;
let erc721cmRoyalties: ERC721CMRoyalties;
let connection: ERC721CMRoyalties;
let owner: SignerWithAddress;

beforeEach(async () => {
const ERC721CMRoyalties = await ethers.getContractFactory('ERC721CMRoyalties');
const erc721cmRoyalties = await ERC721CMRoyalties.deploy(
erc721cmRoyalties = await ERC721CMRoyalties.deploy(
'Test',
'TEST',
'',
Expand All @@ -30,62 +31,75 @@ describe('ERC721CMRoyalties', function () {
await erc721cmRoyalties.deployed();

[owner] = await ethers.getSigners();
contract = erc721cmRoyalties.connect(owner);
connection = erc721cmRoyalties.connect(owner);
});

it('Set default royalty', async () => {
let royaltyInfo = await contract.royaltyInfo(0, 1000);
let royaltyInfo = await connection.royaltyInfo(0, 1000);
expect(royaltyInfo[0]).to.equal(WALLET_1);
expect(royaltyInfo[1].toNumber()).to.equal(1);

royaltyInfo = await contract.royaltyInfo(1, 9999);
royaltyInfo = await connection.royaltyInfo(1, 9999);
expect(royaltyInfo[0]).to.equal(WALLET_1);
expect(royaltyInfo[1].toNumber()).to.equal(9);

royaltyInfo = await contract.royaltyInfo(1111, 9999999999);
royaltyInfo = await connection.royaltyInfo(1111, 9999999999);
expect(royaltyInfo[0]).to.equal(WALLET_1);
expect(royaltyInfo[1].toNumber()).to.equal(9999999);

await contract.setDefaultRoyalty(WALLET_2, 0)
await connection.setDefaultRoyalty(WALLET_2, 0)

royaltyInfo = await contract.royaltyInfo(0, 1000);
royaltyInfo = await connection.royaltyInfo(0, 1000);
expect(royaltyInfo[0]).to.equal(WALLET_2);
expect(royaltyInfo[1].toNumber()).to.equal(0);

royaltyInfo = await contract.royaltyInfo(1, 9999);
royaltyInfo = await connection.royaltyInfo(1, 9999);
expect(royaltyInfo[0]).to.equal(WALLET_2);
expect(royaltyInfo[1].toNumber()).to.equal(0);

royaltyInfo = await contract.royaltyInfo(1111, 9999999999);
royaltyInfo = await connection.royaltyInfo(1111, 9999999999);
expect(royaltyInfo[0]).to.equal(WALLET_2);
expect(royaltyInfo[1].toNumber()).to.equal(0);
});

it('Set token royalty', async () => {
let royaltyInfo = await contract.royaltyInfo(0, 1000);
let royaltyInfo = await connection.royaltyInfo(0, 1000);
expect(royaltyInfo[0]).to.equal(WALLET_1);
expect(royaltyInfo[1].toNumber()).to.equal(1);

royaltyInfo = await contract.royaltyInfo(1, 9999);
royaltyInfo = await connection.royaltyInfo(1, 9999);
expect(royaltyInfo[0]).to.equal(WALLET_1);
expect(royaltyInfo[1].toNumber()).to.equal(9);

royaltyInfo = await contract.royaltyInfo(1111, 9999999999);
royaltyInfo = await connection.royaltyInfo(1111, 9999999999);
expect(royaltyInfo[0]).to.equal(WALLET_1);
expect(royaltyInfo[1].toNumber()).to.equal(9999999);

await contract.setTokenRoyalty(1, WALLET_2, 100)
await connection.setTokenRoyalty(1, WALLET_2, 100)

royaltyInfo = await contract.royaltyInfo(0, 1000);
royaltyInfo = await connection.royaltyInfo(0, 1000);
expect(royaltyInfo[0]).to.equal(WALLET_1);
expect(royaltyInfo[1].toNumber()).to.equal(1);

royaltyInfo = await contract.royaltyInfo(1, 9999);
royaltyInfo = await connection.royaltyInfo(1, 9999);
expect(royaltyInfo[0]).to.equal(WALLET_2);
expect(royaltyInfo[1].toNumber()).to.equal(99);

royaltyInfo = await contract.royaltyInfo(1111, 9999999999);
royaltyInfo = await connection.royaltyInfo(1111, 9999999999);
expect(royaltyInfo[0]).to.equal(WALLET_1);
expect(royaltyInfo[1].toNumber()).to.equal(9999999);
});

it('Non-owner update reverts', async () => {
const [_, nonOwner] = await ethers.getSigners();
const nonOwnerConnection = erc721cmRoyalties.connect(nonOwner);

await expect(
nonOwnerConnection.setTokenRoyalty(1, WALLET_2, 100)
).to.be.revertedWith('Ownable: caller is not the owner');

await expect(
nonOwnerConnection.setDefaultRoyalty(WALLET_2, 0)
).to.be.revertedWith('Ownable: caller is not the owner');
});
});

0 comments on commit c02e471

Please sign in to comment.