Skip to content

Commit

Permalink
fix: parsing of array inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
yi-sun committed Feb 14, 2024
1 parent 28faed4 commit b596acc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
6 changes: 5 additions & 1 deletion build/axiom-std-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ var require_utils = __commonJS({
const rawInputs = (0, viem_1.decodeAbiParameters)(abi, inputs2);
const circuitInputs2 = {};
for (let i = 0; i < keys.length; i++) {
circuitInputs2[keys[i]] = rawInputs[i].toString();
if (Array.isArray(rawInputs[i])) {
circuitInputs2[keys[i]] = rawInputs[i].map((x) => x.toString());
} else {
circuitInputs2[keys[i]] = rawInputs[i].toString();
}
}
return circuitInputs2;
};
Expand Down
8 changes: 6 additions & 2 deletions cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,17 @@ export const getInputs = (inputs: string, inputSchema: string): any => {
const inputSchemaJson = JSON.parse(inputSchema);
const keys = Object.keys(inputSchemaJson);
const abi = getAbi();

const rawInputs: any[] = decodeAbiParameters(abi, inputs as `0x${string}`);

const circuitInputs: any = {};
for (let i = 0; i < keys.length; i++) {
// if (keys[i] !== abi[i].name) throw new Error(`Input key ${keys[i]} does not match ABI name ${abi[i].name}`);
circuitInputs[keys[i]] = rawInputs[i].toString();
if (Array.isArray(rawInputs[i])) {
circuitInputs[keys[i]] = rawInputs[i].map((x: any) => x.toString());
} else {
circuitInputs[keys[i]] = rawInputs[i].toString();
}
}

return circuitInputs;
}
2 changes: 1 addition & 1 deletion src/AxiomCli.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ pragma solidity ^0.8.0;
library AxiomCli {

/// @dev The SHA256 hash of the Axiom CLI binary
bytes public constant CLI_SHASUM = hex"4ee15c16a8d9354fc886f0ad85956e2e130d1aa3110fca277976b4682b24f184";
bytes public constant CLI_SHASUM = hex"e769cc8bcf823a026b3ea8d902aec4190e73e3576b9684b60d2be7c3d9b80410";
}
10 changes: 4 additions & 6 deletions test/AverageBalance.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ contract AverageBalanceTest is AxiomTest {
function setUp() public {
_createSelectForkAndSetupAxiom("sepolia", 5_103_100);

input =
AxiomInput({ blockNumber: 4_205_938, _address: address(0x8018fe32fCFd3d166E8b4c4E37105318A84BA11b) });
input = AxiomInput({ blockNumber: 4_205_938, _address: address(0x8018fe32fCFd3d166E8b4c4E37105318A84BA11b) });
querySchema = axiomVm.readCircuit("test/circuit/average.circuit.ts");
averageBalance = new AverageBalance(axiomV2QueryAddress, uint64(block.chainid), querySchema);
}
Expand All @@ -34,7 +33,7 @@ contract AverageBalanceTest is AxiomTest {
// send the query to Axiom
q.send();

// prank fulfillment of the query, returning the Axiom results
// prank fulfillment of the query, returning the Axiom results
bytes32[] memory results = q.prankFulfill();

// parse Axiom results and verify length is as expected
Expand All @@ -57,9 +56,8 @@ contract AverageBalanceTest is AxiomTest {
overrideAxiomQueryFee: 0
});

// create a query into Axiom with custom `callbackExtraData` and `feeData`
Query memory q =
query(querySchema, abi.encode(input), address(averageBalance), callbackExtraData, feeData);
// create a query into Axiom with custom `callbackExtraData` and `feeData`
Query memory q = query(querySchema, abi.encode(input), address(averageBalance), callbackExtraData, feeData);

// send the query to Axiom
q.send();
Expand Down

0 comments on commit b596acc

Please sign in to comment.