Skip to content

Commit

Permalink
Optimize Simnet account queries for property testing
Browse files Browse the repository at this point in the history
This commit improves the efficiency of Simnet usage in property 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 property
testing infrastructure.
  • Loading branch information
BowTiedRadone authored and moodmosaic committed Jan 3, 2025
1 parent 3fb73de commit 3a5c7cb
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ export const checkProperties = (
return;
}

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, "test");
};
Expand All @@ -93,11 +101,7 @@ export const checkProperties = (
fc
.record({
testContractId: fc.constantFrom(...rendezvousList),
testCaller: fc.constantFrom(
...new Map(
[...simnet.getAccounts()].filter(([key]) => key !== "faucet")
).entries()
),
testCaller: fc.constantFrom(...eligibleAccounts.entries()),
})
.chain((r) => {
const testFunctionsList = getFunctionsListForContract(
Expand Down Expand Up @@ -126,7 +130,7 @@ export const checkProperties = (
.chain((r) => {
const functionArgsArb = functionToArbitrary(
r.selectedTestFunction,
Array.from(simnet.getAccounts().values())
simnetAddresses
);

return fc
Expand Down

0 comments on commit 3a5c7cb

Please sign in to comment.