I am trying to run Solana test validator using this command, so that I can do NFT testing.
solana-test-validator --url https://api.devnet.solana.com --clone metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s --clone PwDiXFxQsGra4sFFTT8r1QWRMd4vfumiWC1jfWNfdYT --clone mgr99QFMYByTqGPWmNqunV7vBLmWWXdSrHUfV8Jf3JM --clone ojLGErfqghuAqpJXE1dguXF7kKfvketCEeah8ig6GU3
The problem I am facing is:
- cli version 1.8.x is not able to deploy the program I am testing
- cli version 1.9.x or 1.10.x runs very slow while testing. Transaction is taking a long time to process
During my search, I came across this issue: https://github.com/solana-labs/solana/issues/23376
Is there some flags that we can use to make the local validator fast for testing?
My Computer: Macbook Pro with M1 Pro
--- Working Solution ---
After referencing the staking contract by cardinal labs, I found out this:
Loading program like this was causing my tests to run slow:
export function loadProgram(walletKeyPair: anchor.web3.Keypair) {
const conn = new anchor.web3.Connection(
process.env.ANCHOR_PROVIDER_URL
);
const walletWrapper = new anchor.Wallet(walletKeyPair);
const provider = new anchor.AnchorProvider(conn, walletWrapper, {
preflightCommitment: "processed",
commitment: "processed",
});
return new anchor.Program(IDL, PROGRAM_ID, provider);
}
Loading program like this made my tests run fast:
const getProvider = (): anchor.AnchorProvider => {
const anchorProvider = anchor.AnchorProvider.env();
anchor.setProvider(anchorProvider);
return anchorProvider;
};
export function loadProgram() {
const provider = getProvider();
return new anchor.Program(IDL, PROGRAM_ID, provider);
}