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";
|
||||
|
||||
abstract contract Fleek is IFleek, FleekBuilds {
|
||||
string name;
|
||||
string description;
|
||||
|
||||
constructor(string memory _name, string memory _description) {
|
||||
name = _name;
|
||||
description = _description;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ import "./Fleek.sol";
|
|||
import "../interfaces/IFleekSite.sol";
|
||||
|
||||
contract FleekSite is IFleekSite, Fleek {
|
||||
string thumbnail;
|
||||
string external_url;
|
||||
|
||||
constructor(
|
||||
string memory _name,
|
||||
string memory _description,
|
||||
|
|
@ -20,13 +23,13 @@ contract FleekSite is IFleekSite, Fleek {
|
|||
string calldata _thumbnail
|
||||
) external override requireController {
|
||||
thumbnail = _thumbnail;
|
||||
emit MetadataUpdated(name, description, thumbnail, external_url);
|
||||
emit SiteMetadataUpdated(name, description, thumbnail, external_url);
|
||||
}
|
||||
|
||||
function setExternalUrl(
|
||||
string calldata _external_url
|
||||
) external override requireController {
|
||||
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";
|
||||
|
||||
interface IFleek is IFleekBuilds, IAccessControl {
|
||||
string name;
|
||||
string description;
|
||||
|
||||
event MetadataUpdated(string name, string description);
|
||||
|
||||
function setName(string calldata _name) external;
|
||||
|
|
|
|||
|
|
@ -5,10 +5,7 @@ pragma solidity ^0.8.7;
|
|||
import "./IFleek.sol";
|
||||
|
||||
interface IFleekSite is IFleek {
|
||||
string thumbnail;
|
||||
string external_url;
|
||||
|
||||
event MetadataUpdated(
|
||||
event SiteMetadataUpdated(
|
||||
string name,
|
||||
string description,
|
||||
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 { loadFixture } = require('ethereum-waffle');
|
||||
|
||||
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', () => {
|
||||
it('Deployment should assign the name and the symbol of the ERC721 contract', async () => {
|
||||
const [owner] = await ethers.getSigners();
|
||||
|
||||
const name = 'Sites NFTs';
|
||||
const symbol = 'SNFT';
|
||||
|
||||
const SitesNFTs = await ethers.getContractFactory('SitesNFTs');
|
||||
|
||||
const hardhatSitesNFTs = await SitesNFTs.deploy('Sites NFTs', 'SNFT');
|
||||
const { hardhatSitesNFTs } = await loadFixture(deploy);
|
||||
|
||||
const contractName = await hardhatSitesNFTs.name();
|
||||
const contractSymbol = await hardhatSitesNFTs.symbol();
|
||||
|
|
@ -20,11 +27,7 @@ describe('SitesNFTs contract', function () {
|
|||
});
|
||||
|
||||
it('Deployment should assign the deployer DEFAULT_ADMIN_ROLE', async () => {
|
||||
const [owner] = await ethers.getSigners();
|
||||
|
||||
const SitesNFTs = await ethers.getContractFactory('SitesNFTs');
|
||||
|
||||
const hardhatSitesNFTs = await SitesNFTs.deploy('Sites NFTs', 'SNFT');
|
||||
const { hardhatSitesNFTs, owner } = await loadFixture(deploy);
|
||||
|
||||
const DEFAULT_ADMIN_ROLE_STRING = '';
|
||||
|
||||
|
|
@ -37,12 +40,7 @@ describe('SitesNFTs contract', function () {
|
|||
});
|
||||
|
||||
it('Deployment should assign initial tokenId to 0', async () => {
|
||||
const [owner] = await ethers.getSigners();
|
||||
|
||||
const SitesNFTs = await ethers.getContractFactory('SitesNFTs');
|
||||
|
||||
const hardhatSitesNFTs = await SitesNFTs.deploy('Sites NFTs', 'SNFT');
|
||||
|
||||
const { hardhatSitesNFTs } = await loadFixture(deploy);
|
||||
const currentTokenId = await hardhatSitesNFTs.getCurrentTokenId();
|
||||
|
||||
expect(currentTokenId).to.equal(0);
|
||||
|
|
@ -51,12 +49,7 @@ describe('SitesNFTs contract', function () {
|
|||
|
||||
describe('Access control', () => {
|
||||
it('User with DEFAULT_ADMIN_ROLE should be able to assign MINTER_ROLE to another user', async () => {
|
||||
const [owner, address1] = await ethers.getSigners();
|
||||
|
||||
const SitesNFTs = await ethers.getContractFactory('SitesNFTs');
|
||||
|
||||
const hardhatSitesNFTs = await SitesNFTs.deploy('Sites NFTs', 'SNFT');
|
||||
|
||||
const { hardhatSitesNFTs, address1 } = await loadFixture(deploy);
|
||||
const MINTER_ROLE = 'MINTER_ROLE';
|
||||
|
||||
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 () => {
|
||||
const [owner] = await ethers.getSigners();
|
||||
|
||||
const SitesNFTs = await ethers.getContractFactory('SitesNFTs');
|
||||
|
||||
const hardhatSitesNFTs = await SitesNFTs.deploy('Sites NFTs', 'SNFT');
|
||||
|
||||
const { hardhatSitesNFTs, owner } = await loadFixture(deploy);
|
||||
const MINTER_ROLE = 'MINTER_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 () => {
|
||||
const [owner, address1] = await ethers.getSigners();
|
||||
|
||||
const SitesNFTs = await ethers.getContractFactory('SitesNFTs');
|
||||
|
||||
const hardhatSitesNFTs = await SitesNFTs.deploy('Sites NFTs', 'SNFT');
|
||||
|
||||
const { hardhatSitesNFTs, address1 } = await loadFixture(deploy);
|
||||
const DEFAULT_ADMIN_ROLE = '';
|
||||
|
||||
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 () => {
|
||||
const [owner, address1] = await ethers.getSigners();
|
||||
|
||||
const SitesNFTs = await ethers.getContractFactory('SitesNFTs');
|
||||
|
||||
const hardhatSitesNFTs = await SitesNFTs.deploy('Sites NFTs', 'SNFT');
|
||||
|
||||
const { hardhatSitesNFTs, owner, address1 } = await loadFixture(deploy);
|
||||
const DEFAULT_ADMIN_ROLE = '';
|
||||
|
||||
await hardhatSitesNFTs.grantRole(
|
||||
|
|
@ -206,12 +184,7 @@ describe('SitesNFTs contract', function () {
|
|||
|
||||
describe('Minting', () => {
|
||||
it('User with DEFAULT_ADMIN_ROLE should be able to mint', async () => {
|
||||
const [owner, address1] = await ethers.getSigners();
|
||||
|
||||
const SitesNFTs = await ethers.getContractFactory('SitesNFTs');
|
||||
|
||||
const hardhatSitesNFTs = await SitesNFTs.deploy('Sites NFTs', 'SNFT');
|
||||
|
||||
const { hardhatSitesNFTs, address1 } = await loadFixture(deploy);
|
||||
const tokenURI = 'tokenURI';
|
||||
|
||||
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 () => {
|
||||
const [owner, address1, address2] = await ethers.getSigners();
|
||||
|
||||
const SitesNFTs = await ethers.getContractFactory('SitesNFTs');
|
||||
|
||||
const hardhatSitesNFTs = await SitesNFTs.deploy('Sites NFTs', 'SNFT');
|
||||
|
||||
const { hardhatSitesNFTs, address1, address2 } = await loadFixture(
|
||||
deploy
|
||||
);
|
||||
const MINTER_ROLE = 'MINTER_ROLE';
|
||||
const tokenURI = 'tokenURI';
|
||||
|
||||
|
|
@ -277,12 +247,7 @@ describe('SitesNFTs contract', function () {
|
|||
});
|
||||
|
||||
it('Minted NFT should have data:application/json;base64, baseURI', async () => {
|
||||
const [owner, address1] = await ethers.getSigners();
|
||||
|
||||
const SitesNFTs = await ethers.getContractFactory('SitesNFTs');
|
||||
|
||||
const hardhatSitesNFTs = await SitesNFTs.deploy('Sites NFTs', 'SNFT');
|
||||
|
||||
const { hardhatSitesNFTs, address1 } = await loadFixture(deploy);
|
||||
const tokenURI = 'tokenURI';
|
||||
|
||||
await hardhatSitesNFTs.mint(tokenURI, await address1.getAddress());
|
||||
|
|
|
|||
Loading…
Reference in New Issue