From 87acd1d494e9c45faca676c1d738099b41c65dc3 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Thu, 21 Nov 2024 08:19:27 +0100 Subject: [PATCH 1/6] feat: delete canister snapshot Signed-off-by: David Dal Busco --- .../src/ic-management.canister.spec.ts | 56 +++++++++++++++++++ .../src/ic-management.canister.ts | 31 ++++++++++ 2 files changed, 87 insertions(+) diff --git a/packages/ic-management/src/ic-management.canister.spec.ts b/packages/ic-management/src/ic-management.canister.spec.ts index e8409dbd..7dae31ca 100644 --- a/packages/ic-management/src/ic-management.canister.spec.ts +++ b/packages/ic-management/src/ic-management.canister.spec.ts @@ -805,4 +805,60 @@ describe("ICManagementCanister", () => { await expect(call).rejects.toThrow(error); }); }); + + describe("deleteCanisterSnapshot", () => { + it("should call delete_canister_snapshot with Uint8Array snapshotId", async () => { + const service = mock(); + service.delete_canister_snapshot.mockResolvedValue(undefined); + + const icManagement = await createICManagement(service); + + const params = { + canisterId: mockCanisterId, + snapshotId: Uint8Array.from([1, 2, 3, 4]), + }; + + await icManagement.deleteCanisterSnapshot(params); + + expect(service.delete_canister_snapshot).toHaveBeenCalledWith({ + canister_id: params.canisterId, + snapshot_id: params.snapshotId, + }); + }); + + it("should call delete_canister_snapshot with string snapshotId", async () => { + const service = mock(); + service.delete_canister_snapshot.mockResolvedValue(undefined); + + const icManagement = await createICManagement(service); + + const params = { + canisterId: mockCanisterId, + snapshotId: "000000000000000201010000000000000001", + }; + + await icManagement.deleteCanisterSnapshot(params); + + expect(service.delete_canister_snapshot).toHaveBeenCalledWith({ + canister_id: params.canisterId, + snapshot_id: decodeSnapshotId(params.snapshotId), + }); + }); + + it("should throw an error if delete_canister_snapshot fails", async () => { + const error = new Error("Test error"); + const service = mock(); + service.delete_canister_snapshot.mockRejectedValue(error); + + const icManagement = await createICManagement(service); + + const call = () => + icManagement.deleteCanisterSnapshot({ + canisterId: mockCanisterId, + snapshotId: Uint8Array.from([1, 2, 3, 4]), + }); + + await expect(call).rejects.toThrow(error); + }); + }); }); diff --git a/packages/ic-management/src/ic-management.canister.ts b/packages/ic-management/src/ic-management.canister.ts index 3b17493a..b9d6e6e0 100644 --- a/packages/ic-management/src/ic-management.canister.ts +++ b/packages/ic-management/src/ic-management.canister.ts @@ -392,4 +392,35 @@ export class ICManagementCanister { ), }); }; + + /** + * Deletes a specific snapshot of a canister. + * + * @link https://internetcomputer.org/docs/current/references/ic-interface-spec#ic-delete_canister_snapshot + * + * @param {Object} params - Parameters for the deletion operation. + * @param {Principal} params.canisterId - The ID of the canister for which the snapshot will be deleted. + * @param {snapshot_id} params.snapshotId - The ID of the snapshot to delete. + * + * @returns {Promise} A promise that resolves when the snapshot is successfully deleted. + * + * @throws {Error} If the deletion operation fails. + */ + deleteCanisterSnapshot = async ({ + canisterId, + snapshotId, + }: { + canisterId: Principal; + snapshotId: SnapshotIdText | snapshot_id; + }): Promise => { + const { delete_canister_snapshot } = this.service; + + await delete_canister_snapshot({ + canister_id: canisterId, + snapshot_id: + typeof snapshotId === "string" + ? decodeSnapshotId(snapshotId) + : snapshotId, + }); + }; } From 50edbe1bc13ccd7db54c25baa353355fb88f3e34 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 21 Nov 2024 07:20:50 +0000 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=A4=96=20Documentation=20auto-update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/ic-management/README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/ic-management/README.md b/packages/ic-management/README.md index 97f1b3a0..04b77ee1 100644 --- a/packages/ic-management/README.md +++ b/packages/ic-management/README.md @@ -74,6 +74,7 @@ const { status, memory_size, ...rest } = await canisterStatus(YOUR_CANISTER_ID); - [provisionalCreateCanisterWithCycles](#gear-provisionalcreatecanisterwithcycles) - [fetchCanisterLogs](#gear-fetchcanisterlogs) - [takeCanisterSnapshot](#gear-takecanistersnapshot) +- [deleteCanisterSnapshot](#gear-deletecanistersnapshot) ##### :gear: create @@ -264,6 +265,22 @@ Parameters: [:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L375) +##### :gear: deleteCanisterSnapshot + +Deletes a specific snapshot of a canister. + +| Method | Type | +| ------------------------ | --------------------------------------------------------------------------------------------------------------- | +| `deleteCanisterSnapshot` | `({ canisterId, snapshotId, }: { canisterId: Principal; snapshotId: string or snapshot_id; }) => Promise` | + +Parameters: + +- `params`: - Parameters for the deletion operation. +- `params.canisterId`: - The ID of the canister for which the snapshot will be deleted. +- `params.snapshotId`: - The ID of the snapshot to delete. + +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L409) + ## Resources From 24d79d8bf892bfd4cd1e60dcec95f52c6e8883d8 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Thu, 21 Nov 2024 12:52:19 +0100 Subject: [PATCH 3/6] feat: use mapSnapshotId Signed-off-by: David Dal Busco --- packages/ic-management/src/ic-management.canister.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/ic-management/src/ic-management.canister.ts b/packages/ic-management/src/ic-management.canister.ts index 0d35f9d9..cb9919f9 100644 --- a/packages/ic-management/src/ic-management.canister.ts +++ b/packages/ic-management/src/ic-management.canister.ts @@ -413,10 +413,7 @@ export class ICManagementCanister { await delete_canister_snapshot({ canister_id: canisterId, - snapshot_id: - typeof snapshotId === "string" - ? decodeSnapshotId(snapshotId) - : snapshotId, + snapshot_id: mapSnapshotId(snapshotId), }); }; } From fc6320b316b9fe258c32781752267805ac4904a6 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:53:46 +0000 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=A4=96=20Documentation=20auto-update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/ic-management/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ic-management/README.md b/packages/ic-management/README.md index 04b77ee1..1fc26011 100644 --- a/packages/ic-management/README.md +++ b/packages/ic-management/README.md @@ -279,7 +279,7 @@ Parameters: - `params.canisterId`: - The ID of the canister for which the snapshot will be deleted. - `params.snapshotId`: - The ID of the snapshot to delete. -[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L409) +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L405) From 4279b53fd609fa3072f19a12f8e51b44d01f83e8 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 21 Nov 2024 12:42:17 +0000 Subject: [PATCH 5/6] =?UTF-8?q?=F0=9F=A4=96=20Documentation=20auto-update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/ic-management/README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/ic-management/README.md b/packages/ic-management/README.md index e933eb0a..d9e12e66 100644 --- a/packages/ic-management/README.md +++ b/packages/ic-management/README.md @@ -75,6 +75,7 @@ const { status, memory_size, ...rest } = await canisterStatus(YOUR_CANISTER_ID); - [fetchCanisterLogs](#gear-fetchcanisterlogs) - [takeCanisterSnapshot](#gear-takecanistersnapshot) - [listCanisterSnapshots](#gear-listcanistersnapshots) +- [deleteCanisterSnapshot](#gear-deletecanistersnapshot) ##### :gear: create @@ -280,6 +281,22 @@ Parameters: [:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L405) +##### :gear: deleteCanisterSnapshot + +Deletes a specific snapshot of a canister. + +| Method | Type | +| ------------------------ | --------------------------------------------------------------------------------------------------------------- | +| `deleteCanisterSnapshot` | `({ canisterId, snapshotId, }: { canisterId: Principal; snapshotId: string or snapshot_id; }) => Promise` | + +Parameters: + +- `params`: - Parameters for the deletion operation. +- `params.canisterId`: - The ID of the canister for which the snapshot will be deleted. +- `params.snapshotId`: - The ID of the snapshot to delete. + +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L430) + ## Resources From f58575ecad595055e3270a3947638c56967b3dba Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 21 Nov 2024 12:59:54 +0000 Subject: [PATCH 6/6] =?UTF-8?q?=F0=9F=A4=96=20Documentation=20auto-update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/ic-management/README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/ic-management/README.md b/packages/ic-management/README.md index 3184e1e1..6670b214 100644 --- a/packages/ic-management/README.md +++ b/packages/ic-management/README.md @@ -76,6 +76,7 @@ const { status, memory_size, ...rest } = await canisterStatus(YOUR_CANISTER_ID); - [takeCanisterSnapshot](#gear-takecanistersnapshot) - [listCanisterSnapshots](#gear-listcanistersnapshots) - [loadCanisterSnapshot](#gear-loadcanistersnapshot) +- [deleteCanisterSnapshot](#gear-deletecanistersnapshot) ##### :gear: create @@ -298,6 +299,22 @@ Parameters: [:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L431) +##### :gear: deleteCanisterSnapshot + +Deletes a specific snapshot of a canister. + +| Method | Type | +| ------------------------ | --------------------------------------------------------------------------------------------------------------- | +| `deleteCanisterSnapshot` | `({ canisterId, snapshotId, }: { canisterId: Principal; snapshotId: string or snapshot_id; }) => Promise` | + +Parameters: + +- `params`: - Parameters for the deletion operation. +- `params.canisterId`: - The ID of the canister for which the snapshot will be deleted. +- `params.snapshotId`: - The ID of the snapshot to delete. + +[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L462) + ## Resources