1
- import type { JsonRpcRequest , PendingJsonRpcResponse } from '@metamask/utils' ;
1
+ import type {
2
+ Hex ,
3
+ JsonRpcRequest ,
4
+ PendingJsonRpcResponse ,
5
+ } from '@metamask/utils' ;
2
6
import { klona } from 'klona' ;
3
7
4
8
import type {
9
+ GetCallsStatusHook ,
5
10
GetCallsStatusParams ,
6
11
GetCallsStatusResult ,
7
- GetTransactionReceiptsByBatchIdHook ,
8
12
} from './wallet-get-calls-status' ;
9
13
import { walletGetCallsStatus } from './wallet-get-calls-status' ;
10
14
11
- const ID_MOCK = '1234-5678 ' ;
15
+ const ID_MOCK = '0x12345678 ' ;
12
16
13
17
const RECEIPT_MOCK = {
14
18
logs : [
@@ -30,15 +34,23 @@ const REQUEST_MOCK = {
30
34
params : [ ID_MOCK ] ,
31
35
} as unknown as JsonRpcRequest < GetCallsStatusParams > ;
32
36
37
+ const RESULT_MOCK = {
38
+ version : '1.0' ,
39
+ id : ID_MOCK ,
40
+ chainId : '0x1' ,
41
+ status : 1 ,
42
+ receipts : [ RECEIPT_MOCK , RECEIPT_MOCK ] ,
43
+ } ;
44
+
33
45
describe ( 'wallet_getCallsStatus' , ( ) => {
34
46
let request : JsonRpcRequest < GetCallsStatusParams > ;
35
47
let params : GetCallsStatusParams ;
36
48
let response : PendingJsonRpcResponse < GetCallsStatusResult > ;
37
- let getTransactionReceiptsByBatchIdMock : jest . MockedFunction < GetTransactionReceiptsByBatchIdHook > ;
49
+ let getCallsStatusMock : jest . MockedFunction < GetCallsStatusHook > ;
38
50
39
51
async function callMethod ( ) {
40
52
return walletGetCallsStatus ( request , response , {
41
- getTransactionReceiptsByBatchId : getTransactionReceiptsByBatchIdMock ,
53
+ getCallsStatus : getCallsStatusMock ,
42
54
} ) ;
43
55
}
44
56
@@ -49,48 +61,17 @@ describe('wallet_getCallsStatus', () => {
49
61
params = request . params as GetCallsStatusParams ;
50
62
response = { } as PendingJsonRpcResponse < GetCallsStatusResult > ;
51
63
52
- getTransactionReceiptsByBatchIdMock = jest
53
- . fn ( )
54
- . mockResolvedValue ( [ RECEIPT_MOCK , RECEIPT_MOCK ] ) ;
64
+ getCallsStatusMock = jest . fn ( ) . mockResolvedValue ( RESULT_MOCK ) ;
55
65
} ) ;
56
66
57
67
it ( 'calls hook' , async ( ) => {
58
68
await callMethod ( ) ;
59
- expect ( getTransactionReceiptsByBatchIdMock ) . toHaveBeenCalledWith (
60
- params [ 0 ] ,
61
- request ,
62
- ) ;
63
- } ) ;
64
-
65
- it ( 'returns confirmed status if all receipts available' , async ( ) => {
66
- await callMethod ( ) ;
67
- expect ( response . result ?. status ) . toBe ( 'CONFIRMED' ) ;
68
- } ) ;
69
-
70
- it ( 'returns pending status if missing receipts' , async ( ) => {
71
- getTransactionReceiptsByBatchIdMock = jest
72
- . fn ( )
73
- . mockResolvedValue ( [ RECEIPT_MOCK , undefined ] ) ;
74
-
75
- await callMethod ( ) ;
76
- expect ( response . result ?. status ) . toBe ( 'PENDING' ) ;
77
- expect ( response . result ?. receipts ) . toBeNull ( ) ;
78
- } ) ;
79
-
80
- it ( 'returns receipts' , async ( ) => {
81
- await callMethod ( ) ;
82
-
83
- expect ( response . result ?. receipts ) . toStrictEqual ( [
84
- RECEIPT_MOCK ,
85
- RECEIPT_MOCK ,
86
- ] ) ;
69
+ expect ( getCallsStatusMock ) . toHaveBeenCalledWith ( params [ 0 ] , request ) ;
87
70
} ) ;
88
71
89
- it ( 'returns null if no receipts' , async ( ) => {
90
- getTransactionReceiptsByBatchIdMock = jest . fn ( ) . mockResolvedValue ( [ ] ) ;
91
-
72
+ it ( 'returns result from hook' , async ( ) => {
92
73
await callMethod ( ) ;
93
- expect ( response . result ) . toBeNull ( ) ;
74
+ expect ( response . result ) . toStrictEqual ( RESULT_MOCK ) ;
94
75
} ) ;
95
76
96
77
it ( 'throws if no hook' , async ( ) => {
@@ -119,27 +100,23 @@ describe('wallet_getCallsStatus', () => {
119
100
` ) ;
120
101
} ) ;
121
102
122
- it ( 'throws if empty ' , async ( ) => {
123
- params [ 0 ] = '' ;
103
+ it ( 'throws if address is not hex ' , async ( ) => {
104
+ params [ 0 ] = '123' as Hex ;
124
105
125
106
await expect ( callMethod ( ) ) . rejects . toMatchInlineSnapshot ( `
126
107
[Error: Invalid params
127
108
128
- 0 - Expected a nonempty string but received an empty one ]
109
+ 0 - Expected a string matching \`/^0x[0-9a-f]+$/\` but received "123" ]
129
110
` ) ;
130
111
} ) ;
131
112
132
- it ( 'removes excess properties from receipts' , async ( ) => {
133
- getTransactionReceiptsByBatchIdMock . mockResolvedValue ( [
134
- {
135
- ...RECEIPT_MOCK ,
136
- extra : 'value1' ,
137
- logs : [ { ...RECEIPT_MOCK . logs [ 0 ] , extra2 : 'value2' } ] ,
138
- } as never ,
139
- ] ) ;
113
+ it ( 'throws if address is empty' , async ( ) => {
114
+ params [ 0 ] = '' as never ;
140
115
141
- await callMethod ( ) ;
116
+ await expect ( callMethod ( ) ) . rejects . toMatchInlineSnapshot ( `
117
+ [Error: Invalid params
142
118
143
- expect ( response . result ?. receipts ) . toStrictEqual ( [ RECEIPT_MOCK ] ) ;
119
+ 0 - Expected a string matching \`/^0x[0-9a-f]+$/\` but received ""]
120
+ ` ) ;
144
121
} ) ;
145
122
} ) ;
0 commit comments