You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey there, I'm trying to run some tests on a simple smart contract that uses Chainlink Functions. This is the very simple smart contract:
contractRetrieveEmailisFunctionsClient, ConfirmedOwner {
using FunctionsRequestfor FunctionsRequest.Request;
// State variables to store the last request ID, response, and errorbytes32public s_lastRequestId;
bytespublic s_lastResponse;
bytespublic s_lastError;
// Custom error typeerror UnexpectedRequestID(bytes32requestId);
// Event to log responsesevent Response(
bytes32indexedrequestId,
stringcharacter,
bytesresponse,
byteserr
);
// Router address - Hardcoded for Sepolia// Check to get the router address for your supported network https://docs.chain.link/chainlink-functions/supported-networksaddress router =0xb83E47C2bC239B3bf370bc41e1459A34b41238D0;
// JavaScript source code// Fetch character name from the Star Wars API.// Documentation: https://swapi.info/peoplestring source ="const characterId = args[0];""const apiResponse = await Functions.makeHttpRequest({""url: `https://swapi.info/api/people/${characterId}/`""});""if (apiResponse.error) {""throw Error('Request failed');""}""const { data } = apiResponse;""return Functions.encodeString(data.name);";
//Callback gas limituint32 gasLimit =300000;
// donID - Hardcoded for Sepolia// Check to get the donID for your supported network https://docs.chain.link/chainlink-functions/supported-networksbytes32 donID =0x66756e2d657468657265756d2d7365706f6c69612d3100000000000000000000;
// State variable to store the returned character informationstringpublic character;
/** * @notice Initializes the contract with the Chainlink router address and sets the contract owner */constructor() FunctionsClient(router) ConfirmedOwner(msg.sender) {}
/** * @notice Sends an HTTP request for character information * @param subscriptionId The ID for the Chainlink subscription * @param args The arguments to pass to the HTTP request * @return requestId The ID of the request */function sendRequest(
uint64subscriptionId,
string[] calldataargs
) external onlyOwner returns (bytes32requestId) {
FunctionsRequest.Request memory req;
req.initializeRequestForInlineJavaScript(source); // Initialize the request with JS codeif (args.length>0) req.setArgs(args); // Set the arguments for the request// Send the request and store the request ID
s_lastRequestId =_sendRequest(
req.encodeCBOR(),
subscriptionId,
gasLimit,
donID
);
return s_lastRequestId;
}
/** * @notice Callback function for fulfilling a request * @param requestId The ID of the request to fulfill * @param response The HTTP response data * @param err Any errors from the Functions request */function fulfillRequest(
bytes32requestId,
bytesmemoryresponse,
bytesmemoryerr
) internaloverride {
if (s_lastRequestId != requestId) {
revertUnexpectedRequestID(requestId); // Check if request IDs match
}
// Update the contract's state variables with the response and any errors
s_lastResponse = response;
character =string(response);
s_lastError = err;
// Emit an event to log the responseemitResponse(requestId, character, s_lastResponse, s_lastError);
}
}
And this is the specific function that I am testing from that smart contract:
function sendRequest(
uint64subscriptionId,
string[] calldataargs
) external onlyOwner returns (bytes32requestId) {
FunctionsRequest.Request memory req;
req.initializeRequestForInlineJavaScript(source); // Initialize the request with JS codeif (args.length>0) req.setArgs(args); // Set the arguments for the request// Send the request and store the request ID
s_lastRequestId =_sendRequest(
req.encodeCBOR(),
subscriptionId,
gasLimit,
donID
);
return s_lastRequestId;
}
So I am just trying to pass it a subscriptionId and the array element to access via a test and save the returned requestId to log to console. However, the following test file:
pragma solidity^0.8.18;
import {Test, console} from"forge-std/Test.sol";
import {RetrieveEmail} from"../src/RetrieveEmail.sol";
contractRetrieveEmailTestisTest {
uint256 number =1;
RetrieveEmail retrieveEmail;
bytes32 requestId;
function setUp() external {
retrieveEmail =newRetrieveEmail();
}
function test_demo() public {
requestId = retrieveEmail.sendRequest(2045, ["1"]);
console.logBytes32(requestId);
}
}
Returns this error:
Compiler run failed: Error (9553): Invalid type for argument in function call. Invalid implicit conversion from string[1] memory to string[] memory requested. --> test/RetrieveEmailTest.t.sol:16:53: | 16 | requestId = retrieveEmail.sendRequest(2045, ["1"]); | ^^^^^
I Also have tried requestId = retrieveEmail.sendRequest(2045, "[1]"); and got the same error. Haven't been able to figure out what this error means or any possible ways to solve it yet.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hey there, I'm trying to run some tests on a simple smart contract that uses Chainlink Functions. This is the very simple smart contract:
And this is the specific function that I am testing from that smart contract:
So I am just trying to pass it a subscriptionId and the array element to access via a test and save the returned requestId to log to console. However, the following test file:
Returns this error:
Compiler run failed: Error (9553): Invalid type for argument in function call. Invalid implicit conversion from string[1] memory to string[] memory requested. --> test/RetrieveEmailTest.t.sol:16:53: | 16 | requestId = retrieveEmail.sendRequest(2045, ["1"]); | ^^^^^
I Also have tried requestId = retrieveEmail.sendRequest(2045, "[1]"); and got the same error. Haven't been able to figure out what this error means or any possible ways to solve it yet.
Beta Was this translation helpful? Give feedback.
All reactions