From 09cd114f96d23a45d20e8cde9f4c009ab0a65653 Mon Sep 17 00:00:00 2001 From: Intizar Date: Mon, 3 Jun 2024 17:29:55 +0900 Subject: [PATCH] fix linting errors --- scripts/performance-test-seq.ts | 141 +++++++++++++++++--------------- scripts/performance-test.ts | 106 ++++++++++++------------ 2 files changed, 128 insertions(+), 119 deletions(-) diff --git a/scripts/performance-test-seq.ts b/scripts/performance-test-seq.ts index b8c4a05..6f1a87d 100644 --- a/scripts/performance-test-seq.ts +++ b/scripts/performance-test-seq.ts @@ -7,88 +7,93 @@ const TOTAL_NUM_CALLS = 100 const RATE_LIMIT_PER_SECOND = 100 function delay(ms) { - return new Promise(resolve => setTimeout(resolve, ms)); + return new Promise((resolve) => setTimeout(resolve, ms)) } async function main() { - const vrfConsumer = await ethers.getContract('VRFConsumer') + const vrfConsumer = await ethers.getContract('VRFConsumer') - const keyHash = '0x47ede773ef09e40658e643fe79f8d1a27c0aa6eb7251749b268f829ea49f2024' - const callbackGasLimit = 500_000 - const numWords = 1 - const value = ethers.utils.parseEther('1.0') + const keyHash = '0x47ede773ef09e40658e643fe79f8d1a27c0aa6eb7251749b268f829ea49f2024' + const callbackGasLimit = 500_000 + const numWords = 1 + const value = ethers.utils.parseEther('1.0') - const providerUrl = 'https://baobab01.fautor.app' - const provider = new ethers.providers.JsonRpcProvider(providerUrl) + const providerUrl = 'https://baobab01.fautor.app' + const provider = new ethers.providers.JsonRpcProvider(providerUrl) - const signer = new ethers.Wallet('0d3046f718bad9413a30559bcb36e10c2c257ce83f760cb5f83bb676bb51a65b', provider) - const signerWithProvider = signer.connect(provider) - const nonceManager = new NonceManager(signerWithProvider) + const signer = new ethers.Wallet( + '0d3046f718bad9413a30559bcb36e10c2c257ce83f760cb5f83bb676bb51a65b', + provider + ) + const signerWithProvider = signer.connect(provider) + const nonceManager = new NonceManager(signerWithProvider) - const vrfConsumerNonce = new ethers.Contract( - vrfConsumer.address, - vrfConsumer.interface, - nonceManager - ) + const vrfConsumerNonce = new ethers.Contract( + vrfConsumer.address, + vrfConsumer.interface, + nonceManager + ) - const limiter = new Bottleneck({ - maxConcurrent: RATE_LIMIT_PER_SECOND, - minTime: 1000 / RATE_LIMIT_PER_SECOND - }) + const limiter = new Bottleneck({ + maxConcurrent: RATE_LIMIT_PER_SECOND, + minTime: 1000 / RATE_LIMIT_PER_SECOND + }) - const txResults = [] - for (let i = 1; i <= TOTAL_NUM_CALLS; i++) { - console.log(`Call ${i}`) - try { - await limiter.schedule(async () => { - const tx = await vrfConsumerNonce.requestRandomWordsDirect( - keyHash, - callbackGasLimit, - numWords, - { - value, - } - ) - const receipt = await tx.wait() - console.log(`Transaction ${i} mined: ${receipt.transactionHash}`) - // const requestId = await vrfConsumerNonce.sLastRequestId() - // console.log(`requestId for transaction ${i}: ${requestId}`) - // let attempts = 0 - // let randomWord - // while (attempts < 5) { - // try { - // randomWord = await vrfConsumerNonce.getRandomWord(requestId) - // if (randomWord != 0) { - // break - // } - // } catch (e) { - // console.log(`Attempt ${attempts + 1} failed: ${e.message}`) - // attempts++ - // await delay(20000) // wait 2 seconds before retrying - // } - // } - // console.log(`Random word for transaction ${i}: ${randomWord}`) - txResults.push({status: 'fulfilled', value: tx}) - }) - } catch (error) { - console.error(`Error in loop ${i}:`, error) - txResults.push({status: 'rejected', reason: error}) - } + const txResults = [] + for (let i = 1; i <= TOTAL_NUM_CALLS; i++) { + console.log(`Call ${i}`) + try { + await limiter.schedule(async () => { + const tx = await vrfConsumerNonce.requestRandomWordsDirect( + keyHash, + callbackGasLimit, + numWords, + { + value + } + ) + const receipt = await tx.wait() + console.log(`Transaction ${i} mined: ${receipt.transactionHash}`) + // const requestId = await vrfConsumerNonce.sLastRequestId() + // console.log(`requestId for transaction ${i}: ${requestId}`) + // let attempts = 0 + // let randomWord + // while (attempts < 5) { + // try { + // randomWord = await vrfConsumerNonce.getRandomWord(requestId) + // if (randomWord != 0) { + // break + // } + // } catch (e) { + // console.log(`Attempt ${attempts + 1} failed: ${e.message}`) + // attempts++ + // await delay(20000) // wait 2 seconds before retrying + // } + // } + // console.log(`Random word for transaction ${i}: ${randomWord}`) + txResults.push({ status: 'fulfilled', value: tx }) + }) + } catch (error) { + console.error(`Error in loop ${i}:`, error) + txResults.push({ status: 'rejected', reason: error }) + } - if (i < TOTAL_NUM_CALLS) { - await delay(WAIT_TIME_MS) - } + if (i < TOTAL_NUM_CALLS) { + await delay(WAIT_TIME_MS) } + } - const successfulTxs = txResults.filter((result) => result.status === 'fulfilled').map((result) => result.value) - const tps = successfulTxs.length / (TOTAL_NUM_CALLS * WAIT_TIME_MS / 1000) + const successfulTxs = txResults + .filter((result) => result.status === 'fulfilled') + .map((result) => result.value) + const tps = successfulTxs.length / ((TOTAL_NUM_CALLS * WAIT_TIME_MS) / 1000) - console.log(`Total transactions: ${TOTAL_NUM_CALLS}`) - console.log(`Successful transactions: ${successfulTxs.length}`) - console.log(`TPS: ${tps}`) + console.log(`Total transactions: ${TOTAL_NUM_CALLS}`) + console.log(`Successful transactions: ${successfulTxs.length}`) + console.log(`TPS: ${tps}`) } main().catch((error) => { - console.error(error) - process.exitCode = 1 + console.error(error) + process.exitCode = 1 }) diff --git a/scripts/performance-test.ts b/scripts/performance-test.ts index ed07111..ce69cdf 100644 --- a/scripts/performance-test.ts +++ b/scripts/performance-test.ts @@ -7,71 +7,75 @@ const TOTAL_NUM_CALLS = 300 const RATE_LIMIT_PER_SECOND = 200 async function main() { - const vrfConsumer = await ethers.getContract('VRFConsumer') + const vrfConsumer = await ethers.getContract('VRFConsumer') - const keyHash = '0x47ede773ef09e40658e643fe79f8d1a27c0aa6eb7251749b268f829ea49f2024' - const callbackGasLimit = 500_000 - const numWords = 1 - const value = ethers.utils.parseEther('1.0') + const keyHash = '0x47ede773ef09e40658e643fe79f8d1a27c0aa6eb7251749b268f829ea49f2024' + const callbackGasLimit = 500_000 + const numWords = 1 + const value = ethers.utils.parseEther('1.0') - const providerUrl = 'https://api.baobab.klaytn.net:8651' - const provider = new ethers.providers.JsonRpcProvider(providerUrl) + const providerUrl = 'https://api.baobab.klaytn.net:8651' + const provider = new ethers.providers.JsonRpcProvider(providerUrl) - const signer = new ethers.Wallet('0d3046f718bad9413a30559bcb36e10c2c257ce83f760cb5f83bb676bb51a65b', provider) - const signerWithProvider = signer.connect(provider) - const nonceManager = new NonceManager(signerWithProvider) + const signer = new ethers.Wallet( + '0d3046f718bad9413a30559bcb36e10c2c257ce83f760cb5f83bb676bb51a65b', + provider + ) + const signerWithProvider = signer.connect(provider) + const nonceManager = new NonceManager(signerWithProvider) - const vrfConsumerNonce = new ethers.Contract( - vrfConsumer.address, - vrfConsumer.interface, - nonceManager - ) + const vrfConsumerNonce = new ethers.Contract( + vrfConsumer.address, + vrfConsumer.interface, + nonceManager + ) - const limiter = new Bottleneck({ - maxConcurrent: RATE_LIMIT_PER_SECOND, - minTime: 1000 / RATE_LIMIT_PER_SECOND - }) + const limiter = new Bottleneck({ + maxConcurrent: RATE_LIMIT_PER_SECOND, + minTime: 1000 / RATE_LIMIT_PER_SECOND + }) - const txPromises = [] + const txPromises = [] - for (let i = 1; i <= TOTAL_NUM_CALLS; i++) { - console.log(`Call ${i}`) - try { - const txPromise = limiter.schedule(async () => { - const tx = await vrfConsumerNonce.requestRandomWordsDirect( - keyHash, - callbackGasLimit, - numWords, - { - value, - } - ) - return tx.wait() - }) - txPromises.push(txPromise) - } catch (error) { - console.error(`Error in loop ${i}:`, error) - } + for (let i = 1; i <= TOTAL_NUM_CALLS; i++) { + console.log(`Call ${i}`) + try { + const txPromise = limiter.schedule(async () => { + const tx = await vrfConsumerNonce.requestRandomWordsDirect( + keyHash, + callbackGasLimit, + numWords, + { + value + } + ) + return tx.wait() + }) + txPromises.push(txPromise) + } catch (error) { + console.error(`Error in loop ${i}:`, error) + } - if (i < TOTAL_NUM_CALLS) { - await new Promise((resolve) => setTimeout(resolve, WAIT_TIME_MS)) - } + if (i < TOTAL_NUM_CALLS) { + await new Promise((resolve) => setTimeout(resolve, WAIT_TIME_MS)) } + } - const txResults = await Promise.allSettled(txPromises) - const successfulTxs = txResults.filter((result) => result.status === 'fulfilled').map((result) => result.value) - const tps = successfulTxs.length / (TOTAL_NUM_CALLS * WAIT_TIME_MS / 1000) + const txResults = await Promise.allSettled(txPromises) + const successfulTxs = txResults + .filter((result) => result.status === 'fulfilled') + .map((result) => result.value) + const tps = successfulTxs.length / ((TOTAL_NUM_CALLS * WAIT_TIME_MS) / 1000) - console.log(`Total transactions: ${TOTAL_NUM_CALLS}`) - console.log(`Successful transactions: ${successfulTxs.length}`) - console.log(`TPS: ${tps}`) + console.log(`Total transactions: ${TOTAL_NUM_CALLS}`) + console.log(`Successful transactions: ${successfulTxs.length}`) + console.log(`TPS: ${tps}`) } main().catch((error) => { - console.error(error) - process.exitCode = 1 + console.error(error) + process.exitCode = 1 }) function delay(arg0: number) { - throw new Error('Function not implemented.') + throw new Error('Function not implemented.') } -