ox 1.8.13 → 1.8.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/dist/core/AbiError.d.ts +2 -2
- package/dist/core/AbiError.d.ts.map +1 -1
- package/dist/core/AbiError.js +6 -2
- package/dist/core/AbiError.js.map +1 -1
- package/dist/core/AbiEvent.d.ts +71 -1
- package/dist/core/AbiEvent.d.ts.map +1 -1
- package/dist/core/AbiEvent.js +160 -19
- package/dist/core/AbiEvent.js.map +1 -1
- package/dist/core/AbiFunction.d.ts +1 -1
- package/dist/core/AbiFunction.d.ts.map +1 -1
- package/dist/core/AbiFunction.js +3 -5
- package/dist/core/AbiFunction.js.map +1 -1
- package/dist/core/AbiItem.d.ts.map +1 -1
- package/dist/core/AbiItem.js +18 -8
- package/dist/core/AbiItem.js.map +1 -1
- package/dist/core/Base32.d.ts +3 -3
- package/dist/core/Base32.d.ts.map +1 -1
- package/dist/core/Base32.js +5 -2
- package/dist/core/Base32.js.map +1 -1
- package/dist/core/Bytes.d.ts.map +1 -1
- package/dist/core/Bytes.js +4 -3
- package/dist/core/Bytes.js.map +1 -1
- package/dist/core/Caches.d.ts +1 -2
- package/dist/core/Caches.d.ts.map +1 -1
- package/dist/core/Caches.js +1 -4
- package/dist/core/Caches.js.map +1 -1
- package/dist/core/Cbor.d.ts.map +1 -1
- package/dist/core/Cbor.js +16 -2
- package/dist/core/Cbor.js.map +1 -1
- package/dist/core/CompactSize.d.ts +8 -1
- package/dist/core/CompactSize.d.ts.map +1 -1
- package/dist/core/CompactSize.js +9 -0
- package/dist/core/CompactSize.js.map +1 -1
- package/dist/core/Hex.d.ts.map +1 -1
- package/dist/core/Hex.js +9 -4
- package/dist/core/Hex.js.map +1 -1
- package/dist/core/Rlp.d.ts +9 -2
- package/dist/core/Rlp.d.ts.map +1 -1
- package/dist/core/Rlp.js +51 -8
- package/dist/core/Rlp.js.map +1 -1
- package/dist/core/RpcTransport.d.ts.map +1 -1
- package/dist/core/RpcTransport.js +11 -4
- package/dist/core/RpcTransport.js.map +1 -1
- package/dist/core/Siwe.d.ts.map +1 -1
- package/dist/core/Siwe.js +24 -9
- package/dist/core/Siwe.js.map +1 -1
- package/dist/core/TypedData.d.ts.map +1 -1
- package/dist/core/TypedData.js +13 -9
- package/dist/core/TypedData.js.map +1 -1
- package/dist/core/Value.d.ts.map +1 -1
- package/dist/core/Value.js +5 -3
- package/dist/core/Value.js.map +1 -1
- package/dist/core/internal/abiItem.d.ts +3 -1
- package/dist/core/internal/abiItem.d.ts.map +1 -1
- package/dist/core/internal/abiItem.js +5 -3
- package/dist/core/internal/abiItem.js.map +1 -1
- package/dist/core/internal/caches.d.ts +10 -0
- package/dist/core/internal/caches.d.ts.map +1 -0
- package/dist/core/internal/caches.js +10 -0
- package/dist/core/internal/caches.js.map +1 -0
- package/dist/core/internal/frameNonce.d.ts.map +1 -1
- package/dist/core/internal/frameNonce.js +2 -2
- package/dist/core/internal/frameNonce.js.map +1 -1
- package/dist/erc4337/UserOperation.d.ts +15 -2
- package/dist/erc4337/UserOperation.d.ts.map +1 -1
- package/dist/erc4337/UserOperation.js +8 -2
- package/dist/erc4337/UserOperation.js.map +1 -1
- package/dist/erc8021/Attribution.d.ts.map +1 -1
- package/dist/erc8021/Attribution.js +12 -3
- package/dist/erc8021/Attribution.js.map +1 -1
- package/dist/tempo/AccountOperation.d.ts +8 -0
- package/dist/tempo/AccountOperation.d.ts.map +1 -1
- package/dist/tempo/AccountOperation.js +26 -6
- package/dist/tempo/AccountOperation.js.map +1 -1
- package/dist/tempo/SignatureEnvelope.d.ts +4 -4
- package/dist/tempo/Tick.d.ts.map +1 -1
- package/dist/tempo/Tick.js +4 -3
- package/dist/tempo/Tick.js.map +1 -1
- package/dist/zod/Address.d.ts.map +1 -1
- package/dist/zod/Address.js +2 -1
- package/dist/zod/Address.js.map +1 -1
- package/dist/zod/FrameRequest.d.ts.map +1 -1
- package/dist/zod/FrameRequest.js +2 -1
- package/dist/zod/FrameRequest.js.map +1 -1
- package/dist/zod/Hex.d.ts.map +1 -1
- package/dist/zod/Hex.js +2 -1
- package/dist/zod/Hex.js.map +1 -1
- package/dist/zod/Solidity.d.ts.map +1 -1
- package/dist/zod/Solidity.js +12 -7
- package/dist/zod/Solidity.js.map +1 -1
- package/dist/zod/TypedData.d.ts +12 -12
- package/package.json +1 -1
- package/src/core/AbiError.ts +33 -22
- package/src/core/AbiEvent.ts +177 -18
- package/src/core/AbiFunction.ts +10 -7
- package/src/core/AbiItem.ts +17 -8
- package/src/core/Base32.ts +8 -3
- package/src/core/Bytes.ts +4 -3
- package/src/core/Caches.ts +1 -6
- package/src/core/Cbor.ts +20 -2
- package/src/core/CompactSize.ts +13 -0
- package/src/core/Hex.ts +10 -5
- package/src/core/Rlp.ts +55 -5
- package/src/core/RpcTransport.ts +11 -4
- package/src/core/Siwe.ts +26 -11
- package/src/core/TypedData.ts +14 -9
- package/src/core/Value.ts +6 -3
- package/src/core/_test/AbiError.test-d.ts +10 -0
- package/src/core/_test/AbiError.test.ts +73 -0
- package/src/core/_test/AbiEvent.fuzz.ts +260 -0
- package/src/core/_test/AbiEvent.snap-d.ts +9 -0
- package/src/core/_test/AbiEvent.test.ts +421 -0
- package/src/core/_test/AbiFunction.snap-d.ts +25 -0
- package/src/core/_test/AbiFunction.test.ts +101 -18
- package/src/core/_test/AbiItem.snap-d.ts +11 -0
- package/src/core/_test/AbiItem.test.ts +155 -1
- package/src/core/_test/Base32.test.ts +16 -0
- package/src/core/_test/Bytes.test.ts +15 -0
- package/src/core/_test/Caches.test.ts +10 -1
- package/src/core/_test/Cbor.test.ts +23 -0
- package/src/core/_test/CompactSize.test.ts +14 -0
- package/src/core/_test/Hex.test.ts +25 -0
- package/src/core/_test/Rlp.test.ts +51 -0
- package/src/core/_test/RpcTransport.test.ts +47 -0
- package/src/core/_test/Siwe.test.ts +28 -0
- package/src/core/_test/TypedData.test.ts +17 -2
- package/src/core/internal/abiItem.ts +16 -7
- package/src/core/internal/caches.ts +12 -0
- package/src/core/internal/frameNonce.ts +3 -4
- package/src/erc4337/UserOperation.ts +30 -3
- package/src/erc4337/_test/UserOperation.test.ts +132 -35
- package/src/erc8021/Attribution.ts +9 -7
- package/src/erc8021/_test/Attribution.test.ts +37 -0
- package/src/tempo/AccountOperation.test.ts +116 -0
- package/src/tempo/AccountOperation.ts +38 -5
- package/src/tempo/AccountSimulation.test.ts +1 -1
- package/src/tempo/SignatureEnvelope.test.ts +12 -0
- package/src/tempo/SignatureEnvelope.ts +4 -4
- package/src/tempo/Tick.test.ts +10 -0
- package/src/tempo/Tick.ts +5 -3
- package/src/version.ts +1 -1
- package/src/zod/Address.ts +3 -3
- package/src/zod/FrameRequest.ts +3 -4
- package/src/zod/Hex.ts +3 -1
- package/src/zod/Solidity.ts +15 -18
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { fc, test } from '@fast-check/vitest'
|
|
2
|
+
import { AbiEvent, Errors } from 'ox'
|
|
3
|
+
import { describe, expect } from 'vp/test'
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
arbitraryEventCase,
|
|
7
|
+
arbitraryNoiseLog,
|
|
8
|
+
type EventCase,
|
|
9
|
+
encodeLog,
|
|
10
|
+
eventNames,
|
|
11
|
+
expectedArgs,
|
|
12
|
+
isHashed,
|
|
13
|
+
type Log,
|
|
14
|
+
lowercase,
|
|
15
|
+
} from '../../../test/fuzz/arbitraries/abiEvent.js'
|
|
16
|
+
import { numRuns } from '../../../test/fuzz/numRuns.js'
|
|
17
|
+
|
|
18
|
+
function logOf(value: EventCase) {
|
|
19
|
+
return encodeLog(value, AbiEvent.getSelector(value.abiEvent))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function indexedCount(abiEvent: AbiEvent.AbiEvent) {
|
|
23
|
+
return abiEvent.inputs.filter((input) => input.indexed).length
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** A random ABI, and logs that its events emit, mixed with noise. */
|
|
27
|
+
const arbitraryAbiCase = fc
|
|
28
|
+
.array(arbitraryEventCase(), { maxLength: 4, minLength: 1 })
|
|
29
|
+
.chain((cases) =>
|
|
30
|
+
fc
|
|
31
|
+
.array(
|
|
32
|
+
fc.oneof(
|
|
33
|
+
fc.constantFrom(...cases).map((value) => logOf(value)),
|
|
34
|
+
arbitraryNoiseLog(),
|
|
35
|
+
),
|
|
36
|
+
{ maxLength: 6 },
|
|
37
|
+
)
|
|
38
|
+
.map((logs) => ({ abi: cases.map((x) => x.abiEvent), logs })),
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A model of the events `extractLogs` matches in strict mode, as its
|
|
43
|
+
* documentation states. A selector match wins. Otherwise anonymous events are
|
|
44
|
+
* only matched when requested, and only when exactly one fits the topic
|
|
45
|
+
* count. The first candidate that decodes is used, then `eventName` filters.
|
|
46
|
+
*/
|
|
47
|
+
function extractModel(
|
|
48
|
+
abi: readonly AbiEvent.AbiEvent[],
|
|
49
|
+
logs: readonly Log[],
|
|
50
|
+
eventName: readonly string[] | undefined,
|
|
51
|
+
) {
|
|
52
|
+
const anonymous = (() => {
|
|
53
|
+
if (eventName)
|
|
54
|
+
return abi.filter((x) => x.anonymous && eventName.includes(x.name))
|
|
55
|
+
if (abi.every((x) => x.anonymous)) return abi
|
|
56
|
+
return []
|
|
57
|
+
})()
|
|
58
|
+
return logs.flatMap((log, index) => {
|
|
59
|
+
const bySelector = abi.filter(
|
|
60
|
+
(x) => !x.anonymous && log.topics[0] === AbiEvent.getSelector(x),
|
|
61
|
+
)
|
|
62
|
+
const candidates = (() => {
|
|
63
|
+
if (bySelector.length > 0) return bySelector
|
|
64
|
+
const fit = anonymous.filter((x) => indexedCount(x) === log.topics.length)
|
|
65
|
+
if (fit.length === 1) return fit
|
|
66
|
+
return []
|
|
67
|
+
})()
|
|
68
|
+
for (const abiEvent of candidates) {
|
|
69
|
+
try {
|
|
70
|
+
AbiEvent.decode(abiEvent, log)
|
|
71
|
+
} catch {
|
|
72
|
+
continue
|
|
73
|
+
}
|
|
74
|
+
if (eventName && !eventName.includes(abiEvent.name)) return []
|
|
75
|
+
return [[index, abiEvent.name] as const]
|
|
76
|
+
}
|
|
77
|
+
return []
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
describe('decode', () => {
|
|
82
|
+
test.prop({ value: arbitraryEventCase() }, { numRuns })(
|
|
83
|
+
'decodes the arguments a log was encoded from',
|
|
84
|
+
({ value }) => {
|
|
85
|
+
const log = logOf(value)
|
|
86
|
+
|
|
87
|
+
const args = AbiEvent.decode(value.abiEvent, log)
|
|
88
|
+
|
|
89
|
+
const array = value.inputs.every((input) => !input.name)
|
|
90
|
+
expect(lowercase(args)).toEqual(lowercase(expectedArgs(value, array)))
|
|
91
|
+
},
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
test.prop(
|
|
95
|
+
{
|
|
96
|
+
abi: fc.array(arbitraryEventCase(), { maxLength: 4 }),
|
|
97
|
+
log: arbitraryNoiseLog(),
|
|
98
|
+
strict: fc.boolean(),
|
|
99
|
+
},
|
|
100
|
+
{ numRuns },
|
|
101
|
+
)('returns or throws an ox error for any log', ({ abi, log, strict }) => {
|
|
102
|
+
for (const { abiEvent } of abi) {
|
|
103
|
+
try {
|
|
104
|
+
AbiEvent.decode(abiEvent, log, { strict } as never)
|
|
105
|
+
} catch (error) {
|
|
106
|
+
expect(error).toBeInstanceOf(Errors.BaseError)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
describe('encode', () => {
|
|
113
|
+
test.prop({ value: arbitraryEventCase() }, { numRuns })(
|
|
114
|
+
'encodes the topics a contract emits',
|
|
115
|
+
({ value }) => {
|
|
116
|
+
// Filters cannot hold tuple or array values.
|
|
117
|
+
fc.pre(
|
|
118
|
+
value.inputs.every(
|
|
119
|
+
(input) =>
|
|
120
|
+
!input.indexed ||
|
|
121
|
+
!isHashed(input.parameter) ||
|
|
122
|
+
input.parameter.type === 'string' ||
|
|
123
|
+
input.parameter.type === 'bytes',
|
|
124
|
+
),
|
|
125
|
+
)
|
|
126
|
+
const args = value.inputs.flatMap((input, i) =>
|
|
127
|
+
input.indexed ? [[input.name || String(i), input.value] as const] : [],
|
|
128
|
+
)
|
|
129
|
+
const named = value.inputs.every((input) => input.name)
|
|
130
|
+
|
|
131
|
+
const { topics } = AbiEvent.encode(
|
|
132
|
+
value.abiEvent,
|
|
133
|
+
(named
|
|
134
|
+
? Object.fromEntries(args)
|
|
135
|
+
: value.inputs.filter((x) => x.indexed).map((x) => x.value)) as never,
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
expect(lowercase(topics)).toEqual(lowercase(logOf(value).topics))
|
|
139
|
+
},
|
|
140
|
+
)
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
describe('decodeLog', () => {
|
|
144
|
+
test.prop(
|
|
145
|
+
{
|
|
146
|
+
others: fc.array(arbitraryEventCase(), { maxLength: 3 }),
|
|
147
|
+
value: arbitraryEventCase({ anonymous: false }),
|
|
148
|
+
},
|
|
149
|
+
{ numRuns },
|
|
150
|
+
)('decodes a selector match the same way in any ABI', ({ others, value }) => {
|
|
151
|
+
const selector = AbiEvent.getSelector(value.abiEvent)
|
|
152
|
+
// An overload with the same selector would be ambiguous.
|
|
153
|
+
fc.pre(
|
|
154
|
+
others.every(
|
|
155
|
+
(x) =>
|
|
156
|
+
x.abiEvent.anonymous || AbiEvent.getSelector(x.abiEvent) !== selector,
|
|
157
|
+
),
|
|
158
|
+
)
|
|
159
|
+
const log = logOf(value)
|
|
160
|
+
|
|
161
|
+
const decoded = AbiEvent.decodeLog(
|
|
162
|
+
[...others.map((x) => x.abiEvent), value.abiEvent],
|
|
163
|
+
log,
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
expect(decoded.event.name).toBe(value.abiEvent.name)
|
|
167
|
+
expect(lowercase(decoded.args)).toEqual(
|
|
168
|
+
lowercase(AbiEvent.decode(value.abiEvent, log)),
|
|
169
|
+
)
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
test.prop(
|
|
173
|
+
{
|
|
174
|
+
others: fc.array(arbitraryEventCase({ anonymous: true }), {
|
|
175
|
+
maxLength: 3,
|
|
176
|
+
}),
|
|
177
|
+
value: arbitraryEventCase({ anonymous: true }),
|
|
178
|
+
},
|
|
179
|
+
{ numRuns },
|
|
180
|
+
)(
|
|
181
|
+
'decodes an anonymous log when every event is anonymous',
|
|
182
|
+
({ others, value }) => {
|
|
183
|
+
const count = indexedCount(value.abiEvent)
|
|
184
|
+
fc.pre(others.every((x) => indexedCount(x.abiEvent) !== count))
|
|
185
|
+
const log = logOf(value)
|
|
186
|
+
|
|
187
|
+
const decoded = AbiEvent.decodeLog(
|
|
188
|
+
[...others.map((x) => x.abiEvent), value.abiEvent],
|
|
189
|
+
log,
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
expect(decoded.event).toBe(value.abiEvent)
|
|
193
|
+
},
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
test.prop(
|
|
197
|
+
{
|
|
198
|
+
named: arbitraryEventCase({ anonymous: false }),
|
|
199
|
+
value: arbitraryEventCase({ anonymous: true }),
|
|
200
|
+
},
|
|
201
|
+
{ numRuns },
|
|
202
|
+
)('does not match anonymous events in a mixed ABI', ({ named, value }) => {
|
|
203
|
+
const log = logOf(value)
|
|
204
|
+
fc.pre(log.topics[0] !== AbiEvent.getSelector(named.abiEvent))
|
|
205
|
+
|
|
206
|
+
expect(() =>
|
|
207
|
+
AbiEvent.decodeLog([named.abiEvent, value.abiEvent], log),
|
|
208
|
+
).toThrow()
|
|
209
|
+
})
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
describe('extractLogs', () => {
|
|
213
|
+
test.prop({ value: arbitraryAbiCase }, { numRuns })(
|
|
214
|
+
'matches the model for any ABI and logs',
|
|
215
|
+
({ value }) => {
|
|
216
|
+
const extracted = AbiEvent.extractLogs(value.abi, value.logs)
|
|
217
|
+
|
|
218
|
+
expect(extracted.map((x) => x.eventName)).toEqual(
|
|
219
|
+
extractModel(value.abi, value.logs, undefined).map(([, name]) => name),
|
|
220
|
+
)
|
|
221
|
+
},
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
test.prop(
|
|
225
|
+
{
|
|
226
|
+
eventName: fc.subarray([...eventNames], { minLength: 1 }),
|
|
227
|
+
value: arbitraryAbiCase,
|
|
228
|
+
},
|
|
229
|
+
{ numRuns },
|
|
230
|
+
)('matches the model for any eventName', ({ eventName, value }) => {
|
|
231
|
+
const extracted = AbiEvent.extractLogs(value.abi, value.logs, {
|
|
232
|
+
eventName: eventName as never,
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
expect(extracted.map((x) => x.eventName)).toEqual(
|
|
236
|
+
extractModel(value.abi, value.logs, eventName).map(([, name]) => name),
|
|
237
|
+
)
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
test.prop({ value: arbitraryEventCase() }, { numRuns })(
|
|
241
|
+
'decodes a log that a lone event emits',
|
|
242
|
+
({ value }) => {
|
|
243
|
+
const log = logOf(value)
|
|
244
|
+
|
|
245
|
+
const extracted = AbiEvent.extractLogs([value.abiEvent], [log])
|
|
246
|
+
|
|
247
|
+
const array = value.inputs.some((input) => !input.name)
|
|
248
|
+
expect(extracted.map((x) => [x.eventName, lowercase(x.args)])).toEqual([
|
|
249
|
+
[value.abiEvent.name, lowercase(expectedArgs(value, array))],
|
|
250
|
+
])
|
|
251
|
+
},
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
test.prop({ value: arbitraryAbiCase }, { numRuns })(
|
|
255
|
+
'does not throw for any ABI and logs in non-strict mode',
|
|
256
|
+
({ value }) => {
|
|
257
|
+
AbiEvent.extractLogs(value.abi, value.logs, { strict: false })
|
|
258
|
+
},
|
|
259
|
+
)
|
|
260
|
+
})
|
|
@@ -291,6 +291,15 @@ describe('fromAbi', () => {
|
|
|
291
291
|
readonly name: "Foo"
|
|
292
292
|
readonly type: "event"
|
|
293
293
|
readonly inputs: readonly []
|
|
294
|
+
readonly overloads: [
|
|
295
|
+
{
|
|
296
|
+
readonly name: "Foo"
|
|
297
|
+
readonly type: "event"
|
|
298
|
+
readonly inputs: readonly [
|
|
299
|
+
{ readonly type: "uint256" }
|
|
300
|
+
]
|
|
301
|
+
}
|
|
302
|
+
]
|
|
294
303
|
}`)
|
|
295
304
|
})
|
|
296
305
|
|