Skip to content

Commit

Permalink
Optimize Simnet account queries for invariant testing
Browse files Browse the repository at this point in the history
This commit improves the efficiency of Simnet usage in invariant testing by
querying account data only once at the start of the invariant testing setup.
The fetched accounts and their addresses are reused throughout the tests.
  • Loading branch information
BowTiedRadone authored and moodmosaic committed Jan 3, 2025
1 parent 8b12635 commit 3fb73de
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions invariant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ export const checkInvariants = (
`\nStarting invariant testing type for the ${sutContractName} contract...`
);

const simnetAccounts = simnet.getAccounts();

const eligibleAccounts = new Map(
[...simnetAccounts].filter(([key]) => key !== "faucet")
);

const simnetAddresses = Array.from(simnetAccounts.values());

const radioReporter = (runDetails: any) => {
reporter(runDetails, radio, "invariant");
};
Expand All @@ -54,16 +62,8 @@ export const checkInvariants = (
fc
.record({
rendezvousContractId: fc.constantFrom(...rendezvousList),
sutCaller: fc.constantFrom(
...new Map(
[...simnet.getAccounts()].filter(([key]) => key !== "faucet")
).entries()
),
invariantCaller: fc.constantFrom(
...new Map(
[...simnet.getAccounts()].filter(([key]) => key !== "faucet")
).entries()
),
sutCaller: fc.constantFrom(...eligibleAccounts.entries()),
invariantCaller: fc.constantFrom(...eligibleAccounts.entries()),
})
.chain((r) => {
const functions = getFunctionsListForContract(
Expand Down Expand Up @@ -108,12 +108,12 @@ export const checkInvariants = (
.chain((r) => {
const functionArgsArb = functionToArbitrary(
r.selectedFunction,
Array.from(simnet.getAccounts().values())
simnetAddresses
);

const invariantArgsArb = functionToArbitrary(
r.selectedInvariant,
Array.from(simnet.getAccounts().values())
simnetAddresses
);

return fc
Expand Down

0 comments on commit 3fb73de

Please sign in to comment.