-
Notifications
You must be signed in to change notification settings - Fork 92
/
Factory.ts
61 lines (55 loc) · 2.11 KB
/
Factory.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { loadFixture } from "@nomicfoundation/hardhat-toolbox-viem/network-helpers";
import { expect } from "chai";
import hre from "hardhat";
describe("Factory", function () {
async function deployFixture() {
const factory = await hre.viem.deployContract("Factory");
const publicClient = await hre.viem.getPublicClient();
return {
factory,
publicClient,
};
}
it("createPool", async function () {
const { factory, publicClient } = await loadFixture(deployFixture);
const tokenA: `0x${string}` = "0xEcd0D12E21805803f70de03B72B1C162dB0898d9";
const tokenB: `0x${string}` = "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984";
const hash = await factory.write.createPool([
tokenA,
tokenB,
1,
100000,
3000,
]);
await publicClient.waitForTransactionReceipt({ hash });
const createEvents = await factory.getEvents.PoolCreated();
expect(createEvents).to.have.lengthOf(1);
expect(createEvents[0].args.pool).to.match(/^0x[a-fA-F0-9]{40}$/);
expect(createEvents[0].args.token0).to.equal(tokenB);
expect(createEvents[0].args.token1).to.equal(tokenA);
expect(createEvents[0].args.tickLower).to.equal(1);
expect(createEvents[0].args.tickUpper).to.equal(100000);
expect(createEvents[0].args.fee).to.equal(3000);
// simulate for test return address
const poolAddress = await factory.simulate.createPool([
tokenA,
tokenB,
1,
100000,
3000,
]);
expect(poolAddress.result).to.match(/^0x[a-fA-F0-9]{40}$/);
expect(poolAddress.result).to.equal(createEvents[0].args.pool);
});
it("createPool with same token", async function () {
const { factory } = await loadFixture(deployFixture);
const tokenA: `0x${string}` = "0xEcd0D12E21805803f70de03B72B1C162dB0898d9";
const tokenB: `0x${string}` = "0xEcd0D12E21805803f70de03B72B1C162dB0898d9";
await expect(
factory.write.createPool([tokenA, tokenB, 1, 100000, 3000])
).to.be.rejectedWith("IDENTICAL_ADDRESSES");
await expect(factory.read.getPool([tokenA, tokenB, 3])).to.be.rejectedWith(
"IDENTICAL_ADDRESSES"
);
});
});