ox 1.0.0-beta.1 → 1.0.0-beta.2
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/dist/core/RpcSchema.d.ts +5 -3
- package/dist/core/RpcSchema.d.ts.map +1 -1
- package/dist/zod/RpcSchema.d.ts +91 -29
- package/dist/zod/RpcSchema.d.ts.map +1 -1
- package/dist/zod/RpcSchema.js +75 -12
- package/dist/zod/RpcSchema.js.map +1 -1
- package/dist/zod/internal/rpcSchemas/Eth.d.ts +12 -12
- package/dist/zod/internal/rpcSchemas/Eth.d.ts.map +1 -1
- package/dist/zod/internal/rpcSchemas/Eth.js +14 -12
- package/dist/zod/internal/rpcSchemas/Eth.js.map +1 -1
- package/package.json +1 -1
- package/src/core/RpcSchema.ts +5 -3
- package/src/version.ts +1 -1
- package/src/zod/RpcSchema.ts +108 -17
- package/src/zod/_test/RpcSchema.test-d.ts +27 -9
- package/src/zod/_test/RpcSchema.test.ts +86 -22
- package/src/zod/internal/rpcSchemas/Eth.ts +14 -12
- package/src/zod/tempo/_test/RpcSchemaTempo.test.ts +1 -1
|
@@ -6,10 +6,10 @@ const address = '0x0000000000000000000000000000000000000000'
|
|
|
6
6
|
const hash = `0x${'11'.repeat(32)}` as const
|
|
7
7
|
const topic = `0x${'33'.repeat(32)}` as const
|
|
8
8
|
|
|
9
|
-
describe('
|
|
9
|
+
describe('decodeParams', () => {
|
|
10
10
|
test('decodes params (block number / tag coercion)', () => {
|
|
11
11
|
expect(
|
|
12
|
-
z_RpcSchema.
|
|
12
|
+
z_RpcSchema.decodeParams(z_RpcSchema.Eth, 'eth_getBlockByNumber', [
|
|
13
13
|
'0x1b4',
|
|
14
14
|
true,
|
|
15
15
|
]),
|
|
@@ -20,7 +20,7 @@ describe('parseParams', () => {
|
|
|
20
20
|
]
|
|
21
21
|
`)
|
|
22
22
|
expect(
|
|
23
|
-
z_RpcSchema.
|
|
23
|
+
z_RpcSchema.decodeParams(z_RpcSchema.Eth, 'eth_getBlockByNumber', [
|
|
24
24
|
'latest',
|
|
25
25
|
false,
|
|
26
26
|
]),
|
|
@@ -34,7 +34,7 @@ describe('parseParams', () => {
|
|
|
34
34
|
|
|
35
35
|
test('decodes wallet params', () => {
|
|
36
36
|
expect(
|
|
37
|
-
z_RpcSchema.
|
|
37
|
+
z_RpcSchema.decodeParams(
|
|
38
38
|
z_RpcSchema.Wallet,
|
|
39
39
|
'wallet_switchEthereumChain',
|
|
40
40
|
[{ chainId: '0x1' }],
|
|
@@ -49,13 +49,27 @@ describe('parseParams', () => {
|
|
|
49
49
|
})
|
|
50
50
|
})
|
|
51
51
|
|
|
52
|
-
describe('
|
|
52
|
+
describe('decodeReturns', () => {
|
|
53
53
|
test('decodes scalar return types', () => {
|
|
54
54
|
expect(
|
|
55
|
-
z_RpcSchema.
|
|
56
|
-
).toMatchInlineSnapshot(`
|
|
57
|
-
expect(
|
|
58
|
-
.
|
|
55
|
+
z_RpcSchema.decodeReturns(z_RpcSchema.Eth, 'eth_blockNumber', '0x1b4'),
|
|
56
|
+
).toMatchInlineSnapshot(`436n`)
|
|
57
|
+
expect(
|
|
58
|
+
z_RpcSchema.decodeReturns(z_RpcSchema.Eth, 'eth_chainId', '0x1'),
|
|
59
|
+
).toMatchInlineSnapshot(`1`)
|
|
60
|
+
expect(
|
|
61
|
+
z_RpcSchema.decodeReturns(
|
|
62
|
+
z_RpcSchema.Eth,
|
|
63
|
+
'eth_getTransactionCount',
|
|
64
|
+
'0x2',
|
|
65
|
+
),
|
|
66
|
+
).toMatchInlineSnapshot(`2`)
|
|
67
|
+
expect(
|
|
68
|
+
z_RpcSchema.decodeReturns(z_RpcSchema.Eth, 'eth_call', '0x1234'),
|
|
69
|
+
).toMatchInlineSnapshot(`"0x1234"`)
|
|
70
|
+
expect(
|
|
71
|
+
z_RpcSchema.decodeReturns(z_RpcSchema.Eth, 'eth_accounts', [address]),
|
|
72
|
+
).toMatchInlineSnapshot(`
|
|
59
73
|
[
|
|
60
74
|
"0x0000000000000000000000000000000000000000",
|
|
61
75
|
]
|
|
@@ -64,7 +78,7 @@ describe('parseReturns', () => {
|
|
|
64
78
|
|
|
65
79
|
test('decodes fee history return type', () => {
|
|
66
80
|
expect(
|
|
67
|
-
z_RpcSchema.
|
|
81
|
+
z_RpcSchema.decodeReturns(z_RpcSchema.Eth, 'eth_feeHistory', {
|
|
68
82
|
baseFeePerGas: ['0x1', '0x2'],
|
|
69
83
|
gasUsedRatio: [0.5],
|
|
70
84
|
oldestBlock: '0x10',
|
|
@@ -91,7 +105,7 @@ describe('parseReturns', () => {
|
|
|
91
105
|
|
|
92
106
|
test('decodes log return types', () => {
|
|
93
107
|
expect(
|
|
94
|
-
z_RpcSchema.
|
|
108
|
+
z_RpcSchema.decodeReturns(z_RpcSchema.Eth, 'eth_getLogs', [
|
|
95
109
|
{
|
|
96
110
|
address,
|
|
97
111
|
blockHash: hash,
|
|
@@ -125,7 +139,7 @@ describe('parseReturns', () => {
|
|
|
125
139
|
|
|
126
140
|
test('decodes nullable return types', () => {
|
|
127
141
|
expect(
|
|
128
|
-
z_RpcSchema.
|
|
142
|
+
z_RpcSchema.decodeReturns(
|
|
129
143
|
z_RpcSchema.Eth,
|
|
130
144
|
'eth_getTransactionReceipt',
|
|
131
145
|
null,
|
|
@@ -134,6 +148,55 @@ describe('parseReturns', () => {
|
|
|
134
148
|
})
|
|
135
149
|
})
|
|
136
150
|
|
|
151
|
+
describe('encodeParams', () => {
|
|
152
|
+
test('encodes params (native → wire)', () => {
|
|
153
|
+
expect(
|
|
154
|
+
z_RpcSchema.encodeParams(z_RpcSchema.Eth, 'eth_getBlockByNumber', [
|
|
155
|
+
436n,
|
|
156
|
+
true,
|
|
157
|
+
]),
|
|
158
|
+
).toMatchInlineSnapshot(`
|
|
159
|
+
[
|
|
160
|
+
"0x1b4",
|
|
161
|
+
true,
|
|
162
|
+
]
|
|
163
|
+
`)
|
|
164
|
+
})
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
describe('encodeReturns', () => {
|
|
168
|
+
test('encodes scalar return types (native → wire)', () => {
|
|
169
|
+
expect(
|
|
170
|
+
z_RpcSchema.encodeReturns(z_RpcSchema.Eth, 'eth_blockNumber', 436n),
|
|
171
|
+
).toMatchInlineSnapshot(`"0x1b4"`)
|
|
172
|
+
expect(
|
|
173
|
+
z_RpcSchema.encodeReturns(z_RpcSchema.Eth, 'eth_chainId', 1),
|
|
174
|
+
).toMatchInlineSnapshot(`"0x1"`)
|
|
175
|
+
expect(
|
|
176
|
+
z_RpcSchema.encodeReturns(z_RpcSchema.Eth, 'eth_call', '0x1234'),
|
|
177
|
+
).toMatchInlineSnapshot(`"0x1234"`)
|
|
178
|
+
})
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
describe('encodeRequest', () => {
|
|
182
|
+
test('encodes a request (native → wire)', () => {
|
|
183
|
+
expect(
|
|
184
|
+
z_RpcSchema.encodeRequest(z_RpcSchema.Eth, {
|
|
185
|
+
method: 'eth_getBlockByNumber',
|
|
186
|
+
params: [436n, true],
|
|
187
|
+
}),
|
|
188
|
+
).toMatchInlineSnapshot(`
|
|
189
|
+
{
|
|
190
|
+
"method": "eth_getBlockByNumber",
|
|
191
|
+
"params": [
|
|
192
|
+
"0x1b4",
|
|
193
|
+
true,
|
|
194
|
+
],
|
|
195
|
+
}
|
|
196
|
+
`)
|
|
197
|
+
})
|
|
198
|
+
})
|
|
199
|
+
|
|
137
200
|
describe('parseItem', () => {
|
|
138
201
|
test('looks up a method schema', () => {
|
|
139
202
|
expect(
|
|
@@ -150,10 +213,10 @@ describe('parseItem', () => {
|
|
|
150
213
|
})
|
|
151
214
|
})
|
|
152
215
|
|
|
153
|
-
describe('
|
|
216
|
+
describe('decodeRequest', () => {
|
|
154
217
|
test('dispatches by method', () => {
|
|
155
218
|
expect(
|
|
156
|
-
z_RpcSchema.
|
|
219
|
+
z_RpcSchema.decodeRequest(z_RpcSchema.Eth, {
|
|
157
220
|
method: 'eth_getBlockByNumber',
|
|
158
221
|
params: ['0x1', true],
|
|
159
222
|
}),
|
|
@@ -168,7 +231,7 @@ describe('parseRequest', () => {
|
|
|
168
231
|
`)
|
|
169
232
|
})
|
|
170
233
|
|
|
171
|
-
test('parse is an alias of
|
|
234
|
+
test('parse is an alias of decodeRequest', () => {
|
|
172
235
|
expect(
|
|
173
236
|
z_RpcSchema.parse(z_RpcSchema.Wallet, {
|
|
174
237
|
method: 'wallet_switchEthereumChain',
|
|
@@ -188,7 +251,7 @@ describe('parseRequest', () => {
|
|
|
188
251
|
|
|
189
252
|
test('Default dispatches across eth_ and wallet_ methods', () => {
|
|
190
253
|
expect(
|
|
191
|
-
z_RpcSchema.
|
|
254
|
+
z_RpcSchema.decodeRequest(z_RpcSchema.Default, {
|
|
192
255
|
method: 'eth_getBlockByNumber',
|
|
193
256
|
params: ['0x1', true],
|
|
194
257
|
}),
|
|
@@ -202,7 +265,7 @@ describe('parseRequest', () => {
|
|
|
202
265
|
}
|
|
203
266
|
`)
|
|
204
267
|
expect(
|
|
205
|
-
z_RpcSchema.
|
|
268
|
+
z_RpcSchema.decodeRequest(z_RpcSchema.Default, {
|
|
206
269
|
method: 'wallet_switchEthereumChain',
|
|
207
270
|
params: [{ chainId: '0x1' }],
|
|
208
271
|
}),
|
|
@@ -226,7 +289,7 @@ describe('parseRequest', () => {
|
|
|
226
289
|
).success,
|
|
227
290
|
).toMatchInlineSnapshot(`false`)
|
|
228
291
|
expect(() =>
|
|
229
|
-
z_RpcSchema.
|
|
292
|
+
z_RpcSchema.decodeRequest(z_RpcSchema.Eth, {
|
|
230
293
|
method: 'eth_unknownMethod',
|
|
231
294
|
params: [],
|
|
232
295
|
} as never),
|
|
@@ -254,17 +317,18 @@ describe('from', () => {
|
|
|
254
317
|
})
|
|
255
318
|
|
|
256
319
|
expect(schema.abe_foo.method).toMatchInlineSnapshot(`"abe_foo"`)
|
|
257
|
-
expect(z_RpcSchema.
|
|
320
|
+
expect(z_RpcSchema.decodeParams(schema, 'abe_foo', [1]))
|
|
258
321
|
.toMatchInlineSnapshot(`
|
|
259
322
|
[
|
|
260
323
|
1,
|
|
261
324
|
]
|
|
262
325
|
`)
|
|
263
326
|
expect(
|
|
264
|
-
z_RpcSchema.
|
|
327
|
+
z_RpcSchema.decodeReturns(schema, 'abe_foo', 'hello'),
|
|
265
328
|
).toMatchInlineSnapshot(`"hello"`)
|
|
266
|
-
expect(
|
|
267
|
-
.
|
|
329
|
+
expect(
|
|
330
|
+
z_RpcSchema.decodeRequest(schema, { method: 'abe_foo', params: [1] }),
|
|
331
|
+
).toMatchInlineSnapshot(`
|
|
268
332
|
{
|
|
269
333
|
"method": "abe_foo",
|
|
270
334
|
"params": [
|
|
@@ -7,10 +7,12 @@ import * as z_Fee from '../../Fee.js'
|
|
|
7
7
|
import * as z_Filter from '../../Filter.js'
|
|
8
8
|
import * as z_Hex from '../../Hex.js'
|
|
9
9
|
import * as z_Log from '../../Log.js'
|
|
10
|
+
import * as z_Number from '../../Number.js'
|
|
10
11
|
import * as z_StateOverrides from '../../StateOverrides.js'
|
|
11
12
|
import * as z_Transaction from '../../Transaction.js'
|
|
12
13
|
import * as z_TransactionReceipt from '../../TransactionReceipt.js'
|
|
13
14
|
import * as z_TransactionRequest from '../../TransactionRequest.js'
|
|
15
|
+
import * as z_Uint from '../../Uint.js'
|
|
14
16
|
import * as z from 'zod/mini'
|
|
15
17
|
import { from } from './from.js'
|
|
16
18
|
|
|
@@ -60,13 +62,13 @@ export const eth_accounts = from({
|
|
|
60
62
|
export const eth_blobBaseFee = from({
|
|
61
63
|
method: 'eth_blobBaseFee',
|
|
62
64
|
params: NoParams,
|
|
63
|
-
returns:
|
|
65
|
+
returns: z_Uint.Uint,
|
|
64
66
|
})
|
|
65
67
|
|
|
66
68
|
export const eth_blockNumber = from({
|
|
67
69
|
method: 'eth_blockNumber',
|
|
68
70
|
params: NoParams,
|
|
69
|
-
returns:
|
|
71
|
+
returns: z_Uint.Uint,
|
|
70
72
|
})
|
|
71
73
|
|
|
72
74
|
export const eth_call = from({
|
|
@@ -78,7 +80,7 @@ export const eth_call = from({
|
|
|
78
80
|
export const eth_chainId = from({
|
|
79
81
|
method: 'eth_chainId',
|
|
80
82
|
params: NoParams,
|
|
81
|
-
returns:
|
|
83
|
+
returns: z_Number.Number,
|
|
82
84
|
})
|
|
83
85
|
|
|
84
86
|
export const eth_coinbase = from({
|
|
@@ -90,7 +92,7 @@ export const eth_coinbase = from({
|
|
|
90
92
|
export const eth_estimateGas = from({
|
|
91
93
|
method: 'eth_estimateGas',
|
|
92
94
|
params: Call,
|
|
93
|
-
returns:
|
|
95
|
+
returns: z_Uint.Uint,
|
|
94
96
|
})
|
|
95
97
|
|
|
96
98
|
export const eth_feeHistory = from({
|
|
@@ -106,13 +108,13 @@ export const eth_feeHistory = from({
|
|
|
106
108
|
export const eth_gasPrice = from({
|
|
107
109
|
method: 'eth_gasPrice',
|
|
108
110
|
params: NoParams,
|
|
109
|
-
returns:
|
|
111
|
+
returns: z_Uint.Uint,
|
|
110
112
|
})
|
|
111
113
|
|
|
112
114
|
export const eth_getBalance = from({
|
|
113
115
|
method: 'eth_getBalance',
|
|
114
116
|
params: z.tuple([z_Address.Address, BlockNumberOrTagOrIdentifier]),
|
|
115
|
-
returns:
|
|
117
|
+
returns: z_Uint.Uint,
|
|
116
118
|
})
|
|
117
119
|
|
|
118
120
|
export const eth_getBlockByHash = from({
|
|
@@ -130,13 +132,13 @@ export const eth_getBlockByNumber = from({
|
|
|
130
132
|
export const eth_getBlockTransactionCountByHash = from({
|
|
131
133
|
method: 'eth_getBlockTransactionCountByHash',
|
|
132
134
|
params: z.tuple([z_Hex.Hex]),
|
|
133
|
-
returns:
|
|
135
|
+
returns: z_Number.Number,
|
|
134
136
|
})
|
|
135
137
|
|
|
136
138
|
export const eth_getBlockTransactionCountByNumber = from({
|
|
137
139
|
method: 'eth_getBlockTransactionCountByNumber',
|
|
138
140
|
params: z.tuple([BlockNumberOrTag]),
|
|
139
|
-
returns:
|
|
141
|
+
returns: z_Number.Number,
|
|
140
142
|
})
|
|
141
143
|
|
|
142
144
|
export const eth_getCode = from({
|
|
@@ -200,7 +202,7 @@ export const eth_getTransactionByHash = from({
|
|
|
200
202
|
export const eth_getTransactionCount = from({
|
|
201
203
|
method: 'eth_getTransactionCount',
|
|
202
204
|
params: z.tuple([z_Address.Address, BlockNumberOrTagOrIdentifier]),
|
|
203
|
-
returns:
|
|
205
|
+
returns: z_Number.Number,
|
|
204
206
|
})
|
|
205
207
|
|
|
206
208
|
export const eth_getTransactionReceipt = from({
|
|
@@ -212,19 +214,19 @@ export const eth_getTransactionReceipt = from({
|
|
|
212
214
|
export const eth_getUncleCountByBlockHash = from({
|
|
213
215
|
method: 'eth_getUncleCountByBlockHash',
|
|
214
216
|
params: z.tuple([z_Hex.Hex]),
|
|
215
|
-
returns:
|
|
217
|
+
returns: z_Number.Number,
|
|
216
218
|
})
|
|
217
219
|
|
|
218
220
|
export const eth_getUncleCountByBlockNumber = from({
|
|
219
221
|
method: 'eth_getUncleCountByBlockNumber',
|
|
220
222
|
params: z.tuple([BlockNumberOrTag]),
|
|
221
|
-
returns:
|
|
223
|
+
returns: z_Number.Number,
|
|
222
224
|
})
|
|
223
225
|
|
|
224
226
|
export const eth_maxPriorityFeePerGas = from({
|
|
225
227
|
method: 'eth_maxPriorityFeePerGas',
|
|
226
228
|
params: NoParams,
|
|
227
|
-
returns:
|
|
229
|
+
returns: z_Uint.Uint,
|
|
228
230
|
})
|
|
229
231
|
|
|
230
232
|
export const eth_newBlockFilter = from({
|