This repository was archived by the owner on Oct 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathtoken-registry.test.ts
More file actions
89 lines (79 loc) · 4.48 KB
/
token-registry.test.ts
File metadata and controls
89 lines (79 loc) · 4.48 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { deployTokenRegistry } from "./token-registry";
import { encodeInitParams } from "./helpers";
import { Contract } from "ethers";
import { DeployTokenRegistryCommand } from "../../../commands/deploy/deploy.types";
import { DeploymentEvent } from "@govtechsg/token-registry/dist/contracts/contracts/utils/TDocDeployer";
const deployParams: DeployTokenRegistryCommand = {
registryName: "Test",
registrySymbol: "Tst",
network: "goerli",
key: "0000000000000000000000000000000000000000000000000000000000000001",
dryRun: false,
};
describe("token-registry", () => {
describe("deployTokenRegistry", () => {
const mockedEthersContract: jest.Mock<Contract> = Contract as any;
// eslint-disable-next-line jest/prefer-spy-on
mockedEthersContract.prototype.deploy = jest.fn();
const mockedDeploy: jest.Mock = mockedEthersContract.prototype.deploy;
// increase timeout because ethers is throttling
jest.setTimeout(30000);
beforeEach(() => {
mockedDeploy.mockReset();
mockedDeploy.mockResolvedValue({
hash: "hash",
blockNumber: "blockNumber",
wait: () =>
Promise.resolve({
events: [
{
topics: [
"0x3588ebb5c75fdf91927f8472318f41513ee567c2612a5ce52ac840dcf6f162f5", // deployment
"0x000000000000000000000000426c58c2b29111eafc53bdcb9c99dc7714fdb262",
"0x000000000000000000000000e5c75026d5f636c89cc77583b6bce7c99f512763",
"0x0000000000000000000000008d366250a96debe81c8619459a503a0eebe33ca6",
],
data: "0x000000000000000000000000878a327daa390bc602ae259d3a374610356b6485000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000008d366250a96debe81c8619459a503a0eebe33ca60000000000000000000000000000000000000000000000000000000000000011563420546f6b656e20526567697374727900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034d54540000000000000000000000000000000000000000000000000000000000",
args: [
"0xd6C249d0756059E21Ef4Aef4711B69b76927BEA7",
"0xC78BA1a49663Ef8b920F36B036E91Ab40D8F26D6",
"0x8d366250A96deBE81C8619459a503a0eEBE33ca6",
"0x878A327daA390Bc602Ae259D3A374610356b6485",
"0x000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000008d366250a96debe81c8619459a503a0eebe33ca60000000000000000000000000000000000000000000000000000000000000011563420546f6b656e20526567697374727900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034d54540000000000000000000000000000000000000000000000000000000000",
] as unknown as DeploymentEvent,
},
],
}),
});
});
it("should pass in the correct params and return the deployed instance", async () => {
await deployTokenRegistry(deployParams);
const expectedInitParams = encodeInitParams({
name: deployParams.registryName,
symbol: deployParams.registrySymbol,
deployer: "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf",
});
expect(mockedDeploy.mock.calls[0][0]).toEqual("0xC78BA1a49663Ef8b920F36B036E91Ab40D8F26D6");
expect(mockedDeploy.mock.calls[0][1]).toEqual(expectedInitParams);
// price should be any length string of digits
// expect(mockedDeploy.mock.calls[0][2].gasPrice.toString()).toStrictEqual(expect.stringMatching(/\d+/));
// expect(instance.contractAddress).toBe("contractAddress"); // TODO
});
it("should allow errors to bubble up", async () => {
mockedDeploy.mockRejectedValue(new Error("An Error"));
await expect(deployTokenRegistry(deployParams)).rejects.toThrow("An Error");
});
it("should throw when keys are not found anywhere", async () => {
await expect(
deployTokenRegistry({
registryName: "Test",
registrySymbol: "Tst",
network: "goerli",
dryRun: false,
})
).rejects.toThrow(
"No private key found in OA_PRIVATE_KEY, key, key-file, please supply at least one or supply an encrypted wallet path, or provide aws kms signer information"
);
});
});
});