|
| 1 | +import { describeBehaviorOfERC165 } from '../../introspection'; |
| 2 | +import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; |
| 3 | +import { describeFilter } from '@solidstate/library'; |
| 4 | +import { ERC2981Mock } from '@solidstate/typechain-types'; |
| 5 | +import { expect } from 'chai'; |
| 6 | +import { BigNumber } from 'ethers'; |
| 7 | +import { ethers } from 'hardhat'; |
| 8 | + |
| 9 | +export function describeBehaviorOfERC2981( |
| 10 | + deploy: () => Promise<ERC2981Mock>, |
| 11 | + skips?: string[], |
| 12 | +) { |
| 13 | + const describe = describeFilter(skips); |
| 14 | + |
| 15 | + describe('::ERC2981', function () { |
| 16 | + let tokenIdOne = BigNumber.from(1); |
| 17 | + let tokenIdTwo = BigNumber.from(2); |
| 18 | + let tokenIdThree = BigNumber.from(3); |
| 19 | + |
| 20 | + let receiver: SignerWithAddress; |
| 21 | + let instance: ERC2981Mock; |
| 22 | + |
| 23 | + before(async function () { |
| 24 | + receiver = (await ethers.getSigners())[1]; |
| 25 | + instance = await deploy(); |
| 26 | + }); |
| 27 | + |
| 28 | + describeBehaviorOfERC165( |
| 29 | + deploy, |
| 30 | + { |
| 31 | + interfaceIds: ['0x2a55205a'], |
| 32 | + }, |
| 33 | + skips, |
| 34 | + ); |
| 35 | + |
| 36 | + describe('#royaltyInfo()', () => { |
| 37 | + it('returns 0 if salePrice is 0', async function () { |
| 38 | + const [, royaltyAmount] = await instance.royaltyInfo( |
| 39 | + 0, |
| 40 | + BigNumber.from(0), |
| 41 | + ); |
| 42 | + |
| 43 | + expect(royaltyAmount).to.equal(BigNumber.from(0)); |
| 44 | + }); |
| 45 | + |
| 46 | + it('returns receiver address', async function () { |
| 47 | + const [recipient] = await instance.royaltyInfo(0, BigNumber.from(0)); |
| 48 | + expect(recipient).to.equal(await receiver.getAddress()); |
| 49 | + }); |
| 50 | + |
| 51 | + it('calculates royalty using global if local does not exist', async function () { |
| 52 | + let [, royaltyAmount] = await instance.royaltyInfo(0, 10000); |
| 53 | + expect(royaltyAmount).to.equal(BigNumber.from(10000)); |
| 54 | + }); |
| 55 | + |
| 56 | + it('calculates royalty using local', async function () { |
| 57 | + let [, royaltyAmount] = await instance.royaltyInfo(tokenIdOne, 10000); |
| 58 | + expect(royaltyAmount).to.equal(BigNumber.from(100)); |
| 59 | + |
| 60 | + [, royaltyAmount] = await instance.royaltyInfo(tokenIdTwo, 10000); |
| 61 | + expect(royaltyAmount).to.equal(BigNumber.from(1000)); |
| 62 | + }); |
| 63 | + }); |
| 64 | + }); |
| 65 | +} |
0 commit comments