Skip to content

Commit 52f4e50

Browse files
committed
Fixing tests
1 parent a6e554d commit 52f4e50

File tree

13 files changed

+76
-171
lines changed

13 files changed

+76
-171
lines changed

packages/wallet/core/test/constants.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
import { Address } from '@0xsequence/wallet-primitives'
12
import { config as dotenvConfig } from 'dotenv'
23
import { Abi, AbiEvent } from 'ox'
34

45
const envFile = process.env.CI ? '.env.test' : '.env.test.local'
56
dotenvConfig({ path: envFile })
67

7-
export const EMITTER_ADDRESS: Address.Checksummed = '0xb7bE532959236170064cf099e1a3395aEf228F44'
8+
export const EMITTER_ADDRESS = Address.checksum('0xb7bE532959236170064cf099e1a3395aEf228F44')
89
export const EMITTER_FUNCTIONS = Abi.from(['function explicitEmit()', 'function implicitEmit()'])
910
export const EMITTER_EVENT_TOPICS = [
1011
AbiEvent.encode(AbiEvent.from('event Explicit(address sender)')).topics[0],
1112
AbiEvent.encode(AbiEvent.from('event Implicit(address sender)')).topics[0],
1213
]
13-
export const USDC_ADDRESS: Address.Checksummed = '0xaf88d065e77c8cc2239327c5edb3a432268e5831'
14+
export const USDC_ADDRESS = Address.checksum('0xaf88d065e77c8cc2239327c5edb3a432268e5831')
1415

1516
// Environment variables
1617
export const LOCAL_RPC_URL = process.env.LOCAL_RPC_URL || 'http://localhost:8545'

packages/wallet/core/test/envelope.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { Address, Hex } from 'ox'
1+
import { Hex } from 'ox'
22
import { describe, expect, it } from 'vitest'
3-
import { Config, Payload, Signature } from '@0xsequence/wallet-primitives'
3+
import { Address, Config, Payload, Signature } from '@0xsequence/wallet-primitives'
44

55
import * as Envelope from '../src/envelope.js'
66

77
// Test addresses and data
8-
const TEST_ADDRESS_1 = Address.from('0x1234567890123456789012345678901234567890')
9-
const TEST_ADDRESS_2 = Address.from('0xabcdefabcdefabcdefabcdefabcdefabcdefabcd')
10-
const TEST_ADDRESS_3 = Address.from('0x9876543210987654321098765432109876543210')
11-
const TEST_WALLET = Address.from('0xfedcbafedcbafedcbafedcbafedcbafedcbafe00')
8+
const TEST_ADDRESS_1 = Address.checksum('0x1234567890123456789012345678901234567890')
9+
const TEST_ADDRESS_2 = Address.checksum('0xabcdefabcdefabcdefabcdefabcdefabcdefabcd')
10+
const TEST_ADDRESS_3 = Address.checksum('0x9876543210987654321098765432109876543210')
11+
const TEST_WALLET = Address.checksum('0xfedcbafedcbafedcbafedcbafedcbafedcbafe00')
1212
const TEST_IMAGE_HASH = Hex.from('0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef')
1313
const TEST_IMAGE_HASH_2 = Hex.from('0x1111111111111111111111111111111111111111111111111111111111111111')
1414

@@ -235,7 +235,7 @@ describe('Envelope', () => {
235235
it('should return undefined for non-existent signer', () => {
236236
const leaf: Config.SignerLeaf = {
237237
type: 'signer',
238-
address: Address.from('0x0000000000000000000000000000000000000000'),
238+
address: Address.checksum('0x0000000000000000000000000000000000000000'),
239239
weight: 1n,
240240
}
241241
const foundSig = Envelope.signatureForLeaf(signedEnvelope, leaf)

packages/wallet/core/test/preconditions.test.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { LocalRelayer } from '../src/relayer/standard/local'
1414
import { CAN_RUN_LIVE, RPC_URL } from './constants'
1515

16-
const ERC20_IMPLICIT_MINT_CONTRACT = '0x041E0CDC028050519C8e6485B2d9840caf63773F'
16+
const ERC20_IMPLICIT_MINT_CONTRACT = Address.checksum('0x041E0CDC028050519C8e6485B2d9840caf63773F')
1717

1818
function randomAddress(): Address.Checksummed {
1919
return Address.fromPublicKey(Secp256k1.getPublicKey({ privateKey: Secp256k1.randomPrivateKey() }))
@@ -63,7 +63,7 @@ describe('Preconditions', () => {
6363
type: precondition.type(),
6464
chainId: chainId.toString(),
6565
data: JSON.stringify({
66-
address: precondition.address.toString(),
66+
address: precondition.address,
6767
min: precondition.min?.toString(),
6868
max: precondition.max?.toString(),
6969
}),
@@ -94,8 +94,8 @@ describe('Preconditions', () => {
9494
type: precondition.type(),
9595
chainId: chainId.toString(),
9696
data: JSON.stringify({
97-
address: precondition.address.toString(),
98-
token: precondition.token.toString(),
97+
address: precondition.address,
98+
token: precondition.token,
9999
min: precondition.min?.toString(),
100100
max: precondition.max?.toString(),
101101
}),
@@ -127,9 +127,9 @@ describe('Preconditions', () => {
127127
type: precondition.type(),
128128
chainId: chainId.toString(),
129129
data: JSON.stringify({
130-
address: precondition.address.toString(),
131-
token: precondition.token.toString(),
132-
operator: precondition.operator.toString(),
130+
address: precondition.address,
131+
token: precondition.token,
132+
operator: precondition.operator,
133133
min: precondition.min.toString(),
134134
}),
135135
}
@@ -159,8 +159,8 @@ describe('Preconditions', () => {
159159
type: precondition.type(),
160160
chainId: chainId.toString(),
161161
data: JSON.stringify({
162-
address: precondition.address.toString(),
163-
token: precondition.token.toString(),
162+
address: precondition.address,
163+
token: precondition.token,
164164
tokenId: precondition.tokenId.toString(),
165165
owned: precondition.owned,
166166
}),
@@ -194,18 +194,16 @@ describe('Preconditions', () => {
194194
type: precondition.type(),
195195
chainId: chainId.toString(),
196196
data: JSON.stringify({
197-
address: precondition.address.toString(),
198-
token: precondition.token.toString(),
197+
address: precondition.address,
198+
token: precondition.token,
199199
tokenId: precondition.tokenId.toString(),
200-
operator: precondition.operator.toString(),
200+
operator: precondition.operator,
201201
}),
202202
}
203203

204204
if (!CAN_RUN_LIVE) {
205205
// Mock the getApproved call
206-
;(provider as any).call.mockResolvedValue(
207-
`0x000000000000000000000000${operator.toString().slice(2).toLowerCase()}`,
208-
)
206+
;(provider as any).call.mockResolvedValue(`0x000000000000000000000000${operator.slice(2).toLowerCase()}`)
209207
}
210208

211209
const isValid = await relayer.checkPrecondition(intentPrecondition)
@@ -229,8 +227,8 @@ describe('Preconditions', () => {
229227
type: precondition.type(),
230228
chainId: chainId.toString(),
231229
data: JSON.stringify({
232-
address: precondition.address.toString(),
233-
token: precondition.token.toString(),
230+
address: precondition.address,
231+
token: precondition.token,
234232
tokenId: precondition.tokenId.toString(),
235233
min: precondition.min?.toString(),
236234
max: precondition.max?.toString(),
@@ -264,10 +262,10 @@ describe('Preconditions', () => {
264262
type: precondition.type(),
265263
chainId: chainId.toString(),
266264
data: JSON.stringify({
267-
address: precondition.address.toString(),
268-
token: precondition.token.toString(),
265+
address: precondition.address,
266+
token: precondition.token,
269267
tokenId: precondition.tokenId.toString(),
270-
operator: precondition.operator.toString(),
268+
operator: precondition.operator,
271269
min: precondition.min.toString(),
272270
}),
273271
}

packages/wallet/core/test/preconditions/codec.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Address } from 'ox'
21
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'
2+
import { Address } from '@0xsequence/wallet-primitives'
33

44
import {
55
decodePrecondition,
@@ -18,9 +18,9 @@ import {
1818
} from '../../src/preconditions/types.js'
1919

2020
// Test addresses
21-
const TEST_ADDRESS = Address.from('0x1234567890123456789012345678901234567890')
22-
const TOKEN_ADDRESS = Address.from('0xabcdefabcdefabcdefabcdefabcdefabcdefabcd')
23-
const OPERATOR_ADDRESS = Address.from('0x9876543210987654321098765432109876543210')
21+
const TEST_ADDRESS = Address.checksum('0x1234567890123456789012345678901234567890')
22+
const TOKEN_ADDRESS = Address.checksum('0xabcdefabcdefabcdefabcdefabcdefabcdefabcd')
23+
const OPERATOR_ADDRESS = Address.checksum('0x9876543210987654321098765432109876543210')
2424

2525
describe('Preconditions Codec', () => {
2626
// Mock console.warn to test error logging

packages/wallet/core/test/preconditions/selectors.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Address } from 'ox'
21
import { describe, expect, it } from 'vitest'
32

43
import {
@@ -13,10 +12,11 @@ import {
1312
Erc20BalancePrecondition,
1413
Erc721OwnershipPrecondition,
1514
} from '../../src/preconditions/types.js'
15+
import { Address } from '@0xsequence/wallet-primitives'
1616

1717
// Test addresses
18-
const TEST_ADDRESS = Address.from('0x1234567890123456789012345678901234567890')
19-
const TOKEN_ADDRESS = Address.from('0xabcdefabcdefabcdefabcdefabcdefabcdefabcd')
18+
const TEST_ADDRESS = Address.checksum('0x1234567890123456789012345678901234567890')
19+
const TOKEN_ADDRESS = Address.checksum('0xabcdefabcdefabcdefabcdefabcdefabcdefabcd')
2020

2121
describe('Preconditions Selectors', () => {
2222
describe('extractChainID', () => {

packages/wallet/core/test/preconditions/types.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Address } from 'ox'
21
import { describe, expect, it } from 'vitest'
2+
import { Address } from '@0xsequence/wallet-primitives'
33

44
import {
55
NativeBalancePrecondition,
@@ -12,9 +12,9 @@ import {
1212
} from '../../src/preconditions/types.js'
1313

1414
// Test addresses
15-
const TEST_ADDRESS = Address.from('0x1234567890123456789012345678901234567890')
16-
const TOKEN_ADDRESS = Address.from('0xabcdefabcdefabcdefabcdefabcdefabcdefabcd')
17-
const OPERATOR_ADDRESS = Address.from('0x9876543210987654321098765432109876543210')
15+
const TEST_ADDRESS = Address.checksum('0x1234567890123456789012345678901234567890')
16+
const TOKEN_ADDRESS = Address.checksum('0xabcdefabcdefabcdefabcdefabcdefabcdefabcd')
17+
const OPERATOR_ADDRESS = Address.checksum('0x9876543210987654321098765432109876543210')
1818

1919
describe('Preconditions Types', () => {
2020
describe('NativeBalancePrecondition', () => {
@@ -53,7 +53,7 @@ describe('Preconditions Types', () => {
5353
})
5454

5555
it('should validate address is required', () => {
56-
const precondition = new NativeBalancePrecondition('' as Address.Address)
56+
const precondition = new NativeBalancePrecondition('' as Address.Checksummed)
5757

5858
const error = precondition.isValid()
5959
expect(error).toBeInstanceOf(Error)
@@ -88,15 +88,15 @@ describe('Preconditions Types', () => {
8888
})
8989

9090
it('should validate address is required', () => {
91-
const precondition = new Erc20BalancePrecondition('' as Address.Address, TOKEN_ADDRESS)
91+
const precondition = new Erc20BalancePrecondition('' as Address.Checksummed, TOKEN_ADDRESS)
9292

9393
const error = precondition.isValid()
9494
expect(error).toBeInstanceOf(Error)
9595
expect(error?.message).toBe('address is required')
9696
})
9797

9898
it('should validate token address is required', () => {
99-
const precondition = new Erc20BalancePrecondition(TEST_ADDRESS, '' as Address.Address)
99+
const precondition = new Erc20BalancePrecondition(TEST_ADDRESS, '' as Address.Checksummed)
100100

101101
const error = precondition.isValid()
102102
expect(error).toBeInstanceOf(Error)

packages/wallet/core/test/relayer/bundler.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { describe, expect, it, vi, beforeEach } from 'vitest'
2-
import { Address, Hex } from 'ox'
2+
import { Hex } from 'ox'
33
import { UserOperation } from 'ox/erc4337'
4-
import { Payload } from '@0xsequence/wallet-primitives'
4+
import { Address, Payload } from '@0xsequence/wallet-primitives'
55
import { Bundler, isBundler } from '../../src/relayer/bundler.js'
66
import { OperationStatus } from '../../src/relayer/relayer.js'
77

88
// Test addresses and data
9-
const TEST_WALLET_ADDRESS = Address.from('0x1234567890123456789012345678901234567890')
10-
const TEST_ENTRYPOINT_ADDRESS = Address.from('0xabcdefabcdefabcdefabcdefabcdefabcdefabcd')
9+
const TEST_WALLET_ADDRESS = Address.checksum('0x1234567890123456789012345678901234567890')
10+
const TEST_ENTRYPOINT_ADDRESS = Address.checksum('0xabcdefabcdefabcdefabcdefabcdefabcdefabcd')
1111
const TEST_CHAIN_ID = 1n
1212
const TEST_OP_HASH = Hex.from('0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef')
1313

@@ -238,11 +238,11 @@ describe('Bundler', () => {
238238
describe('Type compatibility', () => {
239239
it('should work with Address and Hex types from ox', () => {
240240
// Test that the interfaces work correctly with ox types
241-
const address = Address.from('0x1234567890123456789012345678901234567890')
241+
const address = Address.checksum('0x1234567890123456789012345678901234567890')
242242
const hex = Hex.from('0xabcdef')
243243
const chainId = 1n
244244

245-
expect(Address.validate(address)).toBe(true)
245+
expect(Address.isChecksummed(address)).toBe(true)
246246
expect(Hex.validate(hex)).toBe(true)
247247
expect(typeof chainId).toBe('bigint')
248248
})

packages/wallet/core/test/relayer/relayer.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it, vi, beforeEach } from 'vitest'
2-
import { Address, Hex } from 'ox'
3-
import { Payload, Precondition } from '@0xsequence/wallet-primitives'
2+
import { Hex } from 'ox'
3+
import { Address, Payload, Precondition } from '@0xsequence/wallet-primitives'
44
import {
55
Relayer,
66
isRelayer,
@@ -17,8 +17,8 @@ import {
1717
import { FeeTokenType } from '../../src/relayer/standard/rpc/index.js'
1818

1919
// Test addresses and data
20-
const TEST_WALLET_ADDRESS = Address.from('0x1234567890123456789012345678901234567890')
21-
const TEST_TO_ADDRESS = Address.from('0xabcdefabcdefabcdefabcdefabcdefabcdefabcd')
20+
const TEST_WALLET_ADDRESS = Address.checksum('0x1234567890123456789012345678901234567890')
21+
const TEST_TO_ADDRESS = Address.checksum('0xabcdefabcdefabcdefabcdefabcdefabcdefabcd')
2222
const TEST_DATA = Hex.from('0x12345678')
2323
const TEST_CHAIN_ID = 1n
2424
const TEST_OP_HASH = Hex.from('0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef')
@@ -338,11 +338,11 @@ describe('Relayer', () => {
338338
describe('Type compatibility', () => {
339339
it('should work with Address and Hex types from ox', () => {
340340
// Test that the interfaces work correctly with ox types
341-
const address = Address.from('0x1234567890123456789012345678901234567890')
341+
const address = Address.checksum('0x1234567890123456789012345678901234567890')
342342
const hex = Hex.from('0xabcdef')
343343
const chainId = 1n
344344

345-
expect(Address.validate(address)).toBe(true)
345+
expect(Address.isChecksummed(address)).toBe(true)
346346
expect(Hex.validate(hex)).toBe(true)
347347
expect(typeof chainId).toBe('bigint')
348348
})

packages/wallet/core/test/state/cached.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { Address, Hex } from 'ox'
1+
import { Hex } from 'ox'
22
import { describe, expect, it, vi, beforeEach } from 'vitest'
33

4+
import { Address } from '@0xsequence/wallet-primitives'
45
import { Cached } from '../../src/state/cached.js'
56
import type { Provider } from '../../src/state/index.js'
67

78
// Test data
8-
const TEST_ADDRESS = Address.from('0x1234567890123456789012345678901234567890')
9-
const TEST_ADDRESS_2 = Address.from('0xabcdefabcdefabcdefabcdefabcdefabcdefabcd')
9+
const TEST_ADDRESS = Address.checksum('0x1234567890123456789012345678901234567890')
10+
const TEST_ADDRESS_2 = Address.checksum('0xabcdefabcdefabcdefabcdefabcdefabcdefabcd')
1011
const TEST_IMAGE_HASH = Hex.from('0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef')
1112
const TEST_ROOT_HASH = Hex.from('0xfedcba098765432109876543210987654321098765432109876543210987654321')
1213
const TEST_OP_HASH = Hex.from('0x1111111111111111111111111111111111111111111111111111111111111111')
@@ -495,8 +496,8 @@ describe('Cached', () => {
495496
})
496497

497498
it('should handle address normalization correctly', async () => {
498-
const cacheData = { [TEST_ADDRESS.toLowerCase()]: mockWalletData }
499-
const sourceData = { [TEST_ADDRESS_2.toLowerCase()]: mockWalletData }
499+
const cacheData = { [TEST_ADDRESS]: mockWalletData }
500+
const sourceData = { [TEST_ADDRESS_2]: mockWalletData }
500501

501502
vi.mocked(mockCache.getWallets).mockResolvedValue(cacheData)
502503
vi.mocked(mockSource.getWallets).mockResolvedValue(sourceData)

packages/wallet/core/test/state/debug.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { Address, Hex } from 'ox'
1+
import { Hex } from 'ox'
22
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'
33

4+
import { Address } from '@0xsequence/wallet-primitives'
45
import { multiplex } from '../../src/state/debug.js'
56

67
// Test data
7-
const TEST_ADDRESS = Address.from('0x1234567890123456789012345678901234567890')
8-
const TEST_HEX = Hex.from('0xabcdef123456')
8+
const TEST_ADDRESS = Address.checksum('0x1234567890123456789012345678901234567890')
99
const TEST_UINT8ARRAY = new Uint8Array([171, 205, 239, 18, 52, 86])
1010

1111
describe('State Debug', () => {

0 commit comments

Comments
 (0)