Skip to content

Commit

Permalink
fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Intizar-T committed Jun 3, 2024
1 parent f167cbc commit 09cd114
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 119 deletions.
141 changes: 73 additions & 68 deletions scripts/performance-test-seq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
106 changes: 55 additions & 51 deletions scripts/performance-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Check warning on line 79 in scripts/performance-test.ts

View workflow job for this annotation

GitHub Actions / build

'delay' is defined but never used

Check warning on line 79 in scripts/performance-test.ts

View workflow job for this annotation

GitHub Actions / build

'arg0' is defined but never used
throw new Error('Function not implemented.')
throw new Error('Function not implemented.')
}

0 comments on commit 09cd114

Please sign in to comment.