Skip to content

Commit 0f5d3f7

Browse files
committed
feat: migration to hh v3
1 parent 2640de0 commit 0f5d3f7

4 files changed

Lines changed: 65 additions & 72 deletions

File tree

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
1-
import { HardhatRuntimeEnvironment } from "hardhat/types";
2-
import { DeployFunction } from "hardhat-deploy/types";
3-
import { ethers } from "hardhat/";
4-
import { DiceGame } from "../typechain-types/";
5-
6-
const deployDiceGame: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
7-
const { deployer } = await hre.getNamedAccounts();
8-
const { deploy } = hre.deployments;
9-
10-
await deploy("DiceGame", {
11-
from: deployer,
12-
value: String(ethers.parseEther("0.05")),
13-
log: true,
14-
});
15-
16-
// Simple example on how get the deployed dice game contract
17-
const diceGame: DiceGame = await ethers.getContract("DiceGame");
18-
19-
const diceGameAddress = await diceGame.getAddress();
20-
21-
console.log("Deployed Dice Game Contract Address", diceGameAddress);
22-
23-
const balance = await ethers.provider.getBalance(diceGameAddress);
24-
console.log("Deployed Dice Game Contract Balance", ethers.formatEther(balance.toString()));
25-
};
26-
27-
export default deployDiceGame;
28-
29-
deployDiceGame.tags = ["DiceGame"];
1+
import { artifacts, deployScript } from "../rocketh/deploy.js";
2+
import { parseEther, formatEther } from "viem";
3+
4+
export default deployScript(
5+
async env => {
6+
const { deployer } = env.namedAccounts;
7+
8+
const diceGame = await env.deploy("DiceGame", {
9+
account: deployer,
10+
artifact: artifacts.DiceGame,
11+
args: [],
12+
value: parseEther("0.05"),
13+
});
14+
15+
console.log("Deployed Dice Game Contract Address", diceGame.address);
16+
17+
const balanceHex = (await env.network.provider.request({
18+
method: "eth_getBalance",
19+
params: [diceGame.address, "latest"],
20+
})) as `0x${string}`;
21+
console.log("Deployed Dice Game Contract Balance", formatEther(BigInt(balanceHex)));
22+
},
23+
{ tags: ["DiceGame"] },
24+
);
Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
1-
import { HardhatRuntimeEnvironment } from "hardhat/types";
2-
import { DeployFunction } from "hardhat-deploy/types";
3-
import { ethers } from "hardhat/";
4-
import { DiceGame, RiggedRoll } from "../typechain-types";
1+
import { deployScript } from "../rocketh/deploy.js";
52

6-
const deployRiggedRoll: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
7-
const { deployer } = await hre.getNamedAccounts();
8-
const { deploy } = hre.deployments;
3+
export default deployScript(
4+
async env => {
5+
const diceGame = env.get("DiceGame");
6+
const diceGameAddress = diceGame.address;
97

10-
const diceGame: DiceGame = await ethers.getContract("DiceGame");
11-
const diceGameAddress = await diceGame.getAddress();
8+
// Uncomment to deploy RiggedRoll contract
9+
// const riggedRoll = await env.deploy("RiggedRoll", {
10+
// account: env.namedAccounts.deployer,
11+
// artifact: artifacts.RiggedRoll,
12+
// args: [diceGameAddress],
13+
// });
1214

13-
// Uncomment to deploy RiggedRoll contract
14-
// await deploy("RiggedRoll", {
15-
// from: deployer,
16-
// log: true,
17-
// args: [diceGameAddress],
18-
// autoMine: true,
19-
// });
20-
21-
// const riggedRoll: RiggedRoll = await ethers.getContract("RiggedRoll", deployer);
22-
23-
// Please replace the text "Your Address" with your own address.
24-
// try {
25-
// await riggedRoll.transferOwnership("Your Address");
26-
// } catch (err) {
27-
// console.log(err);
28-
// }
29-
};
30-
31-
export default deployRiggedRoll;
32-
33-
deployRiggedRoll.tags = ["RiggedRoll"];
15+
// Please replace the text "Your Address" with your own address.
16+
// try {
17+
// await env.execute(riggedRoll, {
18+
// functionName: "transferOwnership",
19+
// args: ["Your Address"],
20+
// account: env.namedAccounts.deployer,
21+
// });
22+
// } catch (err) {
23+
// console.log(err);
24+
// }
25+
void diceGameAddress;
26+
},
27+
{ tags: ["RiggedRoll"] },
28+
);

extension/packages/hardhat/test/RiggedRoll.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1-
import hre from "hardhat";
1+
import { network } from "hardhat";
22
import { expect } from "chai";
33
// import { parseEther } from "ethers";
4-
import { DiceGame, RiggedRoll, RiggedRoll__factory } from "../typechain-types";
5-
import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";
6-
7-
const { ethers } = hre;
4+
import type { DiceGame, RiggedRoll, RiggedRoll__factory } from "../types/ethers-contracts/index.js";
5+
import type { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/types";
86

97
describe("🚩 Challenge: 🎲 Dice Game", function () {
8+
let ethers: Awaited<ReturnType<typeof network.create>>["ethers"];
9+
let provider: Awaited<ReturnType<typeof network.create>>["ethers"]["provider"];
10+
1011
let diceGame: DiceGame;
1112
let riggedRoll: RiggedRoll;
1213
let deployer: HardhatEthersSigner;
13-
const { provider } = ethers;
1414

1515
const rollAmountString = "0.002";
16-
const rollAmount = ethers.parseEther(rollAmountString);
16+
let rollAmount: bigint;
17+
18+
before(async function () {
19+
({ ethers } = await network.create());
20+
provider = ethers.provider;
21+
rollAmount = ethers.parseEther(rollAmountString);
22+
});
1723

1824
async function deployContracts() {
1925
[deployer] = await ethers.getSigners();
2026
const DiceGame = await ethers.getContractFactory("DiceGame");
21-
diceGame = await DiceGame.deploy();
27+
diceGame = (await DiceGame.deploy()) as unknown as DiceGame;
2228

2329
const contractAddress = process.env.CONTRACT_ADDRESS;
2430
let contractArtifact;
@@ -29,8 +35,8 @@ describe("🚩 Challenge: 🎲 Dice Game", function () {
2935
}
3036

3137
const diceGameAddress = await diceGame.getAddress();
32-
const RiggedRoll = (await ethers.getContractFactory(contractArtifact)) as RiggedRoll__factory;
33-
riggedRoll = await RiggedRoll.deploy(diceGameAddress);
38+
const RiggedRoll = (await ethers.getContractFactory(contractArtifact)) as unknown as RiggedRoll__factory;
39+
riggedRoll = (await RiggedRoll.deploy(diceGameAddress)) as unknown as RiggedRoll;
3440
}
3541

3642
async function fundRiggedContract() {

extension/packages/nextjs/next.config.ts.args.mjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@ export const configOverrides = {
22
typescript: {
33
ignoreBuildErrors: true,
44
},
5-
eslint: {
6-
ignoreDuringBuilds: true,
7-
},
85
};

0 commit comments

Comments
 (0)