Skip to content

Commit

Permalink
apply: eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
seinmyung25 committed Jan 9, 2024
1 parent 823a19c commit 548ae8d
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 141 deletions.
27 changes: 0 additions & 27 deletions scripts/deploy.ts

This file was deleted.

43 changes: 22 additions & 21 deletions tasks/utils.ts
Original file line number Diff line number Diff line change
@@ -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;
}
157 changes: 75 additions & 82 deletions test/proxy.ts
Original file line number Diff line number Diff line change
@@ -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<FT extends ContractFactory> = Awaited<ReturnType<FT['deploy']>>;
type ProxiedContract<FT extends ContractFactory> = Awaited<ReturnType<FT["deploy"]>>;

class ProxyContractTypeTest<FT extends ContractFactory> extends AsyncConstructor {
logicFactory!: FT;
logic!: ProxiedContract<FT>; // 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<FT>;
});
}
Expand All @@ -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;
});
});
});
});
9 changes: 4 additions & 5 deletions test/token/ERC20.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
time,
loadFixture,
loadFixture
} from "@nomicfoundation/hardhat-toolbox/network-helpers";
import { expect } from "chai";
import { ethers } from "hardhat";
Expand Down Expand Up @@ -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;
});

Expand All @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions test/token/ERC721.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
});

Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 548ae8d

Please sign in to comment.