Skip to content

Commit f09f378

Browse files
committed
Fixing type errors within wdk tests
1 parent 57e7f67 commit f09f378

15 files changed

+177
-161
lines changed

packages/wallet/wdk/src/sequence/manager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export type ManagerOptions = {
3737

3838
extensions?: Extensions.Extensions
3939
context?: Context.Context
40+
context4337?: Context.Context
4041
guest?: Address.Address
4142

4243
encryptedPksDb?: CoreSigners.Pk.Encrypted.EncryptedPksDb

packages/wallet/wdk/test/authcode-pkce.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
22
import { Address, Hex, Bytes } from 'ox'
33
import * as Identity from '@0xsequence/identity-instrument'
4-
import { AuthCodePkceHandler } from '../src/sequence/handlers/authcode-pkce'
5-
import { Signatures } from '../src/sequence/signatures'
6-
import * as Db from '../src/dbs'
7-
import { IdentitySigner } from '../src/identity/signer'
4+
import { AuthCodePkceHandler } from '../src/sequence/handlers/authcode-pkce.js'
5+
import { Signatures } from '../src/sequence/signatures.js'
6+
import * as Db from '../src/dbs/index.js'
7+
import { IdentitySigner } from '../src/identity/signer.js'
88

99
describe('AuthCodePkceHandler', () => {
1010
let handler: AuthCodePkceHandler

packages/wallet/wdk/test/authcode.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
22
import { Address, Hex, Bytes } from 'ox'
33
import { Network, Payload } from '@0xsequence/wallet-primitives'
44
import { IdentityInstrument, IdentityType, KeyType, AuthCodeChallenge } from '@0xsequence/identity-instrument'
5-
import { AuthCodeHandler } from '../src/sequence/handlers/authcode'
6-
import { Signatures } from '../src/sequence/signatures'
7-
import * as Db from '../src/dbs'
8-
import { IdentitySigner } from '../src/identity/signer'
9-
import { BaseSignatureRequest } from '../src/sequence/types/signature-request'
5+
import { AuthCodeHandler } from '../src/sequence/handlers/authcode.js'
6+
import { Signatures } from '../src/sequence/signatures.js'
7+
import * as Db from '../src/dbs/index.js'
8+
import { IdentitySigner } from '../src/identity/signer.js'
9+
import { BaseSignatureRequest } from '../src/sequence/types/signature-request.js'
1010

1111
// Mock the global crypto API
1212
const mockCryptoSubtle = {
@@ -254,7 +254,7 @@ describe('AuthCodeHandler', () => {
254254

255255
// Verify commitment was saved
256256
expect(mockAuthCommitmentsSet).toHaveBeenCalledOnce()
257-
const commitmentCall = mockAuthCommitmentsSet.mock.calls[0][0]
257+
const commitmentCall = mockAuthCommitmentsSet.mock.calls[0]![0]!
258258

259259
expect(commitmentCall.kind).toBe('google-pkce')
260260
expect(commitmentCall.signer).toBe(signer)
@@ -279,15 +279,15 @@ describe('AuthCodeHandler', () => {
279279
const result = await authCodeHandler.commitAuth('/target', false, customState)
280280

281281
// Verify commitment uses custom state
282-
const commitmentCall = mockAuthCommitmentsSet.mock.calls[0][0]
282+
const commitmentCall = mockAuthCommitmentsSet.mock.calls[0]![0]!
283283
expect(commitmentCall.id).toBe(customState)
284284
expect(result).toContain(`state=${customState}`)
285285
})
286286

287287
it('Should generate random state when not provided', async () => {
288288
const result = await authCodeHandler.commitAuth('/target', false)
289289

290-
const commitmentCall = mockAuthCommitmentsSet.mock.calls[0][0]
290+
const commitmentCall = mockAuthCommitmentsSet.mock.calls[0]![0]!
291291
expect(commitmentCall.id).toBeDefined()
292292
expect(typeof commitmentCall.id).toBe('string')
293293
expect(commitmentCall.id.startsWith('0x')).toBe(true)
@@ -316,7 +316,7 @@ describe('AuthCodeHandler', () => {
316316
it('Should create commitment without signer', async () => {
317317
const result = await authCodeHandler.commitAuth('/target', true)
318318

319-
const commitmentCall = mockAuthCommitmentsSet.mock.calls[0][0]
319+
const commitmentCall = mockAuthCommitmentsSet.mock.calls[0]![0]!
320320
expect(commitmentCall.signer).toBeUndefined()
321321
expect(commitmentCall.isSignUp).toBe(true)
322322
})
@@ -348,12 +348,12 @@ describe('AuthCodeHandler', () => {
348348

349349
// Verify commitVerifier was called
350350
expect(mockCommitVerifier).toHaveBeenCalledOnce()
351-
const commitVerifierCall = mockCommitVerifier.mock.calls[0]
351+
const commitVerifierCall = mockCommitVerifier.mock.calls[0]!
352352
expect(commitVerifierCall[1]).toBeInstanceOf(AuthCodeChallenge)
353353

354354
// Verify completeAuth was called
355355
expect(mockCompleteAuth).toHaveBeenCalledOnce()
356-
const completeAuthCall = mockCompleteAuth.mock.calls[0]
356+
const completeAuthCall = mockCompleteAuth.mock.calls[0]!
357357
expect(completeAuthCall[1]).toBeInstanceOf(AuthCodeChallenge)
358358

359359
// Verify results
@@ -490,7 +490,7 @@ describe('AuthCodeHandler', () => {
490490
expect(window.location.href).toContain('https://accounts.google.com/o/oauth2/v2/auth')
491491
expect(mockAuthCommitmentsSet).toHaveBeenCalledOnce()
492492

493-
const commitmentCall = mockAuthCommitmentsSet.mock.calls[0][0]
493+
const commitmentCall = mockAuthCommitmentsSet.mock.calls[0]![0]!
494494
expect(commitmentCall.target).toBe(window.location.pathname)
495495
expect(commitmentCall.isSignUp).toBe(false)
496496
expect(commitmentCall.signer).toBe(testWallet)
@@ -711,14 +711,14 @@ describe('AuthCodeHandler', () => {
711711
// Test signup flow
712712
await authCodeHandler.commitAuth('/signup-target', true, 'signup-state')
713713

714-
const signupCall = mockAuthCommitmentsSet.mock.calls[0][0]
714+
const signupCall = mockAuthCommitmentsSet.mock.calls[0]![0]!
715715
expect(signupCall.isSignUp).toBe(true)
716716
expect(signupCall.target).toBe('/signup-target')
717717

718718
// Test login flow
719719
await authCodeHandler.commitAuth('/login-target', false, 'login-state')
720720

721-
const loginCall = mockAuthCommitmentsSet.mock.calls[1][0]
721+
const loginCall = mockAuthCommitmentsSet.mock.calls[1]![0]!
722722
expect(loginCall.isSignUp).toBe(false)
723723
expect(loginCall.target).toBe('/login-target')
724724
})

packages/wallet/wdk/test/constants.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { config as dotenvConfig } from 'dotenv'
22
import { Abi, Address, Provider, RpcTransport } from 'ox'
3-
import { Manager, ManagerOptions, ManagerOptionsDefaults } from '../src/sequence'
4-
import { mockEthereum } from './setup'
5-
import { Signers as CoreSigners, State, Relayer } from '@0xsequence/wallet-core'
6-
import * as Db from '../src/dbs'
3+
import { Manager, ManagerOptions, ManagerOptionsDefaults } from '../src/sequence/index.js'
4+
import { mockEthereum } from './setup.js'
5+
import { Signers as CoreSigners, State, Bundler } from '@0xsequence/wallet-core'
6+
import { Relayer } from '@0xsequence/relayer'
7+
import * as Db from '../src/dbs/index.js'
78
import { Network } from '@0xsequence/wallet-primitives'
89

910
const envFile = process.env.CI ? '.env.test' : '.env.test.local'
@@ -81,16 +82,16 @@ export function newRemoteManager(
8182
: `_testrun_${testIdCounter}`
8283

8384
let relayers: Relayer.Relayer[] = []
84-
let bundlers: Relayer.Bundler[] = []
85+
let bundlers: Bundler.Bundler[] = []
8586

8687
if (remoteManagerOptions.network.relayerPk) {
8788
const provider = Provider.from(RpcTransport.fromHttp(remoteManagerOptions.network.rpcUrl))
88-
relayers.push(new Relayer.Standard.PkRelayer(remoteManagerOptions.network.relayerPk as `0x${string}`, provider))
89+
relayers.push(new Relayer.PkRelayer(remoteManagerOptions.network.relayerPk as `0x${string}`, provider))
8990
}
9091

9192
if (remoteManagerOptions.network.bundlerUrl) {
9293
bundlers.push(
93-
new Relayer.Bundlers.PimlicoBundler(
94+
new Bundler.Bundlers.PimlicoBundler(
9495
remoteManagerOptions.network.bundlerUrl,
9596
Provider.from(RpcTransport.fromHttp(remoteManagerOptions.network.rpcUrl)),
9697
),

packages/wallet/wdk/test/guard.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2-
import { Manager } from '../src/sequence'
3-
import { GuardHandler } from '../src/sequence/handlers/guard'
2+
import { Manager } from '../src/sequence/index.js'
3+
import { GuardHandler } from '../src/sequence/handlers/guard.js'
44
import { Address, Bytes, Hex, TypedData } from 'ox'
55
import { Config, Constants, Network, Payload } from '@0xsequence/wallet-primitives'
6-
import { Kinds } from '../src/sequence/types/signer'
7-
import { newManager } from './constants'
8-
import { GuardRole, Guards } from '../src/sequence/guards'
6+
import { Kinds } from '../src/sequence/types/signer.js'
7+
import { newManager } from './constants.js'
8+
import { GuardRole, Guards } from '../src/sequence/guards.js'
99

1010
// Mock fetch globally for guard API calls
1111
const mockFetch = vi.fn()
@@ -163,7 +163,7 @@ describe('GuardHandler', () => {
163163
expect(result).toBe(true)
164164
expect(mockAddSignature).toHaveBeenCalledOnce()
165165

166-
const [requestId, signatureData] = mockAddSignature.mock.calls[0]
166+
const [requestId, signatureData] = mockAddSignature.mock.calls[0]!
167167
expect(requestId).toBe('test-request-id')
168168
expect(signatureData.address).toBe(guards.getByRole('wallet').address)
169169
expect(signatureData.signature).toBeDefined()
@@ -247,7 +247,7 @@ describe('GuardHandler', () => {
247247
expect(mockCallback).toHaveBeenCalledOnce()
248248
expect(mockAddSignature).toHaveBeenCalledOnce()
249249

250-
const [requestId, signatureData] = mockAddSignature.mock.calls[0]
250+
const [requestId, signatureData] = mockAddSignature.mock.calls[0]!
251251
expect(requestId).toBe('test-request-id')
252252
expect(signatureData.address).toBe(guards.getByRole('wallet').address)
253253
expect(signatureData.signature).toBeDefined()
@@ -300,7 +300,7 @@ describe('GuardHandler', () => {
300300
signatures: [],
301301
})
302302

303-
expect(mockFetch.mock.calls[0][0]).toContain(customGuardUrl)
303+
expect(mockFetch.mock.calls[0]![0]).toContain(customGuardUrl)
304304

305305
await customManager.stop()
306306
})

packages/wallet/wdk/test/identity-auth-dbs.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2-
import { Manager } from '../src/sequence'
3-
import { Address, Hex, Bytes } from 'ox'
4-
import { IdentityInstrument } from '@0xsequence/identity-instrument'
5-
import * as Db from '../src/dbs'
6-
import { LOCAL_RPC_URL } from './constants'
2+
import { Manager } from '../src/sequence/index.js'
3+
import * as Db from '../src/dbs/index.js'
4+
import { LOCAL_RPC_URL } from './constants.js'
75
import { State } from '@0xsequence/wallet-core'
86
import { Network } from '@0xsequence/wallet-primitives'
97

packages/wallet/wdk/test/identity-signer.test.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2-
import { Address, Hex, Bytes } from 'ox'
1+
import { afterEach, beforeEach, describe, expect, it, Mock, vi } from 'vitest'
2+
import { Address, Bytes, Hex } from 'ox'
33
import { Network, Payload } from '@0xsequence/wallet-primitives'
44
import { IdentityInstrument, KeyType } from '@0xsequence/identity-instrument'
55
import { State } from '@0xsequence/wallet-core'
6-
import { IdentitySigner, toIdentityAuthKey } from '../src/identity/signer'
7-
import { AuthKey } from '../src/dbs/auth-keys'
6+
import { IdentitySigner, toIdentityAuthKey } from '../src/identity/signer.js'
7+
import { AuthKey } from '../src/dbs/auth-keys.js'
88

99
// Mock the global crypto API
1010
const mockCryptoSubtle = {
@@ -31,7 +31,7 @@ describe('Identity Signer', () => {
3131
let testAuthKey: AuthKey
3232
let testWallet: Address.Address
3333
let mockStateWriter: State.Writer
34-
let mockSignFn: ReturnType<typeof vi.fn>
34+
let mockSignFn: Mock<IdentityInstrument['sign']>
3535

3636
beforeEach(() => {
3737
vi.clearAllMocks()
@@ -179,7 +179,7 @@ describe('Identity Signer', () => {
179179

180180
// Verify that identityInstrument.sign was called with correct parameters
181181
expect(mockSignFn).toHaveBeenCalledOnce()
182-
const [authKeyArg, digestArg] = mockSignFn.mock.calls[0]
182+
const [authKeyArg, digestArg] = mockSignFn.mock.calls[0]!
183183
expect(authKeyArg.address).toBe(testAuthKey.address)
184184
expect(authKeyArg.signer).toBe(testAuthKey.identitySigner)
185185
expect(digestArg).toBeDefined()
@@ -196,7 +196,7 @@ describe('Identity Signer', () => {
196196

197197
expect(mockSignFn).toHaveBeenCalledOnce()
198198
// The digest should be different for different chainIds
199-
const [, digestArg] = mockSignFn.mock.calls[0]
199+
const [, digestArg] = mockSignFn.mock.calls[0]!
200200
expect(digestArg).toBeDefined()
201201
})
202202

@@ -255,7 +255,7 @@ describe('Identity Signer', () => {
255255
}
256256

257257
expect(mockSignFn).toHaveBeenCalledOnce()
258-
const [authKeyArg, digestArg] = mockSignFn.mock.calls[0]
258+
const [authKeyArg, digestArg] = mockSignFn.mock.calls[0]!
259259
expect(authKeyArg.address).toBe(testAuthKey.address)
260260
expect(digestArg).toBe(digest)
261261
})
@@ -295,7 +295,7 @@ describe('Identity Signer', () => {
295295
it('Should handle malformed signature from identity instrument', async () => {
296296
const digest = Hex.toBytes('0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef')
297297

298-
mockSignFn.mockResolvedValueOnce('invalid-signature')
298+
mockSignFn.mockResolvedValueOnce('invalid-signature' as any)
299299

300300
await expect(identitySigner.signDigest(digest)).rejects.toThrow() // Should throw when Signature.fromHex fails
301301
})
@@ -317,7 +317,7 @@ describe('Identity Signer', () => {
317317

318318
// Verify witness was saved
319319
expect(mockSaveWitnesses).toHaveBeenCalledOnce()
320-
const [wallet, chainId, payload, witness] = mockSaveWitnesses.mock.calls[0]
320+
const [wallet, chainId, payload, witness] = mockSaveWitnesses.mock.calls[0]!
321321

322322
expect(wallet).toBe(testWallet)
323323
expect(chainId).toBe(0) // Witness signatures use chainId 0
@@ -338,7 +338,7 @@ describe('Identity Signer', () => {
338338
await identitySigner.witness(mockStateWriter, testWallet)
339339

340340
// Extract the payload that was signed
341-
const [, , payload] = mockSaveWitnesses.mock.calls[0]
341+
const [, , payload] = mockSaveWitnesses.mock.calls[0]!
342342

343343
// Parse the message content to verify consent structure
344344
const messageHex = payload.message
@@ -367,7 +367,7 @@ describe('Identity Signer', () => {
367367
await identitySigner.witness(mockStateWriter, testWallet, extraData)
368368

369369
// Extract and verify extra data was included
370-
const [, , payload] = mockSaveWitnesses.mock.calls[0]
370+
const [, , payload] = mockSaveWitnesses.mock.calls[0]!
371371
const messageString = Hex.toString(payload.message)
372372
const consentData = JSON.parse(messageString)
373373

@@ -435,7 +435,7 @@ describe('Identity Signer', () => {
435435
expect(mockSaveWitnesses).toHaveBeenCalledOnce()
436436

437437
// Verify witness payload includes extra context
438-
const [, , witnessPayload] = mockSaveWitnesses.mock.calls[0]
438+
const [, , witnessPayload] = mockSaveWitnesses.mock.calls[0]!
439439
const witnessMessage = JSON.parse(Hex.toString(witnessPayload.message))
440440
expect(witnessMessage.signatureId).toBe('sig-123')
441441
expect(witnessMessage.purpose).toBe('authentication')
@@ -469,8 +469,8 @@ describe('Identity Signer', () => {
469469
expect(mockSignFn).toHaveBeenCalledTimes(2)
470470

471471
// Verify different payloads produce different hashes
472-
const [, messageDigest] = mockSignFn.mock.calls[0]
473-
const [, transactionDigest] = mockSignFn.mock.calls[1]
472+
const [, messageDigest] = mockSignFn.mock.calls[0]!
473+
const [, transactionDigest] = mockSignFn.mock.calls[1]!
474474
expect(messageDigest).not.toEqual(transactionDigest)
475475
})
476476
})
@@ -500,7 +500,7 @@ describe('Identity Signer', () => {
500500
it('Should handle malformed hex signatures', async () => {
501501
const digest = Hex.toBytes('0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef')
502502

503-
mockSignFn.mockResolvedValueOnce('not-a-hex-string')
503+
mockSignFn.mockResolvedValueOnce('not-a-hex-string' as any)
504504

505505
await expect(identitySigner.signDigest(digest)).rejects.toThrow()
506506
})

packages/wallet/wdk/test/messages.test.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
2-
import { Manager, SignerActionable } from '../src/sequence'
2+
import { Manager, SignerActionable } from '../src/sequence/index.js'
33
import { Mnemonic } from 'ox'
4-
import { newManager } from './constants'
4+
import { newManager } from './constants.js'
55
import { Network } from '@0xsequence/wallet-primitives'
66

77
describe('Messages', () => {
@@ -41,12 +41,13 @@ describe('Messages', () => {
4141
// Verify message appears in list
4242
const messages = await manager.messages.list()
4343
expect(messages.length).toBe(1)
44-
expect(messages[0].wallet).toBe(wallet)
45-
expect(messages[0].message).toBe(testMessage)
46-
expect(messages[0].status).toBe('requested')
47-
expect(messages[0].signatureId).toBe(signatureId)
48-
expect(messages[0].source).toBe('unknown')
49-
expect(messages[0].id).toBeDefined()
44+
const message = messages[0]!
45+
expect(message.wallet).toBe(wallet)
46+
expect(message.message).toBe(testMessage)
47+
expect(message.status).toBe('requested')
48+
expect(message.signatureId).toBe(signatureId)
49+
expect(message.source).toBe('unknown')
50+
expect(message.id).toBeDefined()
5051
})
5152

5253
it('Should create message request with custom source', async () => {
@@ -63,8 +64,11 @@ describe('Messages', () => {
6364

6465
const messages = await manager.messages.list()
6566
expect(messages.length).toBe(1)
66-
expect(messages[0].source).toBe(customSource)
67-
expect(messages[0].message).toBe(testMessage)
67+
68+
const message = messages[0]!
69+
70+
expect(message.source).toBe(customSource)
71+
expect(message.message).toBe(testMessage)
6872
})
6973

7074
it('Should get message by ID', async () => {
@@ -79,7 +83,7 @@ describe('Messages', () => {
7983

8084
const messages = await manager.messages.list()
8185
expect(messages.length).toBe(1)
82-
const messageId = messages[0].id
86+
const messageId = messages[0]!.id
8387

8488
// Get by message ID
8589
const retrievedMessage = await manager.messages.get(messageId)
@@ -269,7 +273,7 @@ describe('Messages', () => {
269273
const signatureId = await manager.messages.request(wallet!, testMessage)
270274

271275
const messages = await manager.messages.list()
272-
const messageId = messages[0].id
276+
const messageId = messages[0]!.id
273277

274278
let updateCallCount = 0
275279
let lastMessage: any
@@ -315,7 +319,7 @@ describe('Messages', () => {
315319
await manager.messages.request(wallet!, testMessage)
316320

317321
const messages = await manager.messages.list()
318-
const messageId = messages[0].id
322+
const messageId = messages[0]!.id
319323

320324
let callCount = 0
321325
let receivedMessage: any

0 commit comments

Comments
 (0)