diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..e70e457c --- /dev/null +++ b/.eslintignore @@ -0,0 +1,6 @@ +node_modules/* +dist/* +web-dev-server.config.js +tsup.config.ts +**/test/** +vite.config.ts diff --git a/packages/dapp-kit-ui/.eslintignore b/packages/dapp-kit-ui/.eslintignore index 71989e68..59b446e0 100644 --- a/packages/dapp-kit-ui/.eslintignore +++ b/packages/dapp-kit-ui/.eslintignore @@ -2,3 +2,5 @@ node_modules/* dist/* web-dev-server.config.js tsup.config.ts +test +vite.config.ts diff --git a/packages/dapp-kit-ui/.gitignore b/packages/dapp-kit-ui/.gitignore index 7f7160e9..e9c7fb05 100644 --- a/packages/dapp-kit-ui/.gitignore +++ b/packages/dapp-kit-ui/.gitignore @@ -1,6 +1,5 @@ /node_modules/ /lib/ -/test/ custom-elements.json # top level source my-element.js @@ -8,4 +7,4 @@ my-element.js.map my-element.d.ts my-element.d.ts.map # only generated for size check -my-element.bundled.js \ No newline at end of file +my-element.bundled.js diff --git a/packages/dapp-kit-ui/package.json b/packages/dapp-kit-ui/package.json index 73f20f5f..dbada4b4 100644 --- a/packages/dapp-kit-ui/package.json +++ b/packages/dapp-kit-ui/package.json @@ -21,6 +21,7 @@ "format": "prettier \"**/*.{cjs,html,js,json,md,ts}\" --ignore-path ./.eslintignore --write", "lint": "tsc --noEmit && eslint src --ext .js,.jsx,.ts,.tsx", "purge": "yarn clean && rm -rf node_modules", + "test": "vitest run --coverage", "watch": "tsup --watch" }, "dependencies": { @@ -37,10 +38,14 @@ "@typescript-eslint/eslint-plugin": "^5.25.0", "@typescript-eslint/parser": "^5.25.0", "@vechain/repo-config": "https://github.com/vechainfoundation/repo-config#v0.0.1", + "@vitest/coverage-v8": "^0.34.6", "eslint": "^8.15.0", "parcel": "^2.10.2", "prettier": "^2.6.2", "tsup": "^7.2.0", - "typescript": "~5.2.0" + "typechain": "^8.3.2", + "typescript": "~5.2.0", + "vite": "^4.5.0", + "vitest": "^0.34.6" } } diff --git a/packages/dapp-kit-ui/src/components/index.ts b/packages/dapp-kit-ui/src/components/index.ts index b986c786..320cc30c 100644 --- a/packages/dapp-kit-ui/src/components/index.ts +++ b/packages/dapp-kit-ui/src/components/index.ts @@ -4,6 +4,7 @@ import './vwk-connect-button'; import './vwk-connect-button-with-modal'; import './vwk-source-card'; import './vwk-fonts'; +import './vwk-wallet-connect-qrcode'; export * from './base'; export * from './vwk-connect-modal'; diff --git a/packages/dapp-kit-ui/src/index.ts b/packages/dapp-kit-ui/src/index.ts index ece1673e..14d8a782 100644 --- a/packages/dapp-kit-ui/src/index.ts +++ b/packages/dapp-kit-ui/src/index.ts @@ -1,3 +1,5 @@ +import './components'; + export * from './client'; export * from './assets'; export * from './components'; diff --git a/packages/dapp-kit-ui/test/connect-buton-with-modal.test.ts b/packages/dapp-kit-ui/test/connect-buton-with-modal.test.ts new file mode 100644 index 00000000..d00214ea --- /dev/null +++ b/packages/dapp-kit-ui/test/connect-buton-with-modal.test.ts @@ -0,0 +1,57 @@ +import { beforeEach, describe, expect, it } from 'vitest'; + +import { + ConnectButton, + ConnectButtonWithModal, + ConnectModal, + DAppKit, + SourceInfo, +} from '../src'; +import { elementQueries } from './helpers/elemnt-queries'; +import { WalletSource } from '@vechainfoundation/dapp-kit/src'; + +describe('connect-button-with-modal', () => { + beforeEach(() => { + DAppKit.configure({ nodeUrl: 'https://mainnet.vechain.org/' }); + }); + + it('Should callback with source when user clicks a wallet', async () => { + const element: ConnectButtonWithModal = window.document.createElement( + 'vwk-connect-button-with-modal', + ); + + let selectedSource: WalletSource | undefined; + + element.onSourceClick = (source?: SourceInfo) => { + selectedSource = source?.id; + }; + + window.document.body.appendChild(element); + + const connectButton = + (await elementQueries.getConnectButton()) as ConnectButton; + const connectModal = + (await elementQueries.getConnectModal()) as ConnectModal; + + expect(connectModal).toBeDefined(); + expect(connectButton).toBeDefined(); + + expect(connectModal.open).toBe(false); + + connectButton.shadowRoot?.querySelector('button')?.click(); + + await new Promise((resolve) => setTimeout(resolve, 1000)); + + expect(connectModal.open).toBe(true); + + const sourceCards = await elementQueries.getAllSourceCards(); + + expect(sourceCards.length).toBeGreaterThan(0); + + sourceCards[0]?.shadowRoot?.querySelector('div')?.click(); + + await new Promise((resolve) => setTimeout(resolve, 1000)); + + expect(selectedSource).toBeDefined(); + }); +}); diff --git a/packages/dapp-kit-ui/test/helpers/elemnt-queries.ts b/packages/dapp-kit-ui/test/helpers/elemnt-queries.ts new file mode 100644 index 00000000..97164afb --- /dev/null +++ b/packages/dapp-kit-ui/test/helpers/elemnt-queries.ts @@ -0,0 +1,69 @@ +import { ConnectButton, ConnectModal, SourceCard } from '../../src'; + +const performQueryWithTimeout = async ( + timeout: number, + query: () => T | undefined | null, +): Promise => { + const startTime = Date.now(); + + let element = query(); + + while (!element && Date.now() - startTime < timeout) { + await new Promise((resolve) => setTimeout(resolve, 10)); + element = query(); + } + + return element; +}; + +const getConnectButton = ( + timeout = 2000, +): Promise => { + return performQueryWithTimeout(timeout, () => + window.document.body + .querySelector('vwk-connect-button-with-modal') + ?.shadowRoot?.querySelector('vwk-connect-button'), + ); +}; + +const getConnectModal = (): Promise => { + return performQueryWithTimeout(2000, () => + window.document.body + .querySelector('vwk-connect-button-with-modal') + ?.shadowRoot?.querySelector('vwk-connect-modal'), + ); +}; +const getAllSourceCards = async (): Promise => { + const res = await performQueryWithTimeout(2000, () => + window.document.body + .querySelector('vwk-connect-button-with-modal') + ?.shadowRoot?.querySelector('vwk-connect-modal') + ?.shadowRoot?.querySelector('vwk-base-modal') + ?.querySelectorAll('vwk-source-card'), + ); + + const sourceCards: SourceCard[] = []; + + res?.forEach((sourceCard) => { + sourceCards.push(sourceCard); + }); + + return sourceCards; +}; + +const getWalletConnectQrCode = () => { + return performQueryWithTimeout(2000, () => + window.document.body + .querySelector('vwk-connect-button-with-modal') + ?.shadowRoot?.querySelector('vwk-connect-modal') + ?.shadowRoot?.querySelector('vwk-base-modal') + ?.querySelector('vwk-wallet-connect-qrcode'), + ); +}; + +export const elementQueries = { + getConnectButton, + getConnectModal, + getAllSourceCards, + getWalletConnectQrCode, +}; diff --git a/packages/dapp-kit-ui/test/qr-code.test.ts b/packages/dapp-kit-ui/test/qr-code.test.ts new file mode 100644 index 00000000..a6e509ad --- /dev/null +++ b/packages/dapp-kit-ui/test/qr-code.test.ts @@ -0,0 +1,51 @@ +import { describe, expect, it } from 'vitest'; +import { + ConnectButton, + ConnectButtonWithModal, + DAppKit, + dispatchCustomEvent, + WalletConnectQrCode, +} from '../src'; +import { elementQueries } from './helpers/elemnt-queries'; + +const sampleUri = + 'wc:59f6594baa77ca343197f60436e5a188708b045e323aa4d6ce93722772e18deb@2?relay-protocol=irn&symKey=0422890abbd3baf75cefad89e822b01071cd906705d6c9282596de866376a824'; + +describe('qr-code-modal', () => { + beforeEach(() => { + DAppKit.configure({ + nodeUrl: 'https://mainnet.vechain.org/', + walletConnectOptions: { + projectId: '123', + metadata: { + name: 'VeChain', + description: 'VeChain', + icons: ['https://vechain.org/images/logo.svg'], + url: 'https://vechain.org', + }, + }, + }); + }); + + it('should display QR code', async () => { + const element: ConnectButtonWithModal = window.document.createElement( + 'vwk-connect-button-with-modal', + ); + + window.document.body.appendChild(element); + + const connectButton = + (await elementQueries.getConnectButton()) as ConnectButton; + + connectButton.shadowRoot?.querySelector('button')?.click(); + + dispatchCustomEvent('vwk-open-wc-modal', { uri: sampleUri }); + + const qrCode = + (await elementQueries.getWalletConnectQrCode()) as WalletConnectQrCode; + + expect(qrCode).toBeDefined(); + + expect(qrCode.walletConnectQRcode).toBe(sampleUri); + }); +}); diff --git a/packages/dapp-kit-ui/test/setup/setup.ts b/packages/dapp-kit-ui/test/setup/setup.ts new file mode 100644 index 00000000..d1e924ec --- /dev/null +++ b/packages/dapp-kit-ui/test/setup/setup.ts @@ -0,0 +1,17 @@ +import { vi } from 'vitest'; + +vi.mock('@walletconnect/modal'); + +Object.defineProperty(window, 'matchMedia', { + writable: true, + value: vi.fn().mockImplementation((query) => ({ + matches: false, + media: query, + onchange: null, + addListener: vi.fn(), // deprecated + removeListener: vi.fn(), // deprecated + addEventListener: vi.fn(), + removeEventListener: vi.fn(), + dispatchEvent: vi.fn(), + })), +}); diff --git a/packages/dapp-kit-ui/vite.config.ts b/packages/dapp-kit-ui/vite.config.ts new file mode 100644 index 00000000..39c466e4 --- /dev/null +++ b/packages/dapp-kit-ui/vite.config.ts @@ -0,0 +1,29 @@ +/// +import { defineConfig } from 'vitest/config'; +import { resolve } from 'node:path'; // eslint-disable-next-line import/no-default-export + +// eslint-disable-next-line import/no-default-export +export default defineConfig({ + test: { + include: ['test/**/*.test.ts'], + environment: 'jsdom', + reporters: 'dot', + setupFiles: [resolve(__dirname, 'test/setup/setup.ts')], + coverage: { + reporter: [ + 'text', + 'json', + 'html', + 'lcov', + 'json-summary', + 'text-summary', + 'text', + ], + lines: 80, + statements: 80, + functions: 60, + branches: 80, + }, + globals: true, + }, +}); diff --git a/packages/dapp-kit/.eslintignore b/packages/dapp-kit/.eslintignore new file mode 100644 index 00000000..59b446e0 --- /dev/null +++ b/packages/dapp-kit/.eslintignore @@ -0,0 +1,6 @@ +node_modules/* +dist/* +web-dev-server.config.js +tsup.config.ts +test +vite.config.ts diff --git a/packages/dapp-kit/.eslintrc.js b/packages/dapp-kit/.eslintrc.mjs similarity index 100% rename from packages/dapp-kit/.eslintrc.js rename to packages/dapp-kit/.eslintrc.mjs diff --git a/packages/dapp-kit/package.json b/packages/dapp-kit/package.json index ac4ac6be..3a0c3eba 100644 --- a/packages/dapp-kit/package.json +++ b/packages/dapp-kit/package.json @@ -2,6 +2,7 @@ "name": "@vechainfoundation/dapp-kit", "version": "0.0.0", "private": false, + "type": "module", "main": "./dist/index.js", "types": "./dist/index.d.ts", "scripts": { diff --git a/packages/dapp-kit/src/connex.ts b/packages/dapp-kit/src/connex.ts index 87e3c45c..7c1c50dd 100644 --- a/packages/dapp-kit/src/connex.ts +++ b/packages/dapp-kit/src/connex.ts @@ -1,11 +1,31 @@ -import { createNoVendor, LazyDriver } from '@vechain/connex/esm/driver'; -import { newThor } from '@vechain/connex-framework/dist/thor'; -import type { DriverNoVendor } from '@vechain/connex-driver'; -import { newVendor } from '@vechain/connex-framework'; +import { DriverNoVendor, SimpleNet } from '@vechain/connex-driver'; +import { Framework } from '@vechain/connex-framework'; +import { blake2b256 } from 'thor-devkit'; import type { ConnexOptions } from './types'; import { normalizeGenesisBlock } from './genesis'; import { WalletManager } from './wallet-manager'; +const cache: Record = {}; + +const createThorDriver = ( + node: string, + genesis: Connex.Thor.Block, +): DriverNoVendor => { + const key = blake2b256( + JSON.stringify({ + node, + genesis, + }), + ).toString('hex'); + + let driver = cache[key]; + if (!driver) { + driver = new DriverNoVendor(new SimpleNet(node), genesis); + cache[key] = driver; + } + return driver; +}; + class MultiWalletConnex { public readonly thor: Connex.Thor; public readonly vendor: Connex.Vendor; @@ -16,20 +36,17 @@ class MultiWalletConnex { const genesisBlock = normalizeGenesisBlock(genesis); - const thorOnlyDriver: DriverNoVendor = createNoVendor( - nodeUrl, - genesisBlock, - ); + const driver = createThorDriver(nodeUrl, genesisBlock); const walletManager = new WalletManager(options); - const lazyDriver = new LazyDriver(Promise.resolve(walletManager)); - lazyDriver.setNoVendor(thorOnlyDriver); - const thor = newThor(lazyDriver); - const vendor = newVendor(lazyDriver); + driver.signTx = walletManager.signTx.bind(walletManager); + driver.signCert = walletManager.signCert.bind(walletManager); + + const framework = new Framework(driver); - this.thor = thor; - this.vendor = vendor; + this.thor = framework.thor; + this.vendor = framework.vendor; this.wallet = walletManager; } } diff --git a/packages/dapp-kit/src/create-wallet.ts b/packages/dapp-kit/src/create-wallet.ts index 0d25f134..3aed4269 100644 --- a/packages/dapp-kit/src/create-wallet.ts +++ b/packages/dapp-kit/src/create-wallet.ts @@ -1,9 +1,10 @@ -import { createSync, createSync2 } from '@vechain/connex/esm/signer'; +import { Connex } from '@vechain/connex'; import { createWcClient, createWcModal, newWcSigner } from './wallet-connect'; import type { ConnexOptions, ConnexWallet, WalletSource } from './types'; import { CertificateBasedWallet } from './wallets/certificate-wallet'; import { WCWallet } from './wallets/wc-wallet'; import { normalizeGenesisId } from './genesis'; +import { convertVendorToSigner } from './vendor-signer'; type ICreateWallet = ConnexOptions & { source: WalletSource; @@ -25,14 +26,14 @@ export const createWallet = ({ throw new Error('User is not in a Sync wallet'); } - const signer = createSync(genesisId); + const vendor = new Connex.Vendor(genesisId, 'sync'); - return new CertificateBasedWallet(signer); + return new CertificateBasedWallet(convertVendorToSigner(vendor)); } case 'sync2': { - const signer = createSync2(genesisId); + const vendor = new Connex.Vendor(genesisId, 'sync2'); - return new CertificateBasedWallet(signer); + return new CertificateBasedWallet(convertVendorToSigner(vendor)); } case 'veworld-extension': { if (!window.vechain) { @@ -41,7 +42,7 @@ export const createWallet = ({ const signer = window.vechain.newConnexSigner(genesisId); - return new CertificateBasedWallet(Promise.resolve(signer)); + return new CertificateBasedWallet(signer); } case 'wallet-connect': { if (!walletConnectOptions) { diff --git a/packages/dapp-kit/src/genesis.ts b/packages/dapp-kit/src/genesis.ts index 7a38e739..8dc91acb 100644 --- a/packages/dapp-kit/src/genesis.ts +++ b/packages/dapp-kit/src/genesis.ts @@ -1,6 +1,54 @@ -import { genesisBlocks } from '@vechain/connex/esm/config'; import type { Genesis } from './types'; +type NetworkType = 'main' | 'test'; + +export const genesisBlocks: Record = { + main: { + number: 0, + id: '0x00000000851caf3cfdb6e899cf5958bfb1ac3413d346d43539627e6be7ec1b4a', + size: 170, + parentID: + '0xffffffff53616c757465202620526573706563742c20457468657265756d2100', + timestamp: 1530316800, + gasLimit: 10000000, + beneficiary: '0x0000000000000000000000000000000000000000', + gasUsed: 0, + totalScore: 0, + txsRoot: + '0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0', + txsFeatures: 0, + stateRoot: + '0x09bfdf9e24dd5cd5b63f3c1b5d58b97ff02ca0490214a021ed7d99b93867839c', + receiptsRoot: + '0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0', + signer: '0x0000000000000000000000000000000000000000', + isTrunk: true, + transactions: [], + }, + test: { + number: 0, + id: '0x000000000b2bce3c70bc649a02749e8687721b09ed2e15997f466536b20bb127', + size: 170, + parentID: + '0xffffffff00000000000000000000000000000000000000000000000000000000', + timestamp: 1530014400, + gasLimit: 10000000, + beneficiary: '0x0000000000000000000000000000000000000000', + gasUsed: 0, + totalScore: 0, + txsRoot: + '0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0', + txsFeatures: 0, + stateRoot: + '0x4ec3af0acbad1ae467ad569337d2fe8576fe303928d35b8cdd91de47e9ac84bb', + receiptsRoot: + '0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0', + signer: '0x0000000000000000000000000000000000000000', + isTrunk: true, + transactions: [], + }, +}; + const normalizeGenesisId = (genesis?: Genesis): string => { if (!genesis) return genesisBlocks.main.id; diff --git a/packages/dapp-kit/src/index.ts b/packages/dapp-kit/src/index.ts index 2af3eaf9..11d7dd55 100644 --- a/packages/dapp-kit/src/index.ts +++ b/packages/dapp-kit/src/index.ts @@ -2,6 +2,7 @@ export * from './connex'; export * from './wallet'; export * from './wallet-manager'; export * from './wallet-connect'; +export * from './genesis'; export type { ConnexOptions, diff --git a/packages/dapp-kit/src/types.d.ts b/packages/dapp-kit/src/types.d.ts index 155c61f1..4a91641e 100644 --- a/packages/dapp-kit/src/types.d.ts +++ b/packages/dapp-kit/src/types.d.ts @@ -1,4 +1,3 @@ -import type { Connex1 } from '@vechain/connex/esm/signer'; import type { WalletConnectOptions } from '@vechainfoundation/dapp-kit'; import type { WCModal } from './wallet-connect'; @@ -7,7 +6,7 @@ declare global { vechain?: { newConnexSigner: (genesisId: string) => Connex.Signer; }; - connex?: Connex1; + connex?: unknown; } } diff --git a/packages/dapp-kit/src/vendor-signer.ts b/packages/dapp-kit/src/vendor-signer.ts new file mode 100644 index 00000000..ad316bdd --- /dev/null +++ b/packages/dapp-kit/src/vendor-signer.ts @@ -0,0 +1,58 @@ +export const convertVendorToSigner = (vendor: Connex.Vendor): Connex.Signer => { + return { + signTx: (msg, options): Promise => { + const service = vendor.sign('tx', msg); + + if (options.gas) { + service.gas(options.gas); + } + + if (options.signer) { + service.signer(options.signer); + } + + if (options.dependsOn) { + service.dependsOn(options.dependsOn); + } + + if (options.link) { + service.link(options.link); + } + + if (options.comment) { + service.comment(options.comment); + } + + if (options.delegator) { + service.delegate( + options.delegator.url, + options.delegator.signer, + ); + } + + if (options.onAccepted) { + service.accepted(options.onAccepted); + } + + return service.request(); + }, + + signCert: (msg, options): Promise => { + const service = vendor.sign('cert', msg); + + if (options.signer) { + service.signer(options.signer); + } + + if (options.link) { + service.link(options.link); + } + + if (options.onAccepted) { + service.accepted(options.onAccepted); + } + + return service.request(); + }, + }; +}; diff --git a/packages/dapp-kit/src/wallets/certificate-wallet.ts b/packages/dapp-kit/src/wallets/certificate-wallet.ts index 2d8b02a4..f7b4afa6 100644 --- a/packages/dapp-kit/src/wallets/certificate-wallet.ts +++ b/packages/dapp-kit/src/wallets/certificate-wallet.ts @@ -6,7 +6,7 @@ import { DEFAULT_CONNECT_CERT_MESSAGE } from '../certificates'; * A `ConnexWallet` for wallet's that use a certificate connection */ class CertificateBasedWallet implements ConnexWallet { - constructor(private readonly wallet: Promise) {} + constructor(private readonly wallet: BaseWallet) {} connect = async (): Promise => { const cert = DEFAULT_CONNECT_CERT_MESSAGE; @@ -41,16 +41,14 @@ class CertificateBasedWallet implements ConnexWallet { msg: Connex.Vendor.CertMessage, options: Connex.Signer.CertOptions, ): Promise => - this.wallet.then((w) => w.signCert(msg, options)); + this.wallet.signCert(msg, options); signTx = ( msg: Connex.Vendor.TxMessage, options: Connex.Signer.TxOptions, - ): Promise => - this.wallet.then((w) => w.signTx(msg, options)); + ): Promise => this.wallet.signTx(msg, options); - disconnect = async (): Promise => - this.wallet.then((w) => w.disconnect?.()); + disconnect = async (): Promise => this.wallet.disconnect?.(); } export { CertificateBasedWallet }; diff --git a/packages/dapp-kit/test/genesis.test.ts b/packages/dapp-kit/test/genesis.test.ts index 8ebc321d..2c449044 100644 --- a/packages/dapp-kit/test/genesis.test.ts +++ b/packages/dapp-kit/test/genesis.test.ts @@ -1,6 +1,9 @@ import { describe, expect, it } from 'vitest'; -import { genesisBlocks } from '@vechain/connex/esm/config'; -import { normalizeGenesisBlock, normalizeGenesisId } from '../src/genesis'; +import { + genesisBlocks, + normalizeGenesisBlock, + normalizeGenesisId, +} from '../src/genesis'; const customBlock = { number: 0, diff --git a/packages/dapp-kit/test/wallet-tests/sync.test.ts b/packages/dapp-kit/test/wallet-tests/sync.test.ts index bdbe2d44..b99b4669 100644 --- a/packages/dapp-kit/test/wallet-tests/sync.test.ts +++ b/packages/dapp-kit/test/wallet-tests/sync.test.ts @@ -1,21 +1,43 @@ import { beforeEach, expect, vi } from 'vitest'; import { mockedConnexSigner } from '../helpers/mocked-signer'; import { createUnitTestConnex } from '../helpers/connex-helper'; +import { genesisBlocks } from '../../src'; +import { Connex } from '@vechain/connex'; -vi.mock('@vechain/connex/esm/signer', () => { +vi.mock('@vechain/connex'); + +vi.mocked(Connex.Vendor).mockImplementation((): Connex.Vendor => { return { - createSync: (): Promise => - Promise.resolve(mockedConnexSigner), + sign: (type, msg) => { + if (type === 'tx') { + return { + request: () => { + return mockedConnexSigner.signTx(msg, {}); + }, + }; + } else { + return { + request: () => { + return mockedConnexSigner.signCert(msg, {}); + }, + }; + } + }, }; }); describe('sync', () => { describe('is in sync browser', () => { beforeEach(() => { + // @ts-ignore window.connex = { - //eslint-disable-next-line @typescript-eslint/ban-ts-comment - //@ts-expect-error - test: 'hello world', + thor: { + genesis: genesisBlocks.main, + }, + vendor: { + // @ts-ignore + sign: () => Promise.reject('Not implemented'), + }, }; }); diff --git a/packages/dapp-kit/test/wallet-tests/sync2.test.ts b/packages/dapp-kit/test/wallet-tests/sync2.test.ts index 5f54be16..dcba5bb4 100644 --- a/packages/dapp-kit/test/wallet-tests/sync2.test.ts +++ b/packages/dapp-kit/test/wallet-tests/sync2.test.ts @@ -1,11 +1,27 @@ import { expect, vi } from 'vitest'; -import { mockedConnexSigner } from '../helpers/mocked-signer'; import { createUnitTestConnex } from '../helpers/connex-helper'; +import { Connex } from '@vechain/connex'; +import { mockedConnexSigner } from '../helpers/mocked-signer'; + +vi.mock('@vechain/connex'); -vi.mock('@vechain/connex/esm/signer', () => { +vi.mocked(Connex.Vendor).mockImplementation((): Connex.Vendor => { return { - createSync2: (): Promise => - Promise.resolve(mockedConnexSigner), + sign: (type, msg) => { + if (type === 'tx') { + return { + request: () => { + return mockedConnexSigner.signTx(msg, {}); + }, + }; + } else { + return { + request: () => { + return mockedConnexSigner.signCert(msg, {}); + }, + }; + } + }, }; }); diff --git a/packages/dapp-kit/tsconfig.json b/packages/dapp-kit/tsconfig.json index ceb22d38..f34a11a8 100644 --- a/packages/dapp-kit/tsconfig.json +++ b/packages/dapp-kit/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "@vechain/repo-config/src/tsconfig/base.json", "include": ["."], - "exclude": ["dist", "node_modules"], + "exclude": ["dist", "node_modules", "test"], "compilerOptions": { "target": "ES6" } diff --git a/packages/dapp-kit/vite.config.ts b/packages/dapp-kit/vite.config.ts index f0bf9c60..4b12fd57 100644 --- a/packages/dapp-kit/vite.config.ts +++ b/packages/dapp-kit/vite.config.ts @@ -1,6 +1,6 @@ /// import { resolve } from 'node:path'; -import { defineConfig } from 'vitest/config'; +import { defineConfig } from 'vitest/config'; // eslint-disable-next-line import/no-default-export // eslint-disable-next-line import/no-default-export export default defineConfig({ @@ -10,7 +10,19 @@ export default defineConfig({ setupFiles: [resolve(__dirname, 'test/setup/setup.ts')], reporters: 'dot', coverage: { - reporter: ['text', 'json', 'html'], + reporter: [ + 'text', + 'json', + 'html', + 'lcov', + 'json-summary', + 'text-summary', + 'text', + ], + lines: 80, + statements: 80, + functions: 80, + branches: 80, }, globals: true, }, diff --git a/yarn.lock b/yarn.lock index 17f5c0f5..32f99888 100644 --- a/yarn.lock +++ b/yarn.lock @@ -19269,7 +19269,7 @@ type-is@~1.6.18: media-typer "0.3.0" mime-types "~2.1.24" -typechain@^8.2.0: +typechain@^8.2.0, typechain@^8.3.2: version "8.3.2" resolved "https://registry.yarnpkg.com/typechain/-/typechain-8.3.2.tgz#1090dd8d9c57b6ef2aed3640a516bdbf01b00d73" integrity sha512-x/sQYr5w9K7yv3es7jo4KTX05CLxOf7TRWwoHlrjRh8H82G64g+k7VuWPJlgMo6qrjfCulOdfBjiaDtmhFYD/Q==