Skip to content

Commit

Permalink
[SDK] v2 fix secrets schema for process protected data parameter vali… (
Browse files Browse the repository at this point in the history
  • Loading branch information
abbesBenayache authored Apr 26, 2024
2 parents 7cf4c16 + 055fee4 commit 53d468e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
3 changes: 0 additions & 3 deletions packages/sdk/src/utils/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ export const secretsSchema = () =>
({ label }) =>
`${label} must be an object with numeric keys and string values`,
(value) => {
if (!value || typeof value !== 'object') {
return false;
}
for (const key in value) {
const val = value[key];
if (typeof Number(key) !== 'number' || typeof val !== 'string') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('dataProtectorCore.processProtectedData()', () => {
authorizedApp: appAddress,
protectedData: protectedData.address,
authorizedUser: wallet.address,
numberOfAccess: 1000,
});
}, 2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME);
it(
Expand All @@ -77,4 +78,16 @@ describe('dataProtectorCore.processProtectedData()', () => {
},
2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
);
it(
'should successfully process a protected data with the minimum parameters',
async () => {
const taskId = await dataProtectorCore.processProtectedData({
protectedData: protectedData.address,
app: appAddress,
workerpool: workerpoolAddress, // needs to be specified for the test
});
expect(taskId).toBeDefined();
},
2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,27 @@ describe('processProtectedData', () => {
workerpoolorder: MOCK_WORKERPOOL_ORDER.orders[0]?.order,
});
});
it(
'should throw WorkflowError for invalid secret type',
async () => {
mockFetchDatasetOrderbook = jest.fn().mockImplementationOnce(() => {
return Promise.resolve({});
});
iexec.orderbook.fetchDatasetOrderbook = mockFetchDatasetOrderbook;
const secretsValue = 'invalid value';
await expect(
processProtectedData({
iexec,
protectedData: protectedData.address,
app: '0x4605e8af487897faaef16f0709391ef1be828591',
secrets: secretsValue,
})
).rejects.toThrow(
new WorkflowError(
`secrets must be a \`object\` type, but the final value was: \`\"${secretsValue}\"\`.`
)
);
},
2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
);
});

0 comments on commit 53d468e

Please sign in to comment.