mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 17:45:22 +00:00
proper error handling for bad checksum algorithm
This commit is contained in:
@@ -521,6 +521,68 @@ describe('flashFirmware', () => {
|
||||
|
||||
await saga.end();
|
||||
});
|
||||
|
||||
test('bad checksum algorithm', async () => {
|
||||
const metadata: FirmwareMetadata = {
|
||||
'metadata-version': '1.0.0',
|
||||
'device-id': HubType.MoveHub,
|
||||
// @ts-expect-error: testing bad value
|
||||
'checksum-type': 'bad',
|
||||
'firmware-version': '1.2.3',
|
||||
'max-firmware-size': 1024,
|
||||
'mpy-abi-version': 5,
|
||||
'mpy-cross-options': ['-mno-unicode'],
|
||||
'user-mpy-offset': 100,
|
||||
};
|
||||
|
||||
const zip = new JSZip();
|
||||
zip.file('firmware-base.bin', new Uint8Array(64));
|
||||
zip.file('firmware.metadata.json', JSON.stringify(metadata));
|
||||
zip.file('main.py', 'print("test")');
|
||||
zip.file('ReadMe_OSS.txt', 'test');
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
});
|
||||
|
||||
saga.setState({ settings: { flashCurrentProgram: false } });
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
saga.put(
|
||||
flashFirmwareAction(await zip.generateAsync({ type: 'arraybuffer' })),
|
||||
);
|
||||
|
||||
// the first step is to compile main.py to .mpy
|
||||
|
||||
let action = await saga.take();
|
||||
expect(action).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"options": Array [
|
||||
"-mno-unicode",
|
||||
],
|
||||
"script": "print(\\"test\\")",
|
||||
"type": "mpy.action.compile",
|
||||
}
|
||||
`);
|
||||
|
||||
const mpySize = 20;
|
||||
const mpyBinaryData = new Uint8Array(mpySize);
|
||||
saga.put(didCompile(mpyBinaryData));
|
||||
|
||||
// should fail due to bad checksum algorithm
|
||||
|
||||
action = await saga.take();
|
||||
expect(action).toEqual(
|
||||
didFailToStart(
|
||||
FailToStartReasonType.BadMetadata,
|
||||
'checksum-type',
|
||||
MetadataProblem.NotSupported,
|
||||
),
|
||||
);
|
||||
|
||||
await saga.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('user supplied main.py', async () => {
|
||||
|
||||
@@ -183,7 +183,14 @@ function* loadFirmware(
|
||||
firmware.set(mpy.data, metadata['user-mpy-offset'] + 4);
|
||||
|
||||
if (metadata['checksum-type'] !== 'sum') {
|
||||
throw Error(`Unknown checksum type "${metadata['checksum-type']}"`);
|
||||
yield* put(
|
||||
didFailToStart(
|
||||
FailToStartReasonType.BadMetadata,
|
||||
'checksum-type',
|
||||
MetadataProblem.NotSupported,
|
||||
),
|
||||
);
|
||||
yield* cancel();
|
||||
}
|
||||
|
||||
firmwareView.setUint32(
|
||||
|
||||
Reference in New Issue
Block a user