Skip to content

Commit

Permalink
feat: pass conf and extra (extra still WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertolerda committed Nov 6, 2023
1 parent 4819cb9 commit c5690b7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/core/src/slangroom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ export class Slangroom {
}

const requirifyZenParams = (params?: Partial<ZenParams>): Required<ZenParams> => {
if (!params) return { data: {}, keys: {} };
if (!params) return { data: {}, keys: {}, conf: "", extra: {} };
if (!params.data) params.data = {};
if (!params.keys) params.keys = {};
return params as ZenParams;
return {extra: {}, conf: "", ...params} as Required<ZenParams>;
};
9 changes: 8 additions & 1 deletion pkg/shared/src/zenroom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@ export class ZenError extends Error {
* Zenroom parameters suitable for [[zencode_exec]] (after the values of data
* and keys have been piped to [[JSON.stringify]])
*/
export type ZenParams = { data: JsonableObject; keys: JsonableObject };
export type ZenParams = {
data: JsonableObject;
keys: JsonableObject;
extra?: JsonableObject;
conf?: string;
};

const stringify = (params: ZenParams) => {
return {
data: JSON.stringify(params.data),
keys: JSON.stringify(params.keys),
extra: JSON.stringify(params.extra || {}),
conf: params.conf || "",
};
};

Expand Down
13 changes: 13 additions & 0 deletions pkg/shared/test/zenroom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,16 @@ test('zencodeExec(): throws with invalid input', async (t) => {
const promise = zencodeExec(contract, { data: {}, keys: {} });
await t.throwsAsync(promise, { instanceOf: ZenError });
});

test('zencodeExec(): pass conf', async (t) => {
const contract = `
Scenario 'ecdh': Create the key
Given nothing
When I create the ecdh key
Then print the 'keyring'
`;
const res = await zencodeExec(contract, { data: {}, extra: {}, keys: {}, conf: "debug=3, rngseed=hex:74eeeab870a394175fae808dd5dd3b047f3ee2d6a8d01e14bff94271565625e98a63babe8dd6cbea6fedf3e19de4bc80314b861599522e44409fdd20f7cd6cfc" });
t.deepEqual(res.result, {
keyring: { ecdh: "Aku7vkJ7K01gQehKELav3qaQfTeTMZKgK+5VhaR3Ui0=" }
})
});

0 comments on commit c5690b7

Please sign in to comment.