Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose pending UTXOs returned by the minter #477

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Include timestamp and tags in the candid provenance record.
- Upgrade `didc` to `0.3.5`.
- Update ckbtc candid to ic commit `4de99bc27be74048f80d13200f3c75cf2a43438c`.
- Include pending UTXOs in MinterNoNewUtxosError.

# 2023.10.15-0600Z

Expand Down
21 changes: 18 additions & 3 deletions packages/ckbtc/src/errors/minter.errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { nonNullish } from "@dfinity/utils";
import { fromNullable, nonNullish } from "@dfinity/utils";
import type {
PendingUtxo,
RetrieveBtcError,
RetrieveBtcWithApprovalError,
UpdateBalanceError,
Expand All @@ -10,7 +11,21 @@ export class MinterTemporaryUnavailableError extends MinterGenericError {}
export class MinterAlreadyProcessingError extends MinterGenericError {}

export class MinterUpdateBalanceError extends MinterGenericError {}
export class MinterNoNewUtxosError extends MinterUpdateBalanceError {}
export class MinterNoNewUtxosError extends MinterUpdateBalanceError {
readonly pendingUtxos: PendingUtxo[];
readonly requiredConfirmations: number;
constructor({
pending_utxos,
required_confirmations,
}: {
pending_utxos: [] | [PendingUtxo[]];
required_confirmations: number;
}) {
super();
this.pendingUtxos = fromNullable(pending_utxos) || [];
this.requiredConfirmations = required_confirmations;
}
}

export class MinterRetrieveBtcError extends MinterGenericError {}
export class MinterMalformedAddressError extends MinterRetrieveBtcError {}
Expand Down Expand Up @@ -49,7 +64,7 @@ export const createUpdateBalanceError = (
}

if ("NoNewUtxos" in Err) {
return new MinterNoNewUtxosError();
return new MinterNoNewUtxosError(Err.NoNewUtxos);
}

// Handle types added in the backend but not yet added in the frontend
Expand Down
1 change: 1 addition & 0 deletions packages/ckbtc/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export type {
MinterInfo,
PendingUtxo,
RetrieveBtcOk,
Account as WithdrawalAccount,
} from "../candid/minter";
Expand Down
45 changes: 44 additions & 1 deletion packages/ckbtc/src/minter.canister.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,45 @@ describe("ckBTC minter canister", () => {

it("should throw MinterNoNewUtxosError", async () => {
const service = mock<ActorSubclass<CkBTCMinterService>>();
const pendingUtxo = {
confirmations: 3,
value: 3_2000_000n,
outpoint: {
txid: new Uint8Array([6, 5, 2, 7]),
vout: 1,
},
};

const error = {
Err: {
NoNewUtxos: {
required_confirmations: 123,
current_confirmations: toNullable(456),
pending_utxos: [[pendingUtxo]],
},
} as UpdateBalanceError,
};
service.update_balance.mockResolvedValue(error);

const canister = minter(service);

const owner = Principal.fromText("aaaaa-aa");

const call = () =>
canister.updateBalance({
owner,
});

await expect(call).rejects.toThrowError(
new MinterNoNewUtxosError({
pending_utxos: [[pendingUtxo]],
required_confirmations: 12,
}),
);
});

it("should throw MinterNoNewUtxosError without pending UTXOs", async () => {
const service = mock<ActorSubclass<CkBTCMinterService>>();
const error = {
Err: {
NoNewUtxos: {
Expand All @@ -209,7 +247,12 @@ describe("ckBTC minter canister", () => {
owner,
});

await expect(call).rejects.toThrowError(new MinterNoNewUtxosError());
await expect(call).rejects.toThrowError(
new MinterNoNewUtxosError({
pending_utxos: [],
required_confirmations: 12,
}),
);
});

it("should throw unsupported response", async () => {
Expand Down
Loading