Add tests (#4)
* refactor: move strings declarations to contracts * feat: added test for FleekSite contract, also did small refactor on SitesNFTs contract test * refactor: renamed metadadUpdated event due to conflicts * feat: added test for FleekSite contract
This commit is contained in:
parent
3a316a6fea
commit
320a5a45e3
|
|
@ -7,6 +7,9 @@ import "./FleekBuilds.sol";
|
||||||
import "./FleekAccessControl.sol";
|
import "./FleekAccessControl.sol";
|
||||||
|
|
||||||
abstract contract Fleek is IFleek, FleekBuilds {
|
abstract contract Fleek is IFleek, FleekBuilds {
|
||||||
|
string name;
|
||||||
|
string description;
|
||||||
|
|
||||||
constructor(string memory _name, string memory _description) {
|
constructor(string memory _name, string memory _description) {
|
||||||
name = _name;
|
name = _name;
|
||||||
description = _description;
|
description = _description;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,9 @@ import "./Fleek.sol";
|
||||||
import "../interfaces/IFleekSite.sol";
|
import "../interfaces/IFleekSite.sol";
|
||||||
|
|
||||||
contract FleekSite is IFleekSite, Fleek {
|
contract FleekSite is IFleekSite, Fleek {
|
||||||
|
string thumbnail;
|
||||||
|
string external_url;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
string memory _name,
|
string memory _name,
|
||||||
string memory _description,
|
string memory _description,
|
||||||
|
|
@ -20,13 +23,13 @@ contract FleekSite is IFleekSite, Fleek {
|
||||||
string calldata _thumbnail
|
string calldata _thumbnail
|
||||||
) external override requireController {
|
) external override requireController {
|
||||||
thumbnail = _thumbnail;
|
thumbnail = _thumbnail;
|
||||||
emit MetadataUpdated(name, description, thumbnail, external_url);
|
emit SiteMetadataUpdated(name, description, thumbnail, external_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setExternalUrl(
|
function setExternalUrl(
|
||||||
string calldata _external_url
|
string calldata _external_url
|
||||||
) external override requireController {
|
) external override requireController {
|
||||||
external_url = _external_url;
|
external_url = _external_url;
|
||||||
emit MetadataUpdated(name, description, thumbnail, external_url);
|
emit SiteMetadataUpdated(name, description, thumbnail, external_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,6 @@ import "./IFleekBuilds.sol";
|
||||||
import "@openzeppelin/contracts/access/IAccessControl.sol";
|
import "@openzeppelin/contracts/access/IAccessControl.sol";
|
||||||
|
|
||||||
interface IFleek is IFleekBuilds, IAccessControl {
|
interface IFleek is IFleekBuilds, IAccessControl {
|
||||||
string name;
|
|
||||||
string description;
|
|
||||||
|
|
||||||
event MetadataUpdated(string name, string description);
|
event MetadataUpdated(string name, string description);
|
||||||
|
|
||||||
function setName(string calldata _name) external;
|
function setName(string calldata _name) external;
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,7 @@ pragma solidity ^0.8.7;
|
||||||
import "./IFleek.sol";
|
import "./IFleek.sol";
|
||||||
|
|
||||||
interface IFleekSite is IFleek {
|
interface IFleekSite is IFleek {
|
||||||
string thumbnail;
|
event SiteMetadataUpdated(
|
||||||
string external_url;
|
|
||||||
|
|
||||||
event MetadataUpdated(
|
|
||||||
string name,
|
string name,
|
||||||
string description,
|
string description,
|
||||||
string thumbnail,
|
string thumbnail,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
const { expect } = require('chai');
|
||||||
|
const { loadFixture } = require('ethereum-waffle');
|
||||||
|
const { ethers } = require('hardhat');
|
||||||
|
const hre = require('hardhat');
|
||||||
|
|
||||||
|
describe('FleekSite contract', function () {
|
||||||
|
//TODO check values are setted right on the contract
|
||||||
|
const _name = 'Fleek Site';
|
||||||
|
const _description = 'Fleek Site Description';
|
||||||
|
const _thumbnail = 'https://fleek.co';
|
||||||
|
const _externalUrl = 'https://fleek.co';
|
||||||
|
|
||||||
|
async function deploy() {
|
||||||
|
const [owner] = await hre.ethers.getSigners();
|
||||||
|
|
||||||
|
const FleekSite = await hre.ethers.getContractFactory('FleekSite');
|
||||||
|
|
||||||
|
const hardhatFleekSite = await FleekSite.deploy(
|
||||||
|
'Fleek Site',
|
||||||
|
'Fleek Site Description',
|
||||||
|
'https://fleek.co',
|
||||||
|
'https://fleek.co'
|
||||||
|
);
|
||||||
|
|
||||||
|
return { owner, hardhatFleekSite };
|
||||||
|
}
|
||||||
|
describe('Deployment', () => {
|
||||||
|
it('Deploy FleekSit contract with name Fleek Site and builds[] should be 0', async () => {
|
||||||
|
const { hardhatFleekSite } = await loadFixture(deploy);
|
||||||
|
|
||||||
|
const currentBuilds = await hardhatFleekSite.getBuilds();
|
||||||
|
expect(currentBuilds.length).to.equal(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Deployment should assign to OWNER_ROLE the DEFAULT_ADMIN_ROLE', async () => {
|
||||||
|
const { hardhatFleekSite } = await loadFixture(deploy);
|
||||||
|
|
||||||
|
const OWNER_ROLE = 'OWNER_ROLE';
|
||||||
|
const DEFAULT_ADMIN_ROLE_STRING = '';
|
||||||
|
|
||||||
|
const role = await hardhatFleekSite.getRoleAdmin(
|
||||||
|
ethers.utils.formatBytes32String(OWNER_ROLE)
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(role).to.equal(
|
||||||
|
ethers.utils.formatBytes32String(DEFAULT_ADMIN_ROLE_STRING)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -1,16 +1,23 @@
|
||||||
const { expect } = require('chai');
|
const { expect } = require('chai');
|
||||||
|
const { loadFixture } = require('ethereum-waffle');
|
||||||
|
|
||||||
describe('SitesNFTs contract', function () {
|
describe('SitesNFTs contract', function () {
|
||||||
|
const name = 'Sites NFTs';
|
||||||
|
const symbol = 'SNFT';
|
||||||
|
|
||||||
|
async function deploy() {
|
||||||
|
const [owner, address1, address2] = await hre.ethers.getSigners();
|
||||||
|
|
||||||
|
const SitesNFTs = await hre.ethers.getContractFactory('SitesNFTs');
|
||||||
|
|
||||||
|
const hardhatSitesNFTs = await SitesNFTs.deploy(name, symbol);
|
||||||
|
|
||||||
|
return { owner, address1, address2, hardhatSitesNFTs };
|
||||||
|
}
|
||||||
|
|
||||||
describe('Deployment', () => {
|
describe('Deployment', () => {
|
||||||
it('Deployment should assign the name and the symbol of the ERC721 contract', async () => {
|
it('Deployment should assign the name and the symbol of the ERC721 contract', async () => {
|
||||||
const [owner] = await ethers.getSigners();
|
const { hardhatSitesNFTs } = await loadFixture(deploy);
|
||||||
|
|
||||||
const name = 'Sites NFTs';
|
|
||||||
const symbol = 'SNFT';
|
|
||||||
|
|
||||||
const SitesNFTs = await ethers.getContractFactory('SitesNFTs');
|
|
||||||
|
|
||||||
const hardhatSitesNFTs = await SitesNFTs.deploy('Sites NFTs', 'SNFT');
|
|
||||||
|
|
||||||
const contractName = await hardhatSitesNFTs.name();
|
const contractName = await hardhatSitesNFTs.name();
|
||||||
const contractSymbol = await hardhatSitesNFTs.symbol();
|
const contractSymbol = await hardhatSitesNFTs.symbol();
|
||||||
|
|
@ -20,11 +27,7 @@ describe('SitesNFTs contract', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Deployment should assign the deployer DEFAULT_ADMIN_ROLE', async () => {
|
it('Deployment should assign the deployer DEFAULT_ADMIN_ROLE', async () => {
|
||||||
const [owner] = await ethers.getSigners();
|
const { hardhatSitesNFTs, owner } = await loadFixture(deploy);
|
||||||
|
|
||||||
const SitesNFTs = await ethers.getContractFactory('SitesNFTs');
|
|
||||||
|
|
||||||
const hardhatSitesNFTs = await SitesNFTs.deploy('Sites NFTs', 'SNFT');
|
|
||||||
|
|
||||||
const DEFAULT_ADMIN_ROLE_STRING = '';
|
const DEFAULT_ADMIN_ROLE_STRING = '';
|
||||||
|
|
||||||
|
|
@ -37,12 +40,7 @@ describe('SitesNFTs contract', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Deployment should assign initial tokenId to 0', async () => {
|
it('Deployment should assign initial tokenId to 0', async () => {
|
||||||
const [owner] = await ethers.getSigners();
|
const { hardhatSitesNFTs } = await loadFixture(deploy);
|
||||||
|
|
||||||
const SitesNFTs = await ethers.getContractFactory('SitesNFTs');
|
|
||||||
|
|
||||||
const hardhatSitesNFTs = await SitesNFTs.deploy('Sites NFTs', 'SNFT');
|
|
||||||
|
|
||||||
const currentTokenId = await hardhatSitesNFTs.getCurrentTokenId();
|
const currentTokenId = await hardhatSitesNFTs.getCurrentTokenId();
|
||||||
|
|
||||||
expect(currentTokenId).to.equal(0);
|
expect(currentTokenId).to.equal(0);
|
||||||
|
|
@ -51,12 +49,7 @@ describe('SitesNFTs contract', function () {
|
||||||
|
|
||||||
describe('Access control', () => {
|
describe('Access control', () => {
|
||||||
it('User with DEFAULT_ADMIN_ROLE should be able to assign MINTER_ROLE to another user', async () => {
|
it('User with DEFAULT_ADMIN_ROLE should be able to assign MINTER_ROLE to another user', async () => {
|
||||||
const [owner, address1] = await ethers.getSigners();
|
const { hardhatSitesNFTs, address1 } = await loadFixture(deploy);
|
||||||
|
|
||||||
const SitesNFTs = await ethers.getContractFactory('SitesNFTs');
|
|
||||||
|
|
||||||
const hardhatSitesNFTs = await SitesNFTs.deploy('Sites NFTs', 'SNFT');
|
|
||||||
|
|
||||||
const MINTER_ROLE = 'MINTER_ROLE';
|
const MINTER_ROLE = 'MINTER_ROLE';
|
||||||
|
|
||||||
await hardhatSitesNFTs.grantRole(
|
await hardhatSitesNFTs.grantRole(
|
||||||
|
|
@ -73,12 +66,7 @@ describe('SitesNFTs contract', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('User with DEFAULT_ADMIN_ROLE should be able to assign MINTER_ROLE to himself and still have DEFAULT_ADMIN_ROLE', async () => {
|
it('User with DEFAULT_ADMIN_ROLE should be able to assign MINTER_ROLE to himself and still have DEFAULT_ADMIN_ROLE', async () => {
|
||||||
const [owner] = await ethers.getSigners();
|
const { hardhatSitesNFTs, owner } = await loadFixture(deploy);
|
||||||
|
|
||||||
const SitesNFTs = await ethers.getContractFactory('SitesNFTs');
|
|
||||||
|
|
||||||
const hardhatSitesNFTs = await SitesNFTs.deploy('Sites NFTs', 'SNFT');
|
|
||||||
|
|
||||||
const MINTER_ROLE = 'MINTER_ROLE';
|
const MINTER_ROLE = 'MINTER_ROLE';
|
||||||
const DEFAULT_ADMIN_ROLE = '';
|
const DEFAULT_ADMIN_ROLE = '';
|
||||||
|
|
||||||
|
|
@ -101,12 +89,7 @@ describe('SitesNFTs contract', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('User with DEFAULT_ADMIN_ROLE should be able to assign DEFAULT_ADMIN_ROLE to another user', async () => {
|
it('User with DEFAULT_ADMIN_ROLE should be able to assign DEFAULT_ADMIN_ROLE to another user', async () => {
|
||||||
const [owner, address1] = await ethers.getSigners();
|
const { hardhatSitesNFTs, address1 } = await loadFixture(deploy);
|
||||||
|
|
||||||
const SitesNFTs = await ethers.getContractFactory('SitesNFTs');
|
|
||||||
|
|
||||||
const hardhatSitesNFTs = await SitesNFTs.deploy('Sites NFTs', 'SNFT');
|
|
||||||
|
|
||||||
const DEFAULT_ADMIN_ROLE = '';
|
const DEFAULT_ADMIN_ROLE = '';
|
||||||
|
|
||||||
await hardhatSitesNFTs.grantRole(
|
await hardhatSitesNFTs.grantRole(
|
||||||
|
|
@ -123,12 +106,7 @@ describe('SitesNFTs contract', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('User with DEFAULT_ADMIN_ROLE should be able to assign DEFAULT_ADMIN_ROLE to another user and still have DEFAULT_ADMIN_ROLE', async () => {
|
it('User with DEFAULT_ADMIN_ROLE should be able to assign DEFAULT_ADMIN_ROLE to another user and still have DEFAULT_ADMIN_ROLE', async () => {
|
||||||
const [owner, address1] = await ethers.getSigners();
|
const { hardhatSitesNFTs, owner, address1 } = await loadFixture(deploy);
|
||||||
|
|
||||||
const SitesNFTs = await ethers.getContractFactory('SitesNFTs');
|
|
||||||
|
|
||||||
const hardhatSitesNFTs = await SitesNFTs.deploy('Sites NFTs', 'SNFT');
|
|
||||||
|
|
||||||
const DEFAULT_ADMIN_ROLE = '';
|
const DEFAULT_ADMIN_ROLE = '';
|
||||||
|
|
||||||
await hardhatSitesNFTs.grantRole(
|
await hardhatSitesNFTs.grantRole(
|
||||||
|
|
@ -206,12 +184,7 @@ describe('SitesNFTs contract', function () {
|
||||||
|
|
||||||
describe('Minting', () => {
|
describe('Minting', () => {
|
||||||
it('User with DEFAULT_ADMIN_ROLE should be able to mint', async () => {
|
it('User with DEFAULT_ADMIN_ROLE should be able to mint', async () => {
|
||||||
const [owner, address1] = await ethers.getSigners();
|
const { hardhatSitesNFTs, address1 } = await loadFixture(deploy);
|
||||||
|
|
||||||
const SitesNFTs = await ethers.getContractFactory('SitesNFTs');
|
|
||||||
|
|
||||||
const hardhatSitesNFTs = await SitesNFTs.deploy('Sites NFTs', 'SNFT');
|
|
||||||
|
|
||||||
const tokenURI = 'tokenURI';
|
const tokenURI = 'tokenURI';
|
||||||
|
|
||||||
await hardhatSitesNFTs.mint(tokenURI, await address1.getAddress());
|
await hardhatSitesNFTs.mint(tokenURI, await address1.getAddress());
|
||||||
|
|
@ -224,12 +197,9 @@ describe('SitesNFTs contract', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('User with MINTER_ROLE should be able to mint', async () => {
|
it('User with MINTER_ROLE should be able to mint', async () => {
|
||||||
const [owner, address1, address2] = await ethers.getSigners();
|
const { hardhatSitesNFTs, address1, address2 } = await loadFixture(
|
||||||
|
deploy
|
||||||
const SitesNFTs = await ethers.getContractFactory('SitesNFTs');
|
);
|
||||||
|
|
||||||
const hardhatSitesNFTs = await SitesNFTs.deploy('Sites NFTs', 'SNFT');
|
|
||||||
|
|
||||||
const MINTER_ROLE = 'MINTER_ROLE';
|
const MINTER_ROLE = 'MINTER_ROLE';
|
||||||
const tokenURI = 'tokenURI';
|
const tokenURI = 'tokenURI';
|
||||||
|
|
||||||
|
|
@ -277,12 +247,7 @@ describe('SitesNFTs contract', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Minted NFT should have data:application/json;base64, baseURI', async () => {
|
it('Minted NFT should have data:application/json;base64, baseURI', async () => {
|
||||||
const [owner, address1] = await ethers.getSigners();
|
const { hardhatSitesNFTs, address1 } = await loadFixture(deploy);
|
||||||
|
|
||||||
const SitesNFTs = await ethers.getContractFactory('SitesNFTs');
|
|
||||||
|
|
||||||
const hardhatSitesNFTs = await SitesNFTs.deploy('Sites NFTs', 'SNFT');
|
|
||||||
|
|
||||||
const tokenURI = 'tokenURI';
|
const tokenURI = 'tokenURI';
|
||||||
|
|
||||||
await hardhatSitesNFTs.mint(tokenURI, await address1.getAddress());
|
await hardhatSitesNFTs.mint(tokenURI, await address1.getAddress());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue