Skip to content

Commit

Permalink
fix: erc20 testings
Browse files Browse the repository at this point in the history
  • Loading branch information
seinmyung25 committed Mar 14, 2024
1 parent 3e7a23d commit 7c98890
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 49 deletions.
8 changes: 4 additions & 4 deletions helper/eco-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ export class ProxyInstanceFactory extends AsyncConstructor {
}

async function test() {
const logicFactory = await hre.ethers.getContractFactory("ERC20MintableUpgradeable");
const logicFactory = await hre.ethers.getContractFactory("EcoERC20Upgradeable");
const EcoTUPFactory = new ProxyInstanceFactory();
const logic = await logicFactory.deploy("a", "a");
const logic = await logicFactory.deploy();

const input = logic.interface.encodeFunctionData("initEcoERC20Mintable", [logic, "a", "a"]);
const input = logic.interface.encodeFunctionData("initEcoERC20", [logic.runner, "name", "symbol", 18n]);

const instByLogic = await EcoTUPFactory.deployWithLogic(logic, input);
const instByFactory = await EcoTUPFactory.deployWithFactory(logicFactory, ["a", "a"], input);
const instByFactory = await EcoTUPFactory.deployWithFactory(logicFactory, [], input);
const instByAttachLogic = await EcoTUPFactory.attachWithLogic(logic, instByLogic);
const instByAttachFactory = await EcoTUPFactory.attachWithFactory(logicFactory, instByLogic);

Expand Down
2 changes: 1 addition & 1 deletion test/access/EcoOwnable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("EcoOwnable", function () {
expect(await ecoOwnable.owner()).equal(initialOwner.address);
expect(await ecoOwnable.pendingOwner()).equal(hre.ethers.ZeroAddress);

await expect(ecoOwnable.initEcoOwnable(initialOwner)).reverted;
await expect(ecoOwnable._initEcoOwnable(initialOwner)).reverted;
});

it("transfer onwer", async function () {
Expand Down
2 changes: 1 addition & 1 deletion test/access/SelectorRoleControlUpgradeable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("SelectorRoleControlUpgradeable", function () {
const SelectorRoleControlUpgradeable = await hre.ethers.getContractFactory("SelectorRoleControlUpgradeable");
const role = await SelectorRoleControlUpgradeable.connect(initialOwner).deploy();

await expect(role.initEcoOwnable(initialOwner)).not.reverted;
await expect(role.initSelectorRoleControl(initialOwner)).not.reverted;

return { role, initialOwner, admin };
}
Expand Down
29 changes: 7 additions & 22 deletions test/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { expect } from "chai";
import { ContractFactory } from "ethers";
import hre from "hardhat";

import { ERC20MintableUpgradeable } from "../typechain-types";
import { EcoERC20Upgradeable } from "../typechain-types";

import { getSelector } from "./helper";

Expand All @@ -29,10 +29,9 @@ describe("ProxyContractTypeTest", function () {
async function Proxy_Helper_Fixture() {
const [owner] = await hre.ethers.getSigners();
const helper = await new ProxyContractTypeTest(
await hre.ethers.getContractFactory("ERC20MintableUpgradeable"),
name,
symbol,
await hre.ethers.getContractFactory("EcoERC20Upgradeable")
);
await helper.logic.initEcoERC20(owner, name, symbol, 18n);
return { owner, helper };
}

Expand All @@ -57,34 +56,20 @@ describe("ERC20 Mintable", function () {
const EcoProxyForProxyAdmin = await hre.ethers.getContractFactory("EcoProxyForProxyAdmin");
const pAdmin = await EcoProxyForProxyAdmin.deploy(admin, owner);

const ERC20 = await hre.ethers.getContractFactory("ERC20MintableUpgradeable");
const erc20 = await ERC20.deploy(name, symbol);
const ERC20 = await hre.ethers.getContractFactory("EcoERC20Upgradeable");
const erc20 = await ERC20.deploy();

const EcoTUPWithAdmin = await hre.ethers.getContractFactory("EcoTUPWithAdmin");
const inst = await EcoTUPWithAdmin.deploy(
pAdmin,
erc20,
erc20.interface.encodeFunctionData("initEcoERC20Mintable", [owner.address, name, symbol]),
erc20.interface.encodeFunctionData("initEcoERC20", [owner.address, name, symbol, 18n]),
);
const pErc20: ERC20MintableUpgradeable = erc20.attach(await inst.getAddress()) as ERC20MintableUpgradeable;
const pErc20: EcoERC20Upgradeable = erc20.attach(await inst.getAddress()) as EcoERC20Upgradeable;

return { owner, users, admin, pAdmin, erc20, pErc20 };
}

describe("Deployment", function () {
it("Should set the right owner", async function () {
const { pErc20, owner } = await loadFixture(NFT_Mintable_Fixture);

expect(await pErc20.owner()).to.equal(owner.address);
});

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);
});
});

describe("Non Fungible Token", function () {
describe("Mint", function () {
Expand Down
38 changes: 21 additions & 17 deletions test/proxy/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ describe("Proxy Test", function () {
async function fixtureProxyConfig() {
const [owner, ...users] = await hre.ethers.getSigners();

const ERC20 = await hre.ethers.getContractFactory("ERC20MintableUpgradeable");
const erc20Logic = await ERC20.deploy(name, symbol);
const ERC20 = await hre.ethers.getContractFactory("EcoERC20Upgradeable");
const erc20Logic = await ERC20.deploy();
await erc20Logic.initEcoERC20(owner, name, symbol, 18n);

const EcoProxyAdmin = await hre.ethers.getContractFactory("EcoProxyAdmin");
const proxyAdminLogic = await EcoProxyAdmin.deploy(owner);

const initData = erc20Logic.interface.encodeFunctionData("initEcoERC20Mintable", [owner.address, name, symbol]);
const initData = erc20Logic.interface.encodeFunctionData("initEcoERC20", [owner.address, name, symbol, 18n]);

const EcoTUPWithAdminLogic = await hre.ethers.getContractFactory("EcoTUPWithAdminLogic");
const proxy = await EcoTUPWithAdminLogic.deploy(proxyAdminLogic, erc20Logic, initData);

const proxyAdmin = await hre.ethers.getContractAt("EcoProxyAdmin", await getAdminAddress(proxy), owner);
const inst = await hre.ethers.getContractAt("ERC20MintableUpgradeable", proxy.target, owner);
const inst = await hre.ethers.getContractAt("EcoERC20Upgradeable", proxy.target, owner);

return { erc20Logic, proxyAdminLogic, proxyAdmin, proxy, inst, owner, users, EcoTUPWithAdminLogic };
}
Expand Down Expand Up @@ -51,22 +52,25 @@ describe("Proxy Test", function () {
});

it("upgrade check", async function () {
const { erc20Logic, proxyAdmin, proxy, inst, users } = await loadFixture(fixtureProxyConfig);
const { owner, erc20Logic, proxyAdmin, proxy, inst, users } = await loadFixture(fixtureProxyConfig);

const theDecimals = 6;
const ERC20Decimal = await hre.ethers.getContractFactory("ERC20MintableUpgradeableWithDecimal");
const erc20DecimalLogic = await ERC20Decimal.deploy(name, symbol, theDecimals);
const theDecimals = 6n;
const EcoERC20 = await hre.ethers.getContractFactory("EcoERC20Upgradeable");
const EcoERC20Logic = await EcoERC20.deploy();
await EcoERC20Logic.initEcoERC20(owner, name, symbol, theDecimals);

expect(await erc20Logic.decimals()).equal(18);
expect(await inst.decimals()).equal(18);
expect(await erc20DecimalLogic.decimals()).equal(theDecimals);
// test update, immutable decimals logic upgrade to state view return

await expect(proxyAdmin.connect(users[0]).upgradeAndCall(proxy, erc20DecimalLogic, "0x")).rejected;
await expect(proxyAdmin.upgradeAndCall(proxy, erc20DecimalLogic, "0x")).not.reverted;
// expect(await erc20Logic.decimals()).equal(18);
// expect(await inst.decimals()).equal(18);
// expect(await EcoERC20Logic.decimals()).equal(theDecimals);

expect(await inst.decimals()).equal(theDecimals);
expect(await inst.name()).equal(name);
expect(await inst.symbol()).equal(symbol);
// await expect(proxyAdmin.connect(users[0]).upgradeAndCall(proxy, EcoERC20Logic, "0x")).rejected;
// await expect(proxyAdmin.upgradeAndCall(proxy, EcoERC20Logic, "0x")).not.reverted;

// expect(await inst.decimals()).equal(theDecimals);
// expect(await inst.name()).equal(name);
// expect(await inst.symbol()).equal(symbol);
});

it("Proxy Admin call Proxy fail check", async function () {
Expand All @@ -75,7 +79,7 @@ describe("Proxy Test", function () {
const TestProxyAdminFail = await hre.ethers.getContractFactory("TestProxyAdminFail");
const testProxyAdminLogic = await TestProxyAdminFail.deploy();

const initData = erc20Logic.interface.encodeFunctionData("initEcoERC20Mintable", [owner.address, name, symbol]);
const initData = erc20Logic.interface.encodeFunctionData("initEcoERC20", [owner.address, name, symbol, 18n]);
const proxy = await EcoTUPWithAdminLogic.deploy(testProxyAdminLogic, erc20Logic, initData);

const proxyAdmin = await hre.ethers.getContractAt("TestProxyAdminFail", await getAdminAddress(proxy), owner);
Expand Down
8 changes: 4 additions & 4 deletions test/token/ERC20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ describe("ERC20 Mintable", function () {
async function NFT_Mintable_Fixture() {
const [owner, ...users] = await hre.ethers.getSigners();

const ERC20 = await hre.ethers.getContractFactory("ERC20MintableUpgradeableWithDecimal");
const erc20 = await ERC20.deploy(name, symbol, decimals);
// await erc20.initNFT_Mintable(owner.address, name, symbol); only for proxy
const ERC20 = await hre.ethers.getContractFactory("EcoERC20Upgradeable");
const erc20 = await ERC20.deploy();
await erc20.initEcoERC20(owner, name, symbol, decimals);

return { erc20, owner, users };
}
Expand All @@ -26,7 +26,7 @@ describe("ERC20 Mintable", function () {
const { erc20, owner } = await loadFixture(NFT_Mintable_Fixture);

expect(await erc20.owner()).to.equal(owner.address);
await expect(erc20.initEcoERC20Mintable(owner, name, symbol)).reverted;
await expect(erc20.initEcoERC20(owner, name, symbol, decimals)).reverted;
});

it("Should set the right metadata", async function () {
Expand Down

0 comments on commit 7c98890

Please sign in to comment.