-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathTradeTrustTokenPausable.test.ts
249 lines (188 loc) · 8.51 KB
/
TradeTrustTokenPausable.test.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
import { TitleEscrow, TradeTrustToken, TradeTrustTokenMock } from "@tradetrust/contracts";
import faker from "faker";
import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
import { expect } from ".";
import { deployTokenFixture, DeployTokenFixtureRunner, mintTokenFixture } from "./fixtures";
import {
createDeployFixtureRunner,
getTestUsers,
impersonateAccount,
TestUsers,
toAccessControlRevertMessage,
} from "./helpers";
import { roleHash } from "../src/constants";
describe("TradeTrustToken Pausable Behaviour", async () => {
let users: TestUsers;
let registryContract: TradeTrustToken;
let registryContractAsAdmin: TradeTrustToken;
let registryContractAsNonAdmin: TradeTrustToken;
let deployTokenFixturesRunner: DeployTokenFixtureRunner;
// eslint-disable-next-line no-undef
before(async () => {
users = await getTestUsers();
deployTokenFixturesRunner = async () =>
createDeployFixtureRunner(
...(await deployTokenFixture<TradeTrustToken>({
tokenContractName: "TradeTrustToken",
tokenName: "The Great Shipping Company",
tokenInitials: "GSC",
deployer: users.carrier,
}))
);
});
describe("Rights to pause and unpause registry", () => {
beforeEach(async () => {
[, registryContract] = await loadFixture(deployTokenFixturesRunner);
registryContractAsAdmin = registryContract.connect(users.carrier);
registryContractAsNonAdmin = registryContract.connect(users.beneficiary);
});
describe("When registry is paused", () => {
beforeEach(async () => {
await registryContractAsAdmin.pause();
const paused = await registryContract.paused();
expect(paused).to.be.true;
});
it("should allow admin to unpause", async () => {
await registryContractAsAdmin.unpause();
const paused = await registryContract.paused();
expect(paused).to.be.false;
});
it("should not allow non-admin to unpause", async () => {
const tx = registryContractAsNonAdmin.unpause();
await expect(tx).to.be.revertedWith(
toAccessControlRevertMessage(users.beneficiary.address, roleHash.DefaultAdmin)
);
});
});
describe("When registry is unpaused", () => {
beforeEach(async () => {
const paused = await registryContract.paused();
expect(paused).to.be.false;
});
it("should allow admin to pause", async () => {
await registryContractAsAdmin.pause();
const paused = await registryContract.paused();
expect(paused).to.be.true;
});
it("should not allow non-admin to pause", async () => {
const tx = registryContractAsNonAdmin.pause();
await expect(tx).to.be.revertedWith(
toAccessControlRevertMessage(users.beneficiary.address, roleHash.DefaultAdmin)
);
});
});
});
describe("When Token Registry is paused", () => {
let tokenId: string;
beforeEach(async () => {
tokenId = faker.datatype.hexaDecimal(64);
});
describe("Minting and Transfers", () => {
it("should not allow minting of tokens", async () => {
await registryContractAsAdmin.pause();
const tx = registryContractAsAdmin.mint(users.beneficiary.address, users.beneficiary.address, tokenId);
await expect(tx).to.be.revertedWith("Pausable: paused");
});
it("should not allow transfers token", async () => {
const [titleEscrowFactoryContract, registryContractMock] = await deployTokenFixture<TradeTrustTokenMock>({
tokenContractName: "TradeTrustTokenMock",
tokenName: "The Great Shipping Company",
tokenInitials: "GSC",
deployer: users.carrier,
});
const tokenRecipientAddress = await titleEscrowFactoryContract.getAddress(
registryContractMock.address,
tokenId
);
const tokenRecipientSigner = await impersonateAccount({ address: tokenRecipientAddress });
await registryContractMock.mintInternal(tokenRecipientAddress, tokenId);
await registryContractMock.pause();
const tx = registryContractMock
.connect(tokenRecipientSigner)
.transferFrom(tokenRecipientAddress, users.holder.address, tokenId);
await expect(tx).to.be.revertedWith("Pausable: paused");
});
});
describe("Token Registry and Title Escrow Behaviours", () => {
let titleEscrowContract: TitleEscrow;
// eslint-disable-next-line no-undef
let deployFixturesRunner: () => Promise<[TradeTrustToken, TitleEscrow]>;
// eslint-disable-next-line no-undef
before(async () => {
deployFixturesRunner = async () => {
const [, registryContractFixture] = await deployTokenFixture<TradeTrustToken>({
tokenContractName: "TradeTrustToken",
tokenName: "The Great Shipping Company",
tokenInitials: "GSC",
deployer: users.carrier,
});
const registryContractFixtureAsAdmin = registryContractFixture.connect(users.carrier);
const { titleEscrow: titleEscrowFixture } = await mintTokenFixture({
token: registryContractFixtureAsAdmin,
beneficiary: users.beneficiary,
holder: users.beneficiary,
tokenId,
});
return [registryContractFixture, titleEscrowFixture];
};
});
beforeEach(async () => {
[registryContract, titleEscrowContract] = await loadFixture(deployFixturesRunner);
registryContractAsAdmin = registryContract.connect(users.carrier);
registryContractAsNonAdmin = registryContract.connect(users.beneficiary);
});
describe("Token Registry Behaviour", () => {
beforeEach(async () => {
await titleEscrowContract.connect(users.beneficiary).surrender();
await registryContractAsAdmin.pause();
const paused = await registryContract.paused();
expect(paused).to.be.true;
});
it("should not allow restoring token", async () => {
const tx = registryContractAsAdmin.restore(tokenId);
await expect(tx).to.be.revertedWith("Pausable: paused");
});
it("should not allow accepting token", async () => {
const tx = registryContractAsAdmin.burn(tokenId);
await expect(tx).to.be.revertedWith("Pausable: paused");
});
});
describe("Title Escrow Behaviour", () => {
beforeEach(async () => {
await registryContractAsAdmin.pause();
const paused = await registryContract.paused();
expect(paused).to.be.true;
});
it("should not allow onERC721Received", async () => {
const fakeAddress = faker.finance.ethereumAddress();
const tx = titleEscrowContract.onERC721Received(fakeAddress, fakeAddress, tokenId, "0x00");
expect(tx).to.be.revertedWithCustomError(titleEscrowContract, "RegistryContractPaused");
});
it("should not allow surrendering", async () => {
const tx = titleEscrowContract.connect(users.beneficiary).surrender();
await expect(tx).to.be.revertedWithCustomError(titleEscrowContract, "RegistryContractPaused");
});
it("should not allow shredding", async () => {
const tx = titleEscrowContract.shred();
await expect(tx).to.be.revertedWithCustomError(titleEscrowContract, "RegistryContractPaused");
});
it("should not allow nomination of beneficiary", async () => {
const tx = titleEscrowContract.nominate(users.beneficiary.address);
await expect(tx).to.be.revertedWithCustomError(titleEscrowContract, "RegistryContractPaused");
});
it("should not allow transfer of beneficiary", async () => {
const tx = titleEscrowContract.transferBeneficiary(users.beneficiary.address);
await expect(tx).to.be.revertedWithCustomError(titleEscrowContract, "RegistryContractPaused");
});
it("should not allow transfer holder", async () => {
const tx = titleEscrowContract.transferHolder(users.holder.address);
await expect(tx).to.be.revertedWithCustomError(titleEscrowContract, "RegistryContractPaused");
});
it("should not allow endorse beneficiary and transfer holder", async () => {
const tx = titleEscrowContract.transferOwners(users.beneficiary.address, users.holder.address);
await expect(tx).to.be.revertedWithCustomError(titleEscrowContract, "RegistryContractPaused");
});
});
});
});
});