From 3fb73de253e02e7e042ae33317ec9660fe9986c8 Mon Sep 17 00:00:00 2001 From: BowTiedRadone Date: Thu, 2 Jan 2025 18:35:34 +0200 Subject: [PATCH] Optimize Simnet account queries for invariant testing 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. --- invariant.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/invariant.ts b/invariant.ts index 84e4c8c..fcc9358 100644 --- a/invariant.ts +++ b/invariant.ts @@ -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"); }; @@ -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( @@ -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