Skip to content

Commit

Permalink
Merge pull request #1392 from dusk-network/feature-1315
Browse files Browse the repository at this point in the history
web-wallet: Update dusk-wallet-js to 0.4.1
  • Loading branch information
ascartabelli authored Feb 15, 2024
2 parents 8a2a2b6 + ecd7d61 commit 82f7b7f
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 38 deletions.
1 change: 1 addition & 0 deletions web-wallet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Update deprecated Node actions in CI [#1343](https://github.com/dusk-network/rusk/issues/1343)
- Change `setGasSettings` event to `gasSettings` and include `isValidGas` property in event data [#1354](https://github.com/dusk-network/rusk/issues/1354)
- Change "withdraw stake" label to "unstake" [#1403](https://github.com/dusk-network/rusk/issues/1403)
- Update dusk-wallet-js to 0.4.1 [#1315](https://github.com/dusk-network/rusk/issues/1315)

### Removed

Expand Down
7 changes: 7 additions & 0 deletions web-wallet/__mocks__/Wallet.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
class Wallet {
constructor (seed, gasLimit = 2900000000, gasPrice = 1) {
this.gasLimit = gasLimit;
this.gasPrice = gasPrice;
this.seed = seed;
this.wasm = {};
}

gasLimit;
gasPrice;
seed;
Expand Down
12 changes: 0 additions & 12 deletions web-wallet/__mocks__/initDuskWalletCore.js

This file was deleted.

8 changes: 4 additions & 4 deletions web-wallet/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"type": "module",
"version": "1.0.0-beta",
"dependencies": {
"@dusk-network/dusk-wallet-js": "0.3.2",
"@dusk-network/dusk-wallet-js": "0.4.1",
"@floating-ui/dom": "1.5.3",
"@mdi/js": "7.3.67",
"bip39": "3.1.0",
Expand Down
1 change: 0 additions & 1 deletion web-wallet/src/lib/components/__tests__/ScanQR.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
it
} from "vitest";
import { cleanup, render } from "@testing-library/svelte";
import "jsdom-worker";

import { ScanQR } from "..";

Expand Down
1 change: 0 additions & 1 deletion web-wallet/src/lib/components/__tests__/Send.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
vi
} from "vitest";
import { cleanup, fireEvent, render } from "@testing-library/svelte";
import "jsdom-worker";

import { deductLuxFeeFrom } from "$lib/contracts";
import { createCurrencyFormatter } from "$lib/dusk/currency";
Expand Down
12 changes: 8 additions & 4 deletions web-wallet/src/lib/services/wallet/__tests__/getWallet.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,27 @@ import { enumerables } from "lamb";
import { generateMnemonic } from "bip39";

import { getSeedFromMnemonic } from "$lib/wallet";

import { getWallet } from "..";

vi.unmock("@dusk-network/dusk-wallet-js");

describe("getWallet", () => {
it("should get a Wallet instance using a seed", async () => {
it("should get a Wallet instance using a seed", () => {
const mnemonic = generateMnemonic();
const seed = getSeedFromMnemonic(mnemonic);
const wallet = await getWallet(seed);
const wallet = getWallet(seed);
const walletPublicMembers = [
...enumerables(wallet),
...Object.getOwnPropertyNames(Object.getPrototypeOf(wallet))
];

expect(enumerables(wallet)).toMatchInlineSnapshot(`
expect(walletPublicMembers).toMatchInlineSnapshot(`
[
"wasm",
"seed",
"gasLimit",
"gasPrice",
"constructor",
"getBalance",
"getPsks",
"sync",
Expand Down
6 changes: 5 additions & 1 deletion web-wallet/src/lib/stores/__tests__/walletStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe("walletStore", async () => {
const wallet = new Wallet([]);

const getBalanceSpy = vi.spyOn(Wallet.prototype, "getBalance").mockResolvedValue(balance);
const getPsksSpy = vi.spyOn(Wallet.prototype, "getPsks").mockReturnValue(addresses);
const getPsksSpy = vi.spyOn(Wallet.prototype, "getPsks").mockResolvedValue(addresses);
const historySpy = vi.spyOn(Wallet.prototype, "history").mockResolvedValue(transactions);
const resetSpy = vi.spyOn(Wallet.prototype, "reset").mockResolvedValue(void 0);
const stakeInfoSpy = vi.spyOn(Wallet.prototype, "stakeInfo").mockResolvedValue({});
Expand Down Expand Up @@ -104,6 +104,7 @@ describe("walletStore", async () => {
isSyncing: true,
addresses: addresses
});

expect(getPsksSpy).toHaveBeenCalledTimes(1);
expect(getBalanceSpy).not.toHaveBeenCalled();

Expand Down Expand Up @@ -223,6 +224,9 @@ describe("walletStore", async () => {
isSyncing: true,
addresses: addresses
});

await vi.advanceTimersToNextTimerAsync();

expect(getPsksSpy).toHaveBeenCalledTimes(1);
expect(getBalanceSpy).toHaveBeenCalledTimes(1);
expect(getBalanceSpy).toHaveBeenCalledWith(addresses[0]);
Expand Down
2 changes: 1 addition & 1 deletion web-wallet/src/lib/stores/walletStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async function updateAfterSync () {
async function init (wallet) {
walletInstance = wallet;

const addresses = walletInstance.getPsks();
const addresses = await walletInstance.getPsks();
const currentAddress = addresses[0];

set({
Expand Down
4 changes: 4 additions & 0 deletions web-wallet/src/routes/(app)/__tests__/layout.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@ import * as SvelteKit from "@sveltejs/kit";
import { Wallet } from "@dusk-network/dusk-wallet-js";

import * as navigation from "$lib/navigation";
import { addresses } from "$lib/mock-data";
import { walletStore } from "$lib/stores";

import { load } from "../+layout";
import Layout from "../+layout.svelte";

describe("App layout.js", () => {
const getPsksSpy = vi.spyOn(Wallet.prototype, "getPsks").mockResolvedValue(addresses);
const redirectSpy = vi.spyOn(SvelteKit, "redirect");

afterEach(() => {
getPsksSpy.mockClear();
redirectSpy.mockClear();
});

afterAll(() => {
getPsksSpy.mockRestore();
redirectSpy.mockRestore();
});

Expand Down
6 changes: 2 additions & 4 deletions web-wallet/src/routes/(welcome)/login/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/** @type {(wallet: Wallet) => Promise<Wallet>} */
async function checkLocalData (wallet) {
const defaultAddress = wallet.getPsks()[0];
const defaultAddress = (await wallet.getPsks())[0];
const currentAddress = $settingsStore.userId;
if (defaultAddress !== currentAddress) {
Expand Down Expand Up @@ -64,9 +64,7 @@
getSeed(secretText.trim())
.then(getWallet)
.then(checkLocalData)
.then(wallet => {
walletStore.init(wallet);
})
.then(wallet => walletStore.init(wallet))
.then(() => {
goto("/dashboard");
})
Expand Down
8 changes: 6 additions & 2 deletions web-wallet/src/routes/(welcome)/login/__tests__/page.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { get } from "svelte/store";
import { Wallet } from "@dusk-network/dusk-wallet-js";
import { setKey } from "lamb";

import { addresses } from "$lib/mock-data";
import { getAsHTMLElement } from "$lib/dusk/test-helpers";
import { settingsStore, walletStore } from "$lib/stores";
import { encryptMnemonic, getSeedFromMnemonic } from "$lib/wallet";
Expand All @@ -29,17 +30,18 @@ function getTextInput (container) {
}

describe("Login", async () => {
const walletGetPsksSpy = vi.spyOn(Wallet.prototype, "getPsks").mockResolvedValue(addresses);
const walletResetSpy = vi.spyOn(Wallet.prototype, "reset").mockResolvedValue(void 0);
const mnemonic = generateMnemonic();
const pwd = "some pwd";
const loginInfo = await encryptMnemonic(mnemonic, pwd);
const seed = getSeedFromMnemonic(mnemonic);
const userId = new Wallet(seed).getPsks()[0];
const userId = (await new Wallet(seed).getPsks())[0];
const getErrorElement = () => document.querySelector(".login__error");
const getWalletSpy = vi.spyOn(walletService, "getWallet");
const gotoSpy = vi.spyOn(appNavigation, "goto");
const initSpy = vi.spyOn(walletStore, "init");
const settingsResetSpy = vi.spyOn(settingsStore, "reset");
const walletResetSpy = vi.spyOn(Wallet.prototype, "reset").mockResolvedValue(void 0);

afterEach(() => {
cleanup();
Expand All @@ -48,6 +50,7 @@ describe("Login", async () => {
initSpy.mockClear();
settingsStore.reset();
settingsResetSpy.mockClear();
walletGetPsksSpy.mockClear();
walletResetSpy.mockClear();
walletStore.reset();
});
Expand All @@ -57,6 +60,7 @@ describe("Login", async () => {
gotoSpy.mockRestore();
initSpy.mockRestore();
settingsResetSpy.mockRestore();
walletGetPsksSpy.mockRestore();
walletResetSpy.mockRestore();
});

Expand Down
8 changes: 1 addition & 7 deletions web-wallet/vite-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@ import * as matchers from "@testing-library/jest-dom/matchers";
import { expect, vi } from "vitest";
import { readable } from "svelte/store";
import crypto from "node:crypto";
import "jsdom-worker";

import { IntersectionObserver, ResizeObserver } from "./src/lib/dusk/mocks";
import init from "./__mocks__/initDuskWalletCore.js";
import Wallet from "./__mocks__/Wallet.js";

// Mocking the wallet core wasm
vi.doMock(
"@dusk-network/dusk-wallet-core/dusk_wallet_core_bg.wasm?init",
() => ({ default: vi.fn(init) })
);

// Mocking the Wallet
vi.doMock(
"@dusk-network/dusk-wallet-js",
Expand Down

0 comments on commit 82f7b7f

Please sign in to comment.