@@ -3,6 +3,7 @@ import { klona } from 'klona';
3
3
4
4
import type {
5
5
ProcessSendCallsHook ,
6
+ SendCalls ,
6
7
SendCallsParams ,
7
8
} from './wallet-send-calls' ;
8
9
import { walletSendCalls } from './wallet-send-calls' ;
@@ -12,7 +13,7 @@ type GetAccounts = WalletMiddlewareOptions['getAccounts'];
12
13
13
14
const ADDRESS_MOCK = '0x123abc123abc123abc123abc123abc123abc123a' ;
14
15
const HEX_MOCK = '0x123abc' ;
15
- const ID_MOCK = '1234-5678 ' ;
16
+ const ID_MOCK = '0x12345678 ' ;
16
17
17
18
const REQUEST_MOCK = {
18
19
params : [
@@ -52,8 +53,14 @@ describe('wallet_sendCalls', () => {
52
53
params = request . params as SendCallsParams ;
53
54
response = { } as PendingJsonRpcResponse < string > ;
54
55
55
- getAccountsMock = jest . fn ( ) . mockResolvedValue ( [ ADDRESS_MOCK ] ) ;
56
- processSendCallsMock = jest . fn ( ) . mockResolvedValue ( ID_MOCK ) ;
56
+ getAccountsMock = jest . fn ( ) ;
57
+ processSendCallsMock = jest . fn ( ) ;
58
+
59
+ getAccountsMock . mockResolvedValue ( [ ADDRESS_MOCK ] ) ;
60
+
61
+ processSendCallsMock . mockResolvedValue ( {
62
+ id : ID_MOCK ,
63
+ } ) ;
57
64
} ) ;
58
65
59
66
it ( 'calls hook' , async ( ) => {
@@ -63,12 +70,34 @@ describe('wallet_sendCalls', () => {
63
70
64
71
it ( 'returns ID from hook' , async ( ) => {
65
72
await callMethod ( ) ;
66
- expect ( response . result ) . toStrictEqual ( ID_MOCK ) ;
73
+ expect ( response . result ) . toStrictEqual ( { id : ID_MOCK } ) ;
67
74
} ) ;
68
75
69
- it ( 'supports capabilities' , async ( ) => {
70
- params [ 0 ] . capabilities = { test : 'value' } ;
76
+ it ( 'supports top-level capabilities' , async ( ) => {
77
+ params [ 0 ] . capabilities = {
78
+ 'test-capability' : { test : 'value' , optional : true } ,
79
+ } as SendCalls [ 'capabilities' ] ;
80
+
71
81
await callMethod ( ) ;
82
+
83
+ expect ( processSendCallsMock ) . toHaveBeenCalledWith ( params [ 0 ] , request ) ;
84
+ } ) ;
85
+
86
+ it ( 'supports call capabilities' , async ( ) => {
87
+ params [ 0 ] . calls [ 0 ] . capabilities = {
88
+ 'test-capability' : { test : 'value' , optional : false } ,
89
+ } as SendCalls [ 'capabilities' ] ;
90
+
91
+ await callMethod ( ) ;
92
+
93
+ expect ( processSendCallsMock ) . toHaveBeenCalledWith ( params [ 0 ] , request ) ;
94
+ } ) ;
95
+
96
+ it ( 'supports custom ID' , async ( ) => {
97
+ params [ 0 ] . id = ID_MOCK ;
98
+
99
+ await callMethod ( ) ;
100
+
72
101
expect ( processSendCallsMock ) . toHaveBeenCalledWith ( params [ 0 ] , request ) ;
73
102
} ) ;
74
103
@@ -99,39 +128,47 @@ describe('wallet_sendCalls', () => {
99
128
[Error: Invalid params
100
129
101
130
0 > from - Expected a string, but received: undefined
131
+ 0 > chainId - Expected a string, but received: undefined
102
132
0 > calls - Expected an array value, but received: undefined]
103
133
` ) ;
104
134
} ) ;
105
135
106
136
it ( 'throws if wrong types' , async ( ) => {
137
+ params [ 0 ] . id = 123 as never ;
107
138
params [ 0 ] . from = '123' as never ;
108
139
params [ 0 ] . chainId = 123 as never ;
109
140
params [ 0 ] . calls = '123' as never ;
141
+ params [ 0 ] . capabilities = '123' as never ;
110
142
111
143
await expect ( callMethod ( ) ) . rejects . toMatchInlineSnapshot ( `
112
144
[Error: Invalid params
113
145
146
+ 0 > id - Expected a string, but received: 123
114
147
0 > from - Expected a string matching \`/^0x[0-9a-fA-F]{40}$/\` but received "123"
115
148
0 > chainId - Expected a string, but received: 123
116
- 0 > calls - Expected an array value, but received: "123"]
149
+ 0 > calls - Expected an array value, but received: "123"
150
+ 0 > capabilities - Expected an object, but received: "123"]
117
151
` ) ;
118
152
} ) ;
119
153
120
154
it ( 'throws if calls have wrong types' , async ( ) => {
121
155
params [ 0 ] . calls [ 0 ] . data = 123 as never ;
122
156
params [ 0 ] . calls [ 0 ] . to = 123 as never ;
123
157
params [ 0 ] . calls [ 0 ] . value = 123 as never ;
158
+ params [ 0 ] . calls [ 0 ] . capabilities = '123' as never ;
124
159
125
160
await expect ( callMethod ( ) ) . rejects . toMatchInlineSnapshot ( `
126
161
[Error: Invalid params
127
162
128
163
0 > calls > 0 > to - Expected a string, but received: 123
129
164
0 > calls > 0 > data - Expected a string, but received: 123
130
- 0 > calls > 0 > value - Expected a string, but received: 123]
165
+ 0 > calls > 0 > value - Expected a string, but received: 123
166
+ 0 > calls > 0 > capabilities - Expected an object, but received: "123"]
131
167
` ) ;
132
168
} ) ;
133
169
134
170
it ( 'throws if not hex' , async ( ) => {
171
+ params [ 0 ] . id = '123' as never ;
135
172
params [ 0 ] . from = '123' as never ;
136
173
params [ 0 ] . chainId = '123' as never ;
137
174
params [ 0 ] . calls [ 0 ] . data = '123' as never ;
@@ -141,6 +178,7 @@ describe('wallet_sendCalls', () => {
141
178
await expect ( callMethod ( ) ) . rejects . toMatchInlineSnapshot ( `
142
179
[Error: Invalid params
143
180
181
+ 0 > id - Expected a string matching \`/^0x[0-9a-f]+$/\` but received "123"
144
182
0 > from - Expected a string matching \`/^0x[0-9a-fA-F]{40}$/\` but received "123"
145
183
0 > chainId - Expected a string matching \`/^0x[0-9a-f]+$/\` but received "123"
146
184
0 > calls > 0 > to - Expected a string matching \`/^0x[0-9a-fA-F]{40}$/\` but received "123"
0 commit comments