Skip to content

Commit

Permalink
Add GetPrimaryNameNone invariant
Browse files Browse the repository at this point in the history
This commit:
- Adds the GetPrimaryNameNone invariant to the stateful testing. This checks that get-primary-name always returns none if the checked address does not own any BNS.
- Adds the newly generated invariant to the invariants list.
  • Loading branch information
BowTiedRadone committed Jul 16, 2024
1 parent a014071 commit c4977c9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/BNS-V2.stateful.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { it } from "vitest";
import { GetLastTokenId } from "./state/GetLastTokenId.ts";
import { GetOwnerNone } from "./state/GetOwnerNone.ts";
import { GetBnsFromIdNone } from "./state/GetBnsFromIdNone.ts";
import { GetPrimaryNameNone } from "./state/GetPrimaryNameNone.ts";

it("executes BNS-V2 state interactions", async () => {
const excludedAccounts = ["faucet", "deployer"];
Expand All @@ -17,6 +18,7 @@ it("executes BNS-V2 state interactions", async () => {
GetLastTokenId(filteredAccounts),
GetOwnerNone(filteredAccounts),
GetBnsFromIdNone(filteredAccounts),
GetPrimaryNameNone(filteredAccounts),
];

const model = {
Expand Down
46 changes: 46 additions & 0 deletions tests/state/GetPrimaryNameNone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import fc from "fast-check";
import { Model } from "./types";
import { Simnet } from "@hirosystems/clarinet-sdk";
import { expect } from "vitest";
import { Cl } from "@stacks/transactions";
import { prettyConsoleLog } from "../BNS-V2.helper";

export const GetPrimaryNameNone = (accounts: Map<string, string>) =>
fc
.record({
sender: fc.constantFrom(...accounts),
owner: fc.constantFrom(...accounts),
})
.map((r) => ({
check: (model: Readonly<Model>) => {
const [, ownerAddress] = r.owner;
return !(Array.from(model.owners.values()).includes(ownerAddress));
},
run: (_model: Model, real: Simnet) => {
const [wallet, address] = r.sender;
const [ownerWallet, ownerAddress] = r.owner;
// Act
const { result: primaryNameOptional } = real.callReadOnlyFn(
"BNS-V2",
"get-primary-name",
[Cl.principal(ownerAddress)],
address,
);

// Assert
expect(primaryNameOptional).toBeNone();

prettyConsoleLog(
"Ӿ tx-sender",
wallet,
"✓",
"get-primary-name",
`owner: ${ownerWallet}`,
"primary-name: none",
);
},
toString: () => {
const [ownerWallet] = r.owner;
return `get-primary-name owner ${ownerWallet} primary-name none`;
},
}));

0 comments on commit c4977c9

Please sign in to comment.