diff --git a/scripts/deploy.ts b/scripts/deploy.ts deleted file mode 100644 index 1819253..0000000 --- a/scripts/deploy.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { ethers } from "hardhat"; - -async function main() { - const currentTimestampInSeconds = Math.round(Date.now() / 1000); - const unlockTime = currentTimestampInSeconds + 60; - - const lockedAmount = ethers.parseEther("0.001"); - - const lock = await ethers.deployContract("Lock", [unlockTime], { - value: lockedAmount, - }); - - await lock.waitForDeployment(); - - console.log( - `Lock with ${ethers.formatEther( - lockedAmount - )}ETH and unlock timestamp ${unlockTime} deployed to ${lock.target}` - ); -} - -// We recommend this pattern to be able to use async/await everywhere -// and properly handle errors. -main().catch((error) => { - console.error(error); - process.exitCode = 1; -}); diff --git a/tasks/utils.ts b/tasks/utils.ts index a6a0574..345e814 100644 --- a/tasks/utils.ts +++ b/tasks/utils.ts @@ -1,32 +1,33 @@ -import { task, types } from "hardhat/config"; -import { HardhatRuntimeEnvironment } from "hardhat/types"; -import { ethers } from "ethers"; +import { task } from "hardhat/config"; +import { HardhatRuntimeEnvironment } from "hardhat/types"; task("calc-slot", "calc slot value from string(ERC7201)") - .addParam("string", "ERC7201 string for slot") - .setAction(async (args, hre: HardhatRuntimeEnvironment) => { - await namespaceSlot(args.string) - }); + .addParam("string", "ERC7201 string for slot") + .setAction(async (args, hre: HardhatRuntimeEnvironment) => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access + namespaceSlot(hre, args.string); + }); task("slots", "calc slot value from string(ERC7201)") - .setAction(async (_, hre: HardhatRuntimeEnvironment) => { - const namespaces = [ - "eco.storage.ERC721TypedUpgradeable", - "eco.storage.ERC721SequencialMintUpbradeable", - ] - namespaces.map(async (namespace) => console.log(await namespaceSlot(namespace), namespace)) - }); + .setAction(async (_, hre: HardhatRuntimeEnvironment) => { + const namespaces = [ + "eco.storage.ERC721TypedUpgradeable", + "eco.storage.ERC721SequencialMintUpbradeable" + ]; + + namespaces.map((namespace) => console.log(namespaceSlot(hre, namespace), namespace)); + }); -async function namespaceSlot(namespace:string) { - // keccak256(abi.encode(uint256(keccak256(namespace)) - 1)) & ~bytes32(uint256(0xff)) - let hashNamespace = ethers.keccak256(ethers.toUtf8Bytes(namespace)); +function namespaceSlot(hre: HardhatRuntimeEnvironment, namespace:string) { + // keccak256(abi.encode(uint256(keccak256(namespace)) - 1)) & ~bytes32(uint256(0xff)) + const hashNamespace = hre.ethers.keccak256(hre.ethers.toUtf8Bytes(namespace)); - let number = ethers.toBigInt(hashNamespace) -1n; + const number = hre.ethers.toBigInt(hashNamespace) -1n; - let hash_second = ethers.keccak256(ethers.AbiCoder.defaultAbiCoder().encode(["uint256"], [number])); + const hash_second = hre.ethers.keccak256(hre.ethers.AbiCoder.defaultAbiCoder().encode(["uint256"], [number])); - let finalMasked = (ethers.toBigInt(hash_second) & (ethers.MaxUint256 - 255n)).toString(16); + const finalMasked = (hre.ethers.toBigInt(hash_second) & (hre.ethers.MaxUint256 - 255n)).toString(16); - return finalMasked; + return finalMasked; } \ No newline at end of file diff --git a/test/proxy.ts b/test/proxy.ts index 5eb1bc3..4ef6b84 100644 --- a/test/proxy.ts +++ b/test/proxy.ts @@ -1,26 +1,22 @@ import { - time, - loadFixture, + loadFixture } from "@nomicfoundation/hardhat-toolbox/network-helpers"; - +import { AsyncConstructor } from "async-constructor"; import { expect } from "chai"; -import { ethers } from "hardhat"; - -import { EcoERC20Mintable } from "../typechain-types"; - import { ContractFactory } from "ethers"; +import hre from "hardhat"; -import { AsyncConstructor } from 'async-constructor' +import { EcoERC20Mintable } from "../typechain-types"; -type ProxiedContract = Awaited>; +type ProxiedContract = Awaited>; class ProxyContractTypeTest extends AsyncConstructor { logicFactory!: FT; logic!: ProxiedContract; // FT의 deploy 메서드 반환 타입으로 정의 - constructor(logicFactory: FT, ...args: any[]) { + constructor(logicFactory: FT, ...args: unknown[]) { super(async () => { - this.logicFactory = logicFactory; + this.logicFactory= logicFactory; this.logic = await this.logicFactory.deploy(...args) as ProxiedContract; }); } @@ -30,101 +26,98 @@ describe("ProxyContractTypeTest", function () { const name = "Mintable Token"; const symbol = "M ERC20"; - const amount = ethers.parseEther("100"); - - async function Proxy_Helper_Fixture() { - const [owner, ...users] = await ethers.getSigners(); - const helper = await new ProxyContractTypeTest(await ethers.getContractFactory("EcoERC20Mintable"), name, symbol); - return {owner, helper} - } + async function Proxy_Helper_Fixture() { + const [owner] = await hre.ethers.getSigners(); + const helper = await new ProxyContractTypeTest(await hre.ethers.getContractFactory("EcoERC20Mintable"), name, symbol); + return {owner, helper}; + } - it("testing proxy", async function () { - const { helper } = await loadFixture(Proxy_Helper_Fixture); - expect(await helper.logic.symbol()).equal(symbol); - }); + it("testing proxy", async function () { + const { helper } = await loadFixture(Proxy_Helper_Fixture); + expect(await helper.logic.symbol()).equal(symbol); + }); }); describe("ERC20 Mintable", function () { -const name = "Mintable Token"; -const symbol = "M ERC20"; + const name = "Mintable Token"; + const symbol = "M ERC20"; -const amount = ethers.parseEther("100"); + const amount = hre.ethers.parseEther("100"); + async function NFT_Mintable_Fixture() { + // TODO: apply proxyFactory + const [owner, ...users] = await hre.ethers.getSigners(); - async function NFT_Mintable_Fixture() { - const [owner, ...users] = await ethers.getSigners(); + const EcoProxyAdmin = await hre.ethers.getContractFactory("EcoProxyAdmin"); + const admin = await EcoProxyAdmin.deploy(owner); - const EcoProxyAdmin = await ethers.getContractFactory("EcoProxyAdmin"); - const admin = await EcoProxyAdmin.deploy(owner); + const EcoProxyForProxyAdmin = await hre.ethers.getContractFactory("EcoProxyForProxyAdmin"); + const pAdmin = await EcoProxyForProxyAdmin.deploy(admin, owner); - const EcoProxyForProxyAdmin = await ethers.getContractFactory("EcoProxyForProxyAdmin"); - const pAdmin = await EcoProxyForProxyAdmin.deploy(admin, owner); + const ERC20 = await hre.ethers.getContractFactory("EcoERC20Mintable"); + const erc20 = await ERC20.deploy(name,symbol); - const ERC20 = await ethers.getContractFactory("EcoERC20Mintable"); - const erc20 = await ERC20.deploy(name, symbol); + const EcoTUPWithAdmin = await hre.ethers.getContractFactory("EcoTUPWithAdmin"); + const inst = await EcoTUPWithAdmin.deploy(pAdmin, erc20, erc20.interface.encodeFunctionData("initEcoERC20Mintable", [owner.address, name, symbol])); + const pErc20:EcoERC20Mintable = erc20.attach( await inst.getAddress() ) as EcoERC20Mintable; + return { owner, users, admin, pAdmin, erc20, pErc20 }; + } - const EcoTUPWithAdmin = await ethers.getContractFactory("EcoTUPWithAdmin"); - let inst = await EcoTUPWithAdmin.deploy(pAdmin, erc20, erc20.interface.encodeFunctionData("initEcoERC20Mintable", [owner.address, name, symbol])) - const pErc20:EcoERC20Mintable = erc20.attach( await inst.getAddress() ) + describe("Deployment", function () { + it("Should set the right owner", async function () { + const { pErc20, owner } = await loadFixture(NFT_Mintable_Fixture); - return { owner, users, admin, pAdmin, erc20, pErc20 }; - } + expect(await pErc20.owner()).to.equal(owner.address); + }); - describe("Deployment", function () { - it("Should set the right owner", async function () { - const { pErc20, owner } = await loadFixture(NFT_Mintable_Fixture); + it("Should set the right metadata", async function () { + const { pErc20 } = await loadFixture(NFT_Mintable_Fixture); - expect(await pErc20.owner()).to.equal(owner.address); + expect(await pErc20.name()).to.equal(name); + expect(await pErc20.symbol()).to.equal(symbol); + }); + }); + + describe("Non Fungible Token", function () { + describe("Mint", function () { + it("Should revert with the right error if mint called from another account", async function () { + const { pErc20, users } = await loadFixture(NFT_Mintable_Fixture); + const user_connected_nft = pErc20.connect(users[0]); + await expect( user_connected_nft.mint(users[0], amount) ).reverted; }); - it("Should set the right metadata", async function () { - const { pErc20 } = await loadFixture(NFT_Mintable_Fixture); - - expect(await pErc20.name()).to.equal(name); - expect(await pErc20.symbol()).to.equal(symbol); + it("Shouldn't fail mint with the right owner", async function () { + const { pErc20, users } = await loadFixture(NFT_Mintable_Fixture); + await expect( pErc20.mint(users[0], amount) ).not.reverted; }); - }); - - describe("Non Fungible Token", function () { - describe("Mint", function () { - it("Should revert with the right error if mint called from another account", async function () { - const { pErc20, users } = await loadFixture(NFT_Mintable_Fixture); - const user_connected_nft = pErc20.connect(users[0]) - await expect( user_connected_nft.mint(users[0], amount) ).reverted; - }); - it("Shouldn't fail mint with the right owner", async function () { - const { pErc20, users } = await loadFixture(NFT_Mintable_Fixture); - await expect( pErc20.mint(users[0], amount) ).not.reverted; - }); + it("Shouldn't fail mint with the right role access account", async function () { + const { pErc20, users } = await loadFixture(NFT_Mintable_Fixture); - it("Shouldn't fail mint with the right role access account", async function () { - const { pErc20, users } = await loadFixture(NFT_Mintable_Fixture); + const nextMintSelector = hre.ethers.zeroPadBytes(pErc20.mint.fragment.selector, 32); + await expect( pErc20.grantRole(nextMintSelector, users[0]) ).not.reverted; - const nextMintSelector = ethers.zeroPadBytes(pErc20.mint.fragment.selector, 32) - await expect( pErc20.grantRole(nextMintSelector, users[0]) ).not.reverted; + const user_connected_nft = pErc20.connect(users[0]); + await expect( user_connected_nft.mint(users[0], amount) ).not.reverted; - const user_connected_nft = pErc20.connect(users[0]) - await expect( user_connected_nft.mint(users[0], amount) ).not.reverted; - - await expect( pErc20.revokeRole(nextMintSelector, users[0]) ).not.reverted; - await expect( user_connected_nft.mint(users[0], amount) ).reverted; - }); + await expect( pErc20.revokeRole(nextMintSelector, users[0]) ).not.reverted; + await expect( user_connected_nft.mint(users[0], amount) ).reverted; }); + }); - describe("Transfer", function () { - it("Should revert with the right error if mint called from another account", async function () { - const { owner, pErc20, users } = await loadFixture(NFT_Mintable_Fixture); - await expect( pErc20.mint(users[0], amount) ).not.reverted; - - await pErc20.connect(users[0]).approve(owner, ethers.MaxUint256); - await expect( pErc20.transferFrom(users[0], users[1], await pErc20.balanceOf(users[0])) ).not.reverted; - await expect( pErc20.transferFrom(users[0], users[1], amount) ).reverted; - await expect( pErc20.connect(users[1]).transferFrom(users[1], users[0], await pErc20.balanceOf(users[1])) ).reverted; - await pErc20.connect(users[1]).approve(owner, ethers.MaxUint256); - await expect( pErc20.transferFrom(users[1], users[0], await pErc20.balanceOf(users[1])) ).not.reverted; - }); + describe("Transfer", function () { + it("Should revert with the right error if mint called from another account", async function () { + const { owner, pErc20, users } = await loadFixture(NFT_Mintable_Fixture); + await expect( pErc20.mint(users[0], amount) ).not.reverted; + + await pErc20.connect(users[0]).approve(owner, hre.ethers.MaxUint256); + await expect( pErc20.transferFrom(users[0], users[1], await pErc20.balanceOf(users[0])) ).not.reverted; + await expect( pErc20.transferFrom(users[0], users[1], amount) ).reverted; + await expect( pErc20.connect(users[1]).transferFrom(users[1], users[0], await pErc20.balanceOf(users[1])) ).reverted; + await pErc20.connect(users[1]).approve(owner, hre.ethers.MaxUint256); + await expect( pErc20.transferFrom(users[1], users[0], await pErc20.balanceOf(users[1])) ).not.reverted; }); }); + }); }); diff --git a/test/token/ERC20.ts b/test/token/ERC20.ts index 4e127af..ccad53b 100644 --- a/test/token/ERC20.ts +++ b/test/token/ERC20.ts @@ -1,6 +1,5 @@ import { - time, - loadFixture, + loadFixture } from "@nomicfoundation/hardhat-toolbox/network-helpers"; import { expect } from "chai"; import { ethers } from "hardhat"; @@ -40,7 +39,7 @@ describe("ERC20 Mintable", function () { describe("Mint", function () { it("Should revert with the right error if mint called from another account", async function () { const { erc20, users } = await loadFixture(NFT_Mintable_Fixture); - const user_connected_nft = erc20.connect(users[0]) + const user_connected_nft = erc20.connect(users[0]); await expect( user_connected_nft.mint(users[0], amount) ).reverted; }); @@ -52,10 +51,10 @@ describe("ERC20 Mintable", function () { it("Shouldn't fail mint with the right role access account", async function () { const { erc20, users } = await loadFixture(NFT_Mintable_Fixture); - const nextMintSelector = ethers.zeroPadBytes(erc20.mint.fragment.selector, 32) + const nextMintSelector = ethers.zeroPadBytes(erc20.mint.fragment.selector, 32); await expect( erc20.grantRole(nextMintSelector, users[0]) ).not.reverted; - const user_connected_nft = erc20.connect(users[0]) + const user_connected_nft = erc20.connect(users[0]); await expect( user_connected_nft.mint(users[0], amount) ).not.reverted; await expect( erc20.revokeRole(nextMintSelector, users[0]) ).not.reverted; diff --git a/test/token/ERC721.ts b/test/token/ERC721.ts index 7b5768f..ee7377f 100644 --- a/test/token/ERC721.ts +++ b/test/token/ERC721.ts @@ -1,10 +1,10 @@ import { - time, - loadFixture, + loadFixture } from "@nomicfoundation/hardhat-toolbox/network-helpers"; import { expect } from "chai"; import { ethers } from "hardhat"; + describe("NFT Mintable", function () { const name = "Mintable NFT"; const symbol = "MNFT"; @@ -38,7 +38,7 @@ describe("NFT Mintable", function () { describe("Mint", function () { it("Should revert with the right error if mint called from another account", async function () { const { nft, users } = await loadFixture(NFT_Mintable_Fixture); - const user_connected_nft = nft.connect(users[0]) + const user_connected_nft = nft.connect(users[0]); await expect( user_connected_nft.nextMint(users[0]) ).reverted; }); @@ -50,10 +50,10 @@ describe("NFT Mintable", function () { it("Shouldn't fail mint with the right role access account", async function () { const { nft, users } = await loadFixture(NFT_Mintable_Fixture); - const nextMintSelector = ethers.zeroPadBytes(nft.nextMint.fragment.selector, 32) + const nextMintSelector = ethers.zeroPadBytes(nft.nextMint.fragment.selector, 32); await expect( nft.grantRole(nextMintSelector, users[0]) ).not.reverted; - const user_connected_nft = nft.connect(users[0]) + const user_connected_nft = nft.connect(users[0]); await expect( user_connected_nft.nextMint(users[0]) ).not.reverted; await expect( nft.revokeRole(nextMintSelector, users[0]) ).not.reverted; @@ -66,7 +66,7 @@ describe("NFT Mintable", function () { const { nft, users } = await loadFixture(NFT_Mintable_Fixture); await expect( nft.nextMint(users[0]) ).not.reverted; - const user_connected_nft = nft.connect(users[0]) + const user_connected_nft = nft.connect(users[0]); await expect( user_connected_nft.transferFrom(users[0], users[1], 1) ).not.reverted; await expect( user_connected_nft.transferFrom(users[0], users[1], 1) ).reverted; await expect( nft.connect(users[1]).transferFrom(users[1], users[0], 1) ).not.reverted;