ox 1.8.15 → 1.8.16
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 +66 -0
- package/dist/core/AbiError.d.ts +52 -6
- package/dist/core/AbiError.d.ts.map +1 -1
- package/dist/core/AbiError.js +60 -4
- package/dist/core/AbiError.js.map +1 -1
- package/dist/core/AbiEvent.d.ts +4 -2
- package/dist/core/AbiEvent.d.ts.map +1 -1
- package/dist/core/AbiEvent.js +62 -36
- package/dist/core/AbiEvent.js.map +1 -1
- package/dist/core/AbiFunction.d.ts +48 -2
- package/dist/core/AbiFunction.d.ts.map +1 -1
- package/dist/core/AbiFunction.js +59 -3
- package/dist/core/AbiFunction.js.map +1 -1
- package/dist/core/Address.d.ts +17 -2
- package/dist/core/Address.d.ts.map +1 -1
- package/dist/core/Address.js +17 -1
- package/dist/core/Address.js.map +1 -1
- package/dist/core/Authorization.d.ts +24 -2
- package/dist/core/Authorization.d.ts.map +1 -1
- package/dist/core/Authorization.js +29 -2
- package/dist/core/Authorization.js.map +1 -1
- package/dist/core/Keystore.d.ts +31 -2
- package/dist/core/Keystore.d.ts.map +1 -1
- package/dist/core/Keystore.js +28 -2
- package/dist/core/Keystore.js.map +1 -1
- package/dist/core/Secp256k1.d.ts.map +1 -1
- package/dist/core/Secp256k1.js +4 -1
- package/dist/core/Secp256k1.js.map +1 -1
- package/dist/core/Signature.d.ts +1 -1
- package/dist/core/Signature.d.ts.map +1 -1
- package/dist/core/Signature.js +4 -2
- package/dist/core/Signature.js.map +1 -1
- package/dist/core/Siwe.d.ts +4 -0
- package/dist/core/Siwe.d.ts.map +1 -1
- package/dist/core/Siwe.js +29 -3
- package/dist/core/Siwe.js.map +1 -1
- package/dist/core/TxEnvelopeEip1559.d.ts.map +1 -1
- package/dist/core/TxEnvelopeEip1559.js +2 -1
- package/dist/core/TxEnvelopeEip1559.js.map +1 -1
- package/dist/core/TxEnvelopeEip2930.d.ts.map +1 -1
- package/dist/core/TxEnvelopeEip2930.js +2 -1
- package/dist/core/TxEnvelopeEip2930.js.map +1 -1
- package/dist/core/TxEnvelopeEip7702.d.ts +1 -1
- package/dist/core/TxEnvelopeEip7702.d.ts.map +1 -1
- package/dist/core/TxEnvelopeEip7702.js +6 -1
- package/dist/core/TxEnvelopeEip7702.js.map +1 -1
- package/dist/core/TxEnvelopeLegacy.d.ts.map +1 -1
- package/dist/core/TxEnvelopeLegacy.js +49 -7
- package/dist/core/TxEnvelopeLegacy.js.map +1 -1
- package/dist/core/TypedData.d.ts +3 -1
- package/dist/core/TypedData.d.ts.map +1 -1
- package/dist/core/TypedData.js +9 -9
- package/dist/core/TypedData.js.map +1 -1
- package/dist/core/Value.d.ts.map +1 -1
- package/dist/core/Value.js +14 -3
- package/dist/core/Value.js.map +1 -1
- package/dist/core/internal/abiParameters.d.ts +1 -1
- package/dist/core/internal/abiParameters.d.ts.map +1 -1
- package/dist/core/internal/abiParameters.js +7 -2
- package/dist/core/internal/abiParameters.js.map +1 -1
- package/dist/core/internal/cursor.d.ts +13 -0
- package/dist/core/internal/cursor.d.ts.map +1 -1
- package/dist/core/internal/cursor.js +27 -0
- package/dist/core/internal/cursor.js.map +1 -1
- package/dist/erc4337/UserOperation.d.ts.map +1 -1
- package/dist/erc4337/UserOperation.js +1 -3
- package/dist/erc4337/UserOperation.js.map +1 -1
- package/dist/erc7821/Execute.d.ts +45 -0
- package/dist/erc7821/Execute.d.ts.map +1 -1
- package/dist/erc7821/Execute.js +70 -2
- package/dist/erc7821/Execute.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/tempo/KeyAuthorization.d.ts +9 -3
- package/dist/tempo/KeyAuthorization.d.ts.map +1 -1
- package/dist/tempo/KeyAuthorization.js +16 -0
- package/dist/tempo/KeyAuthorization.js.map +1 -1
- package/dist/tempo/SignatureEnvelope.d.ts +1 -1
- package/dist/tempo/SignatureEnvelope.d.ts.map +1 -1
- package/dist/tempo/SignatureEnvelope.js +46 -13
- package/dist/tempo/SignatureEnvelope.js.map +1 -1
- package/dist/tempo/TransactionRequest.d.ts +1 -1
- package/dist/tempo/TransactionRequest.d.ts.map +1 -1
- package/dist/tempo/TransactionRequest.js +5 -2
- package/dist/tempo/TransactionRequest.js.map +1 -1
- package/dist/tempo/TxEnvelopeTempo.d.ts +30 -1
- package/dist/tempo/TxEnvelopeTempo.d.ts.map +1 -1
- package/dist/tempo/TxEnvelopeTempo.js +51 -2
- package/dist/tempo/TxEnvelopeTempo.js.map +1 -1
- package/dist/webauthn/Registration.d.ts +2 -0
- package/dist/webauthn/Registration.d.ts.map +1 -1
- package/dist/webauthn/Registration.js +2 -6
- package/dist/webauthn/Registration.js.map +1 -1
- package/dist/zod/tempo/KeyAuthorization.d.ts.map +1 -1
- package/dist/zod/tempo/KeyAuthorization.js +4 -2
- package/dist/zod/tempo/KeyAuthorization.js.map +1 -1
- package/dist/zod/tempo/SignatureEnvelope.d.ts.map +1 -1
- package/dist/zod/tempo/SignatureEnvelope.js +24 -14
- package/dist/zod/tempo/SignatureEnvelope.js.map +1 -1
- package/package.json +1 -1
- package/src/core/AbiError.ts +82 -8
- package/src/core/AbiEvent.ts +90 -45
- package/src/core/AbiFunction.ts +76 -4
- package/src/core/Address.ts +18 -1
- package/src/core/Authorization.ts +34 -4
- package/src/core/Keystore.ts +40 -3
- package/src/core/Secp256k1.ts +4 -1
- package/src/core/Signature.ts +7 -3
- package/src/core/Siwe.ts +29 -3
- package/src/core/TxEnvelopeEip1559.ts +4 -1
- package/src/core/TxEnvelopeEip2930.ts +4 -1
- package/src/core/TxEnvelopeEip7702.ts +9 -2
- package/src/core/TxEnvelopeLegacy.ts +58 -7
- package/src/core/TypedData.ts +10 -9
- package/src/core/Value.ts +14 -3
- package/src/core/_test/AbiError.test.ts +105 -2
- package/src/core/_test/AbiEvent.fuzz.ts +1 -1
- package/src/core/_test/AbiEvent.test-d.ts +46 -0
- package/src/core/_test/AbiEvent.test.ts +563 -11
- package/src/core/_test/AbiFunction.test.ts +74 -2
- package/src/core/_test/AbiParameters.adversarial.fuzz.ts +1 -0
- package/src/core/_test/AbiParameters.decode.test.ts +110 -0
- package/src/core/_test/AbiParameters.encode.test.ts +26 -1
- package/src/core/_test/Address.test.ts +41 -0
- package/src/core/_test/Authorization.test.ts +130 -0
- package/src/core/_test/Keystore.test.ts +65 -1
- package/src/core/_test/Secp256k1.test.ts +36 -0
- package/src/core/_test/Signature.test.ts +102 -0
- package/src/core/_test/Siwe.test.ts +123 -0
- package/src/core/_test/TransactionEnvelopeEip1559.test.ts +28 -0
- package/src/core/_test/TransactionEnvelopeEip2930.test.ts +28 -0
- package/src/core/_test/TransactionEnvelopeEip7702.test.ts +133 -0
- package/src/core/_test/TransactionEnvelopeLegacy.test.ts +322 -1
- package/src/core/_test/TypedData.test.ts +178 -0
- package/src/core/_test/Value.test.ts +21 -0
- package/src/core/_test/internal/cursor.test.ts +35 -0
- package/src/core/internal/abiParameters.ts +7 -2
- package/src/core/internal/cursor.ts +36 -0
- package/src/erc4337/UserOperation.ts +3 -4
- package/src/erc4337/_test/UserOperation.test.ts +59 -1
- package/src/erc7821/Execute.ts +83 -2
- package/src/erc7821/_test/Execute.test.ts +217 -1
- package/src/index.ts +1 -1
- package/src/tempo/KeyAuthorization.test.ts +91 -0
- package/src/tempo/KeyAuthorization.ts +32 -3
- package/src/tempo/SignatureEnvelope.test.ts +211 -27
- package/src/tempo/SignatureEnvelope.ts +55 -11
- package/src/tempo/TransactionRequest.test.ts +30 -0
- package/src/tempo/TransactionRequest.ts +7 -2
- package/src/tempo/TxEnvelopeTempo.test.ts +310 -0
- package/src/tempo/TxEnvelopeTempo.ts +64 -1
- package/src/tempo/configurableAccounts.e2e.test.ts +1 -1
- package/src/version.ts +1 -1
- package/src/webauthn/Registration.ts +4 -6
- package/src/webauthn/_test/Registration.browser.test.ts +14 -0
- package/src/webauthn/_test/Registration.test.ts +60 -0
- package/src/zod/tempo/KeyAuthorization.ts +12 -5
- package/src/zod/tempo/SignatureEnvelope.ts +31 -16
- package/src/zod/tempo/_test/KeyAuthorization.test.ts +36 -0
- package/src/zod/tempo/_test/SignatureEnvelope.test.ts +101 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Abi, AbiEvent, AbiParameters, Hash, Hex } from 'ox'
|
|
1
|
+
import { Abi, AbiEvent, AbiParameters, Address, Hash, Hex } from 'ox'
|
|
2
2
|
import { describe, expect, test } from 'vp/test'
|
|
3
3
|
import { wagmiContractConfig } from '../../../test/constants/abis.js'
|
|
4
4
|
import { address } from '../../../test/constants/addresses.js'
|
|
@@ -216,6 +216,104 @@ describe('assertArgs', () => {
|
|
|
216
216
|
`)
|
|
217
217
|
})
|
|
218
218
|
|
|
219
|
+
test('behavior: named + unnamed inputs', () => {
|
|
220
|
+
const abiEvent = AbiEvent.from(
|
|
221
|
+
'event Transfer(address indexed from, address indexed, uint256)',
|
|
222
|
+
)
|
|
223
|
+
const args = AbiEvent.decode(abiEvent, {
|
|
224
|
+
data: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
225
|
+
topics: [
|
|
226
|
+
AbiEvent.getSelector(abiEvent),
|
|
227
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
228
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ad',
|
|
229
|
+
],
|
|
230
|
+
})
|
|
231
|
+
AbiEvent.assertArgs(abiEvent, args, {
|
|
232
|
+
1: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ad',
|
|
233
|
+
2: 1n,
|
|
234
|
+
from: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
235
|
+
})
|
|
236
|
+
expect(() =>
|
|
237
|
+
AbiEvent.assertArgs(abiEvent, args, {
|
|
238
|
+
1: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
239
|
+
}),
|
|
240
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
241
|
+
[AbiEvent.ArgsMismatchError: Given arguments do not match the expected arguments.
|
|
242
|
+
|
|
243
|
+
Event: event Transfer(address indexed from, address indexed, uint256)
|
|
244
|
+
Expected Arguments:
|
|
245
|
+
1: 0xa5Cc3C03994DB5B0d9a5EEdD10CaBab0813678ad
|
|
246
|
+
2: 1
|
|
247
|
+
from: 0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC
|
|
248
|
+
Given Arguments:
|
|
249
|
+
1: 0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac]
|
|
250
|
+
`)
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
test('error: args mismatch, positional and keyed', () => {
|
|
254
|
+
const abiEvent = AbiEvent.from(
|
|
255
|
+
'event Transfer(address indexed from, address indexed to, uint256 value)',
|
|
256
|
+
)
|
|
257
|
+
const args = AbiEvent.decode(abiEvent, {
|
|
258
|
+
data: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
259
|
+
topics: [
|
|
260
|
+
AbiEvent.getSelector(abiEvent),
|
|
261
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
262
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ad',
|
|
263
|
+
],
|
|
264
|
+
})
|
|
265
|
+
expect(() =>
|
|
266
|
+
// @ts-expect-error
|
|
267
|
+
AbiEvent.assertArgs(abiEvent, args, [
|
|
268
|
+
'0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
269
|
+
]),
|
|
270
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
271
|
+
[AbiEvent.ArgsMismatchError: Given arguments do not match the expected arguments.
|
|
272
|
+
|
|
273
|
+
Event: event Transfer(address indexed from, address indexed to, uint256 value)
|
|
274
|
+
Expected Arguments:
|
|
275
|
+
from: 0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC
|
|
276
|
+
to: 0xa5Cc3C03994DB5B0d9a5EEdD10CaBab0813678ad
|
|
277
|
+
value: 1
|
|
278
|
+
Given Arguments:
|
|
279
|
+
0: 0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac]
|
|
280
|
+
`)
|
|
281
|
+
expect(() =>
|
|
282
|
+
AbiEvent.assertArgs(
|
|
283
|
+
abiEvent,
|
|
284
|
+
[
|
|
285
|
+
'0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
286
|
+
'0xa5cc3c03994db5b0d9a5eedd10cabab0813678ad',
|
|
287
|
+
1n,
|
|
288
|
+
],
|
|
289
|
+
{ from: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac' },
|
|
290
|
+
),
|
|
291
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
292
|
+
[AbiEvent.ArgsMismatchError: Given arguments do not match the expected arguments.
|
|
293
|
+
|
|
294
|
+
Event: event Transfer(address indexed from, address indexed to, uint256 value)
|
|
295
|
+
Expected Arguments:
|
|
296
|
+
0: 0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac
|
|
297
|
+
1: 0xa5cc3c03994db5b0d9a5eedd10cabab0813678ad
|
|
298
|
+
2: 1
|
|
299
|
+
Given Arguments:
|
|
300
|
+
from: 0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac]
|
|
301
|
+
`)
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
test('behavior: filter without values', () => {
|
|
305
|
+
const abiEvent = AbiEvent.from(
|
|
306
|
+
'event Transfer(address indexed from, address indexed to, uint256 value)',
|
|
307
|
+
)
|
|
308
|
+
const args = [
|
|
309
|
+
'0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
310
|
+
'0xa5cc3c03994db5b0d9a5eedd10cabab0813678ad',
|
|
311
|
+
1n,
|
|
312
|
+
]
|
|
313
|
+
AbiEvent.assertArgs(abiEvent, args, {})
|
|
314
|
+
AbiEvent.assertArgs(abiEvent, args, { from: undefined, to: null })
|
|
315
|
+
})
|
|
316
|
+
|
|
219
317
|
test('error: args mismatch, string', () => {
|
|
220
318
|
const abiEvent = AbiEvent.from('event Transfer(string indexed a)')
|
|
221
319
|
const args = AbiEvent.decode(abiEvent, {
|
|
@@ -613,6 +711,161 @@ describe('decode', () => {
|
|
|
613
711
|
)
|
|
614
712
|
})
|
|
615
713
|
|
|
714
|
+
test('behavior: canonical indexed `address`, `bool`, `intN` and `uintN` topics', () => {
|
|
715
|
+
const abiEvent = AbiEvent.from(
|
|
716
|
+
'event Foo(address indexed a, bool indexed b, int8 indexed c, uint8 d)',
|
|
717
|
+
)
|
|
718
|
+
expect(
|
|
719
|
+
AbiEvent.decode(abiEvent, {
|
|
720
|
+
data: '0x00000000000000000000000000000000000000000000000000000000000000ff',
|
|
721
|
+
topics: [
|
|
722
|
+
AbiEvent.getSelector(abiEvent),
|
|
723
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
724
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
725
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80',
|
|
726
|
+
],
|
|
727
|
+
}),
|
|
728
|
+
).toMatchInlineSnapshot(`
|
|
729
|
+
{
|
|
730
|
+
"a": "0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC",
|
|
731
|
+
"b": true,
|
|
732
|
+
"c": -128,
|
|
733
|
+
"d": 255,
|
|
734
|
+
}
|
|
735
|
+
`)
|
|
736
|
+
|
|
737
|
+
const abiEvent_2 = AbiEvent.from(
|
|
738
|
+
'event Foo(bool indexed a, uint8 indexed b, int256 indexed c)',
|
|
739
|
+
)
|
|
740
|
+
expect(
|
|
741
|
+
AbiEvent.decode(abiEvent_2, {
|
|
742
|
+
topics: [
|
|
743
|
+
AbiEvent.getSelector(abiEvent_2),
|
|
744
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
745
|
+
'0x00000000000000000000000000000000000000000000000000000000000000ff',
|
|
746
|
+
'0x8000000000000000000000000000000000000000000000000000000000000000',
|
|
747
|
+
],
|
|
748
|
+
}),
|
|
749
|
+
).toMatchInlineSnapshot(`
|
|
750
|
+
{
|
|
751
|
+
"a": false,
|
|
752
|
+
"b": 255,
|
|
753
|
+
"c": -57896044618658097711785492504343953926634992332820282019728792003956564819968n,
|
|
754
|
+
}
|
|
755
|
+
`)
|
|
756
|
+
})
|
|
757
|
+
|
|
758
|
+
test('error: non-canonical indexed `address` topic', () => {
|
|
759
|
+
const abiEvent = AbiEvent.from('event Foo(address indexed a)')
|
|
760
|
+
const topic =
|
|
761
|
+
'0xdeadbeef0000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac'
|
|
762
|
+
|
|
763
|
+
expect(() =>
|
|
764
|
+
AbiParameters.decode([{ type: 'address' }], topic),
|
|
765
|
+
).toThrowError(Address.InvalidAddressError)
|
|
766
|
+
expect(() =>
|
|
767
|
+
AbiEvent.decode(abiEvent, {
|
|
768
|
+
topics: [AbiEvent.getSelector(abiEvent), topic],
|
|
769
|
+
}),
|
|
770
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
771
|
+
[Address.InvalidAddressError: Address "0xdeadbeef0000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac" is invalid.
|
|
772
|
+
|
|
773
|
+
Details: Address is not a 20 byte (40 hexadecimal character) value.]
|
|
774
|
+
`)
|
|
775
|
+
})
|
|
776
|
+
|
|
777
|
+
test('error: non-canonical indexed `bool` topic', () => {
|
|
778
|
+
const abiEvent = AbiEvent.from('event Foo(bool indexed a)')
|
|
779
|
+
|
|
780
|
+
expect(() =>
|
|
781
|
+
AbiEvent.decode(abiEvent, {
|
|
782
|
+
topics: [
|
|
783
|
+
AbiEvent.getSelector(abiEvent),
|
|
784
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
785
|
+
],
|
|
786
|
+
}),
|
|
787
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
788
|
+
[Bytes.InvalidBytesBooleanError: Bytes value \`2\` is not a valid boolean.
|
|
789
|
+
|
|
790
|
+
The bytes array must contain a single byte of either a \`0\` or \`1\` value.]
|
|
791
|
+
`)
|
|
792
|
+
expect(() =>
|
|
793
|
+
AbiEvent.decode(abiEvent, {
|
|
794
|
+
topics: [
|
|
795
|
+
AbiEvent.getSelector(abiEvent),
|
|
796
|
+
'0x0000000000000000000000000000000000000000000000000000000000000011',
|
|
797
|
+
],
|
|
798
|
+
}),
|
|
799
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
800
|
+
[Bytes.InvalidBytesBooleanError: Bytes value \`17\` is not a valid boolean.
|
|
801
|
+
|
|
802
|
+
The bytes array must contain a single byte of either a \`0\` or \`1\` value.]
|
|
803
|
+
`)
|
|
804
|
+
})
|
|
805
|
+
|
|
806
|
+
test('error: indexed `intN` and `uintN` topics out of range', () => {
|
|
807
|
+
const uint8 = AbiEvent.from('event Foo(uint8 indexed a)')
|
|
808
|
+
expect(() =>
|
|
809
|
+
AbiEvent.decode(uint8, {
|
|
810
|
+
topics: [
|
|
811
|
+
AbiEvent.getSelector(uint8),
|
|
812
|
+
'0x0000000000000000000000000000000000000000000000000000000000000100',
|
|
813
|
+
],
|
|
814
|
+
}),
|
|
815
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
816
|
+
`[Hex.IntegerOutOfRangeError: Number \`256\` is not in safe 8-bit unsigned integer range (\`0\` to \`255\`)]`,
|
|
817
|
+
)
|
|
818
|
+
|
|
819
|
+
const int8 = AbiEvent.from('event Foo(int8 indexed a)')
|
|
820
|
+
expect(() =>
|
|
821
|
+
AbiEvent.decode(int8, {
|
|
822
|
+
topics: [
|
|
823
|
+
AbiEvent.getSelector(int8),
|
|
824
|
+
'0x0000000000000000000000000000000000000000000000000000000000000080',
|
|
825
|
+
],
|
|
826
|
+
}),
|
|
827
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
828
|
+
`[Hex.IntegerOutOfRangeError: Number \`128\` is not in safe 8-bit signed integer range (\`-128\` to \`127\`)]`,
|
|
829
|
+
)
|
|
830
|
+
expect(() =>
|
|
831
|
+
AbiEvent.decode(int8, {
|
|
832
|
+
topics: [
|
|
833
|
+
AbiEvent.getSelector(int8),
|
|
834
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f',
|
|
835
|
+
],
|
|
836
|
+
}),
|
|
837
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
838
|
+
`[Hex.IntegerOutOfRangeError: Number \`-129\` is not in safe 8-bit signed integer range (\`-128\` to \`127\`)]`,
|
|
839
|
+
)
|
|
840
|
+
|
|
841
|
+
const uint64 = AbiEvent.from('event Foo(uint64 indexed a)')
|
|
842
|
+
expect(() =>
|
|
843
|
+
AbiEvent.decode(uint64, {
|
|
844
|
+
topics: [
|
|
845
|
+
AbiEvent.getSelector(uint64),
|
|
846
|
+
'0x8000000000000000000000000000000000000000000000000000000000000000',
|
|
847
|
+
],
|
|
848
|
+
}),
|
|
849
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
850
|
+
`[Hex.IntegerOutOfRangeError: Number \`57896044618658097711785492504343953926634992332820282019728792003956564819968\` is not in safe 64-bit unsigned integer range (\`0\` to \`18446744073709551615\`)]`,
|
|
851
|
+
)
|
|
852
|
+
})
|
|
853
|
+
|
|
854
|
+
test('error: indexed topic shorter than 32 bytes', () => {
|
|
855
|
+
const abiEvent = AbiEvent.from('event Foo(uint256 indexed a)')
|
|
856
|
+
|
|
857
|
+
expect(() =>
|
|
858
|
+
AbiEvent.decode(abiEvent, {
|
|
859
|
+
topics: [AbiEvent.getSelector(abiEvent), '0x01'],
|
|
860
|
+
}),
|
|
861
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
862
|
+
[AbiParameters.DataSizeTooSmallError: Data size of 1 bytes is too small for given parameters.
|
|
863
|
+
|
|
864
|
+
Params: (uint256 indexed a)
|
|
865
|
+
Data: 0x01 (1 bytes)]
|
|
866
|
+
`)
|
|
867
|
+
})
|
|
868
|
+
|
|
616
869
|
test('error: event selector topic mismatch', () => {
|
|
617
870
|
const transfer = AbiEvent.from(
|
|
618
871
|
'event Transfer(address indexed from, address indexed to, bool sender)',
|
|
@@ -719,6 +972,127 @@ describe('decode', () => {
|
|
|
719
972
|
}
|
|
720
973
|
`)
|
|
721
974
|
})
|
|
975
|
+
|
|
976
|
+
test('behavior: with overloads, zero-input and named', () => {
|
|
977
|
+
const abi = Abi.from(['event Foo()', 'event Foo(address indexed who)'])
|
|
978
|
+
const log = {
|
|
979
|
+
topics: [
|
|
980
|
+
AbiEvent.getSelector('event Foo(address indexed who)'),
|
|
981
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
982
|
+
],
|
|
983
|
+
} as const
|
|
984
|
+
|
|
985
|
+
expect(AbiEvent.decode(abi, 'Foo', log)).toMatchInlineSnapshot(`
|
|
986
|
+
{
|
|
987
|
+
"who": "0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC",
|
|
988
|
+
}
|
|
989
|
+
`)
|
|
990
|
+
expect(AbiEvent.decode(AbiEvent.fromAbi(abi, 'Foo'), log))
|
|
991
|
+
.toMatchInlineSnapshot(`
|
|
992
|
+
{
|
|
993
|
+
"who": "0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC",
|
|
994
|
+
}
|
|
995
|
+
`)
|
|
996
|
+
expect(
|
|
997
|
+
AbiEvent.decode(abi, 'Foo', {
|
|
998
|
+
topics: [AbiEvent.getSelector('event Foo()')],
|
|
999
|
+
}),
|
|
1000
|
+
).toMatchInlineSnapshot(`undefined`)
|
|
1001
|
+
})
|
|
1002
|
+
|
|
1003
|
+
test('behavior: with overloads, anonymous and named', () => {
|
|
1004
|
+
const abi = Abi.from([
|
|
1005
|
+
{ anonymous: true, inputs: [], name: 'Foo', type: 'event' },
|
|
1006
|
+
{
|
|
1007
|
+
inputs: [{ indexed: true, name: 'who', type: 'address' }],
|
|
1008
|
+
name: 'Foo',
|
|
1009
|
+
type: 'event',
|
|
1010
|
+
},
|
|
1011
|
+
])
|
|
1012
|
+
const log = {
|
|
1013
|
+
topics: [
|
|
1014
|
+
AbiEvent.getSelector('event Foo(address indexed who)'),
|
|
1015
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
1016
|
+
],
|
|
1017
|
+
} as const
|
|
1018
|
+
|
|
1019
|
+
expect(AbiEvent.decode(abi, 'Foo', log)).toMatchInlineSnapshot(`
|
|
1020
|
+
{
|
|
1021
|
+
"who": "0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC",
|
|
1022
|
+
}
|
|
1023
|
+
`)
|
|
1024
|
+
expect(AbiEvent.decode(AbiEvent.fromAbi(abi, 'Foo'), log))
|
|
1025
|
+
.toMatchInlineSnapshot(`
|
|
1026
|
+
{
|
|
1027
|
+
"who": "0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC",
|
|
1028
|
+
}
|
|
1029
|
+
`)
|
|
1030
|
+
// Without a selector match, the log decodes with the event picked by name.
|
|
1031
|
+
expect(AbiEvent.decode(abi, 'Foo', { topics: [] })).toMatchInlineSnapshot(
|
|
1032
|
+
`undefined`,
|
|
1033
|
+
)
|
|
1034
|
+
})
|
|
1035
|
+
|
|
1036
|
+
test('behavior: with overloads, two named', () => {
|
|
1037
|
+
const abi = Abi.from([
|
|
1038
|
+
'event Deposit(address indexed who, uint256 amount)',
|
|
1039
|
+
'event Deposit(address indexed who, uint256 amount, bytes32 indexed ref)',
|
|
1040
|
+
])
|
|
1041
|
+
const [deposit, depositWithRef] = abi
|
|
1042
|
+
|
|
1043
|
+
expect(
|
|
1044
|
+
AbiEvent.decode(abi, 'Deposit', {
|
|
1045
|
+
data: '0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1046
|
+
topics: [
|
|
1047
|
+
AbiEvent.getSelector(depositWithRef),
|
|
1048
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
1049
|
+
'0x1111111111111111111111111111111111111111111111111111111111111111',
|
|
1050
|
+
],
|
|
1051
|
+
}),
|
|
1052
|
+
).toMatchInlineSnapshot(`
|
|
1053
|
+
{
|
|
1054
|
+
"amount": 5n,
|
|
1055
|
+
"ref": "0x1111111111111111111111111111111111111111111111111111111111111111",
|
|
1056
|
+
"who": "0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC",
|
|
1057
|
+
}
|
|
1058
|
+
`)
|
|
1059
|
+
expect(
|
|
1060
|
+
AbiEvent.decode(abi, 'Deposit', {
|
|
1061
|
+
data: '0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1062
|
+
topics: [
|
|
1063
|
+
AbiEvent.getSelector(deposit),
|
|
1064
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
1065
|
+
],
|
|
1066
|
+
}),
|
|
1067
|
+
).toMatchInlineSnapshot(`
|
|
1068
|
+
{
|
|
1069
|
+
"amount": 5n,
|
|
1070
|
+
"who": "0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC",
|
|
1071
|
+
}
|
|
1072
|
+
`)
|
|
1073
|
+
})
|
|
1074
|
+
|
|
1075
|
+
test('error: with overloads, selector topic matches no overload', () => {
|
|
1076
|
+
const abi = Abi.from([
|
|
1077
|
+
'event Deposit(address indexed who, uint256 amount)',
|
|
1078
|
+
'event Deposit(address indexed who, uint256 amount, bytes32 indexed ref)',
|
|
1079
|
+
])
|
|
1080
|
+
|
|
1081
|
+
expect(() =>
|
|
1082
|
+
AbiEvent.decode(abi, 'Deposit', {
|
|
1083
|
+
data: '0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1084
|
+
topics: [
|
|
1085
|
+
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
1086
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
1087
|
+
],
|
|
1088
|
+
}),
|
|
1089
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
1090
|
+
[AbiEvent.SelectorTopicMismatchError: topics[0]="0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" does not match the expected topics[0]="0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c".
|
|
1091
|
+
|
|
1092
|
+
Event: event Deposit(address indexed who, uint256 amount)
|
|
1093
|
+
Selector: 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c]
|
|
1094
|
+
`)
|
|
1095
|
+
})
|
|
722
1096
|
})
|
|
723
1097
|
|
|
724
1098
|
describe('decodeLog', () => {
|
|
@@ -1073,6 +1447,67 @@ describe('extractLogs', () => {
|
|
|
1073
1447
|
expect(decoded).toMatchInlineSnapshot(`[]`)
|
|
1074
1448
|
})
|
|
1075
1449
|
|
|
1450
|
+
test('behavior: skips logs with non-canonical indexed topics', () => {
|
|
1451
|
+
const abi = Abi.from([
|
|
1452
|
+
'event Transfer(address indexed from, address indexed to, uint256 value)',
|
|
1453
|
+
'event Paused(bool indexed paused)',
|
|
1454
|
+
'event Count(uint8 indexed count)',
|
|
1455
|
+
])
|
|
1456
|
+
const [transfer, paused, count] = abi
|
|
1457
|
+
const logs = [
|
|
1458
|
+
{
|
|
1459
|
+
data: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1460
|
+
topics: [
|
|
1461
|
+
AbiEvent.getSelector(transfer),
|
|
1462
|
+
'0xdeadbeef0000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
1463
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
1464
|
+
],
|
|
1465
|
+
},
|
|
1466
|
+
{
|
|
1467
|
+
data: '0x',
|
|
1468
|
+
topics: [
|
|
1469
|
+
AbiEvent.getSelector(paused),
|
|
1470
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1471
|
+
],
|
|
1472
|
+
},
|
|
1473
|
+
{
|
|
1474
|
+
data: '0x',
|
|
1475
|
+
topics: [
|
|
1476
|
+
AbiEvent.getSelector(count),
|
|
1477
|
+
'0x0000000000000000000000000000000000000000000000000000000000000100',
|
|
1478
|
+
],
|
|
1479
|
+
},
|
|
1480
|
+
] as const
|
|
1481
|
+
|
|
1482
|
+
expect(AbiEvent.extractLogs(abi, logs)).toMatchInlineSnapshot(`[]`)
|
|
1483
|
+
expect(
|
|
1484
|
+
AbiEvent.extractLogs(abi, logs, {
|
|
1485
|
+
args: { paused: false },
|
|
1486
|
+
eventName: 'Paused',
|
|
1487
|
+
}),
|
|
1488
|
+
).toMatchInlineSnapshot(`[]`)
|
|
1489
|
+
expect(
|
|
1490
|
+
AbiEvent.extractLogs(abi, logs, { strict: false }).map(
|
|
1491
|
+
({ args, eventName }) => ({ args, eventName }),
|
|
1492
|
+
),
|
|
1493
|
+
).toMatchInlineSnapshot(`
|
|
1494
|
+
[
|
|
1495
|
+
{
|
|
1496
|
+
"args": {},
|
|
1497
|
+
"eventName": "Transfer",
|
|
1498
|
+
},
|
|
1499
|
+
{
|
|
1500
|
+
"args": {},
|
|
1501
|
+
"eventName": "Paused",
|
|
1502
|
+
},
|
|
1503
|
+
{
|
|
1504
|
+
"args": {},
|
|
1505
|
+
"eventName": "Count",
|
|
1506
|
+
},
|
|
1507
|
+
]
|
|
1508
|
+
`)
|
|
1509
|
+
})
|
|
1510
|
+
|
|
1076
1511
|
test('behavior: filters by event name', () => {
|
|
1077
1512
|
const transfer = AbiEvent.from(
|
|
1078
1513
|
'event Transfer(address indexed from, address indexed to, uint256 value)',
|
|
@@ -1351,6 +1786,118 @@ describe('extractLogs', () => {
|
|
|
1351
1786
|
`)
|
|
1352
1787
|
})
|
|
1353
1788
|
|
|
1789
|
+
test('behavior: filters by arguments of named + unnamed inputs', () => {
|
|
1790
|
+
const transfer = AbiEvent.from(
|
|
1791
|
+
'event Transfer(address indexed from, address indexed, uint256)',
|
|
1792
|
+
)
|
|
1793
|
+
const log = {
|
|
1794
|
+
data: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1795
|
+
topics: [
|
|
1796
|
+
AbiEvent.getSelector(transfer),
|
|
1797
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
1798
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ad',
|
|
1799
|
+
],
|
|
1800
|
+
} as const
|
|
1801
|
+
|
|
1802
|
+
expect(
|
|
1803
|
+
AbiEvent.extractLogs([transfer], [log], {
|
|
1804
|
+
args: { from: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ad' },
|
|
1805
|
+
}),
|
|
1806
|
+
).toMatchInlineSnapshot(`[]`)
|
|
1807
|
+
expect(
|
|
1808
|
+
AbiEvent.extractLogs([transfer], [log], {
|
|
1809
|
+
args: { 1: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac' },
|
|
1810
|
+
}),
|
|
1811
|
+
).toMatchInlineSnapshot(`[]`)
|
|
1812
|
+
expect(
|
|
1813
|
+
AbiEvent.extractLogs([transfer], [log], {
|
|
1814
|
+
args: {
|
|
1815
|
+
1: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ad',
|
|
1816
|
+
2: 1n,
|
|
1817
|
+
from: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
1818
|
+
},
|
|
1819
|
+
}),
|
|
1820
|
+
).toMatchInlineSnapshot(`
|
|
1821
|
+
[
|
|
1822
|
+
{
|
|
1823
|
+
"args": {
|
|
1824
|
+
"1": "0xa5Cc3C03994DB5B0d9a5EEdD10CaBab0813678ad",
|
|
1825
|
+
"2": 1n,
|
|
1826
|
+
"from": "0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC",
|
|
1827
|
+
},
|
|
1828
|
+
"data": "0x0000000000000000000000000000000000000000000000000000000000000001",
|
|
1829
|
+
"eventName": "Transfer",
|
|
1830
|
+
"topics": [
|
|
1831
|
+
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
|
|
1832
|
+
"0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac",
|
|
1833
|
+
"0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ad",
|
|
1834
|
+
],
|
|
1835
|
+
},
|
|
1836
|
+
]
|
|
1837
|
+
`)
|
|
1838
|
+
})
|
|
1839
|
+
|
|
1840
|
+
test('behavior: non-strict mode keys named + unnamed inputs like `decode`', () => {
|
|
1841
|
+
const transfer = AbiEvent.from(
|
|
1842
|
+
'event Transfer(address indexed from, address indexed, uint256)',
|
|
1843
|
+
)
|
|
1844
|
+
const selector = AbiEvent.getSelector(transfer)
|
|
1845
|
+
const from =
|
|
1846
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac'
|
|
1847
|
+
const logs = [
|
|
1848
|
+
// The second indexed input is read from data.
|
|
1849
|
+
{
|
|
1850
|
+
data: '0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ad0000000000000000000000000000000000000000000000000000000000000001',
|
|
1851
|
+
topics: [selector, from],
|
|
1852
|
+
},
|
|
1853
|
+
// The topic does not decode as an address.
|
|
1854
|
+
{ data: '0x', topics: [selector, '0xdead'] },
|
|
1855
|
+
] as const
|
|
1856
|
+
|
|
1857
|
+
expect(
|
|
1858
|
+
AbiEvent.extractLogs([transfer], logs, { strict: false }).map(
|
|
1859
|
+
(log) => log.args,
|
|
1860
|
+
),
|
|
1861
|
+
).toMatchInlineSnapshot(`
|
|
1862
|
+
[
|
|
1863
|
+
{
|
|
1864
|
+
"1": "0xa5Cc3C03994DB5B0d9a5EEdD10CaBab0813678ad",
|
|
1865
|
+
"2": 1n,
|
|
1866
|
+
"from": "0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC",
|
|
1867
|
+
},
|
|
1868
|
+
{},
|
|
1869
|
+
]
|
|
1870
|
+
`)
|
|
1871
|
+
expect(
|
|
1872
|
+
AbiEvent.extractLogs([transfer], logs, {
|
|
1873
|
+
args: { from: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ad' },
|
|
1874
|
+
strict: false,
|
|
1875
|
+
}),
|
|
1876
|
+
).toMatchInlineSnapshot(`[]`)
|
|
1877
|
+
})
|
|
1878
|
+
|
|
1879
|
+
test('behavior: positional and keyed arguments do not match', () => {
|
|
1880
|
+
const named = AbiEvent.from('event Transfer(address indexed from)')
|
|
1881
|
+
const unnamed = AbiEvent.from('event Transfer(address indexed)')
|
|
1882
|
+
const topic =
|
|
1883
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac'
|
|
1884
|
+
|
|
1885
|
+
expect(
|
|
1886
|
+
AbiEvent.extractLogs(
|
|
1887
|
+
[named] as readonly unknown[],
|
|
1888
|
+
[{ data: '0x', topics: [AbiEvent.getSelector(named), topic] }],
|
|
1889
|
+
{ args: ['0xa5cc3c03994db5b0d9a5eedd10cabab0813678ad'] },
|
|
1890
|
+
),
|
|
1891
|
+
).toMatchInlineSnapshot(`[]`)
|
|
1892
|
+
expect(
|
|
1893
|
+
AbiEvent.extractLogs(
|
|
1894
|
+
[unnamed] as readonly unknown[],
|
|
1895
|
+
[{ data: '0x', topics: [AbiEvent.getSelector(unnamed), topic] }],
|
|
1896
|
+
{ args: { from: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ad' } },
|
|
1897
|
+
),
|
|
1898
|
+
).toMatchInlineSnapshot(`[]`)
|
|
1899
|
+
})
|
|
1900
|
+
|
|
1354
1901
|
test('behavior: filters by non-indexed `bytes` and `bytes32` arguments in either case', () => {
|
|
1355
1902
|
const payload = AbiEvent.from('event Payload(bytes data, bytes32 key)')
|
|
1356
1903
|
const log = {
|
|
@@ -1905,16 +2452,21 @@ describe('encode', () => {
|
|
|
1905
2452
|
`)
|
|
1906
2453
|
})
|
|
1907
2454
|
|
|
1908
|
-
test('
|
|
1909
|
-
const event = AbiEvent.from(
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
2455
|
+
test('error: odd-length indexed bytesN arg', () => {
|
|
2456
|
+
const event = AbiEvent.from(
|
|
2457
|
+
'event Foo(bytes4 indexed a, bytes32 indexed b)',
|
|
2458
|
+
)
|
|
2459
|
+
expect(() => AbiEvent.encode(event, { a: '0x1234567' }))
|
|
2460
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
2461
|
+
[Hex.InvalidLengthError: Hex value \`"0x1234567"\` is an odd length (7 nibbles).
|
|
2462
|
+
|
|
2463
|
+
It must be an even length.]
|
|
2464
|
+
`)
|
|
2465
|
+
expect(() => AbiEvent.encode(event, { b: `0x${'1'.repeat(63)}` }))
|
|
2466
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
2467
|
+
[Hex.InvalidLengthError: Hex value \`"0x111111111111111111111111111111111111111111111111111111111111111"\` is an odd length (63 nibbles).
|
|
2468
|
+
|
|
2469
|
+
It must be an even length.]
|
|
1918
2470
|
`)
|
|
1919
2471
|
})
|
|
1920
2472
|
|