|
@@ -1,24 +1,38 @@
|
|
|
+import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
|
|
|
import type { SignerWithAddress } from "@nomiclabs/hardhat-ethers/dist/src/signer-with-address";
|
|
|
-import { artifacts, ethers, waffle } from "hardhat";
|
|
|
-import type { Artifact } from "hardhat/types";
|
|
|
+import { ethers } from "hardhat";
|
|
|
|
|
|
import type { Greeter } from "../../src/types/Greeter";
|
|
|
-import { Signers } from "../types";
|
|
|
+import type { Greeter__factory } from "../../src/types/factories/Greeter__factory";
|
|
|
+import type { Signers } from "../types";
|
|
|
import { shouldBehaveLikeGreeter } from "./Greeter.behavior";
|
|
|
|
|
|
describe("Unit tests", function () {
|
|
|
+ async function deployGreeterFixture(): Promise<{ greeter: Greeter }> {
|
|
|
+ const signers: SignerWithAddress[] = await ethers.getSigners();
|
|
|
+ const admin: SignerWithAddress = signers[0];
|
|
|
+
|
|
|
+ const greeting: string = "Hello, world!";
|
|
|
+ const greeterFactory: Greeter__factory = <Greeter__factory>await ethers.getContractFactory("Greeter");
|
|
|
+ const greeter: Greeter = <Greeter>await greeterFactory.connect(admin).deploy(greeting);
|
|
|
+ await greeter.deployed();
|
|
|
+
|
|
|
+ return { greeter };
|
|
|
+ }
|
|
|
+
|
|
|
before(async function () {
|
|
|
this.signers = {} as Signers;
|
|
|
|
|
|
const signers: SignerWithAddress[] = await ethers.getSigners();
|
|
|
this.signers.admin = signers[0];
|
|
|
+
|
|
|
+ this.loadFixture = loadFixture;
|
|
|
});
|
|
|
|
|
|
describe("Greeter", function () {
|
|
|
beforeEach(async function () {
|
|
|
- const greeting: string = "Hello, world!";
|
|
|
- const greeterArtifact: Artifact = await artifacts.readArtifact("Greeter");
|
|
|
- this.greeter = <Greeter>await waffle.deployContract(this.signers.admin, greeterArtifact, [greeting]);
|
|
|
+ const { greeter } = await this.loadFixture(deployGreeterFixture);
|
|
|
+ this.greeter = greeter;
|
|
|
});
|
|
|
|
|
|
shouldBehaveLikeGreeter();
|