Skip to content

Commit

Permalink
さらにテストコードを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
mashharuki committed Oct 27, 2024
1 parent c3af7fb commit 676d3a8
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 10 deletions.
4 changes: 3 additions & 1 deletion pkgs/contract/gas-report.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
··························|··············|·············|·············|···············|··············
| BigBang · - · - · 1248128 · 4.2 % · - │
··························|··············|·············|·············|···············|··············
| BigBang_Mock_v2 · - · - · 1326614 · 4.4 % · - │
··························|··············|·············|·············|···············|··············
| FractionToken · - · - · 2893315 · 9.6 % · - │
··························|··············|·············|·············|···············|··············
| FractionToken_Mock_v2 · - · - · 3037174 · 10.1 % · - │
Expand All @@ -17,7 +19,7 @@
··························|··············|·············|·············|···············|··············
| HatsModule · - · - · 754132 · 2.5 % · - │
··························|··············|·············|·············|···············|··············
| HatsModuleFactory · 1101110 · 1101122 · 1101118 · 3.7 % · - │
| HatsModuleFactory · - · - · 1101122 · 3.7 % · - │
··························|··············|·············|·············|···············|··············
| HatsTimeFrameModule · - · - · 1287099 · 4.3 % · - │
··························|··············|·············|·············|···············|··············
Expand Down
11 changes: 2 additions & 9 deletions pkgs/contract/helpers/upgrade.ts/bigbang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,10 @@ export const upgradeBigBang = async (
// アップグレードを実行
const _BigBang = (await upgrades.upgradeProxy(
contractAddress,
BigBang_Mock_v2,
params && {
call: {
fn: "initialize",
args: params,
},
}
BigBang_Mock_v2
)) as any;

await _BigBang.deployed();
const address = await _BigBang.getAddress();
const address = _BigBang.target;

console.log("upgraded address:", address);

Expand Down
2 changes: 2 additions & 0 deletions pkgs/contract/helpers/upgrade.ts/fractionToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export const upgradeFractionToken = async (

const address = _FractionToken.target;

console.log("upgraded address:", address);

// create a new instance of the contract
const newFractionToken = await viem.getContractAt(
contractName,
Expand Down
60 changes: 60 additions & 0 deletions pkgs/contract/test/BigBang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
SplitsCreatorFactory,
SplitsWarehouse,
} from "../helpers/deploy/Splits";
import { upgradeBigBang } from "../helpers/upgrade.ts/bigbang";

describe("BigBang", () => {
let Hats: Hats;
Expand Down Expand Up @@ -131,4 +132,63 @@ describe("BigBang", () => {
} catch (error) {}
}
});

/**
* 以降は、Upgradeのテストコードになる。
* Upgrade後に再度機能をテストする。
*/
describe("Upgrade Test", () => {
it("upgrde", async () => {
// BigBangをアップグレード
const newBigBang = await upgradeBigBang(
BigBang.address,
"BigBang_Mock_v2",
["", 10000n, Hats.address, zeroAddress]
);

// upgrade後にしかないメソッドを実行
const result = await newBigBang.read.testUpgradeFunction();
expect(result).to.equal("testUpgradeFunction");
});

it("should execute bigbang after upgrade", async () => {
// BigBangをアップグレード
const newBigBang = await upgradeBigBang(
BigBang.address,
"BigBang_Mock_v2",
["", 10000n, Hats.address, zeroAddress]
);

const txHash = await newBigBang.write.bigbang(
[
address1.account?.address!,
"tophatDetails",
"tophatURI",
"hatterhatDetails",
"hatterhatURI",
address1.account?.address!,
],
{ account: address1.account }
);

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

for (const log of receipt.logs) {
try {
const decodedLog: any = decodeEventLog({
abi: newBigBang.abi as any,
data: log.data,
topics: log.topics,
});
if (decodedLog.eventName == "Executed") {
expect(decodedLog.args.owner.toLowerCase()).to.be.equal(
address1.account?.address!
);
}
} catch (error) {}
}
});
});
});

0 comments on commit 676d3a8

Please sign in to comment.