From c02e471197f6330c7aaa489f842b3843111de368 Mon Sep 17 00:00:00 2001 From: Channing Date: Fri, 23 Feb 2024 22:30:07 -0800 Subject: [PATCH] add test --- test/ERC721CMRoyalties.test.ts | 48 ++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/test/ERC721CMRoyalties.test.ts b/test/ERC721CMRoyalties.test.ts index d1fc9b9..ff5459b 100644 --- a/test/ERC721CMRoyalties.test.ts +++ b/test/ERC721CMRoyalties.test.ts @@ -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', '', @@ -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'); + }); });