Skip to content

Commit

Permalink
add localhost options
Browse files Browse the repository at this point in the history
  • Loading branch information
Intizar-T committed Jun 3, 2024
1 parent 46675ae commit 1de7e62
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
10 changes: 7 additions & 3 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ const config: HardhatUserConfig = {
networks: {
localhost: {
gas: 1_400_000,
gasPrice: 250_000_000_000
gasPrice: 250_000_000_000,
...commonConfig,
url: process.env.PROVIDER || 'http://127.0.0.1:8545'
},
baobab: {
url: process.env.PROVIDER || 'https://api.baobab.klaytn.net:8651',
Expand All @@ -57,11 +59,13 @@ const config: HardhatUserConfig = {
},
prepayment: {
baobab: '0x8d3A1663d10eEb0bC9C9e537e1BBeA69383194e7',
cypress: '0xc2C88492Cf7e5240C3EB49353539E75336960600'
cypress: '0xc2C88492Cf7e5240C3EB49353539E75336960600',
localhost: '0x5FbDB2315678afecb367f032d93F642f64180aa3'
},
vrfCoordinator: {
baobab: '0xDA8c0A00A372503aa6EC80f9b29Cc97C454bE499',
cypress: '0x3F247f70DC083A2907B8E76635986fd09AA80EFb'
cypress: '0x3F247f70DC083A2907B8E76635986fd09AA80EFb',
localhost: '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512'
}
}
}
Expand Down
69 changes: 69 additions & 0 deletions scripts/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { ethers } from 'hardhat'
import { getKeyHash } from './utils'
import { Prepayment__factory } from '@bisonai/orakl-contracts'
import hre from 'hardhat'
import { readFileSync } from 'fs'
import { join } from 'path'

const ACC_ID = process.env.ACC_ID

async function createContracts(count: number) {

Check warning on line 10 in scripts/test.ts

View workflow job for this annotation

GitHub Actions / build

'createContracts' is defined but never used
const { getNamedAccounts } = hre
const { vrfCoordinator, prepayment: prepaymentAddress } = await getNamedAccounts()
const prepayment = await ethers.getContractAt(Prepayment__factory.abi, prepaymentAddress)

const VRFConsumerFactory = await ethers.getContractFactory('VRFConsumer')

const contracts = []
for (let i = 0; i < count; i++) {
const userContract = await VRFConsumerFactory.deploy(vrfCoordinator)
await userContract.deployed()
contracts.push(userContract.address)

await (await prepayment.addConsumer(ACC_ID, userContract.address)).wait()
}

return contracts
}

async function requestRandomWords(contracts: string[]) {

Check warning on line 29 in scripts/test.ts

View workflow job for this annotation

GitHub Actions / build

'requestRandomWords' is defined but never used
const path = join(__dirname, '../deployments/localhost/VRFConsumer.json')
const VRFConsumerABI = JSON.parse(readFileSync(path, 'utf-8')).abi
for (const contractAddr of contracts) {
const keyHash = getKeyHash()
const callbackGasLimit = 500_000
const numWords = 1

const contract = await ethers.getContractAt(VRFConsumerABI, contractAddr)
await contract.requestRandomWords(keyHash, ACC_ID, callbackGasLimit, numWords)
}
}

async function readRandomwords(contracts: string[]) {
const path = join(__dirname, '../deployments/localhost/VRFConsumer.json')
const VRFConsumerABI = JSON.parse(readFileSync(path, 'utf-8')).abi
for (const contractAddr of contracts) {
const contract = await ethers.getContractAt(VRFConsumerABI, contractAddr)
const randomWord = await contract.sRandomWord()
console.log(`${contract.address} randomWord ${randomWord.toString()}`)
}
}

async function main() {
// const contracts = await createContracts(5)
// console.log(contracts)
const contracts = [
'0x8A791620dd6260079BF849Dc5567aDC3F2FdC318',
'0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e',
'0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82',
'0x0B306BF915C4d645ff596e518fAf3F9669b97016',
'0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE'
]
// await requestRandomWords(contracts)
await readRandomwords(contracts)
}

main().catch((error) => {
console.error(error)
process.exitCode = 1
})
2 changes: 2 additions & 0 deletions scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export function getKeyHash() {
return '0xd9af33106d664a53cb9946df5cd81a30695f5b72224ee64e798b278af812779c'
} else if (networkName == 'cypress') {
return '0x6cff5233743b3c0321a19ae11ab38ae0ddc7ddfe1e91b162fa8bb657488fb157'
} else if (networkName == 'localhost') {
return '0xeaec8ebbc75ec18c1d761e4e11d2eab84392a55786264a3aa7385ab4532db1e4'
} else {
throw new Error(`Key Hash is not defined for network: ${networkName}`)
}
Expand Down

0 comments on commit 1de7e62

Please sign in to comment.