Skip to content

Commit

Permalink
fix: update test formats, remove unnecessary async and simnet
Browse files Browse the repository at this point in the history
This addresses feedback in hirosystems/clarinet#1359 and removes the created simnet object in favor of the existing global.
  • Loading branch information
whoabuddy committed Feb 21, 2024
1 parent bf65308 commit 4a9b051
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 102 deletions.
85 changes: 29 additions & 56 deletions tests/stacks-m2m-v1.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { initSimnet } from "@hirosystems/clarinet-sdk";
import { Cl, cvToValue } from "@stacks/transactions";
import { describe, expect, it } from "vitest";

Expand Down Expand Up @@ -46,9 +45,8 @@ const expectedBlock0Resource1 = Buffer.from(
);

describe("Adding a resource", () => {
it("add-resource() fails if not called by deployer", async () => {
it("add-resource() fails if not called by deployer", () => {
// ARRANGE
const simnet = await initSimnet();
const accounts = simnet.getAccounts();
const address1 = accounts.get("wallet_1")!;
// ACT
Expand All @@ -62,9 +60,8 @@ describe("Adding a resource", () => {
expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_UNAUTHORIZED));
});

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

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

it("add-resource() fails if price is 0", async () => {
it("add-resource() fails if price is 0", () => {
// ARRANGE
const simnet = await initSimnet();
const accounts = simnet.getAccounts();
const deployer = accounts.get("deployer")!;
// ACT
Expand All @@ -109,9 +104,8 @@ describe("Adding a resource", () => {
// ASSERT
expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_INVALID_PARAMS));
});
it("add-resource() fails if name already used", async () => {
it("add-resource() fails if name already used", () => {
// ARRANGE
const simnet = await initSimnet();
const accounts = simnet.getAccounts();
const deployer = accounts.get("deployer")!;
const expectedCount = 1;
Expand All @@ -135,9 +129,8 @@ describe("Adding a resource", () => {
);
});

it("add-resource() succeeds and increments resource count", async () => {
it("add-resource() succeeds and increments resource count", () => {
// ARRANGE
const simnet = await initSimnet();
const accounts = simnet.getAccounts();
const deployer = accounts.get("deployer")!;
const expectedCount = 1;
Expand Down Expand Up @@ -168,9 +161,8 @@ describe("Adding a resource", () => {
});

describe("Deleting a Resource", () => {
it("delete-resource() fails if not called by deployer", async () => {
it("delete-resource() fails if not called by deployer", () => {
// ARRANGE
const simnet = await initSimnet();
const accounts = simnet.getAccounts();
const deployer = accounts.get("deployer")!;
const address1 = accounts.get("wallet_1")!;
Expand All @@ -195,9 +187,8 @@ describe("Deleting a Resource", () => {
expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_UNAUTHORIZED));
});

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

it("delete-resource() fails if executed twice on the same resource", async () => {
it("delete-resource() fails if executed twice on the same resource", () => {
// ARRANGE
const simnet = await initSimnet();
const accounts = simnet.getAccounts();
const deployer = accounts.get("deployer")!;
// ACT
Expand Down Expand Up @@ -248,9 +238,8 @@ describe("Deleting a Resource", () => {
);
});

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

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

it("pay-invoice() fails for a deleted resource", async () => {
it("pay-invoice() fails for a deleted resource", () => {
// ARRANGE
const simnet = await initSimnet();
const accounts = simnet.getAccounts();
const address1 = accounts.get("wallet_1")!;
const deployer = accounts.get("deployer")!;
Expand Down Expand Up @@ -332,9 +319,8 @@ describe("Deleting a Resource", () => {
});

describe("Setting a Payment Address", () => {
it("set-payment-address() fails if not called by deployer", async () => {
it("set-payment-address() fails if not called by deployer", () => {
// ARRANGE
const simnet = await initSimnet();
const accounts = simnet.getAccounts();
const address1 = accounts.get("wallet_1")!;
// ACT
Expand Down Expand Up @@ -363,9 +349,8 @@ describe("Setting a Payment Address", () => {
expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_UNAUTHORIZED));
});

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

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

it("set-payment-address() succeeds if called by current payment address", async () => {
it("set-payment-address() succeeds if called by current payment address", () => {
// ARRANGE
const simnet = await initSimnet();
const accounts = simnet.getAccounts();
const deployer = accounts.get("deployer")!;
const address1 = accounts.get("wallet_1")!;
Expand Down Expand Up @@ -472,9 +455,8 @@ describe("Setting a Payment Address", () => {
});

describe("Generating an invoice hash", () => {
it("get-invoice-hash() returns none if resource is not found", async () => {
it("get-invoice-hash() returns none if resource is not found", () => {
// ARRANGE
const simnet = await initSimnet();
const accounts = simnet.getAccounts();
const deployer = accounts.get("deployer")!;
// ACT
Expand All @@ -492,9 +474,8 @@ describe("Generating an invoice hash", () => {
expect(response.result).toBeNone();
});

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

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

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

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

describe("Paying an invoice", () => {
it("pay-invoice() fails if resource is not found", async () => {
it("pay-invoice() fails if resource is not found", () => {
// ARRANGE
const simnet = await initSimnet();
const accounts = simnet.getAccounts();
const address1 = accounts.get("wallet_1")!;
// ACT
Expand All @@ -670,14 +647,13 @@ describe("Paying an invoice", () => {
expect(response.result).toBeErr(Cl.uint(ErrCode.ERR_RESOURCE_NOT_FOUND));
});
// not expecting ERR_USER_NOT_FOUND, not sure if we can force?
// it("pay-invoice() fails if user cannot be created or found", async () => {})
// it("pay-invoice() fails if user cannot be created or found", () => {})
// not expecting ERR_INVOICE_HASH_NOT_FOUND, same as above
// it("pay-invoice() fails if invoice hash cannot be found", async () => {})
// it("pay-invoice() fails if invoice hash cannot be found", () => {})
// not expecting ERR_SAVING_INVOICE in two spots, same as above
// it("pay-invoice() fails if invoice cannot be saved", async () => {})
it("pay-invoice() succeeds and returns invoice count without memo", async () => {
// it("pay-invoice() fails if invoice cannot be saved", () => {})
it("pay-invoice() succeeds and returns invoice count without memo", () => {
// ARRANGE
const simnet = await initSimnet();
const accounts = simnet.getAccounts();
const deployer = accounts.get("deployer")!;
const address1 = accounts.get("wallet_1")!;
Expand All @@ -704,9 +680,8 @@ describe("Paying an invoice", () => {
expect(response.result).toBeOk(Cl.uint(expectedCount));
});

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

it("pay-invoice() succeeds and returns invoice count with memo over several blocks", async () => {
it("pay-invoice() succeeds and returns invoice count with memo over several blocks", () => {
// ARRANGE
const simnet = await initSimnet();
const accounts = simnet.getAccounts();
const deployer = accounts.get("deployer")!;
const address1 = accounts.get("wallet_1")!;
Expand Down Expand Up @@ -820,9 +794,8 @@ describe("Paying an invoice", () => {
}
});

it("pay-invoice() succeeds and updates resource and user data", async () => {
it("pay-invoice() succeeds and updates resource and user data", () => {
// ARRANGE
const simnet = await initSimnet();
const accounts = simnet.getAccounts();
const address1 = accounts.get("wallet_1")!;
const address2 = accounts.get("wallet_2")!;
Expand Down
Loading

0 comments on commit 4a9b051

Please sign in to comment.