Skip to content

Commit

Permalink
テストコード修正しました。
Browse files Browse the repository at this point in the history
  • Loading branch information
mashharuki committed Oct 21, 2024
1 parent d55f21b commit 0856cee
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 231 deletions.
70 changes: 31 additions & 39 deletions pkgs/contract/gas-report.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
·--------------------------------------|----------------------------|-------------|-----------------------------·
| Solc version: 0.8.24 · Optimizer enabled: false · Runs: 200 · Block limit: 30000000 gas │
·······································|····························|·············|······························
| Methods │
··················|····················|··············|·············|·············|···············|··············
| Contract · Method · Min · Max · Avg · # calls · usd (avg) │
··················|····················|··············|·············|·············|···············|··············
| BigBang · bigbang · - · - · 603669 · 2 · - │
··················|····················|··············|·············|·············|···············|··············
| FractionToken · burn · 41544 · 55511 · 47442 · 4 · - │
··················|····················|··············|·············|·············|···············|··············
| FractionToken · mint · 135046 · 137558 · 136717 · 9 · - │
··················|····················|··············|·············|·············|···············|··············
| FractionToken · safeTransferFrom · 106335 · 106347 · 106339 · 3 · - │
··················|····················|··············|·············|·············|···············|··············
| Deployments · · % of limit · │
·······································|··············|·············|·············|···············|··············
| BigBang · - · - · 1248128 · 4.2 % · - │
·······································|··············|·············|·············|···············|··············
| FractionToken · - · - · 2859199 · 9.5 % · - │
·······································|··············|·············|·············|···············|··············
| Hats · - · - · 7032431 · 23.4 % · - │
·······································|··············|·············|·············|···············|··············
| HatsModule · - · - · 754132 · 2.5 % · - │
·······································|··············|·············|·············|···············|··············
| HatsModuleFactory · - · - · 1101122 · 3.7 % · - │
·······································|··············|·············|·············|···············|··············
| HatsTimeFrameModule · - · - · 1287099 · 4.3 % · - │
·······································|··············|·············|·············|···············|··············
| PullSplitFactory · 4535815 · 4535827 · 4535825 · 15.1 % · - │
·······································|··············|·············|·············|···············|··············
| PushSplitFactory · 4483101 · 4483113 · 4483111 · 14.9 % · - │
·······································|··············|·············|·············|···············|··············
| SplitsCreator · - · - · 1487532 · 5 % · - │
·······································|··············|·············|·············|···············|··············
| SplitsCreatorFactory · 526824 · 526836 · 526833 · 1.8 % · - │
·······································|··············|·············|·············|···············|··············
| SplitsWarehouse · - · - · 3934655 · 13.1 % · - │
·--------------------------------------|--------------|-------------|-------------|---------------|-------------·
·------------------------|----------------------------|-------------|-----------------------------·
| Solc version: 0.8.24 · Optimizer enabled: false · Runs: 200 · Block limit: 30000000 gas │
·························|····························|·············|······························
| Methods │
··············|··········|··············|·············|·············|···············|··············
| Contract · Method · Min · Max · Avg · # calls · usd (avg) │
··············|··········|··············|·············|·············|···············|··············
| Deployments · · % of limit · │
·························|··············|·············|·············|···············|··············
| BigBang · - · - · 1248128 · 4.2 % · - │
·························|··············|·············|·············|···············|··············
| FractionToken · - · - · 2859199 · 9.5 % · - │
·························|··············|·············|·············|···············|··············
| Hats · - · - · 7032431 · 23.4 % · - │
·························|··············|·············|·············|···············|··············
| HatsModule · - · - · 754132 · 2.5 % · - │
·························|··············|·············|·············|···············|··············
| HatsModuleFactory · - · - · 1101122 · 3.7 % · - │
·························|··············|·············|·············|···············|··············
| HatsTimeFrameModule · - · - · 1287099 · 4.3 % · - │
·························|··············|·············|·············|···············|··············
| PullSplitFactory · - · - · 4535827 · 15.1 % · - │
·························|··············|·············|·············|···············|··············
| PushSplitFactory · - · - · 4483113 · 14.9 % · - │
·························|··············|·············|·············|···············|··············
| SplitsCreator · - · - · 1487532 · 5 % · - │
·························|··············|·············|·············|···············|··············
| SplitsCreatorFactory · - · - · 526836 · 1.8 % · - │
·························|··············|·············|·············|···············|··············
| SplitsWarehouse · - · - · 3934655 · 13.1 % · - │
·------------------------|--------------|-------------|-------------|---------------|-------------·
12 changes: 6 additions & 6 deletions pkgs/contract/helpers/deploy/BigBang.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ethers, upgrades } from "hardhat";
import { ethers, upgrades, viem } from "hardhat";
import { Address } from "viem";

export type BigBang = Awaited<ReturnType<typeof deployBigBang>>["BigBang"];
Expand All @@ -25,7 +25,7 @@ export const deployBigBang = async (params: {
*/

const bigBang = await ethers.getContractFactory("BigBang");
const BigBang = await upgrades.deployProxy(
const _BigBang = await upgrades.deployProxy(
bigBang,
[
params.trustedForwarder,
Expand All @@ -41,11 +41,11 @@ export const deployBigBang = async (params: {
}
);

const tx = await BigBang.deploymentTransaction();
await tx?.wait();
await _BigBang.waitForDeployment();
const address = await _BigBang.getAddress();

// console.log("BigBang deployed at", tx);
// console.log("BigBang deployed at", BigBang.target);
// create a new instance of the contract
const BigBang = await viem.getContractAt("BigBang", address as Address);

return { BigBang };
};
14 changes: 10 additions & 4 deletions pkgs/contract/helpers/deploy/FractionToken.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ethers, upgrades } from "hardhat";
import { ethers, upgrades, viem } from "hardhat";
import { Address } from "viem";

export type FractionToken = Awaited<
Expand All @@ -12,16 +12,22 @@ export const deployFractionToken = async (
forwarderAddress: Address
) => {
const fractionToken = await ethers.getContractFactory("FractionToken");
const FractionToken = await upgrades.deployProxy(
const _FractionToken = await upgrades.deployProxy(
fractionToken,
[uri, tokenSupply, hatsContractAddress, forwarderAddress],
{
initializer: "initialize",
}
);

const tx = await FractionToken.deploymentTransaction();
await tx?.wait();
await _FractionToken.waitForDeployment();
const address = await _FractionToken.getAddress();

// create a new instance of the contract
const FractionToken = await viem.getContractAt(
"FractionToken",
address as Address
);

return { FractionToken };
};
6 changes: 3 additions & 3 deletions pkgs/contract/scripts/deploy/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const deployAll = async () => {
hatsTimeFrameModule_impl: HatsTimeFrameModule.address,
splitsCreatorFactoryAddress: SplitsCreatorFactory.address,
splitsFactoryV2Address: PullSplitsFactory as Address,
fractionTokenAddress: FractionToken.target as `0x${string}`,
fractionTokenAddress: FractionToken.address,
});

console.log("BigBang deployed at", BigBang.address);
Expand All @@ -64,13 +64,13 @@ const deployAll = async () => {
writeContractAddress({
group: "contracts",
name: "BigBang",
value: BigBang.target as `0x${string}`,
value: BigBang.address,
network: network.name,
});
writeContractAddress({
group: "contracts",
name: "FractionToken",
value: FractionToken.target as `0x${string}`,
value: FractionToken.address,
network: network.name,
});
writeContractAddress({
Expand Down
22 changes: 12 additions & 10 deletions pkgs/contract/test/BigBang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,29 @@ describe("BigBang", () => {
hatsTimeFrameModule_impl: HatsTimeFrameModule_IMPL.address,
splitsCreatorFactoryAddress: SplitsCreatorFactory.address,
splitsFactoryV2Address: PullSplitsFactory.address,
fractionTokenAddress: FractionToken.target as `0x${string}`,
fractionTokenAddress: FractionToken.address,
});

expect(_BigBang.target).to.not.be.undefined;
expect(_BigBang.address).to.not.be.undefined;

BigBang = _BigBang;
});

it("should execute bigbang", async () => {
const tx = await BigBang.bigbang(
address1.account?.address!,
"tophatDetails",
"tophatURI",
"hatterhatDetails",
"hatterhatURI",
address1.account?.address!,
const txHash = await BigBang.write.bigbang(
[
address1.account?.address!,
"tophatDetails",
"tophatURI",
"hatterhatDetails",
"hatterhatURI",
address1.account?.address!,
],
{ account: address1.account }
);

const receipt = await publicClient.waitForTransactionReceipt({
hash: tx.hash,
hash: txHash,
});

for (const log of receipt.logs) {
Expand Down
78 changes: 33 additions & 45 deletions pkgs/contract/test/Burn.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { expect } from "chai";
import { Signer } from "ethers";
import { ethers, viem } from "hardhat";
import { viem } from "hardhat";
import { decodeEventLog, PublicClient, WalletClient, zeroAddress } from "viem";
import {
deployFractionToken,
Expand All @@ -16,10 +15,6 @@ describe("Burn", () => {
let address2: WalletClient;
let address3: WalletClient;

let signer1: Signer;
let signer2: Signer;
let signer3: Signer;

let hatId: bigint;

let publicClient: PublicClient;
Expand All @@ -38,8 +33,6 @@ describe("Burn", () => {

[address1, address2, address3] = await viem.getWalletClients();

[signer1, signer2, signer3] = await ethers.getSigners();

publicClient = await viem.getPublicClient();

await Hats.write.mintTopHat([
Expand Down Expand Up @@ -80,55 +73,50 @@ describe("Burn", () => {
await Hats.write.mintHat([hatId, address2.account?.address!]);

// address1とaddress2にFractionTokenをmint
await FractionToken.mint(hatId, address1.account?.address!);
await FractionToken.mint(hatId, address2.account?.address!);
await FractionToken.write.mint([hatId, address1.account?.address!]);
await FractionToken.write.mint([hatId, address2.account?.address!]);

const tokenId = await FractionToken.getTokenId(
const tokenId = await FractionToken.read.getTokenId([
hatId,
address2.account?.address!
);
address2.account?.address!,
]);

// address2のtokenの半分をaddress3に移動
await (FractionToken as any)
.connect(signer2)
.safeTransferFrom(
await FractionToken.write.safeTransferFrom(
[
address2.account?.address!,
address3.account?.address!,
tokenId,
5000n,
"0x"
);
"0x",
],
{
account: address2.account!,
}
);
});

it("should burn tokens", async () => {
// address1のtokenを自身で半分burnする
await FractionToken.burn(
address1.account?.address!,
address1.account?.address!,
hatId,
5000n,
await FractionToken.write.burn(
[address1.account?.address!, address1.account?.address!, hatId, 5000n],
{
account: address1.account!,
}
);

// address3のtokenをaddress2によってすべてburnする
await (FractionToken as any)
.connect(signer3)
.burn(
address3.account?.address!,
address2.account?.address!,
hatId,
5000n
);
await FractionToken.write.burn(
[address3.account?.address!, address2.account?.address!, hatId, 5000n],
{
account: address2.account!,
}
);

// address3のtokenをaddress1によってすべてburnするとRevertする
await expect(
FractionToken.burn(
address3.account?.address!,
address2.account?.address!,
hatId,
5000n,
FractionToken.write.burn(
[address3.account?.address!, address2.account?.address!, hatId, 5000n],
{
account: address1.account!,
}
Expand All @@ -138,27 +126,27 @@ describe("Burn", () => {
let balance: bigint;

// address1のbalance
balance = await FractionToken["balanceOf(address,address,uint256)"](
balance = await FractionToken.read.balanceOf([
address1.account?.address!,
address1.account?.address!,
hatId
);
hatId,
]);
expect(balance).to.equal(5000n);

// address2のbalance
balance = await FractionToken["balanceOf(address,address,uint256)"](
balance = await FractionToken.read.balanceOf([
address2.account?.address!,
address2.account?.address!,
hatId
);
hatId,
]);
expect(balance).to.equal(5000n);

// address3のbalance
balance = await FractionToken["balanceOf(address,address,uint256)"](
balance = await FractionToken.read.balanceOf([
address3.account?.address!,
address2.account?.address!,
hatId
);
hatId,
]);
expect(balance).to.equal(0n);
});
});
Loading

0 comments on commit 0856cee

Please sign in to comment.