From 0d279ed46ea0308cd0c0a7e44e38b7732640c468 Mon Sep 17 00:00:00 2001 From: Arie Trouw Date: Fri, 15 Nov 2024 12:05:36 -0800 Subject: [PATCH] Some tests fixed --- .../packages/account/src/spec/AddressValue.spec.ts | 4 ++-- .../src/spec/HDWallet/HDWallet.browser.spec.ts | 2 +- .../src/spec/HDWallet/HDWallet.node.spec.ts | 4 ++-- .../account/src/spec/HDWallet/HDWallet.spec.ts | 14 ++++++++++---- .../packages/account/src/spec/PrivateKey.spec.ts | 2 +- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/protocol/packages/account/src/spec/AddressValue.spec.ts b/packages/protocol/packages/account/src/spec/AddressValue.spec.ts index 75555476653..0a771ce0150 100644 --- a/packages/protocol/packages/account/src/spec/AddressValue.spec.ts +++ b/packages/protocol/packages/account/src/spec/AddressValue.spec.ts @@ -1,6 +1,6 @@ import { toUint8Array } from '@xylabs/arraybuffer' -import { Elliptic } from '../Elliptic' +import { Elliptic } from '../Elliptic.ts' describe('AddressValue', () => { const valid: [string, string, string][] = [ @@ -70,7 +70,7 @@ describe('AddressValue', () => { describe('verify', () => { it.each(valid)('Verifies a signature', async (message, signature, address) => { const result = await Elliptic.verify(toUint8Array(message), toUint8Array(signature), toUint8Array(address)) - expect(result).toBeTrue() + expect(result).toBeTruthy() }) }) }) diff --git a/packages/protocol/packages/account/src/spec/HDWallet/HDWallet.browser.spec.ts b/packages/protocol/packages/account/src/spec/HDWallet/HDWallet.browser.spec.ts index 348a199f57e..0eafe9b3c21 100644 --- a/packages/protocol/packages/account/src/spec/HDWallet/HDWallet.browser.spec.ts +++ b/packages/protocol/packages/account/src/spec/HDWallet/HDWallet.browser.spec.ts @@ -15,6 +15,6 @@ describe('Node Wallet Test - Commented Out', () => { it('Stub', () => { - expect(true).toBeTrue() + expect(true).toBe(true) }) }) diff --git a/packages/protocol/packages/account/src/spec/HDWallet/HDWallet.node.spec.ts b/packages/protocol/packages/account/src/spec/HDWallet/HDWallet.node.spec.ts index a32957168a8..3f74ea4d8e7 100644 --- a/packages/protocol/packages/account/src/spec/HDWallet/HDWallet.node.spec.ts +++ b/packages/protocol/packages/account/src/spec/HDWallet/HDWallet.node.spec.ts @@ -1,5 +1,5 @@ -import { HDWallet } from '../../HDWallet' -import { generateHDWalletTests } from './HDWallet.spec' +import { HDWallet } from '../../HDWallet.ts' +import { generateHDWalletTests } from './HDWallet.spec.ts' /** * @group nodejs diff --git a/packages/protocol/packages/account/src/spec/HDWallet/HDWallet.spec.ts b/packages/protocol/packages/account/src/spec/HDWallet/HDWallet.spec.ts index c342f49020a..07e209667a8 100644 --- a/packages/protocol/packages/account/src/spec/HDWallet/HDWallet.spec.ts +++ b/packages/protocol/packages/account/src/spec/HDWallet/HDWallet.spec.ts @@ -4,7 +4,7 @@ import { defaultPath, Mnemonic, SigningKey, } from 'ethers' -import { HDWallet } from '../../HDWallet' +import { HDWallet } from '../../HDWallet.ts' /** * The wallet types that can be tested @@ -68,9 +68,9 @@ const snapshotWalletInstances = (walletA: Wallet, walletB: Wallet) => { const expectWalletsEqual = (sutA: WalletInstance, sutB: Wallet) => { expect(sutA.address).toEqual(formatHexString(sutB.address)) expect(sutA.privateKey).toEqual(sutB.privateKey) - expect(sutA.private.hex).toEqual(formatHexString(sutB.privateKey)) + expect(sutA.private?.hex).toEqual(formatHexString(sutB.privateKey)) expect(sutA.publicKey).toEqual(sutB.publicKey) - expect(sutA.public.hex).toEqual(toUncompressedPublicKey(sutB.publicKey)) + expect(sutA.public?.hex).toEqual(toUncompressedPublicKey(sutB.publicKey)) } /** @@ -173,7 +173,7 @@ export const generateHDWalletTests = (title: string, HDWallet: WalletStatic) => } test('HDWallet tests generator is defined', () => { - expect(generateHDWalletTests).toBeFunction() + expect(typeof generateHDWalletTests).toBe('function') }) test('Same address, two paths', async () => { @@ -205,3 +205,9 @@ test('Random Wallet', async () => { expect(sut.path).toBeDefined() expect(sut.path).toBe(defaultPath) }) + +test('HDWallet can be created from mnemonic', async () => { + const sut = await HDWallet.fromPhrase('abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about', "m/44'/0'/0'/0/0") + expect(sut).toBeDefined() + console.log('address', sut.privateKey) +}) diff --git a/packages/protocol/packages/account/src/spec/PrivateKey.spec.ts b/packages/protocol/packages/account/src/spec/PrivateKey.spec.ts index aaf00e80c5f..8700168d0cd 100644 --- a/packages/protocol/packages/account/src/spec/PrivateKey.spec.ts +++ b/packages/protocol/packages/account/src/spec/PrivateKey.spec.ts @@ -29,7 +29,7 @@ describe('PrivateKey', () => { const data = toUint8Array(hash) const wasmSignature = await privateKey.sign(data) const wasmVerify = await privateKey.verify(data, wasmSignature) - expect(wasmVerify).toBeTrue() + expect(wasmVerify).toBeTruthy() }) // TODO: Negative verification testing test('wasm vs js (performance-serial)', async () => {