Skip to content

Commit

Permalink
test: transfer complete royalty to royaltyReceiver for type 3
Browse files Browse the repository at this point in the history
  • Loading branch information
capedcrusader21 authored and mvanmeerbeck committed Oct 4, 2023
1 parent e6b0f90 commit 22d32bb
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 1 deletion.
116 changes: 115 additions & 1 deletion packages/marketplace/test/exchange/Exchange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,121 @@ describe('Exchange.sol', function () {
);
});

it('should execute a complete match order with royalties 2981(type 3)', async function () {
it('should execute a complete match order with royalties 2981(type 3) transferred to royaltyReceiver', async function () {
const {
ExchangeContractAsUser,
OrderValidatorAsDeployer,
ERC20Contract,
ERC721WithRoyalty,
defaultFeeReceiver,
deployer: royaltyReceiver,
user1: maker,
user2: taker,
admin: receiver1,
user: receiver2,
} = await loadFixture(deployFixtures);

// set royalty
await ERC721WithRoyalty.setRoyalties(5000);

const fees = [
{account: receiver1.address, value: 4000},
{account: receiver2.address, value: 5000},
];
await ERC721WithRoyalty.mint(maker.address, 1, fees);

await ERC721WithRoyalty.connect(maker).approve(
await ExchangeContractAsUser.getAddress(),
1
);

// set up receiver
await ERC721WithRoyalty.setRoyaltiesReceiver(1, royaltyReceiver.address);

await ERC20Contract.mint(taker.address, 100000000000);
await ERC20Contract.connect(taker).approve(
await ExchangeContractAsUser.getAddress(),
100000000000
);

expect(await ERC721WithRoyalty.ownerOf(1)).to.be.equal(maker.address);
expect(await ERC20Contract.balanceOf(taker.address)).to.be.equal(
100000000000
);
const makerAsset = await AssetERC721(ERC721WithRoyalty, 1);
const takerAsset = await AssetERC20(ERC20Contract, 100000000000);
const orderLeft = await OrderDefault(
maker,
makerAsset,
ZeroAddress,
takerAsset,
1,
0,
0
);
const orderRight = await OrderDefault(
taker,
takerAsset,
ZeroAddress,
makerAsset,
1,
0,
0
);
const makerSig = await signOrder(
orderLeft,
maker,
OrderValidatorAsDeployer
);
const takerSig = await signOrder(
orderRight,
taker,
OrderValidatorAsDeployer
);

expect(await ExchangeContractAsUser.fills(hashKey(orderLeft))).to.be.equal(
0
);
expect(await ExchangeContractAsUser.fills(hashKey(orderRight))).to.be.equal(
0
);

await ExchangeContractAsUser.matchOrders([
{
orderLeft,
signatureLeft: makerSig,
orderRight,
signatureRight: takerSig,
},
]);

expect(await ExchangeContractAsUser.fills(hashKey(orderLeft))).to.be.equal(
100000000000
);
expect(await ExchangeContractAsUser.fills(hashKey(orderRight))).to.be.equal(
1
);
expect(await ERC721WithRoyalty.ownerOf(1)).to.be.equal(taker.address);

// check primary market protocol fee
expect(
await ERC20Contract.balanceOf(defaultFeeReceiver.address)
).to.be.equal(2500000000); // 250 * 100000000000 / 10000 = 2500000000

expect(await ERC20Contract.balanceOf(receiver1.address)).to.be.equal(0);

expect(await ERC20Contract.balanceOf(receiver2.address)).to.be.equal(0);

expect(await ERC20Contract.balanceOf(royaltyReceiver.address)).to.be.equal(
50000000000 // 5000 * 100000000000 / 10000 = 50000000000
);

expect(await ERC20Contract.balanceOf(maker.address)).to.be.equal(
47500000000 // 100000000000 - royalty - protocolFee
);
});

it('should execute a complete match order with royalties 2981(type 3) transferred to fee recipients', async function () {
const {
ExchangeContractAsUser,
OrderValidatorAsAdmin,
Expand Down
13 changes: 13 additions & 0 deletions packages/marketplace/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ async function deploy() {
);
await ERC721WithRoyaltyV2981.waitForDeployment();

const TestERC721WithRoyaltyFactory = await ethers.getContractFactory(
'TestERC721WithRoyaltyV2981'
);
const ERC721WithRoyalty = await upgrades.deployProxy(
TestERC721WithRoyaltyFactory,
[],
{
initializer: 'initialize',
}
);
await ERC721WithRoyalty.waitForDeployment();

const ERC20ContractFactory = await ethers.getContractFactory('TestERC20');
const ERC20Contract = await ERC20ContractFactory.deploy();
await ERC20Contract.waitForDeployment();
Expand Down Expand Up @@ -123,6 +135,7 @@ async function deploy() {
RoyaltiesRegistryAsDeployer,
RoyaltiesRegistryAsUser,
ERC721WithRoyaltyV2981,
ERC721WithRoyalty,
RoyaltiesProvider,
deployer,
admin,
Expand Down

0 comments on commit 22d32bb

Please sign in to comment.