ox 1.8.12 → 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 +62 -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/TxEnvelope.d.ts.map +1 -1
- package/dist/core/TxEnvelope.js +5 -3
- package/dist/core/TxEnvelope.js.map +1 -1
- package/dist/core/TxEnvelopeEip1559.d.ts.map +1 -1
- package/dist/core/TxEnvelopeEip1559.js +6 -2
- package/dist/core/TxEnvelopeEip1559.js.map +1 -1
- package/dist/core/TxEnvelopeEip4844.d.ts.map +1 -1
- package/dist/core/TxEnvelopeEip4844.js +4 -0
- package/dist/core/TxEnvelopeEip4844.js.map +1 -1
- package/dist/core/TxEnvelopeEip7702.d.ts.map +1 -1
- package/dist/core/TxEnvelopeEip7702.js +4 -0
- package/dist/core/TxEnvelopeEip7702.js.map +1 -1
- package/dist/core/TypedData.d.ts +8 -1
- package/dist/core/TypedData.d.ts.map +1 -1
- package/dist/core/TypedData.js +55 -14
- 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 +46 -13
- package/dist/core/internal/abiItem.js.map +1 -1
- package/dist/core/internal/abiParameters.d.ts +2 -2
- package/dist/core/internal/abiParameters.d.ts.map +1 -1
- package/dist/core/internal/abiParameters.js +24 -7
- package/dist/core/internal/abiParameters.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/core/internal/rpcSchemas/eth.d.ts +3 -2
- package/dist/core/internal/rpcSchemas/eth.d.ts.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/KeyAuthorization.d.ts +21 -6
- package/dist/tempo/KeyAuthorization.d.ts.map +1 -1
- package/dist/tempo/KeyAuthorization.js +7 -4
- package/dist/tempo/KeyAuthorization.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/tempo/TxEnvelopeTempo.d.ts.map +1 -1
- package/dist/tempo/TxEnvelopeTempo.js +6 -2
- package/dist/tempo/TxEnvelopeTempo.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 +5 -2
- 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/TxEnvelope.ts +5 -3
- package/src/core/TxEnvelopeEip1559.ts +8 -2
- package/src/core/TxEnvelopeEip4844.ts +6 -0
- package/src/core/TxEnvelopeEip7702.ts +6 -0
- package/src/core/TypedData.ts +62 -13
- 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 +393 -5
- package/src/core/_test/AbiParameters.decode.test.ts +140 -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/RpcSchema.test-d.ts +23 -1
- package/src/core/_test/RpcTransport.test.ts +47 -0
- package/src/core/_test/Siwe.test.ts +28 -0
- package/src/core/_test/TransactionEnvelopeEip1559.test.ts +24 -0
- package/src/core/_test/TransactionEnvelopeEip4844.test.ts +13 -0
- package/src/core/_test/TransactionEnvelopeEip7702.test.ts +13 -0
- package/src/core/_test/TypedData.test.ts +203 -1
- package/src/core/internal/abiItem.ts +58 -18
- package/src/core/internal/abiParameters.ts +26 -8
- package/src/core/internal/caches.ts +12 -0
- package/src/core/internal/frameNonce.ts +3 -4
- package/src/core/internal/rpcSchemas/eth.ts +2 -1
- 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/KeyAuthorization.test.ts +6 -4
- package/src/tempo/KeyAuthorization.ts +26 -8
- 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/tempo/TxEnvelopeTempo.test.ts +26 -0
- package/src/tempo/TxEnvelopeTempo.ts +8 -2
- package/src/tempo/e2e.test.ts +73 -17
- 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
package/src/core/Value.ts
CHANGED
|
@@ -9,6 +9,9 @@ export const exponents = {
|
|
|
9
9
|
ether: 18,
|
|
10
10
|
} as const
|
|
11
11
|
|
|
12
|
+
const decimalNumberRegex = /^-?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)$/
|
|
13
|
+
const trailingZerosRegex = /(0+)$/
|
|
14
|
+
|
|
12
15
|
/**
|
|
13
16
|
* Formats a `bigint` Value to its string representation (divided by the given exponent).
|
|
14
17
|
*
|
|
@@ -39,7 +42,7 @@ export function format(value: bigint, decimals = 0) {
|
|
|
39
42
|
display.slice(0, display.length - decimals),
|
|
40
43
|
display.slice(display.length - decimals),
|
|
41
44
|
]
|
|
42
|
-
fraction = fraction.replace(
|
|
45
|
+
fraction = fraction.replace(trailingZerosRegex, '')
|
|
43
46
|
return `${negative ? '-' : ''}${integer || '0'}${
|
|
44
47
|
fraction ? `.${fraction}` : ''
|
|
45
48
|
}`
|
|
@@ -120,7 +123,7 @@ export function from(value: string, decimals = 0) {
|
|
|
120
123
|
// Require at least one digit overall. Rejects '', '.', '-', '-.' which
|
|
121
124
|
// the previous regex accepted (and which then either produced garbage or
|
|
122
125
|
// threw a raw `SyntaxError` from `BigInt('')`).
|
|
123
|
-
if (
|
|
126
|
+
if (!decimalNumberRegex.test(value))
|
|
124
127
|
throw new InvalidDecimalNumberError({ value })
|
|
125
128
|
|
|
126
129
|
let [integer = '', fraction = '0'] = value.split('.')
|
|
@@ -130,7 +133,7 @@ export function from(value: string, decimals = 0) {
|
|
|
130
133
|
if (integer === '') integer = '0'
|
|
131
134
|
|
|
132
135
|
// trim trailing zeros.
|
|
133
|
-
fraction = fraction.replace(
|
|
136
|
+
fraction = fraction.replace(trailingZerosRegex, '')
|
|
134
137
|
|
|
135
138
|
// round off if the fraction is larger than the number of decimals.
|
|
136
139
|
if (decimals === 0) {
|
|
@@ -36,6 +36,16 @@ describe('AbiError.decode', () => {
|
|
|
36
36
|
expectTypeOf(decoded).toEqualTypeOf<number>()
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
+
test('behavior: with overloads', () => {
|
|
40
|
+
const abi = Abi.from([
|
|
41
|
+
'error Example()',
|
|
42
|
+
'error Example(uint256 amount)',
|
|
43
|
+
'error Example(string reason)',
|
|
44
|
+
])
|
|
45
|
+
const decoded = AbiError.decode(abi, 'Example', '0x')
|
|
46
|
+
expectTypeOf(decoded).toEqualTypeOf<bigint | string | undefined>()
|
|
47
|
+
})
|
|
48
|
+
|
|
39
49
|
test('not narrowable', () => {
|
|
40
50
|
const abiError = {} as AbiError.AbiError
|
|
41
51
|
const decoded = AbiError.decode(abiError, '0x')
|
|
@@ -76,6 +76,37 @@ describe('decode', () => {
|
|
|
76
76
|
expect(decoded).toEqual(1)
|
|
77
77
|
})
|
|
78
78
|
|
|
79
|
+
test('behavior: with overloads, resolved by name', () => {
|
|
80
|
+
const abi = Abi.from([
|
|
81
|
+
'error Example()',
|
|
82
|
+
'error Example(uint256 amount)',
|
|
83
|
+
'error Example(string reason)',
|
|
84
|
+
])
|
|
85
|
+
expect(
|
|
86
|
+
AbiError.decode(
|
|
87
|
+
abi,
|
|
88
|
+
'Example',
|
|
89
|
+
AbiError.encode(AbiError.from('error Example(uint256 amount)'), [5n]),
|
|
90
|
+
),
|
|
91
|
+
).toEqual(5n)
|
|
92
|
+
expect(
|
|
93
|
+
AbiError.decode(
|
|
94
|
+
abi,
|
|
95
|
+
'Example',
|
|
96
|
+
AbiError.encode(AbiError.from('error Example(string reason)'), [
|
|
97
|
+
'denied',
|
|
98
|
+
]),
|
|
99
|
+
),
|
|
100
|
+
).toEqual('denied')
|
|
101
|
+
expect(
|
|
102
|
+
AbiError.decode(
|
|
103
|
+
abi,
|
|
104
|
+
'Example',
|
|
105
|
+
AbiError.encode(AbiError.from('error Example()')),
|
|
106
|
+
),
|
|
107
|
+
).toEqual(undefined)
|
|
108
|
+
})
|
|
109
|
+
|
|
79
110
|
test('error: invalid data', () => {
|
|
80
111
|
const error = AbiError.from('error Example(uint256 a)')
|
|
81
112
|
expect(() =>
|
|
@@ -828,6 +859,17 @@ describe('fromAbi', () => {
|
|
|
828
859
|
"hash": "0xbfb4ebcfff8f360b39de1de85df1edc256d63337b743120bf6e2e2144b973d38",
|
|
829
860
|
"inputs": [],
|
|
830
861
|
"name": "Foo",
|
|
862
|
+
"overloads": [
|
|
863
|
+
{
|
|
864
|
+
"inputs": [
|
|
865
|
+
{
|
|
866
|
+
"type": "uint256",
|
|
867
|
+
},
|
|
868
|
+
],
|
|
869
|
+
"name": "Foo",
|
|
870
|
+
"type": "error",
|
|
871
|
+
},
|
|
872
|
+
],
|
|
831
873
|
"type": "error",
|
|
832
874
|
}
|
|
833
875
|
`)
|
|
@@ -841,6 +883,17 @@ describe('fromAbi', () => {
|
|
|
841
883
|
"hash": "0xbfb4ebcfff8f360b39de1de85df1edc256d63337b743120bf6e2e2144b973d38",
|
|
842
884
|
"inputs": [],
|
|
843
885
|
"name": "Foo",
|
|
886
|
+
"overloads": [
|
|
887
|
+
{
|
|
888
|
+
"inputs": [
|
|
889
|
+
{
|
|
890
|
+
"type": "uint256",
|
|
891
|
+
},
|
|
892
|
+
],
|
|
893
|
+
"name": "Foo",
|
|
894
|
+
"type": "error",
|
|
895
|
+
},
|
|
896
|
+
],
|
|
844
897
|
"type": "error",
|
|
845
898
|
}
|
|
846
899
|
`)
|
|
@@ -858,6 +911,26 @@ describe('fromAbi', () => {
|
|
|
858
911
|
"hash": "0x34c73884fbbb790762253ae313e57da96c00670344647f0cb8d41ee92b9f1971",
|
|
859
912
|
"inputs": [],
|
|
860
913
|
"name": "Mint",
|
|
914
|
+
"overloads": [
|
|
915
|
+
{
|
|
916
|
+
"inputs": [
|
|
917
|
+
{
|
|
918
|
+
"type": "uint256",
|
|
919
|
+
},
|
|
920
|
+
],
|
|
921
|
+
"name": "Mint",
|
|
922
|
+
"type": "error",
|
|
923
|
+
},
|
|
924
|
+
{
|
|
925
|
+
"inputs": [
|
|
926
|
+
{
|
|
927
|
+
"type": "string",
|
|
928
|
+
},
|
|
929
|
+
],
|
|
930
|
+
"name": "Mint",
|
|
931
|
+
"type": "error",
|
|
932
|
+
},
|
|
933
|
+
],
|
|
861
934
|
"type": "error",
|
|
862
935
|
}
|
|
863
936
|
`)
|
|
@@ -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
|
|