Skip to content

Commit 4a9b051

Browse files
committed
fix: update test formats, remove unnecessary async and simnet
This addresses feedback in hirosystems/clarinet#1359 and removes the created simnet object in favor of the existing global.
1 parent bf65308 commit 4a9b051

File tree

2 files changed

+53
-102
lines changed

2 files changed

+53
-102
lines changed

tests/stacks-m2m-v1.test.ts

Lines changed: 29 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { initSimnet } from "@hirosystems/clarinet-sdk";
21
import { Cl, cvToValue } from "@stacks/transactions";
32
import { describe, expect, it } from "vitest";
43

@@ -46,9 +45,8 @@ const expectedBlock0Resource1 = Buffer.from(
4645
);
4746

4847
describe("Adding a resource", () => {
49-
it("add-resource() fails if not called by deployer", async () => {
48+
it("add-resource() fails if not called by deployer", () => {
5049
// ARRANGE
51-
const simnet = await initSimnet();
5250
const accounts = simnet.getAccounts();
5351
const address1 = accounts.get("wallet_1")!;
5452
// ACT
@@ -62,9 +60,8 @@ describe("Adding a resource", () => {
6260
expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_UNAUTHORIZED));
6361
});
6462

65-
it("add-resource() fails if name is blank", async () => {
63+
it("add-resource() fails if name is blank", () => {
6664
// ARRANGE
67-
const simnet = await initSimnet();
6865
const accounts = simnet.getAccounts();
6966
const deployer = accounts.get("deployer")!;
7067
// ACT
@@ -78,9 +75,8 @@ describe("Adding a resource", () => {
7875
expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_INVALID_PARAMS));
7976
});
8077

81-
it("add-resource() fails if description is blank", async () => {
78+
it("add-resource() fails if description is blank", () => {
8279
// ARRANGE
83-
const simnet = await initSimnet();
8480
const accounts = simnet.getAccounts();
8581
const deployer = accounts.get("deployer")!;
8682
// ACT
@@ -94,9 +90,8 @@ describe("Adding a resource", () => {
9490
expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_INVALID_PARAMS));
9591
});
9692

97-
it("add-resource() fails if price is 0", async () => {
93+
it("add-resource() fails if price is 0", () => {
9894
// ARRANGE
99-
const simnet = await initSimnet();
10095
const accounts = simnet.getAccounts();
10196
const deployer = accounts.get("deployer")!;
10297
// ACT
@@ -109,9 +104,8 @@ describe("Adding a resource", () => {
109104
// ASSERT
110105
expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_INVALID_PARAMS));
111106
});
112-
it("add-resource() fails if name already used", async () => {
107+
it("add-resource() fails if name already used", () => {
113108
// ARRANGE
114-
const simnet = await initSimnet();
115109
const accounts = simnet.getAccounts();
116110
const deployer = accounts.get("deployer")!;
117111
const expectedCount = 1;
@@ -135,9 +129,8 @@ describe("Adding a resource", () => {
135129
);
136130
});
137131

138-
it("add-resource() succeeds and increments resource count", async () => {
132+
it("add-resource() succeeds and increments resource count", () => {
139133
// ARRANGE
140-
const simnet = await initSimnet();
141134
const accounts = simnet.getAccounts();
142135
const deployer = accounts.get("deployer")!;
143136
const expectedCount = 1;
@@ -168,9 +161,8 @@ describe("Adding a resource", () => {
168161
});
169162

170163
describe("Deleting a Resource", () => {
171-
it("delete-resource() fails if not called by deployer", async () => {
164+
it("delete-resource() fails if not called by deployer", () => {
172165
// ARRANGE
173-
const simnet = await initSimnet();
174166
const accounts = simnet.getAccounts();
175167
const deployer = accounts.get("deployer")!;
176168
const address1 = accounts.get("wallet_1")!;
@@ -195,9 +187,8 @@ describe("Deleting a Resource", () => {
195187
expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_UNAUTHORIZED));
196188
});
197189

198-
it("delete-resource() fails if provided index is greater than current resource count", async () => {
190+
it("delete-resource() fails if provided index is greater than current resource count", () => {
199191
// ARRANGE
200-
const simnet = await initSimnet();
201192
const accounts = simnet.getAccounts();
202193
const deployer = accounts.get("deployer")!;
203194
// ACT
@@ -211,9 +202,8 @@ describe("Deleting a Resource", () => {
211202
expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_INVALID_PARAMS));
212203
});
213204

214-
it("delete-resource() fails if executed twice on the same resource", async () => {
205+
it("delete-resource() fails if executed twice on the same resource", () => {
215206
// ARRANGE
216-
const simnet = await initSimnet();
217207
const accounts = simnet.getAccounts();
218208
const deployer = accounts.get("deployer")!;
219209
// ACT
@@ -248,9 +238,8 @@ describe("Deleting a Resource", () => {
248238
);
249239
});
250240

251-
it("delete-resource-by-name() fails if not called by deployer", async () => {
241+
it("delete-resource-by-name() fails if not called by deployer", () => {
252242
// ARRANGE
253-
const simnet = await initSimnet();
254243
const accounts = simnet.getAccounts();
255244
const deployer = accounts.get("deployer")!;
256245
const address1 = accounts.get("wallet_1")!;
@@ -275,9 +264,8 @@ describe("Deleting a Resource", () => {
275264
expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_UNAUTHORIZED));
276265
});
277266

278-
it("delete-resource-by-name() fails if provided name is not found", async () => {
267+
it("delete-resource-by-name() fails if provided name is not found", () => {
279268
// ARRANGE
280-
const simnet = await initSimnet();
281269
const accounts = simnet.getAccounts();
282270
const deployer = accounts.get("deployer")!;
283271
// ACT
@@ -291,9 +279,8 @@ describe("Deleting a Resource", () => {
291279
expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_INVALID_PARAMS));
292280
});
293281

294-
it("pay-invoice() fails for a deleted resource", async () => {
282+
it("pay-invoice() fails for a deleted resource", () => {
295283
// ARRANGE
296-
const simnet = await initSimnet();
297284
const accounts = simnet.getAccounts();
298285
const address1 = accounts.get("wallet_1")!;
299286
const deployer = accounts.get("deployer")!;
@@ -332,9 +319,8 @@ describe("Deleting a Resource", () => {
332319
});
333320

334321
describe("Setting a Payment Address", () => {
335-
it("set-payment-address() fails if not called by deployer", async () => {
322+
it("set-payment-address() fails if not called by deployer", () => {
336323
// ARRANGE
337-
const simnet = await initSimnet();
338324
const accounts = simnet.getAccounts();
339325
const address1 = accounts.get("wallet_1")!;
340326
// ACT
@@ -363,9 +349,8 @@ describe("Setting a Payment Address", () => {
363349
expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_UNAUTHORIZED));
364350
});
365351

366-
it("set-payment-address() fails if old address param is incorrect", async () => {
352+
it("set-payment-address() fails if old address param is incorrect", () => {
367353
// ARRANGE
368-
const simnet = await initSimnet();
369354
const accounts = simnet.getAccounts();
370355
const address1 = accounts.get("wallet_1")!;
371356
const deployer = accounts.get("deployer")!;
@@ -381,9 +366,8 @@ describe("Setting a Payment Address", () => {
381366
expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_UNAUTHORIZED));
382367
});
383368

384-
it("set-payment-address() succeeds if called by the deployer", async () => {
369+
it("set-payment-address() succeeds if called by the deployer", () => {
385370
// ARRANGE
386-
const simnet = await initSimnet();
387371
const accounts = simnet.getAccounts();
388372
const deployer = accounts.get("deployer")!;
389373
const address1 = accounts.get("wallet_1")!;
@@ -414,9 +398,8 @@ describe("Setting a Payment Address", () => {
414398
expect(response.result).toBeOk(Cl.bool(true));
415399
});
416400

417-
it("set-payment-address() succeeds if called by current payment address", async () => {
401+
it("set-payment-address() succeeds if called by current payment address", () => {
418402
// ARRANGE
419-
const simnet = await initSimnet();
420403
const accounts = simnet.getAccounts();
421404
const deployer = accounts.get("deployer")!;
422405
const address1 = accounts.get("wallet_1")!;
@@ -472,9 +455,8 @@ describe("Setting a Payment Address", () => {
472455
});
473456

474457
describe("Generating an invoice hash", () => {
475-
it("get-invoice-hash() returns none if resource is not found", async () => {
458+
it("get-invoice-hash() returns none if resource is not found", () => {
476459
// ARRANGE
477-
const simnet = await initSimnet();
478460
const accounts = simnet.getAccounts();
479461
const deployer = accounts.get("deployer")!;
480462
// ACT
@@ -492,9 +474,8 @@ describe("Generating an invoice hash", () => {
492474
expect(response.result).toBeNone();
493475
});
494476

495-
it("get-invoice-hash() succeeds and returns the correct value", async () => {
477+
it("get-invoice-hash() succeeds and returns the correct value", () => {
496478
// ARRANGE
497-
const simnet = await initSimnet();
498479
const accounts = simnet.getAccounts();
499480
const deployer = accounts.get("deployer")!;
500481
// ACT
@@ -518,9 +499,8 @@ describe("Generating an invoice hash", () => {
518499
expect(response.result).toBeSome(Cl.buffer(expectedBlock0Resource1));
519500
});
520501

521-
it("get-invoice-hash() succeeds and returns the correct value after the chain progresses", async () => {
502+
it("get-invoice-hash() succeeds and returns the correct value after the chain progresses", () => {
522503
// ARRANGE
523-
const simnet = await initSimnet();
524504
const accounts = simnet.getAccounts();
525505
const deployer = accounts.get("deployer")!;
526506
// ACT
@@ -545,9 +525,8 @@ describe("Generating an invoice hash", () => {
545525
expect(response.result).toBeSome(Cl.buffer(expectedBlock0Resource1));
546526
});
547527

548-
it("get-invoice-hash() succeeds and generates unique values for different users at different block heights", async () => {
528+
it("get-invoice-hash() succeeds and generates unique values for different users at different block heights", () => {
549529
// ARRANGE
550-
const simnet = await initSimnet();
551530
const accounts = simnet.getAccounts();
552531
const deployer = accounts.get("deployer")!;
553532
const address1 = accounts.get("wallet_1")!;
@@ -588,9 +567,8 @@ describe("Generating an invoice hash", () => {
588567
expect(uniqueInvoiceHashes.size).toEqual(invoiceHashes.length);
589568
});
590569

591-
it("get-invoice-hash() succeeds and generates consistent values for different users at different block heights", async () => {
570+
it("get-invoice-hash() succeeds and generates consistent values for different users at different block heights", () => {
592571
// ARRANGE
593-
const simnet = await initSimnet();
594572
const accounts = simnet.getAccounts();
595573
const deployer = accounts.get("deployer")!;
596574
const address1 = accounts.get("wallet_1")!;
@@ -651,9 +629,8 @@ describe("Generating an invoice hash", () => {
651629
});
652630

653631
describe("Paying an invoice", () => {
654-
it("pay-invoice() fails if resource is not found", async () => {
632+
it("pay-invoice() fails if resource is not found", () => {
655633
// ARRANGE
656-
const simnet = await initSimnet();
657634
const accounts = simnet.getAccounts();
658635
const address1 = accounts.get("wallet_1")!;
659636
// ACT
@@ -670,14 +647,13 @@ describe("Paying an invoice", () => {
670647
expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_RESOURCE_NOT_FOUND));
671648
});
672649
// not expecting ERR_USER_NOT_FOUND, not sure if we can force?
673-
// it("pay-invoice() fails if user cannot be created or found", async () => {})
650+
// it("pay-invoice() fails if user cannot be created or found", () => {})
674651
// not expecting ERR_INVOICE_HASH_NOT_FOUND, same as above
675-
// it("pay-invoice() fails if invoice hash cannot be found", async () => {})
652+
// it("pay-invoice() fails if invoice hash cannot be found", () => {})
676653
// not expecting ERR_SAVING_INVOICE in two spots, same as above
677-
// it("pay-invoice() fails if invoice cannot be saved", async () => {})
678-
it("pay-invoice() succeeds and returns invoice count without memo", async () => {
654+
// it("pay-invoice() fails if invoice cannot be saved", () => {})
655+
it("pay-invoice() succeeds and returns invoice count without memo", () => {
679656
// ARRANGE
680-
const simnet = await initSimnet();
681657
const accounts = simnet.getAccounts();
682658
const deployer = accounts.get("deployer")!;
683659
const address1 = accounts.get("wallet_1")!;
@@ -704,9 +680,8 @@ describe("Paying an invoice", () => {
704680
expect(response.result).toBeOk(Cl.uint(expectedCount));
705681
});
706682

707-
it("pay-invoice() succeeds and returns invoice count with memo", async () => {
683+
it("pay-invoice() succeeds and returns invoice count with memo", () => {
708684
// ARRANGE
709-
const simnet = await initSimnet();
710685
const accounts = simnet.getAccounts();
711686
const deployer = accounts.get("deployer")!;
712687
const address1 = accounts.get("wallet_1")!;
@@ -734,9 +709,8 @@ describe("Paying an invoice", () => {
734709
expect(response.result).toBeOk(Cl.uint(expectedCount));
735710
});
736711

737-
it("pay-invoice() succeeds and returns invoice count with memo over several blocks", async () => {
712+
it("pay-invoice() succeeds and returns invoice count with memo over several blocks", () => {
738713
// ARRANGE
739-
const simnet = await initSimnet();
740714
const accounts = simnet.getAccounts();
741715
const deployer = accounts.get("deployer")!;
742716
const address1 = accounts.get("wallet_1")!;
@@ -820,9 +794,8 @@ describe("Paying an invoice", () => {
820794
}
821795
});
822796

823-
it("pay-invoice() succeeds and updates resource and user data", async () => {
797+
it("pay-invoice() succeeds and updates resource and user data", () => {
824798
// ARRANGE
825-
const simnet = await initSimnet();
826799
const accounts = simnet.getAccounts();
827800
const address1 = accounts.get("wallet_1")!;
828801
const address2 = accounts.get("wallet_2")!;

0 commit comments

Comments
 (0)