-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdeploy.test.ts
More file actions
322 lines (300 loc) · 10.4 KB
/
Copy pathdeploy.test.ts
File metadata and controls
322 lines (300 loc) · 10.4 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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/**
* E2E tests for `dot deploy`.
*
* These tests verify the deploy pipeline behavior. Tests that require
* full network connectivity (Paseo testnet + IPFS) are marked accordingly.
*
* All headless deploys require: --signer, --domain, --buildDir, --playground
* to trigger the non-interactive path (see isFullySpecified() in deploy/index.ts).
*
* Developer-requested priorities:
* - Projects with multiple contracts (multi-contract fixture)
* - EVM (Foundry/Hardhat) vs PVM (Rust/CDM) backends
* - The --contracts flag
*/
import { describe, test, expect } from "vitest";
import { resolve } from "node:path";
import { dot } from "./helpers/dot.js";
import { SIGNER, BOB, E2E_DOMAINS } from "./fixtures/accounts.js";
import { fixturePath } from "./fixtures/templates.js";
const frontendOnly = fixturePath("frontend-only");
const foundry = fixturePath("foundry");
const hardhat = fixturePath("hardhat");
const rustCdm = fixturePath("rust-cdm");
const multiContract = fixturePath("multi-contract");
/** buildDir must be absolute — it's resolved relative to cwd, not --dir */
function absBuildDir(fixture: string, dir = "dist"): string {
return resolve(fixture, dir);
}
/**
* Shared helper for contract-deploy end-to-end tests.
*
* `--no-contract-build` skips the toolchain subprocess (forge / npx hardhat
* compile / cargo-contract) so the CI runner doesn't need the EVM/Rust
* toolchain installed. Each fixture ships pre-built bytecode in its out/ or
* artifacts/ directory.
*/
interface ContractDeployTestConfig {
/** describe-block discriminator: "foundry", "hardhat", "multi" */
name: string;
/** E2E_DOMAINS.<name> */
domain: string;
/** fixturePath() result */
fixture: string;
}
function runContractDeployTest(cfg: ContractDeployTestConfig): void {
describe(`dot deploy — ${cfg.name} (requires Paseo + IPFS)`, () => {
test(`${cfg.name} deploy completes end-to-end`, { timeout: 450_000 }, async () => {
const result = await dot([
"deploy",
"--signer", "dev",
"--domain", cfg.domain,
"--buildDir", absBuildDir(cfg.fixture),
"--contracts",
"--no-contract-build",
"--playground",
"--suri", SIGNER.suri,
"--dir", cfg.fixture,
], { timeout: 400_000 });
expect(
result.exitCode,
`${cfg.name} deploy failed: ${result.stdout}\n${result.stderr}`,
).toBe(0);
expect(result.stdout).toContain("Deploy complete");
expect(result.stdout).toContain(cfg.domain);
});
});
}
describe("dot deploy — preflight and validation", () => {
test("reports mainnet not yet supported", async () => {
const result = await dot([
"deploy",
"--signer", "dev",
"--domain", E2E_DOMAINS.preflight,
"--buildDir", absBuildDir(frontendOnly),
"--playground",
"--env", "mainnet",
"--suri", SIGNER.suri,
"--dir", frontendOnly,
], { timeout: 400_000 });
const output = result.stdout + result.stderr;
expect(output).toMatch(/mainnet/i);
expect(output).toMatch(/not.*supported/i);
});
test("detects foundry contracts type in project", async () => {
const result = await dot([
"deploy",
"--signer", "dev",
"--domain", E2E_DOMAINS.preflight,
"--buildDir", absBuildDir(foundry),
"--no-build",
"--contracts",
"--playground",
"--suri", SIGNER.suri,
"--dir", foundry,
]);
const output = result.stdout + result.stderr;
// foundry.toml present → should not complain about missing contract project
expect(output).not.toContain("no foundry/hardhat/cdm project was detected");
// Should proceed to at least the availability check
expect(output).toMatch(/checking availability|deploy/i);
});
test("detects hardhat contracts type in project", async () => {
const result = await dot([
"deploy",
"--signer", "dev",
"--domain", E2E_DOMAINS.preflight,
"--buildDir", absBuildDir(hardhat),
"--no-build",
"--contracts",
"--playground",
"--suri", SIGNER.suri,
"--dir", hardhat,
]);
const output = result.stdout + result.stderr;
expect(output).not.toContain("no foundry/hardhat/cdm project was detected");
expect(output).toMatch(/checking availability|deploy/i);
});
test("detects CDM/Rust contracts type in project", async () => {
const result = await dot([
"deploy",
"--signer", "dev",
"--domain", E2E_DOMAINS.preflight,
"--buildDir", absBuildDir(rustCdm),
"--no-build",
"--contracts",
"--playground",
"--suri", SIGNER.suri,
"--dir", rustCdm,
]);
const output = result.stdout + result.stderr;
expect(output).not.toContain("no foundry/hardhat/cdm project was detected");
expect(output).toMatch(/checking availability|deploy/i);
});
test("detects multiple contracts in multi-contract project", async () => {
const result = await dot([
"deploy",
"--signer", "dev",
"--domain", E2E_DOMAINS.preflight,
"--buildDir", absBuildDir(multiContract),
"--no-build",
"--contracts",
"--playground",
"--suri", SIGNER.suri,
"--dir", multiContract,
]);
const output = result.stdout + result.stderr;
expect(output).not.toContain("no foundry/hardhat/cdm project was detected");
expect(output).toMatch(/checking availability|deploy/i);
});
test("--contracts reports error when no contract project detected", async () => {
const result = await dot([
"deploy",
"--signer", "dev",
"--domain", E2E_DOMAINS.preflight,
"--buildDir", absBuildDir(frontendOnly),
"--no-build",
"--contracts",
"--playground",
"--suri", SIGNER.suri,
"--dir", frontendOnly,
], { timeout: 400_000 });
const output = result.stdout + result.stderr;
expect(output).toContain("no foundry/hardhat/cdm project was detected");
});
test("domain availability check runs before build/upload", { timeout: 300_000 }, async () => {
const domain = E2E_DOMAINS.preflight;
const result = await dot([
"deploy",
"--signer", "dev",
"--domain", domain,
"--buildDir", absBuildDir(frontendOnly),
"--playground",
"--suri", SIGNER.suri,
"--dir", frontendOnly,
], { timeout: 400_000 });
const output = result.stdout + result.stderr;
expect(output).toContain("Checking availability");
expect(output).toContain(domain);
});
});
describe("dot deploy --playground — full pipeline (requires Paseo + IPFS)", () => {
test("frontend-only deploy completes end-to-end", { timeout: 450_000 }, async () => {
const domain = E2E_DOMAINS.storage;
const result = await dot([
"deploy",
"--signer", "dev",
"--domain", domain,
"--buildDir", absBuildDir(frontendOnly),
"--playground",
"--suri", SIGNER.suri,
"--dir", frontendOnly,
], { timeout: 400_000 });
expect(
result.exitCode,
`deploy failed: ${result.stdout}\n${result.stderr}`,
).toBe(0);
expect(result.stdout).toContain("Deploy complete");
expect(result.stdout).toContain("URL");
expect(result.stdout).toContain(domain);
});
test("re-deploy same domain succeeds for same owner", { timeout: 900_000 }, async () => {
const domain = E2E_DOMAINS.redeploy;
const first = await dot([
"deploy",
"--signer", "dev",
"--domain", domain,
"--buildDir", absBuildDir(frontendOnly),
"--playground",
"--suri", SIGNER.suri,
"--dir", frontendOnly,
], { timeout: 400_000 });
expect(first.exitCode, `first deploy failed: ${first.stdout}\n${first.stderr}`).toBe(0);
expect(first.stdout).toContain("Deploy complete");
const second = await dot([
"deploy",
"--signer", "dev",
"--domain", domain,
"--buildDir", absBuildDir(frontendOnly),
"--no-build",
"--playground",
"--suri", SIGNER.suri,
"--dir", frontendOnly,
], { timeout: 400_000 });
expect(
second.exitCode,
`re-deploy failed: ${second.stdout}\n${second.stderr}`,
).toBe(0);
expect(second.stdout).toContain("Deploy complete");
});
test("domain taken by another account shows unavailable", { timeout: 900_000 }, async () => {
const domain = E2E_DOMAINS.collision;
const ownerDeploy = await dot([
"deploy",
"--signer", "dev",
"--domain", domain,
"--buildDir", absBuildDir(frontendOnly),
"--playground",
"--suri", SIGNER.suri,
"--dir", frontendOnly,
], { timeout: 400_000 });
expect(
ownerDeploy.exitCode,
`owner deploy failed: ${ownerDeploy.stdout}\n${ownerDeploy.stderr}`,
).toBe(0);
const bobDeploy = await dot([
"deploy",
"--signer", "dev",
"--domain", domain,
"--buildDir", absBuildDir(frontendOnly),
"--playground",
"--suri", BOB.suri,
"--dir", frontendOnly,
], { timeout: 400_000 });
// Must fail — domain is owned by SIGNER, not Bob.
const output = bobDeploy.stdout + bobDeploy.stderr;
expect(
bobDeploy.exitCode,
`bob deploy unexpectedly succeeded: ${bobDeploy.stdout}\n${bobDeploy.stderr}`,
).not.toBe(0);
expect(output.toLowerCase()).toMatch(/revert|taken|registered|owned|unavailable|already/);
});
});
// Contract-deploy tests — parametrized via runContractDeployTest
runContractDeployTest({ name: "foundry", domain: E2E_DOMAINS.foundry, fixture: foundry });
runContractDeployTest({ name: "hardhat", domain: E2E_DOMAINS.hardhat, fixture: hardhat });
// Multi-contract foundry project — exercises the contracts-batch publish path
// (TokenA.sol + TokenB.sol deployed in a single --contracts run).
runContractDeployTest({ name: "multi", domain: E2E_DOMAINS.multi, fixture: multiContract });
// SKIPPED: the rust-cdm fixture's `target/flipper.contract` is a stub
// (`{"source":{"hash":"0xabc"}}`) and there is no `target/<crate>.release.polkavm`
// for the skip-build path to read. A working fixture needs:
// 1. a real `src/lib.rs` so `cargo metadata` parses the manifest
// (currently fails: "no targets specified in the manifest")
// 2. a committed `target/<crate>.release.polkavm` produced by an
// actual `cargo-contract build` of a minimal flipper contract
// Tracked as Phase 5 follow-up. Until then, CDM detection is covered by
// the preflight test in `dot deploy — preflight and validation` and the
// skip-build path itself is unit-tested in `src/utils/deploy/contracts.test.ts`.
describe.skip("dot deploy — CDM (requires Paseo + IPFS)", () => {
test("CDM deploy completes end-to-end", { timeout: 450_000 }, async () => {
const domain = E2E_DOMAINS.cdm;
const result = await dot([
"deploy",
"--signer", "dev",
"--domain", domain,
"--buildDir", absBuildDir(rustCdm),
"--contracts",
"--no-contract-build",
"--playground",
"--suri", SIGNER.suri,
"--dir", rustCdm,
], { timeout: 400_000 });
expect(
result.exitCode,
`CDM deploy failed: ${result.stdout}\n${result.stderr}`,
).toBe(0);
expect(result.stdout).toContain("Deploy complete");
expect(result.stdout).toContain(domain);
});
});