Reputation: 83
On the hardhat starter kit, the unit test checks if you can make an api request. But it doesn't actually fulfill the request. In the tasks, it requests volume data but it isn't shown how to fulfill the request.
From looking at the code for the mockOracle I found this function.
const r = await mockOracle.fulfillOracleRequest(requestId, data)
I dont have any idea how to make the data be what I want it to be. For example when I pass the following data it returns the huge seamingly random number 24516769870864860957297836120308737325622166553046088662895407649136392011776.
const data = ethers.utils.formatBytes32String("64")
How do I mock the api response with the data I pass to fulfillOracleRequest? Also, because I couldn't find any examples of this in the chainlink starter kit, is this even the right way to be doing this on the local hardhat network?
Upvotes: 2
Views: 929
Reputation: 856
The fulfillOracleRequest function in the MockOracle contract takes a bytes32 param for the response, so you need to encode it properly. This is how you can mock a response as part of the APIConsumer Unit Test:
let mockResponse = '777'
const responseBytes = ethers.utils.formatBytes32String(mockResponse)
const r = await mockOracle.fulfillOracleRequest(requestId, responseBytes)
To answer your second question, yes this is the correct thing to do when working with local chains that aren't integrated to Chainlink oracles. There is actually an open issue to implement these for the unit tests. Feel free to take it on if you want!
Upvotes: 1