Skip to content

Commit

Permalink
## Version -- 1.5.14
Browse files Browse the repository at this point in the history
- Implement shared 1155URI tests.
  • Loading branch information
mvillere committed Oct 23, 2023
1 parent 875a483 commit 635412f
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ As of 12/13/2022, this repo has been renamed from "nftc-open-contracts" to "nftc
## Version -- 1.5.next [Not published]
- TODO

## Version -- 1.5.14
- Implement shared 1155URI tests.

## Version -- 1.5.13
- Implement shared baseURI tests.

Expand Down
12 changes: 12 additions & 0 deletions contracts/mocks/token/ERC1155/MockERC1155ConfigurableURI.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import '@openzeppelin/contracts/token/ERC1155/ERC1155.sol';

contract MockERC1155ConfigurableURI is ERC1155 {
constructor(string memory __URI) ERC1155(__URI) {}

function mint(uint256 itemId, uint256 quantity) public {
_mint(msg.sender, itemId, quantity, '');
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nftculture/nftc-contracts",
"version": "1.5.13",
"version": "1.5.14",
"description": "NFTCulture Open Source Contracts Project",
"author": "@NFTCulture",
"license": "MIT",
Expand Down
52 changes: 50 additions & 2 deletions src/behaviors/token/URI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { expect } from 'chai';

import { skipIfDefault } from '../../for-tests';

export function shouldDefineBaseURI(contractName: string, expectedURIFn: () => Promise<string | null>) {
export function shouldDefineBaseURI(contractName: string, expectedBaseURIFn: () => Promise<string | null>) {
describe(`Base URI for ${contractName}:`, function () {
beforeEach(async function () {
expect(this).to.have.property('contractUnderTest'); // Must be set in caller

this.expectedURI = await expectedURIFn();
this.expectedURI = await expectedBaseURIFn();
});

describe('is defined:', function () {
Expand Down Expand Up @@ -51,3 +51,51 @@ export function shouldDefineBaseURI(contractName: string, expectedURIFn: () => P
});
});
}

export function shouldDefine1155URI(contractName: string, expectedURIFn: () => Promise<string | null>) {
describe(`ERC1155 URI for ${contractName}:`, function () {
beforeEach(async function () {
expect(this).to.have.property('contractUnderTest'); // Must be set in caller

this.expectedURI = await expectedURIFn();
});

describe('is defined:', function () {
it('not as zero.', async function () {
const erc1155Uri = await this.contractUnderTest.uri(0);
const isSetToZero = erc1155Uri === 'https://nftc-media.mypinata.cloud/ipfs/Qm000000/{id}.json'; // Zero

const defaultConfigurationCheck = !isSetToZero;
expect(skipIfDefault(this, defaultConfigurationCheck)).to.equal(true);
});

it('not as pinata public gateway.', async function () {
const erc1155Uri = await this.contractUnderTest.uri(0);
const isSetToPublicPinata = erc1155Uri === 'https://gateway.pinata.cloud/ipfs/ipfs/Qm000000/{id}.json'; // Pinata Public gateway

const defaultConfigurationCheck = !isSetToPublicPinata;
expect(skipIfDefault(this, defaultConfigurationCheck)).to.equal(true);
});

it('not as default for NFTC tokens.', async function () {
const erc1155Uri = await this.contractUnderTest.uri(0);
const isSetToDefault =
erc1155Uri ===
'https://nftc-media.mypinata.cloud/ipfs/QmNaNCsufrof7s9xp7whbo8dq1hdYdjmjYfgKvGSFbg23f/{id}.json'; // Dr3amLabs_Reference1155_Metadata_V1cb

const defaultConfigurationCheck = !isSetToDefault;
expect(skipIfDefault(this, defaultConfigurationCheck)).to.equal(true);
});

it('as expected.', async function () {
const placeholderValue = 'DELIBERATELY BAD VALUE'; // Used if expectedURI is null.

const erc1155Uri = await this.contractUnderTest.uri(0);
const erc1155UriIsCorrect = erc1155Uri === (this.expectedURI ?? placeholderValue);

const defaultConfigurationCheck = erc1155UriIsCorrect;
expect(skipIfDefault(this, defaultConfigurationCheck)).to.equal(true);
});
});
});
}
32 changes: 32 additions & 0 deletions test/typescript/behaviors/token/URI.1155.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as dotenv from 'dotenv';
import hre from 'hardhat';

import { addHardhatSignersToContext, shouldDefine1155URI } from '../../../../src';
import { MockERC1155ConfigurableURI, MockERC1155ConfigurableURI__factory } from '../../../../typechain-types';

dotenv.config();

const TESTHARNESS_CONTRACT_NAME = 'MockERC1155ConfigurableURI';

let _testHarnessContractFactory: MockERC1155ConfigurableURI__factory;
let _testHarnessInstance: MockERC1155ConfigurableURI;

// Some plausibly real ERC1155 URI
const ERC1155URI = 'https://nftculture.mypinata.com/ipfs/Qm000abcdefghijkl/{id}.json';

// Start test block
describe(`${TESTHARNESS_CONTRACT_NAME} Unit Tests`, function () {
before(async function () {
_testHarnessContractFactory = await hre.ethers.getContractFactory(TESTHARNESS_CONTRACT_NAME);
});

beforeEach(async function () {
_testHarnessInstance = await _testHarnessContractFactory.deploy(ERC1155URI);
await _testHarnessInstance.deployed();
this.contractUnderTest = _testHarnessInstance;
});

addHardhatSignersToContext();

shouldDefine1155URI(TESTHARNESS_CONTRACT_NAME, async () => ERC1155URI);
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as dotenv from 'dotenv';
import hre from 'hardhat';

import { addHardhatSignersToContext } from '../../../../src';
import { shouldDefineBaseURI } from '../../../../src/behaviors/token/URI';
import { addHardhatSignersToContext, shouldDefineBaseURI } from '../../../../src';
import { MockERC721SolBase, MockERC721SolBase__factory } from '../../../../typechain-types';

dotenv.config();
Expand All @@ -12,24 +11,22 @@ const TESTHARNESS_CONTRACT_NAME = 'MockERC721SolBase';
let _testHarnessContractFactory: MockERC721SolBase__factory;
let _testHarnessInstance: MockERC721SolBase;

// Some plausibly real ERC721 baseURI
const ERC721BaseURI = 'https://nftculture.mypinata.cloud/ipfs/Qm000abcdefghijkl/';

// Start test block
describe(`${TESTHARNESS_CONTRACT_NAME} Unit Tests`, function () {
before(async function () {
_testHarnessContractFactory = await hre.ethers.getContractFactory(TESTHARNESS_CONTRACT_NAME);
});

beforeEach(async function () {
_testHarnessInstance = await _testHarnessContractFactory.deploy(
'https://nftculture.mypinata.cloud/ipfs/Qm000abcdefghijkl/'
);
_testHarnessInstance = await _testHarnessContractFactory.deploy(ERC721BaseURI);
await _testHarnessInstance.deployed();
this.contractUnderTest = _testHarnessInstance;
});

addHardhatSignersToContext();

shouldDefineBaseURI(
TESTHARNESS_CONTRACT_NAME,
async () => 'https://nftculture.mypinata.cloud/ipfs/Qm000abcdefghijkl/' // Some plausibly real baseURI
);
shouldDefineBaseURI(TESTHARNESS_CONTRACT_NAME, async () => ERC721BaseURI);
});

0 comments on commit 635412f

Please sign in to comment.