Skip to content

Commit

Permalink
All test pass, several broken typings yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
steven2308 committed Jan 10, 2024
1 parent e70b541 commit 19ed1d3
Show file tree
Hide file tree
Showing 23 changed files with 2,257 additions and 2,123 deletions.
19 changes: 15 additions & 4 deletions contracts/mocks/OwnableMintableERC721Mock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@ pragma solidity ^0.8.21;
/// @dev This mock smart contract is intended to be used with `@defi-wonderland/smock` and doesn't need any business
/// logic.
contract OwnableMintableERC721Mock {
function owner() public pure returns (address) {
return address(0);

address private _mockOwner;
address private _mockOwnerOf;

constructor (
address mockOwner, address mockOwnerOf
) {
_mockOwner = mockOwner;
_mockOwnerOf = mockOwnerOf;
}

function owner() public view returns (address) {
return _mockOwner;
}

function ownerOf(uint256) public pure returns (address) {
return address(0);
function ownerOf(uint256) public view returns (address) {
return _mockOwnerOf;
}
}
16 changes: 8 additions & 8 deletions test/behavior/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ async function shouldBehaveLikeCatalog(contractName: string, metadataURI: string
let addrs: SignerWithAddress[];
const metadataUriDefault = 'src';

const noType = 0;
const slotType = 1;
const fixedType = 2;
const noType = 0n;
const slotType = 1n;
const fixedType = 2n;

const sampleSlotPartData = {
itemType: slotType,
Expand Down Expand Up @@ -64,13 +64,13 @@ async function shouldBehaveLikeCatalog(contractName: string, metadataURI: string
const partId = 1;

await testCatalog.addPart({ partId: partId, part: sampleFixedPartData });
expect(await testCatalog.getPart(partId)).to.eql([2, 0, [], metadataUriDefault]);
expect(await testCatalog.getPart(partId)).to.eql([2n, 0n, [], metadataUriDefault]);
});

it('can add slot part', async function () {
const partId = 2;
await testCatalog.addPart({ partId: partId, part: sampleSlotPartData });
expect(await testCatalog.getPart(partId)).to.eql([1, 0, [], metadataUriDefault]);
expect(await testCatalog.getPart(partId)).to.eql([1n, 0n, [], metadataUriDefault]);
});

it('can add parts list', async function () {
Expand All @@ -93,8 +93,8 @@ async function shouldBehaveLikeCatalog(contractName: string, metadataURI: string
{ partId: partId2, part: partData2 },
]);
expect(await testCatalog.getParts([partId, partId2])).to.eql([
[slotType, 0, [], 'src1'],
[fixedType, 1, [], 'src2'],
[slotType, 0n, [], 'src1'],
[fixedType, 1n, [], 'src2'],
]);
});

Expand Down Expand Up @@ -249,7 +249,7 @@ async function shouldBehaveLikeCatalog(contractName: string, metadataURI: string
await testCatalog.setEquippableToAll(partId);

// This should reset it:
testCatalog.setEquippableAddresses(partId, [addrs[1].address]);
await testCatalog.setEquippableAddresses(partId, [addrs[1].address]);
expect(await testCatalog.checkIsEquippableToAll(partId)).to.eql(false);
});

Expand Down
20 changes: 10 additions & 10 deletions test/behavior/equippableAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,10 @@ async function shouldBehaveLikeEquippableAssets(
.withArgs(tokenId, resId2, resId);

expect(await chunkyEquip.getActiveAssets(tokenId)).to.be.eql([resId2]);
expect(await chunkyEquip.getActiveAssetPriorities(tokenId)).to.be.eql([bn(0)]);
expect(await chunkyEquip.getActiveAssetPriorities(tokenId)).to.be.eql([0n]);

// Replacements should be gone
expect(await chunkyEquip.getAssetReplacements(tokenId, resId2)).to.eql(bn(0));
expect(await chunkyEquip.getAssetReplacements(tokenId, resId2)).to.eql(0n);
});

it('can replace non existing asset to token, it could have been deleted', async function () {
Expand All @@ -352,7 +352,7 @@ async function shouldBehaveLikeEquippableAssets(
await chunkyEquip.acceptAsset(tokenId, 0, resId);

expect(await chunkyEquip.getActiveAssets(tokenId)).to.be.eql([resId]);
expect(await chunkyEquip.getActiveAssetPriorities(tokenId)).to.eql([bn(0)]);
expect(await chunkyEquip.getActiveAssetPriorities(tokenId)).to.eql([0n]);
});
});

Expand Down Expand Up @@ -384,7 +384,7 @@ async function shouldBehaveLikeEquippableAssets(
await chunkyEquip.addAssetToToken(tokenId, resId2, resId);
await chunkyEquip.rejectAsset(tokenId, 0, resId2);

expect(await chunkyEquip.getAssetReplacements(tokenId, resId2)).to.eql(bn(0));
expect(await chunkyEquip.getAssetReplacements(tokenId, resId2)).to.eql(0n);
});

it('can reject asset if approved', async function () {
Expand Down Expand Up @@ -429,7 +429,7 @@ async function shouldBehaveLikeEquippableAssets(
await chunkyEquip.addAssetToToken(tokenId, resId2, resId);
await chunkyEquip.rejectAllAssets(tokenId, 1);

expect(await chunkyEquip.getAssetReplacements(tokenId, resId2)).to.eql(bn(0));
expect(await chunkyEquip.getAssetReplacements(tokenId, resId2)).to.eql(0n);
});

it('can reject all pending assets at max capacity', async function () {
Expand All @@ -446,7 +446,7 @@ async function shouldBehaveLikeEquippableAssets(
}
await chunkyEquip.rejectAllAssets(tokenId, 128);

expect(await chunkyEquip.getAssetReplacements(1, 2)).to.eql(bn(0));
expect(await chunkyEquip.getAssetReplacements(1, 2)).to.eql(0n);
});

it('can reject all assets if approved', async function () {
Expand Down Expand Up @@ -509,11 +509,11 @@ async function shouldBehaveLikeEquippableAssets(
it('can set and get priorities', async function () {
const tokenId = await addAssetsToToken();

expect(await chunkyEquip.getActiveAssetPriorities(tokenId)).to.be.eql([bn(0), bn(1)]);
expect(await chunkyEquip.getActiveAssetPriorities(tokenId)).to.be.eql([0n, bn(1)]);
await expect(chunkyEquip.setPriority(tokenId, [1, 0]))
.to.emit(chunkyEquip, 'AssetPrioritySet')
.withArgs(tokenId);
expect(await chunkyEquip.getActiveAssetPriorities(tokenId)).to.be.eql([bn(1), bn(0)]);
expect(await chunkyEquip.getActiveAssetPriorities(tokenId)).to.be.eql([bn(1), 0n]);
});

it('can set and get priorities if approved', async function () {
Expand All @@ -522,11 +522,11 @@ async function shouldBehaveLikeEquippableAssets(

await chunkyEquip.approveForAssets(await approvedAddress.getAddress(), tokenId);

expect(await chunkyEquip.getActiveAssetPriorities(tokenId)).to.be.eql([bn(0), bn(1)]);
expect(await chunkyEquip.getActiveAssetPriorities(tokenId)).to.be.eql([0n, bn(1)]);
await expect(chunkyEquip.connect(approvedAddress).setPriority(tokenId, [1, 0]))
.to.emit(chunkyEquip, 'AssetPrioritySet')
.withArgs(tokenId);
expect(await chunkyEquip.getActiveAssetPriorities(tokenId)).to.be.eql([bn(1), bn(0)]);
expect(await chunkyEquip.getActiveAssetPriorities(tokenId)).to.be.eql([bn(1), 0n]);
});

it('cannot set priorities for non owned token', async function () {
Expand Down
2 changes: 1 addition & 1 deletion test/behavior/equippableParts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async function shouldBehaveLikeEquippableWithParts() {
);
expect(allAssets).to.eql([
'ipfs:neonRes/1', // metadataURI
bn(0), // equippableGroupId
0n, // equippableGroupId
await catalogContract.getAddress(), // catalogAddress,
expectedFixedParts,
expectedSlotParts,
Expand Down
24 changes: 12 additions & 12 deletions test/behavior/equippableSlots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ async function shouldBehaveLikeEquippableWithSlots(
});

it('cannot set a valid equippable group with part id 0', async function () {
const equippableGroupId = 1;
const equippableGroupId = 1n;
const partId = 0;
// The malicious child indicates it can be equipped into soldier:
await expect(
Expand Down Expand Up @@ -610,15 +610,15 @@ async function shouldBehaveLikeEquippableWithSlots(
const expectedFixedParts = [
[
bn(partIdForBody), // partId
1, // z
1n, // z
'genericBody.png', // metadataURI
],
];
const expectedSlotParts = [
[
bn(partIdForWeapon), // partId
bn(weaponAssetsEquip[0]), // childAssetId
2, // z
2n, // z
await weapon.getAddress(), // childAddress
weaponsIds[0], // childTokenId
'ipfs:weapon/equip/5', // childAssetMetadata
Expand All @@ -627,10 +627,10 @@ async function shouldBehaveLikeEquippableWithSlots(
[
// Nothing on equipped on background slot:
bn(partIdForBackground), // partId
bn(0), // childAssetId
0, // z
0n, // childAssetId
0n, // z
ethers.ZeroAddress, // childAddress
bn(0), // childTokenId
0n, // childTokenId
'', // childAssetMetadata
'noBackground.png', // partMetadata
],
Expand All @@ -642,7 +642,7 @@ async function shouldBehaveLikeEquippableWithSlots(
);
expect(allAssets).to.eql([
'ipfs:soldier/', // metadataURI
bn(0), // equippableGroupId
0n, // equippableGroupId
await catalog.getAddress(), // catalogAddress
expectedFixedParts,
expectedSlotParts,
Expand Down Expand Up @@ -683,8 +683,8 @@ async function shouldBehaveLikeEquippableWithSlots(
[
expectedSlots,
[
[bn(0), bn(0), bn(0), ethers.ZeroAddress],
[bn(0), bn(0), bn(0), ethers.ZeroAddress],
[0n, 0n, 0n, ethers.ZeroAddress],
[0n, 0n, 0n, ethers.ZeroAddress],
],
['', ''],
],
Expand All @@ -708,7 +708,7 @@ async function shouldBehaveLikeEquippableWithSlots(
// If a slot has nothing equipped, it returns an empty equip:
const expectedEquips = [
[bn(soldierResId), bn(weaponResId), weaponsIds[0], await weapon.getAddress()],
[bn(0), bn(0), bn(0), ethers.ZeroAddress],
[0n, 0n, 0n, ethers.ZeroAddress],
];
const expectedMetadata = ['ipfs:weapon/equip/5', ''];
expect(await view.getEquipped(await soldier.getAddress(), soldiersIds[0], soldierResId)).to.eql(
Expand Down Expand Up @@ -736,8 +736,8 @@ async function shouldBehaveLikeEquippableWithSlots(
const expectedSlots = [bn(partIdForWeapon), bn(partIdForBackground)];
// If a slot has nothing equipped, it returns an empty equip:
const expectedEquips = [
[bn(0), bn(0), bn(0), ethers.ZeroAddress],
[bn(0), bn(0), bn(0), ethers.ZeroAddress],
[0n, 0n, 0n, ethers.ZeroAddress],
[0n, 0n, 0n, ethers.ZeroAddress],
];
const expectedMetadata = ['', ''];
expect(await view.getEquipped(await soldier.getAddress(), soldiersIds[0], soldierResId)).to.eql(
Expand Down
5 changes: 3 additions & 2 deletions test/behavior/erc721.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ethers } from 'hardhat';
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers';
import { Contract, ContractTransaction } from 'ethers';
import { bn } from '../utils';
import { RMRKNestableLazyMintErc20 } from '../../typechain-types';

// Based on https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/test/token/ERC721/ERC721.behavior.js

Expand Down Expand Up @@ -58,7 +59,7 @@ async function shouldBehaveLikeERC721(name: string, symbol: string) {

context('when the given address does not own any tokens', function () {
it('returns 0', async function () {
expect(await this.token.balanceOf(others[0].address)).to.eql(bn(0));
expect(await this.token.balanceOf(others[0].address)).to.eql(0n);
});
});

Expand Down Expand Up @@ -225,7 +226,7 @@ async function shouldBehaveLikeERC721(name: string, symbol: string) {
context('when the sender is not authorized for the token id', function () {
it('reverts', async function () {
// Standard ERC721 will use the latter. Every Nestable would have it defined and use it instead
const error = this.token.interface.errors['RMRKNotApprovedOrDirectOwner()']
const error = this.token.interface.getError('RMRKNotApprovedOrDirectOwner()')
? 'RMRKNotApprovedOrDirectOwner'
: 'ERC721NotApprovedOrOwner';
await expect(
Expand Down
2 changes: 1 addition & 1 deletion test/behavior/mintingImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async function shouldControlValidMinting(): Promise<void> {
});

it('cannot mint under price', async function () {
const HALF_ETH = ethers.parseEther('0.05');
const HALF_ETH = ONE_ETH / 2n;
await expect(
this.token.mint(addrs[0].address, 1, { value: HALF_ETH }),
).to.be.revertedWithCustomError(this.token, 'RMRKWrongValueSent');
Expand Down
26 changes: 13 additions & 13 deletions test/behavior/multiasset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ async function shouldBehaveLikeMultiAsset(
.withArgs(tokenId, resId3, resId2);

expect(await this.token.getActiveAssets(tokenId)).to.be.eql([resId, resId3]);
expect(await this.token.getActiveAssetPriorities(tokenId)).to.be.eql([bn(0), bn(1)]);
expect(await this.token.getActiveAssetPriorities(tokenId)).to.be.eql([0n, bn(1)]);

// Replacements should be gone
expect(await this.token.getAssetReplacements(tokenId, resId3)).to.eql(bn(0));
expect(await this.token.getAssetReplacements(tokenId, resId3)).to.eql(0n);
});

it('can replace non existing asset to token, it could have been deleted', async function () {
Expand All @@ -158,7 +158,7 @@ async function shouldBehaveLikeMultiAsset(
await this.token.connect(tokenOwner).acceptAsset(tokenId, 0, resId);

expect(await this.token.getActiveAssets(tokenId)).to.be.eql([resId]);
expect(await this.token.getActiveAssetPriorities(tokenId)).to.be.eql([bn(0)]);
expect(await this.token.getActiveAssetPriorities(tokenId)).to.be.eql([0n]);
});

it('can reject asset and replacements are cleared', async function () {
Expand All @@ -170,7 +170,7 @@ async function shouldBehaveLikeMultiAsset(
await addAssetToTokenFunc(this.token, tokenId, resId2, resId);
await this.token.connect(tokenOwner).rejectAsset(tokenId, 0, resId2);

expect(await this.token.getAssetReplacements(tokenId, resId2)).to.eql(bn(0));
expect(await this.token.getAssetReplacements(tokenId, resId2)).to.eql(0n);
});

it('can reject all assets and replacements are cleared', async function () {
Expand All @@ -182,7 +182,7 @@ async function shouldBehaveLikeMultiAsset(
await addAssetToTokenFunc(this.token, tokenId, resId2, resId);
await this.token.connect(tokenOwner).rejectAllAssets(tokenId, 1);

expect(await this.token.getAssetReplacements(tokenId, resId2)).to.eql(bn(0));
expect(await this.token.getAssetReplacements(tokenId, resId2)).to.eql(0n);
});
});
});
Expand All @@ -207,8 +207,8 @@ async function shouldBehaveLikeMultiAsset(
expect(
await this.renderUtils.getPendingAssets(await this.token.getAddress(), tokenId),
).to.eql([
[resId1, bn(0), bn(0), resData1],
[resId2, bn(1), bn(0), resData2],
[resId1, 0n, 0n, resData1],
[resId2, bn(1), 0n, resData2],
]);

await expect(this.token.connect(tokenOwner).acceptAsset(tokenId, 0, resId1))
Expand All @@ -217,7 +217,7 @@ async function shouldBehaveLikeMultiAsset(

expect(
await this.renderUtils.getPendingAssets(await this.token.getAddress(), tokenId),
).to.eql([[resId2, bn(0), bn(0), resData2]]);
).to.eql([[resId2, 0n, 0n, resData2]]);
expect(await this.token.getActiveAssets(tokenId)).to.be.eql([resId1]);
expect(await this.token.getAssetMetadata(tokenId, resId1)).equal(resData1);
});
Expand Down Expand Up @@ -384,12 +384,12 @@ async function shouldBehaveLikeMultiAsset(

describe('Priorities', async function () {
it('can set and get priorities', async function () {
expect(await this.token.getActiveAssetPriorities(tokenId)).to.be.eql([bn(0), bn(1)]);
expect(await this.token.getActiveAssetPriorities(tokenId)).to.be.eql([0n, bn(1)]);

await expect(this.token.connect(tokenOwner).setPriority(tokenId, [1, 0]))
.to.emit(this.token, 'AssetPrioritySet')
.withArgs(tokenId);
expect(await this.token.getActiveAssetPriorities(tokenId)).to.be.eql([bn(1), bn(0)]);
expect(await this.token.getActiveAssetPriorities(tokenId)).to.be.eql([bn(1), 0n]);
});

it('can set and get priorities if approved', async function () {
Expand All @@ -400,19 +400,19 @@ async function shouldBehaveLikeMultiAsset(
await expect(this.token.connect(approved).setPriority(tokenId, [1, 0]))
.to.emit(this.token, 'AssetPrioritySet')
.withArgs(tokenId);
expect(await this.token.getActiveAssetPriorities(tokenId)).to.be.eql([bn(1), bn(0)]);
expect(await this.token.getActiveAssetPriorities(tokenId)).to.be.eql([bn(1), 0n]);
});

it('can set and get priorities if approved for all', async function () {
await this.token
.connect(tokenOwner)
.setApprovalForAllForAssets(await operator.getAddress(), true);

expect(await this.token.getActiveAssetPriorities(tokenId)).to.be.eql([bn(0), bn(1)]);
expect(await this.token.getActiveAssetPriorities(tokenId)).to.be.eql([0n, bn(1)]);
await expect(this.token.connect(operator).setPriority(tokenId, [1, 0]))
.to.emit(this.token, 'AssetPrioritySet')
.withArgs(tokenId);
expect(await this.token.getActiveAssetPriorities(tokenId)).to.be.eql([bn(1), bn(0)]);
expect(await this.token.getActiveAssetPriorities(tokenId)).to.be.eql([bn(1), 0n]);
});

it('cannot set priorities for non owned token', async function () {
Expand Down
Loading

0 comments on commit 19ed1d3

Please sign in to comment.