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
|
@@ -5,6 +5,66 @@ import { address } from '../../../test/constants/addresses.js'
|
|
|
5
5
|
import { anvilMainnet } from '../../../test/prool.js'
|
|
6
6
|
|
|
7
7
|
describe('assertArgs', () => {
|
|
8
|
+
test('behavior: integer number and bigint arguments', () => {
|
|
9
|
+
const abiEvent = AbiEvent.from(
|
|
10
|
+
'event Deposit(uint8 indexed tier, uint256 amount)',
|
|
11
|
+
)
|
|
12
|
+
const args = AbiEvent.decode(abiEvent, {
|
|
13
|
+
data: AbiParameters.encode(AbiParameters.from('uint256'), [5n]),
|
|
14
|
+
topics: [
|
|
15
|
+
AbiEvent.getSelector(abiEvent),
|
|
16
|
+
AbiParameters.encode(AbiParameters.from('uint8'), [1]),
|
|
17
|
+
],
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
AbiEvent.assertArgs(abiEvent, args, { amount: 5, tier: 1n } as never)
|
|
21
|
+
AbiEvent.assertArgs(abiEvent, args, { amount: [4, 5], tier: [1n] } as never)
|
|
22
|
+
expect(() => AbiEvent.assertArgs(abiEvent, args, { tier: 2n } as never))
|
|
23
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
24
|
+
[AbiEvent.ArgsMismatchError: Given arguments do not match the expected arguments.
|
|
25
|
+
|
|
26
|
+
Event: event Deposit(uint8 indexed tier, uint256 amount)
|
|
27
|
+
Expected Arguments:
|
|
28
|
+
tier: 1
|
|
29
|
+
amount: 5
|
|
30
|
+
Given Arguments:
|
|
31
|
+
tier: 2]
|
|
32
|
+
`)
|
|
33
|
+
expect(() => AbiEvent.assertArgs(abiEvent, args, { amount: 5.5 } as never))
|
|
34
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
35
|
+
[AbiEvent.ArgsMismatchError: Given arguments do not match the expected arguments.
|
|
36
|
+
|
|
37
|
+
Event: event Deposit(uint8 indexed tier, uint256 amount)
|
|
38
|
+
Expected Arguments:
|
|
39
|
+
tier: 1
|
|
40
|
+
amount: 5
|
|
41
|
+
Given Arguments:
|
|
42
|
+
amount: 5.5]
|
|
43
|
+
`)
|
|
44
|
+
expect(
|
|
45
|
+
AbiEvent.extractLogs(
|
|
46
|
+
[abiEvent],
|
|
47
|
+
[
|
|
48
|
+
{
|
|
49
|
+
data: AbiParameters.encode(AbiParameters.from('uint256'), [5n]),
|
|
50
|
+
topics: [
|
|
51
|
+
AbiEvent.getSelector(abiEvent),
|
|
52
|
+
AbiParameters.encode(AbiParameters.from('uint8'), [1]),
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
{ args: { amount: 5, tier: 1n } as never },
|
|
57
|
+
).map((x) => x.args),
|
|
58
|
+
).toMatchInlineSnapshot(`
|
|
59
|
+
[
|
|
60
|
+
{
|
|
61
|
+
"amount": 5n,
|
|
62
|
+
"tier": 1,
|
|
63
|
+
},
|
|
64
|
+
]
|
|
65
|
+
`)
|
|
66
|
+
})
|
|
67
|
+
|
|
8
68
|
test('behavior: non-indexed `string` and `bytes`', () => {
|
|
9
69
|
const abiEvent = AbiEvent.from(
|
|
10
70
|
'event Message(string indexed topic, string text, bytes data, bytes32 key)',
|
|
@@ -706,6 +766,135 @@ describe('decodeLog', () => {
|
|
|
706
766
|
`)
|
|
707
767
|
})
|
|
708
768
|
|
|
769
|
+
test('behavior: decodes an anonymous event when every event is anonymous', () => {
|
|
770
|
+
const abi = Abi.from([
|
|
771
|
+
{
|
|
772
|
+
anonymous: true,
|
|
773
|
+
inputs: [{ indexed: true, name: 'from', type: 'address' }],
|
|
774
|
+
name: 'Ping',
|
|
775
|
+
type: 'event',
|
|
776
|
+
},
|
|
777
|
+
{
|
|
778
|
+
anonymous: true,
|
|
779
|
+
inputs: [
|
|
780
|
+
{ indexed: true, name: 'from', type: 'address' },
|
|
781
|
+
{ indexed: true, name: 'to', type: 'address' },
|
|
782
|
+
],
|
|
783
|
+
name: 'Pair',
|
|
784
|
+
type: 'event',
|
|
785
|
+
},
|
|
786
|
+
])
|
|
787
|
+
|
|
788
|
+
const decoded = AbiEvent.decodeLog(abi, {
|
|
789
|
+
data: '0x',
|
|
790
|
+
topics: [
|
|
791
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
792
|
+
],
|
|
793
|
+
})
|
|
794
|
+
|
|
795
|
+
expect(decoded.event.name).toMatchInlineSnapshot(`"Ping"`)
|
|
796
|
+
expect(decoded.args).toMatchInlineSnapshot(`
|
|
797
|
+
{
|
|
798
|
+
"from": "0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC",
|
|
799
|
+
}
|
|
800
|
+
`)
|
|
801
|
+
})
|
|
802
|
+
|
|
803
|
+
test('behavior: a selector match wins over an anonymous event', () => {
|
|
804
|
+
const transfer = AbiEvent.from(
|
|
805
|
+
'event Transfer(address indexed from, uint256 value)',
|
|
806
|
+
)
|
|
807
|
+
const abi = [
|
|
808
|
+
{
|
|
809
|
+
anonymous: true,
|
|
810
|
+
inputs: [
|
|
811
|
+
{ indexed: true, name: 'a', type: 'bytes32' },
|
|
812
|
+
{ indexed: true, name: 'b', type: 'bytes32' },
|
|
813
|
+
],
|
|
814
|
+
name: 'Anon',
|
|
815
|
+
type: 'event',
|
|
816
|
+
},
|
|
817
|
+
transfer,
|
|
818
|
+
]
|
|
819
|
+
|
|
820
|
+
const decoded = AbiEvent.decodeLog(abi, {
|
|
821
|
+
data: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
822
|
+
topics: [
|
|
823
|
+
AbiEvent.getSelector(transfer),
|
|
824
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
825
|
+
],
|
|
826
|
+
})
|
|
827
|
+
|
|
828
|
+
expect(decoded.event.name).toMatchInlineSnapshot(`"Transfer"`)
|
|
829
|
+
})
|
|
830
|
+
|
|
831
|
+
test('error: anonymous events are not matched in a mixed ABI', () => {
|
|
832
|
+
const abi = [
|
|
833
|
+
AbiEvent.from('event Transfer(address indexed from, uint256 value)'),
|
|
834
|
+
AbiEvent.from({
|
|
835
|
+
anonymous: true,
|
|
836
|
+
inputs: [
|
|
837
|
+
{ indexed: true, name: 'a', type: 'address' },
|
|
838
|
+
{ indexed: true, name: 'b', type: 'address' },
|
|
839
|
+
],
|
|
840
|
+
name: 'Anon',
|
|
841
|
+
type: 'event',
|
|
842
|
+
}),
|
|
843
|
+
]
|
|
844
|
+
|
|
845
|
+
expect(() =>
|
|
846
|
+
AbiEvent.decodeLog(abi, {
|
|
847
|
+
data: '0x',
|
|
848
|
+
topics: [
|
|
849
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
850
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
851
|
+
],
|
|
852
|
+
}),
|
|
853
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
854
|
+
`[AbiItem.NotFoundError: ABI item with name "0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac" not found.]`,
|
|
855
|
+
)
|
|
856
|
+
})
|
|
857
|
+
|
|
858
|
+
test('error: anonymous events with the same topic count', () => {
|
|
859
|
+
const abi = Abi.from([
|
|
860
|
+
{
|
|
861
|
+
anonymous: true,
|
|
862
|
+
inputs: [
|
|
863
|
+
{ indexed: true, name: 'from', type: 'address' },
|
|
864
|
+
{ indexed: false, name: 'value', type: 'uint256' },
|
|
865
|
+
],
|
|
866
|
+
name: 'Count',
|
|
867
|
+
type: 'event',
|
|
868
|
+
},
|
|
869
|
+
{
|
|
870
|
+
anonymous: true,
|
|
871
|
+
inputs: [
|
|
872
|
+
{ indexed: true, name: 'from', type: 'address' },
|
|
873
|
+
{ indexed: false, name: 'note', type: 'string' },
|
|
874
|
+
],
|
|
875
|
+
name: 'Message',
|
|
876
|
+
type: 'event',
|
|
877
|
+
},
|
|
878
|
+
])
|
|
879
|
+
|
|
880
|
+
expect(() =>
|
|
881
|
+
AbiEvent.decodeLog(abi, {
|
|
882
|
+
data: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
883
|
+
topics: [
|
|
884
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
885
|
+
],
|
|
886
|
+
}),
|
|
887
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
888
|
+
[AbiEvent.AnonymousEventAmbiguityError: Found ambiguous anonymous events for the log.
|
|
889
|
+
|
|
890
|
+
- \`event Count(address indexed from, uint256 value)\`
|
|
891
|
+
- \`event Message(address indexed from, string note)\`
|
|
892
|
+
|
|
893
|
+
These events take the same number of indexed topics.
|
|
894
|
+
Decode the log with \`AbiEvent.decode\` and the intended event.]
|
|
895
|
+
`)
|
|
896
|
+
})
|
|
897
|
+
|
|
709
898
|
test('error: selector topic not found', () => {
|
|
710
899
|
const transfer = AbiEvent.from('event Transfer(address indexed from)')
|
|
711
900
|
|
|
@@ -717,6 +906,115 @@ describe('decodeLog', () => {
|
|
|
717
906
|
})
|
|
718
907
|
|
|
719
908
|
describe('extractLogs', () => {
|
|
909
|
+
test('behavior: anonymous events', () => {
|
|
910
|
+
const abi = [
|
|
911
|
+
AbiEvent.from('event Transfer(address indexed from, uint256 value)'),
|
|
912
|
+
AbiEvent.from({
|
|
913
|
+
anonymous: true,
|
|
914
|
+
inputs: [
|
|
915
|
+
{ indexed: true, name: 'from', type: 'address' },
|
|
916
|
+
{ indexed: true, name: 'to', type: 'address' },
|
|
917
|
+
],
|
|
918
|
+
name: 'Ping',
|
|
919
|
+
type: 'event',
|
|
920
|
+
}),
|
|
921
|
+
]
|
|
922
|
+
const transfer = {
|
|
923
|
+
data: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
924
|
+
topics: [
|
|
925
|
+
AbiEvent.getSelector(abi[0]!),
|
|
926
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
927
|
+
],
|
|
928
|
+
} as const
|
|
929
|
+
const ping = {
|
|
930
|
+
data: '0x',
|
|
931
|
+
topics: [
|
|
932
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
933
|
+
'0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266',
|
|
934
|
+
],
|
|
935
|
+
} as const
|
|
936
|
+
|
|
937
|
+
// Without `eventName`, an anonymous event in a mixed ABI is not requested,
|
|
938
|
+
// so a log with an unknown selector is not extracted as it.
|
|
939
|
+
expect(AbiEvent.extractLogs(abi, [transfer, ping]).map((x) => x.eventName))
|
|
940
|
+
.toMatchInlineSnapshot(`
|
|
941
|
+
[
|
|
942
|
+
"Transfer",
|
|
943
|
+
]
|
|
944
|
+
`)
|
|
945
|
+
expect(
|
|
946
|
+
AbiEvent.extractLogs(abi, [transfer, ping], {
|
|
947
|
+
eventName: ['Ping', 'Transfer'],
|
|
948
|
+
}).map((x) => [x.eventName, x.args]),
|
|
949
|
+
).toMatchInlineSnapshot(`
|
|
950
|
+
[
|
|
951
|
+
[
|
|
952
|
+
"Transfer",
|
|
953
|
+
{
|
|
954
|
+
"from": "0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC",
|
|
955
|
+
"value": 1n,
|
|
956
|
+
},
|
|
957
|
+
],
|
|
958
|
+
[
|
|
959
|
+
"Ping",
|
|
960
|
+
{
|
|
961
|
+
"from": "0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC",
|
|
962
|
+
"to": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
963
|
+
},
|
|
964
|
+
],
|
|
965
|
+
]
|
|
966
|
+
`)
|
|
967
|
+
expect(
|
|
968
|
+
AbiEvent.extractLogs([abi[1]], [ping], {
|
|
969
|
+
args: { to: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' },
|
|
970
|
+
}).map((x) => x.eventName),
|
|
971
|
+
).toMatchInlineSnapshot(`
|
|
972
|
+
[
|
|
973
|
+
"Ping",
|
|
974
|
+
]
|
|
975
|
+
`)
|
|
976
|
+
})
|
|
977
|
+
|
|
978
|
+
test('behavior: skips logs that fit several anonymous events', () => {
|
|
979
|
+
const abi = Abi.from([
|
|
980
|
+
{
|
|
981
|
+
anonymous: true,
|
|
982
|
+
inputs: [
|
|
983
|
+
{ indexed: true, name: 'from', type: 'address' },
|
|
984
|
+
{ indexed: false, name: 'value', type: 'uint256' },
|
|
985
|
+
],
|
|
986
|
+
name: 'Count',
|
|
987
|
+
type: 'event',
|
|
988
|
+
},
|
|
989
|
+
{
|
|
990
|
+
anonymous: true,
|
|
991
|
+
inputs: [
|
|
992
|
+
{ indexed: true, name: 'from', type: 'address' },
|
|
993
|
+
{ indexed: false, name: 'note', type: 'string' },
|
|
994
|
+
],
|
|
995
|
+
name: 'Message',
|
|
996
|
+
type: 'event',
|
|
997
|
+
},
|
|
998
|
+
])
|
|
999
|
+
const log = {
|
|
1000
|
+
data: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1001
|
+
topics: [
|
|
1002
|
+
'0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
1003
|
+
],
|
|
1004
|
+
} as const
|
|
1005
|
+
|
|
1006
|
+
expect(AbiEvent.extractLogs(abi, [log])).toMatchInlineSnapshot(`[]`)
|
|
1007
|
+
expect(
|
|
1008
|
+
AbiEvent.extractLogs(abi, [log], { eventName: 'Count' }).map(
|
|
1009
|
+
(x) => x.eventName,
|
|
1010
|
+
),
|
|
1011
|
+
).toMatchInlineSnapshot(`
|
|
1012
|
+
[
|
|
1013
|
+
"Count",
|
|
1014
|
+
]
|
|
1015
|
+
`)
|
|
1016
|
+
})
|
|
1017
|
+
|
|
720
1018
|
test('behavior: decodes matching logs', () => {
|
|
721
1019
|
const transfer = AbiEvent.from(
|
|
722
1020
|
'event Transfer(address indexed from, address indexed to, uint256 value)',
|
|
@@ -1580,6 +1878,86 @@ describe('encode', () => {
|
|
|
1580
1878
|
)
|
|
1581
1879
|
})
|
|
1582
1880
|
|
|
1881
|
+
test('behavior: narrow indexed args at their type bounds', () => {
|
|
1882
|
+
const event = AbiEvent.from(
|
|
1883
|
+
'event Foo(int8 indexed a, uint8 indexed b, bytes4 indexed c)',
|
|
1884
|
+
)
|
|
1885
|
+
expect(AbiEvent.encode(event, { a: -128, b: 255, c: '0x01020304' }))
|
|
1886
|
+
.toMatchInlineSnapshot(`
|
|
1887
|
+
{
|
|
1888
|
+
"topics": [
|
|
1889
|
+
"0xd6e31c53a9a68addf818ebcdb6a5b6f8a18be2d94c1c57fb0f1d4c8014bbbe8c",
|
|
1890
|
+
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80",
|
|
1891
|
+
"0x00000000000000000000000000000000000000000000000000000000000000ff",
|
|
1892
|
+
"0x0102030400000000000000000000000000000000000000000000000000000000",
|
|
1893
|
+
],
|
|
1894
|
+
}
|
|
1895
|
+
`)
|
|
1896
|
+
expect(AbiEvent.encode(event, { a: 127, b: 0 })).toMatchInlineSnapshot(`
|
|
1897
|
+
{
|
|
1898
|
+
"topics": [
|
|
1899
|
+
"0xd6e31c53a9a68addf818ebcdb6a5b6f8a18be2d94c1c57fb0f1d4c8014bbbe8c",
|
|
1900
|
+
"0x000000000000000000000000000000000000000000000000000000000000007f",
|
|
1901
|
+
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
1902
|
+
null,
|
|
1903
|
+
],
|
|
1904
|
+
}
|
|
1905
|
+
`)
|
|
1906
|
+
})
|
|
1907
|
+
|
|
1908
|
+
test('behavior: odd-length indexed bytes32 arg', () => {
|
|
1909
|
+
const event = AbiEvent.from('event Foo(bytes32 indexed a)')
|
|
1910
|
+
expect(AbiEvent.encode(event, { a: `0x${'1'.repeat(63)}` }))
|
|
1911
|
+
.toMatchInlineSnapshot(`
|
|
1912
|
+
{
|
|
1913
|
+
"topics": [
|
|
1914
|
+
"0x54b5e571557045df8a69633aeac8e206d92b03f48563fab6a430493d299de727",
|
|
1915
|
+
"0x1111111111111111111111111111111111111111111111111111111111111110",
|
|
1916
|
+
],
|
|
1917
|
+
}
|
|
1918
|
+
`)
|
|
1919
|
+
})
|
|
1920
|
+
|
|
1921
|
+
test('error: indexed integer out of range', () => {
|
|
1922
|
+
const event = AbiEvent.from('event Foo(int8 indexed a, uint8 indexed b)')
|
|
1923
|
+
expect(() =>
|
|
1924
|
+
AbiEvent.encode(event, { a: 128 }),
|
|
1925
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1926
|
+
`[Hex.IntegerOutOfRangeError: Number \`128\` is not in safe 8-bit signed integer range (\`-128\` to \`127\`)]`,
|
|
1927
|
+
)
|
|
1928
|
+
expect(() =>
|
|
1929
|
+
AbiEvent.encode(event, { a: -129 }),
|
|
1930
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1931
|
+
`[Hex.IntegerOutOfRangeError: Number \`-129\` is not in safe 8-bit signed integer range (\`-128\` to \`127\`)]`,
|
|
1932
|
+
)
|
|
1933
|
+
expect(() =>
|
|
1934
|
+
AbiEvent.encode(event, { b: 256 }),
|
|
1935
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1936
|
+
`[Hex.IntegerOutOfRangeError: Number \`256\` is not in safe 8-bit unsigned integer range (\`0\` to \`255\`)]`,
|
|
1937
|
+
)
|
|
1938
|
+
})
|
|
1939
|
+
|
|
1940
|
+
test('error: indexed bytesN size mismatch', () => {
|
|
1941
|
+
const event = AbiEvent.from(
|
|
1942
|
+
'event Foo(bytes4 indexed a, bytes32 indexed b)',
|
|
1943
|
+
)
|
|
1944
|
+
expect(() =>
|
|
1945
|
+
AbiEvent.encode(event, { a: '0x0102030405' }),
|
|
1946
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1947
|
+
`[AbiParameters.BytesSizeMismatchError: Size of bytes "0x0102030405" (bytes5) does not match expected size (bytes4).]`,
|
|
1948
|
+
)
|
|
1949
|
+
expect(() =>
|
|
1950
|
+
AbiEvent.encode(event, { a: '0x0102' }),
|
|
1951
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1952
|
+
`[AbiParameters.BytesSizeMismatchError: Size of bytes "0x0102" (bytes2) does not match expected size (bytes4).]`,
|
|
1953
|
+
)
|
|
1954
|
+
expect(() =>
|
|
1955
|
+
AbiEvent.encode(event, { b: `0x${'11'.repeat(31)}` }),
|
|
1956
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1957
|
+
`[AbiParameters.BytesSizeMismatchError: Size of bytes "0x11111111111111111111111111111111111111111111111111111111111111" (bytes31) does not match expected size (bytes32).]`,
|
|
1958
|
+
)
|
|
1959
|
+
})
|
|
1960
|
+
|
|
1583
1961
|
test('behavior: network', async () => {
|
|
1584
1962
|
const transfer = AbiEvent.from(
|
|
1585
1963
|
'event Transfer(address indexed from, address indexed to, uint256 value)',
|
|
@@ -1974,6 +2352,17 @@ describe('fromAbi', () => {
|
|
|
1974
2352
|
"hash": "0xbfb4ebcfff8f360b39de1de85df1edc256d63337b743120bf6e2e2144b973d38",
|
|
1975
2353
|
"inputs": [],
|
|
1976
2354
|
"name": "Foo",
|
|
2355
|
+
"overloads": [
|
|
2356
|
+
{
|
|
2357
|
+
"inputs": [
|
|
2358
|
+
{
|
|
2359
|
+
"type": "uint256",
|
|
2360
|
+
},
|
|
2361
|
+
],
|
|
2362
|
+
"name": "Foo",
|
|
2363
|
+
"type": "event",
|
|
2364
|
+
},
|
|
2365
|
+
],
|
|
1977
2366
|
"type": "event",
|
|
1978
2367
|
}
|
|
1979
2368
|
`)
|
|
@@ -1987,6 +2376,17 @@ describe('fromAbi', () => {
|
|
|
1987
2376
|
"hash": "0xbfb4ebcfff8f360b39de1de85df1edc256d63337b743120bf6e2e2144b973d38",
|
|
1988
2377
|
"inputs": [],
|
|
1989
2378
|
"name": "Foo",
|
|
2379
|
+
"overloads": [
|
|
2380
|
+
{
|
|
2381
|
+
"inputs": [
|
|
2382
|
+
{
|
|
2383
|
+
"type": "uint256",
|
|
2384
|
+
},
|
|
2385
|
+
],
|
|
2386
|
+
"name": "Foo",
|
|
2387
|
+
"type": "event",
|
|
2388
|
+
},
|
|
2389
|
+
],
|
|
1990
2390
|
"type": "event",
|
|
1991
2391
|
}
|
|
1992
2392
|
`)
|
|
@@ -2004,6 +2404,26 @@ describe('fromAbi', () => {
|
|
|
2004
2404
|
"hash": "0x34c73884fbbb790762253ae313e57da96c00670344647f0cb8d41ee92b9f1971",
|
|
2005
2405
|
"inputs": [],
|
|
2006
2406
|
"name": "Mint",
|
|
2407
|
+
"overloads": [
|
|
2408
|
+
{
|
|
2409
|
+
"inputs": [
|
|
2410
|
+
{
|
|
2411
|
+
"type": "uint256",
|
|
2412
|
+
},
|
|
2413
|
+
],
|
|
2414
|
+
"name": "Mint",
|
|
2415
|
+
"type": "event",
|
|
2416
|
+
},
|
|
2417
|
+
{
|
|
2418
|
+
"inputs": [
|
|
2419
|
+
{
|
|
2420
|
+
"type": "string",
|
|
2421
|
+
},
|
|
2422
|
+
],
|
|
2423
|
+
"name": "Mint",
|
|
2424
|
+
"type": "event",
|
|
2425
|
+
},
|
|
2426
|
+
],
|
|
2007
2427
|
"type": "event",
|
|
2008
2428
|
}
|
|
2009
2429
|
`)
|
|
@@ -2215,6 +2635,7 @@ test('exports', () => {
|
|
|
2215
2635
|
"SelectorTopicMismatchError",
|
|
2216
2636
|
"SelectorTopicNotFoundError",
|
|
2217
2637
|
"FilterTypeNotSupportedError",
|
|
2638
|
+
"AnonymousEventAmbiguityError",
|
|
2218
2639
|
]
|
|
2219
2640
|
`)
|
|
2220
2641
|
})
|
|
@@ -66,6 +66,20 @@ describe('decodeData', () => {
|
|
|
66
66
|
),
|
|
67
67
|
).type.toString.snap('readonly [bigint] | readonly [`0x${string}`]')
|
|
68
68
|
})
|
|
69
|
+
|
|
70
|
+
test('behavior: with overloads, one with zero inputs', () => {
|
|
71
|
+
const abi = Abi.from([
|
|
72
|
+
'function deposit()',
|
|
73
|
+
'function deposit(uint256 assets)',
|
|
74
|
+
])
|
|
75
|
+
attest(
|
|
76
|
+
AbiFunction.decodeData(
|
|
77
|
+
abi,
|
|
78
|
+
'deposit',
|
|
79
|
+
'0xb6b55f25000000000000000000000000000000000000000000000000000000000000007b',
|
|
80
|
+
),
|
|
81
|
+
).type.toString.snap('readonly [bigint] | undefined')
|
|
82
|
+
})
|
|
69
83
|
})
|
|
70
84
|
|
|
71
85
|
describe('decodeResult', () => {
|
|
@@ -222,6 +236,17 @@ describe('fromAbi', () => {
|
|
|
222
236
|
readonly stateMutability: "nonpayable"
|
|
223
237
|
readonly inputs: readonly []
|
|
224
238
|
readonly outputs: readonly []
|
|
239
|
+
readonly overloads: [
|
|
240
|
+
{
|
|
241
|
+
readonly name: "foo"
|
|
242
|
+
readonly type: "function"
|
|
243
|
+
readonly stateMutability: "nonpayable"
|
|
244
|
+
readonly inputs: readonly [
|
|
245
|
+
{ readonly type: "uint256" }
|
|
246
|
+
]
|
|
247
|
+
readonly outputs: readonly []
|
|
248
|
+
}
|
|
249
|
+
]
|
|
225
250
|
}`)
|
|
226
251
|
})
|
|
227
252
|
|
|
@@ -91,6 +91,39 @@ describe('decodeData', () => {
|
|
|
91
91
|
),
|
|
92
92
|
).toEqual(['0xdeadbeef'])
|
|
93
93
|
})
|
|
94
|
+
|
|
95
|
+
test('behavior: with overloads, resolved by name (one overload has zero inputs)', () => {
|
|
96
|
+
const abi = Abi.from([
|
|
97
|
+
{
|
|
98
|
+
inputs: [],
|
|
99
|
+
name: 'deposit',
|
|
100
|
+
outputs: [],
|
|
101
|
+
stateMutability: 'payable',
|
|
102
|
+
type: 'function',
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
inputs: [{ name: 'assets', type: 'uint256' }],
|
|
106
|
+
name: 'deposit',
|
|
107
|
+
outputs: [],
|
|
108
|
+
stateMutability: 'nonpayable',
|
|
109
|
+
type: 'function',
|
|
110
|
+
},
|
|
111
|
+
])
|
|
112
|
+
|
|
113
|
+
const withArgs = AbiFunction.fromAbi(abi, 'deposit', { args: [123n] })
|
|
114
|
+
const dataWithArgs = AbiFunction.encodeData(withArgs, [123n])
|
|
115
|
+
// Resolving by name alone (no args) must still disambiguate the
|
|
116
|
+
// zero-input overload from the one actually encoded in `data`.
|
|
117
|
+
expect(AbiFunction.decodeData(abi, 'deposit', dataWithArgs)).toEqual([123n])
|
|
118
|
+
expect(AbiFunction.decodeData(abi, dataWithArgs)).toEqual([123n])
|
|
119
|
+
|
|
120
|
+
const withoutArgs = AbiFunction.fromAbi(abi, 'deposit', { args: [] })
|
|
121
|
+
const dataWithoutArgs = AbiFunction.encodeData(withoutArgs)
|
|
122
|
+
expect(AbiFunction.decodeData(abi, 'deposit', dataWithoutArgs)).toEqual(
|
|
123
|
+
undefined,
|
|
124
|
+
)
|
|
125
|
+
expect(AbiFunction.decodeData(abi, dataWithoutArgs)).toEqual(undefined)
|
|
126
|
+
})
|
|
94
127
|
})
|
|
95
128
|
|
|
96
129
|
describe('decodeResult', () => {
|
|
@@ -707,15 +740,28 @@ describe('fromAbi', () => {
|
|
|
707
740
|
])
|
|
708
741
|
const item = AbiFunction.fromAbi(abi, 'foo')
|
|
709
742
|
expect(item).toMatchInlineSnapshot(`
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
743
|
+
{
|
|
744
|
+
"hash": "0xc2985578b8f3b75f7dc66a767be2a4ef7d7c2224896a1c86e92ccf30bae678b7",
|
|
745
|
+
"inputs": [],
|
|
746
|
+
"name": "foo",
|
|
747
|
+
"outputs": [],
|
|
748
|
+
"overloads": [
|
|
749
|
+
{
|
|
750
|
+
"inputs": [
|
|
751
|
+
{
|
|
752
|
+
"type": "uint256",
|
|
753
|
+
},
|
|
754
|
+
],
|
|
755
|
+
"name": "foo",
|
|
756
|
+
"outputs": [],
|
|
757
|
+
"stateMutability": "nonpayable",
|
|
758
|
+
"type": "function",
|
|
759
|
+
},
|
|
760
|
+
],
|
|
761
|
+
"stateMutability": "nonpayable",
|
|
762
|
+
"type": "function",
|
|
763
|
+
}
|
|
764
|
+
`)
|
|
719
765
|
})
|
|
720
766
|
|
|
721
767
|
test('overloads: no args', () => {
|
|
@@ -726,15 +772,28 @@ describe('fromAbi', () => {
|
|
|
726
772
|
])
|
|
727
773
|
const item = AbiFunction.fromAbi(abi, 'foo')
|
|
728
774
|
expect(item).toMatchInlineSnapshot(`
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
775
|
+
{
|
|
776
|
+
"hash": "0xc2985578b8f3b75f7dc66a767be2a4ef7d7c2224896a1c86e92ccf30bae678b7",
|
|
777
|
+
"inputs": [],
|
|
778
|
+
"name": "foo",
|
|
779
|
+
"outputs": [],
|
|
780
|
+
"overloads": [
|
|
781
|
+
{
|
|
782
|
+
"inputs": [
|
|
783
|
+
{
|
|
784
|
+
"type": "uint256",
|
|
785
|
+
},
|
|
786
|
+
],
|
|
787
|
+
"name": "foo",
|
|
788
|
+
"outputs": [],
|
|
789
|
+
"stateMutability": "nonpayable",
|
|
790
|
+
"type": "function",
|
|
791
|
+
},
|
|
792
|
+
],
|
|
793
|
+
"stateMutability": "nonpayable",
|
|
794
|
+
"type": "function",
|
|
795
|
+
}
|
|
796
|
+
`)
|
|
738
797
|
})
|
|
739
798
|
|
|
740
799
|
test('behavior: overloads: different lengths without abi order define effect', () => {
|
|
@@ -838,6 +897,30 @@ describe('fromAbi', () => {
|
|
|
838
897
|
"inputs": [],
|
|
839
898
|
"name": "mint",
|
|
840
899
|
"outputs": [],
|
|
900
|
+
"overloads": [
|
|
901
|
+
{
|
|
902
|
+
"inputs": [
|
|
903
|
+
{
|
|
904
|
+
"type": "uint256",
|
|
905
|
+
},
|
|
906
|
+
],
|
|
907
|
+
"name": "mint",
|
|
908
|
+
"outputs": [],
|
|
909
|
+
"stateMutability": "nonpayable",
|
|
910
|
+
"type": "function",
|
|
911
|
+
},
|
|
912
|
+
{
|
|
913
|
+
"inputs": [
|
|
914
|
+
{
|
|
915
|
+
"type": "string",
|
|
916
|
+
},
|
|
917
|
+
],
|
|
918
|
+
"name": "mint",
|
|
919
|
+
"outputs": [],
|
|
920
|
+
"stateMutability": "nonpayable",
|
|
921
|
+
"type": "function",
|
|
922
|
+
},
|
|
923
|
+
],
|
|
841
924
|
"stateMutability": "nonpayable",
|
|
842
925
|
"type": "function",
|
|
843
926
|
}
|
|
@@ -74,6 +74,17 @@ describe('fromAbi', () => {
|
|
|
74
74
|
readonly stateMutability: "nonpayable"
|
|
75
75
|
readonly inputs: readonly []
|
|
76
76
|
readonly outputs: readonly []
|
|
77
|
+
readonly overloads: [
|
|
78
|
+
{
|
|
79
|
+
readonly name: "foo"
|
|
80
|
+
readonly type: "function"
|
|
81
|
+
readonly stateMutability: "nonpayable"
|
|
82
|
+
readonly inputs: readonly [
|
|
83
|
+
{ readonly type: "uint256" }
|
|
84
|
+
]
|
|
85
|
+
readonly outputs: readonly []
|
|
86
|
+
}
|
|
87
|
+
]
|
|
77
88
|
}`)
|
|
78
89
|
})
|
|
79
90
|
|