ox 1.8.16 → 1.8.19
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 +70 -0
- package/dist/core/AbiError.d.ts +3 -3
- package/dist/core/AbiError.js +2 -2
- package/dist/core/AbiEvent.d.ts +3 -3
- package/dist/core/AbiEvent.d.ts.map +1 -1
- package/dist/core/AbiEvent.js +29 -24
- package/dist/core/AbiEvent.js.map +1 -1
- package/dist/core/AbiItem.d.ts.map +1 -1
- package/dist/core/AbiItem.js +15 -5
- package/dist/core/AbiItem.js.map +1 -1
- package/dist/core/AbiParameters.d.ts +1 -1
- package/dist/core/AbiParameters.d.ts.map +1 -1
- package/dist/core/AbiParameters.js +8 -2
- package/dist/core/AbiParameters.js.map +1 -1
- package/dist/core/Authorization.d.ts.map +1 -1
- package/dist/core/Authorization.js +6 -3
- package/dist/core/Authorization.js.map +1 -1
- package/dist/core/Base58.d.ts.map +1 -1
- package/dist/core/Base58.js +16 -4
- package/dist/core/Base58.js.map +1 -1
- package/dist/core/BinaryStateTree.js +3 -1
- package/dist/core/BinaryStateTree.js.map +1 -1
- package/dist/core/Blobs.d.ts +4 -5
- package/dist/core/Blobs.d.ts.map +1 -1
- package/dist/core/Blobs.js +40 -45
- package/dist/core/Blobs.js.map +1 -1
- package/dist/core/Block.d.ts +2 -0
- package/dist/core/Block.d.ts.map +1 -1
- package/dist/core/Block.js +1 -0
- package/dist/core/Block.js.map +1 -1
- package/dist/core/BlockOverrides.d.ts +3 -2
- package/dist/core/BlockOverrides.d.ts.map +1 -1
- package/dist/core/BlockOverrides.js +4 -2
- package/dist/core/BlockOverrides.js.map +1 -1
- package/dist/core/Bytes.d.ts.map +1 -1
- package/dist/core/Bytes.js +10 -2
- package/dist/core/Bytes.js.map +1 -1
- package/dist/core/Cbor.d.ts +13 -6
- package/dist/core/Cbor.d.ts.map +1 -1
- package/dist/core/Cbor.js +31 -18
- package/dist/core/Cbor.js.map +1 -1
- package/dist/core/Ens.d.ts +1 -1
- package/dist/core/Ens.js +3 -3
- package/dist/core/Ens.js.map +1 -1
- package/dist/core/FrameReceipt.d.ts.map +1 -1
- package/dist/core/FrameReceipt.js +4 -1
- package/dist/core/FrameReceipt.js.map +1 -1
- package/dist/core/Hash.d.ts +1 -1
- package/dist/core/Hash.js +1 -1
- package/dist/core/Hex.d.ts.map +1 -1
- package/dist/core/Hex.js +34 -31
- package/dist/core/Hex.js.map +1 -1
- package/dist/core/Rlp.d.ts +1 -1
- package/dist/core/Rlp.d.ts.map +1 -1
- package/dist/core/Rlp.js +107 -0
- package/dist/core/Rlp.js.map +1 -1
- package/dist/core/RpcTransport.d.ts.map +1 -1
- package/dist/core/RpcTransport.js +3 -1
- package/dist/core/RpcTransport.js.map +1 -1
- package/dist/core/Siwe.d.ts +1 -0
- package/dist/core/Siwe.d.ts.map +1 -1
- package/dist/core/Siwe.js +15 -8
- package/dist/core/Siwe.js.map +1 -1
- package/dist/core/Transaction.d.ts.map +1 -1
- package/dist/core/Transaction.js +9 -3
- package/dist/core/Transaction.js.map +1 -1
- package/dist/core/TransactionReceipt.d.ts.map +1 -1
- package/dist/core/TransactionReceipt.js +8 -2
- package/dist/core/TransactionReceipt.js.map +1 -1
- package/dist/core/TypedData.d.ts +2 -2
- package/dist/core/TypedData.d.ts.map +1 -1
- package/dist/core/TypedData.js +16 -4
- package/dist/core/TypedData.js.map +1 -1
- package/dist/core/internal/abiParameters.d.ts +3 -3
- package/dist/core/internal/abiParameters.d.ts.map +1 -1
- package/dist/core/internal/abiParameters.js +93 -68
- package/dist/core/internal/abiParameters.js.map +1 -1
- package/dist/core/internal/base58.d.ts.map +1 -1
- package/dist/core/internal/base58.js +9 -3
- package/dist/core/internal/base58.js.map +1 -1
- package/dist/core/internal/caches.d.ts +6 -0
- package/dist/core/internal/caches.d.ts.map +1 -1
- package/dist/core/internal/caches.js +3 -1
- package/dist/core/internal/caches.js.map +1 -1
- package/dist/core/internal/codec/hex.d.ts +13 -0
- package/dist/core/internal/codec/hex.d.ts.map +1 -1
- package/dist/core/internal/codec/hex.js +25 -2
- package/dist/core/internal/codec/hex.js.map +1 -1
- package/dist/core/internal/codec/int.d.ts.map +1 -1
- package/dist/core/internal/codec/int.js +48 -32
- package/dist/core/internal/codec/int.js.map +1 -1
- package/dist/core/internal/cursor.d.ts +11 -4
- package/dist/core/internal/cursor.d.ts.map +1 -1
- package/dist/core/internal/cursor.js +39 -15
- package/dist/core/internal/cursor.js.map +1 -1
- package/dist/core/internal/lru.d.ts +11 -12
- package/dist/core/internal/lru.d.ts.map +1 -1
- package/dist/core/internal/lru.js +22 -32
- package/dist/core/internal/lru.js.map +1 -1
- package/dist/core/internal/promise.d.ts.map +1 -1
- package/dist/core/internal/promise.js +13 -7
- package/dist/core/internal/promise.js.map +1 -1
- package/dist/erc6492/SignatureErc6492.d.ts +1 -1
- package/dist/erc6492/SignatureErc6492.d.ts.map +1 -1
- package/dist/erc6492/SignatureErc6492.js +1 -1
- package/dist/erc6492/SignatureErc6492.js.map +1 -1
- package/dist/tempo/SignatureEnvelope.d.ts.map +1 -1
- package/dist/tempo/SignatureEnvelope.js +7 -41
- package/dist/tempo/SignatureEnvelope.js.map +1 -1
- package/dist/tempo/TransactionReceipt.d.ts.map +1 -1
- package/dist/tempo/TransactionReceipt.js +4 -1
- package/dist/tempo/TransactionReceipt.js.map +1 -1
- package/dist/tempo/ZoneId.d.ts +3 -1
- package/dist/tempo/ZoneId.d.ts.map +1 -1
- package/dist/tempo/ZoneId.js +7 -1
- package/dist/tempo/ZoneId.js.map +1 -1
- package/dist/tempo/internal/virtualMasterPool.d.ts.map +1 -1
- package/dist/tempo/internal/virtualMasterPool.js +17 -6
- package/dist/tempo/internal/virtualMasterPool.js.map +1 -1
- package/dist/tempo/internal/webauthnData.d.ts +23 -0
- package/dist/tempo/internal/webauthnData.d.ts.map +1 -0
- package/dist/tempo/internal/webauthnData.js +75 -0
- package/dist/tempo/internal/webauthnData.js.map +1 -0
- package/dist/zod/Authorization.d.ts +14 -14
- package/dist/zod/Authorization.d.ts.map +1 -1
- package/dist/zod/Authorization.js +9 -2
- package/dist/zod/Authorization.js.map +1 -1
- package/dist/zod/Block.d.ts +12 -6
- package/dist/zod/Block.d.ts.map +1 -1
- package/dist/zod/Block.js +1 -0
- package/dist/zod/Block.js.map +1 -1
- package/dist/zod/BlockOverrides.d.ts.map +1 -1
- package/dist/zod/BlockOverrides.js +15 -4
- package/dist/zod/BlockOverrides.js.map +1 -1
- package/dist/zod/RpcSchema.d.ts +58 -46
- package/dist/zod/RpcSchema.d.ts.map +1 -1
- package/dist/zod/Signature.d.ts.map +1 -1
- package/dist/zod/Signature.js +2 -1
- package/dist/zod/Signature.js.map +1 -1
- package/dist/zod/Transaction.d.ts +12 -12
- package/dist/zod/TransactionEnvelope.d.ts +8 -8
- package/dist/zod/TransactionRequest.d.ts +4 -4
- package/dist/zod/TxEnvelopeEip7702.d.ts +8 -8
- package/dist/zod/TypedData.d.ts +4 -4
- package/dist/zod/internal/rpcSchemas/Eth.d.ts +58 -46
- package/dist/zod/internal/rpcSchemas/Eth.d.ts.map +1 -1
- package/dist/zod/internal/rpcSchemas/Wallet.d.ts +4 -4
- package/dist/zod/tempo/RpcSchemaTempo.d.ts +16 -8
- package/dist/zod/tempo/RpcSchemaTempo.d.ts.map +1 -1
- package/dist/zod/tempo/SignatureEnvelope.d.ts.map +1 -1
- package/dist/zod/tempo/SignatureEnvelope.js +5 -15
- package/dist/zod/tempo/SignatureEnvelope.js.map +1 -1
- package/dist/zod/tempo/Transaction.d.ts +6 -6
- package/package.json +2 -2
- package/src/core/AbiError.ts +3 -3
- package/src/core/AbiEvent.bench.ts +45 -0
- package/src/core/AbiEvent.ts +32 -25
- package/src/core/AbiFunction.bench.ts +16 -0
- package/src/core/AbiItem.ts +13 -4
- package/src/core/AbiParameters.bench.ts +33 -0
- package/src/core/AbiParameters.ts +8 -1
- package/src/core/Authorization.ts +6 -3
- package/src/core/Base58.bench.ts +28 -0
- package/src/core/Base58.ts +15 -4
- package/src/core/BinaryStateTree.ts +4 -1
- package/src/core/Blobs.bench.ts +40 -0
- package/src/core/Blobs.ts +49 -57
- package/src/core/Block.ts +3 -0
- package/src/core/BlockOverrides.ts +7 -3
- package/src/core/Bytes.bench.ts +34 -0
- package/src/core/Bytes.ts +10 -2
- package/src/core/Cbor.ts +36 -14
- package/src/core/Ens.ts +3 -3
- package/src/core/FrameReceipt.ts +4 -1
- package/src/core/Hash.ts +1 -1
- package/src/core/Hex.bench.ts +17 -0
- package/src/core/Hex.ts +29 -32
- package/src/core/Rlp.ts +139 -1
- package/src/core/Rlp_tx.bench.ts +55 -0
- package/src/core/RpcTransport.ts +3 -1
- package/src/core/Siwe.ts +18 -8
- package/src/core/Transaction.ts +9 -3
- package/src/core/TransactionReceipt.ts +8 -2
- package/src/core/TypedData.bench.ts +50 -0
- package/src/core/TypedData.ts +16 -4
- package/src/core/_test/AbiEvent.test.ts +83 -0
- package/src/core/_test/AbiFunction.test.ts +7 -6
- package/src/core/_test/AbiParameters.decode.test.ts +34 -1
- package/src/core/_test/AbiParameters.encode.test.ts +10 -0
- package/src/core/_test/AbiParameters.test.ts +15 -0
- package/src/core/_test/Authorization.test.ts +36 -0
- package/src/core/_test/BinaryStateTree.test.ts +35 -0
- package/src/core/_test/Block.test.ts +54 -0
- package/src/core/_test/BlockOverrides.test.ts +14 -1
- package/src/core/_test/Bytes.test.ts +33 -0
- package/src/core/_test/Caches.test.ts +20 -1
- package/src/core/_test/Cbor.test.ts +26 -0
- package/src/core/_test/FrameReceipt.test.ts +13 -0
- package/src/core/_test/Rlp.fuzz.ts +55 -1
- package/src/core/_test/Rlp.test.ts +64 -0
- package/src/core/_test/RpcTransport.test.ts +15 -2
- package/src/core/_test/Siwe.test.ts +126 -1
- package/src/core/_test/Transaction.test.ts +47 -2
- package/src/core/_test/TransactionEnvelopeEip7702.test.ts +2 -2
- package/src/core/_test/TransactionReceipt.test.ts +41 -0
- package/src/core/_test/TypedData.test.ts +19 -0
- package/src/core/_test/internal/cursor.test.ts +42 -6
- package/src/core/internal/abiParameters.ts +117 -80
- package/src/core/internal/base58.ts +9 -3
- package/src/core/internal/caches.ts +3 -1
- package/src/core/internal/codec/hex.ts +27 -2
- package/src/core/internal/codec/int.ts +45 -32
- package/src/core/internal/cursor.ts +52 -23
- package/src/core/internal/lru.ts +21 -35
- package/src/core/internal/promise.ts +11 -5
- package/src/erc4337/_test/UserOperation.test.ts +2 -2
- package/src/erc6492/SignatureErc6492.ts +1 -1
- package/src/erc6492/_test/SignatureErc6492.test.ts +48 -1
- package/src/tempo/SignatureEnvelope.test.ts +89 -1
- package/src/tempo/SignatureEnvelope.ts +7 -43
- package/src/tempo/TransactionReceipt.test.ts +8 -0
- package/src/tempo/TransactionReceipt.ts +4 -1
- package/src/tempo/VirtualMaster.bench.ts +7 -0
- package/src/tempo/ZoneId.test.ts +11 -0
- package/src/tempo/ZoneId.ts +7 -1
- package/src/tempo/internal/virtualMasterPool.ts +20 -6
- package/src/tempo/internal/webauthnData.ts +84 -0
- package/src/version.ts +1 -1
- package/src/zod/Authorization.ts +10 -2
- package/src/zod/Block.ts +1 -0
- package/src/zod/BlockOverrides.ts +26 -7
- package/src/zod/Signature.ts +2 -1
- package/src/zod/_test/Authorization.test.ts +26 -0
- package/src/zod/_test/Block.test-d.ts +6 -0
- package/src/zod/_test/Block.test.ts +5 -0
- package/src/zod/_test/BlockOverrides.test.ts +36 -1
- package/src/zod/_test/Signature.test.ts +12 -0
- package/src/zod/tempo/SignatureEnvelope.ts +7 -16
- package/src/zod/tempo/_test/SignatureEnvelope.test.ts +37 -1
- package/src/core/_test/internal/lru.test.ts +0 -38
- package/src/core/_test/internal/uid.test.ts +0 -7
- package/src/core/internal/uid.ts +0 -15
|
@@ -243,6 +243,21 @@ describe('encodePacked', () => {
|
|
|
243
243
|
)
|
|
244
244
|
})
|
|
245
245
|
|
|
246
|
+
test('error: odd-length bytes', () => {
|
|
247
|
+
expect(() => AbiParameters.encodePacked(['bytes', 'uint8'], ['0x123', 1]))
|
|
248
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
249
|
+
[Hex.InvalidLengthError: Hex value \`"0x123"\` is an odd length (3 nibbles).
|
|
250
|
+
|
|
251
|
+
It must be an even length.]
|
|
252
|
+
`)
|
|
253
|
+
expect(() => AbiParameters.encodePacked(['bytes[]'], [['0x0123', '0x123']]))
|
|
254
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
255
|
+
[Hex.InvalidLengthError: Hex value \`"0x123"\` is an odd length (3 nibbles).
|
|
256
|
+
|
|
257
|
+
It must be an even length.]
|
|
258
|
+
`)
|
|
259
|
+
})
|
|
260
|
+
|
|
246
261
|
test('error: unsupported type', () => {
|
|
247
262
|
expect(
|
|
248
263
|
// @ts-expect-error
|
|
@@ -681,6 +681,42 @@ describe('toRpc', () => {
|
|
|
681
681
|
`)
|
|
682
682
|
})
|
|
683
683
|
|
|
684
|
+
test('behavior: r and s with leading zeros', () => {
|
|
685
|
+
// Authorization from mainnet tx 0x701f5911c66298aee60c1fc2b56063de81efcde3186d0ad317d083098bbb7b51.
|
|
686
|
+
const rpc = {
|
|
687
|
+
address: '0x77021100bd87b7008e5e1989d0eb38555d0d0000',
|
|
688
|
+
chainId: '0x1',
|
|
689
|
+
nonce: '0x0',
|
|
690
|
+
r: '0x3baad1283c99f51e583a6a11c677c1a0bdad1b544345cfbcbd52b15d98a01ab8',
|
|
691
|
+
s: '0xcd04e7ee3547adf0fb459aed29f7cf11f015574dfdfaf6b154d9946579ce84',
|
|
692
|
+
yParity: '0x1',
|
|
693
|
+
} as const
|
|
694
|
+
const authorization = Authorization.fromRpc(rpc)
|
|
695
|
+
expect(authorization.s).toMatchInlineSnapshot(
|
|
696
|
+
`"0x00cd04e7ee3547adf0fb459aed29f7cf11f015574dfdfaf6b154d9946579ce84"`,
|
|
697
|
+
)
|
|
698
|
+
expect(Authorization.toRpc(authorization)).toEqual(rpc)
|
|
699
|
+
expect(
|
|
700
|
+
Authorization.toRpc({
|
|
701
|
+
address: '0x0000000000000000000000000000000000000000',
|
|
702
|
+
chainId: 1,
|
|
703
|
+
nonce: 0n,
|
|
704
|
+
r: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
705
|
+
s: '0x0aae27418bfc5e027aad1241dd50ba59a0bf138a1860283f8cc01adc319e505a',
|
|
706
|
+
yParity: 0,
|
|
707
|
+
}),
|
|
708
|
+
).toMatchInlineSnapshot(`
|
|
709
|
+
{
|
|
710
|
+
"address": "0x0000000000000000000000000000000000000000",
|
|
711
|
+
"chainId": "0x1",
|
|
712
|
+
"nonce": "0x0",
|
|
713
|
+
"r": "0x0",
|
|
714
|
+
"s": "0xaae27418bfc5e027aad1241dd50ba59a0bf138a1860283f8cc01adc319e505a",
|
|
715
|
+
"yParity": "0x0",
|
|
716
|
+
}
|
|
717
|
+
`)
|
|
718
|
+
})
|
|
719
|
+
|
|
684
720
|
test('error: yParity above 2**8 - 1', () => {
|
|
685
721
|
expect(() =>
|
|
686
722
|
Authorization.toRpc({
|
|
@@ -180,3 +180,38 @@ describe('insert', () => {
|
|
|
180
180
|
)
|
|
181
181
|
})
|
|
182
182
|
})
|
|
183
|
+
|
|
184
|
+
describe('merkelize', () => {
|
|
185
|
+
test('behavior: single zero value', () => {
|
|
186
|
+
const tree = BinaryStateTree.create()
|
|
187
|
+
BinaryStateTree.insert(
|
|
188
|
+
tree,
|
|
189
|
+
Bytes.fromHex(('0x' + '00'.repeat(32)) as Hex.Hex),
|
|
190
|
+
Bytes.fromHex(('0x' + '00'.repeat(32)) as Hex.Hex),
|
|
191
|
+
)
|
|
192
|
+
expect(
|
|
193
|
+
Hex.fromBytes(BinaryStateTree.merkelize(tree)),
|
|
194
|
+
).toMatchInlineSnapshot(
|
|
195
|
+
`"0x03ecb31f2982654be96b0ced7a59db5e056a1511f6a01b7a6dab182a79ab3a83"`,
|
|
196
|
+
)
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
test('behavior: zero value next to non-zero value', () => {
|
|
200
|
+
const tree = BinaryStateTree.create()
|
|
201
|
+
BinaryStateTree.insert(
|
|
202
|
+
tree,
|
|
203
|
+
Bytes.fromHex(('0x' + '00'.repeat(32)) as Hex.Hex),
|
|
204
|
+
Bytes.fromHex(('0x' + '00'.repeat(32)) as Hex.Hex),
|
|
205
|
+
)
|
|
206
|
+
BinaryStateTree.insert(
|
|
207
|
+
tree,
|
|
208
|
+
Bytes.fromHex(('0x' + '00'.repeat(31) + '01') as Hex.Hex),
|
|
209
|
+
Bytes.fromHex(('0x' + '01'.repeat(32)) as Hex.Hex),
|
|
210
|
+
)
|
|
211
|
+
expect(
|
|
212
|
+
Hex.fromBytes(BinaryStateTree.merkelize(tree)),
|
|
213
|
+
).toMatchInlineSnapshot(
|
|
214
|
+
`"0x8b1fd0f39922fc0fe0633c4bb9bfe5cc92aabf717313fe0cdc6e985f0a5cb8c1"`,
|
|
215
|
+
)
|
|
216
|
+
})
|
|
217
|
+
})
|
|
@@ -508,6 +508,7 @@ describe('toRpc', () => {
|
|
|
508
508
|
"parentBeaconBlockRoot": undefined,
|
|
509
509
|
"parentHash": "0xe55516ad8029e53cd32087f14653d851401b05245abb1b2d6ed4ddcc597ac5a6",
|
|
510
510
|
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
|
511
|
+
"requestsHash": undefined,
|
|
511
512
|
"sealFields": [
|
|
512
513
|
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
513
514
|
"0x0000000000000000",
|
|
@@ -715,6 +716,7 @@ describe('toRpc', () => {
|
|
|
715
716
|
"parentBeaconBlockRoot": undefined,
|
|
716
717
|
"parentHash": "0xe55516ad8029e53cd32087f14653d851401b05245abb1b2d6ed4ddcc597ac5a6",
|
|
717
718
|
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
|
719
|
+
"requestsHash": undefined,
|
|
718
720
|
"sealFields": [
|
|
719
721
|
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
720
722
|
"0x0000000000000000",
|
|
@@ -734,6 +736,58 @@ describe('toRpc', () => {
|
|
|
734
736
|
}
|
|
735
737
|
`)
|
|
736
738
|
})
|
|
739
|
+
|
|
740
|
+
test('behavior: requestsHash', () => {
|
|
741
|
+
// Mainnet block 26428234 (post-Prague), trimmed to one transaction and one withdrawal.
|
|
742
|
+
const rpc = {
|
|
743
|
+
baseFeePerGas: '0x3b8ea6e7',
|
|
744
|
+
blobGasUsed: '0x2a0000',
|
|
745
|
+
difficulty: '0x0',
|
|
746
|
+
excessBlobGas: '0xc514585',
|
|
747
|
+
extraData: '0x546974616e2028746974616e6275696c6465722e78797a29',
|
|
748
|
+
gasLimit: '0x3938700',
|
|
749
|
+
gasUsed: '0x23a6eaa',
|
|
750
|
+
hash: '0xc0177acc8fe87d5eba942ebc003ffa8064ec63eec83ec5ded6b98d53dff487e2',
|
|
751
|
+
logsBloom:
|
|
752
|
+
'0xfee7fd7ef5fa1cfde8ea756da7dffda6dbfdf3fabfb09971efbbcffd765fffcfbc2f527af3fe2eef4b3befdce177b13fdb7beffffedfeffdf7971ffec7efaa86fc8d3feb96eceb7efdea777abaeff5ff46fdf1fdf3dfedff71d25a7fb0feb5ca3c4cc45fbb7ebb13df9f9bc536416fedfa5df5bfaddff7b25e85ce9e45effe69abe8bf6dfc5ab86fe5fdf76d0ef37bf7f331858ff70fffbffcafea5777de35d97feffbf3fdddfefefa397fee9f4bfdd477d67f77b179ae59ffeff62d4b8cfbf1ce5b7c57e7d9cbf7f29e7f32f7df78db759cabf6e7aca3dcf91737afde697ad6fddf7d6b8f77f9efb7ccfeef9baeb9eccdff553fbdebed431fa96e7fe566cee7',
|
|
753
|
+
miner: '0x4838b106fce9647bdf1e7877bf73ce8b0bad5f97',
|
|
754
|
+
mixHash:
|
|
755
|
+
'0x476de780f38343d977f060944820a57667e21e2e3eed284dbc0f0f45cb999f23',
|
|
756
|
+
nonce: '0x0000000000000000',
|
|
757
|
+
number: '0x193434a',
|
|
758
|
+
parentBeaconBlockRoot:
|
|
759
|
+
'0x645e5dd10df2fdcfceedcd462666cedd03117e061c9272187521b9d5dea80174',
|
|
760
|
+
parentHash:
|
|
761
|
+
'0xe350f46ce9c96bcb3a2f2a8a47b205b1e5afc4cd9d01872948636285a81c0554',
|
|
762
|
+
receiptsRoot:
|
|
763
|
+
'0x3a9b4be502301b9379d07b5e23519dd572180336ac427097476f2690d92c3dcd',
|
|
764
|
+
requestsHash:
|
|
765
|
+
'0x6bb55db879cfce5155bbf84c5036f07cd6692ce4a23929423f84a88cd2e9701c',
|
|
766
|
+
sha3Uncles:
|
|
767
|
+
'0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
|
|
768
|
+
size: '0x27ce4',
|
|
769
|
+
stateRoot:
|
|
770
|
+
'0x5aa416b56ad1464a1a88e38f7127b8f181319475911abb0f73a401f44392e532',
|
|
771
|
+
timestamp: '0x6afb1517',
|
|
772
|
+
transactions: [
|
|
773
|
+
'0x955efe228355dc2fedba87f948c28f79c591ede57eeffef5fdd7ae66650c32cd',
|
|
774
|
+
],
|
|
775
|
+
transactionsRoot:
|
|
776
|
+
'0xc0f6df9afa194592d42a662a6ed63ed2685496ecfab488aa4e38e3d6224bb3d6',
|
|
777
|
+
uncles: [],
|
|
778
|
+
withdrawals: [
|
|
779
|
+
{
|
|
780
|
+
address: '0xb9d7934878b5fb9610b3fe8a5e441e8fad7e293f',
|
|
781
|
+
amount: '0xbe7483',
|
|
782
|
+
index: '0x8f5478b',
|
|
783
|
+
validatorIndex: '0x22db72',
|
|
784
|
+
},
|
|
785
|
+
],
|
|
786
|
+
withdrawalsRoot:
|
|
787
|
+
'0xaeb0321b253d63f458b83a49fedbb1af38821135acd64df5c3c41841ec4cbdc7',
|
|
788
|
+
} as const
|
|
789
|
+
expect(Block.toRpc(Block.fromRpc(rpc))).toEqual(rpc)
|
|
790
|
+
})
|
|
737
791
|
})
|
|
738
792
|
|
|
739
793
|
test('exports', () => {
|
|
@@ -88,7 +88,7 @@ describe('toRpc', () => {
|
|
|
88
88
|
"feeRecipient": "0x0000000000000000000000000000000000000000",
|
|
89
89
|
"gasLimit": "0x4",
|
|
90
90
|
"number": "0x5",
|
|
91
|
-
"prevRandao": "
|
|
91
|
+
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000006",
|
|
92
92
|
"time": "0x1234567890",
|
|
93
93
|
"withdrawals": [
|
|
94
94
|
{
|
|
@@ -157,4 +157,17 @@ describe('toRpc', () => {
|
|
|
157
157
|
expect(fromBigint).toEqual(fromNumber)
|
|
158
158
|
expect(fromBigint).toEqual(fromHex)
|
|
159
159
|
})
|
|
160
|
+
|
|
161
|
+
test('behavior: prevRandao is a 32-byte hash', () => {
|
|
162
|
+
expect(BlockOverrides.toRpc({ prevRandao: 6n })).toMatchInlineSnapshot(`
|
|
163
|
+
{
|
|
164
|
+
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000006",
|
|
165
|
+
}
|
|
166
|
+
`)
|
|
167
|
+
expect(BlockOverrides.toRpc({ prevRandao: '0x6' })).toMatchInlineSnapshot(`
|
|
168
|
+
{
|
|
169
|
+
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000006",
|
|
170
|
+
}
|
|
171
|
+
`)
|
|
172
|
+
})
|
|
160
173
|
})
|
|
@@ -1371,6 +1371,39 @@ describe('toBigInt', () => {
|
|
|
1371
1371
|
).toMatchInlineSnapshot('4206942069420694206942069420694206942069n')
|
|
1372
1372
|
})
|
|
1373
1373
|
|
|
1374
|
+
test('behavior: zero-padded values', () => {
|
|
1375
|
+
for (const value of [
|
|
1376
|
+
0n,
|
|
1377
|
+
2n ** 48n - 1n,
|
|
1378
|
+
2n ** 48n,
|
|
1379
|
+
2n ** 64n - 1n,
|
|
1380
|
+
2n ** 64n,
|
|
1381
|
+
2n ** 72n + 1n,
|
|
1382
|
+
2n ** 200n + 12345n,
|
|
1383
|
+
2n ** 256n - 1n,
|
|
1384
|
+
])
|
|
1385
|
+
for (const size of [32, 33, 40, 47])
|
|
1386
|
+
expect(Bytes.toBigInt(Bytes.fromNumber(value, { size }))).toBe(value)
|
|
1387
|
+
})
|
|
1388
|
+
|
|
1389
|
+
test('behavior: values wider than 64 bytes', () => {
|
|
1390
|
+
const ones = new Uint8Array(65).fill(0xff)
|
|
1391
|
+
expect(Bytes.toBigInt(ones)).toEqual((1n << 520n) - 1n)
|
|
1392
|
+
expect(Bytes.toBigInt(ones, { signed: true })).toEqual(-1n)
|
|
1393
|
+
|
|
1394
|
+
const high = new Uint8Array(65)
|
|
1395
|
+
high[0] = 0x80
|
|
1396
|
+
expect(Bytes.toBigInt(high)).toEqual(1n << 519n)
|
|
1397
|
+
expect(Bytes.toBigInt(high, { signed: true })).toEqual(-(1n << 519n))
|
|
1398
|
+
|
|
1399
|
+
// Leading zeros, read from an offset into a larger buffer.
|
|
1400
|
+
const padded = new Uint8Array(101).fill(0x01).subarray(1)
|
|
1401
|
+
padded.fill(0, 0, 20)
|
|
1402
|
+
expect(Bytes.toBigInt(padded, { signed: true })).toEqual(
|
|
1403
|
+
BigInt(`0x${'01'.repeat(80)}`),
|
|
1404
|
+
)
|
|
1405
|
+
})
|
|
1406
|
+
|
|
1374
1407
|
test('args: size', () => {
|
|
1375
1408
|
expect(
|
|
1376
1409
|
Bytes.toBigInt(Bytes.fromNumber(420n, { size: 32 }), {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbiItem, Caches } from 'ox'
|
|
1
|
+
import { AbiItem, Caches, Engine } from 'ox'
|
|
2
2
|
import { expect, test } from 'vp/test'
|
|
3
3
|
import { caches } from '../internal/caches.js'
|
|
4
4
|
|
|
@@ -27,3 +27,22 @@ test('behavior: clears signature hashes', () => {
|
|
|
27
27
|
Caches.clear()
|
|
28
28
|
expect(caches.signatureHash.size).toBe(0)
|
|
29
29
|
})
|
|
30
|
+
|
|
31
|
+
test('behavior: an engine change re-derives ABI item signature hashes', () => {
|
|
32
|
+
const abiItem = {
|
|
33
|
+
inputs: [{ type: 'uint256' }],
|
|
34
|
+
name: 'ownerOf',
|
|
35
|
+
outputs: [],
|
|
36
|
+
stateMutability: 'view',
|
|
37
|
+
type: 'function',
|
|
38
|
+
} as const
|
|
39
|
+
const hash = AbiItem.getSignatureHash(abiItem)
|
|
40
|
+
expect(
|
|
41
|
+
Engine.with({ Hash: { keccak256: () => new Uint8Array(32) } }, () =>
|
|
42
|
+
AbiItem.getSignatureHash(abiItem),
|
|
43
|
+
),
|
|
44
|
+
).toMatchInlineSnapshot(
|
|
45
|
+
`"0x0000000000000000000000000000000000000000000000000000000000000000"`,
|
|
46
|
+
)
|
|
47
|
+
expect(AbiItem.getSignatureHash(abiItem)).toBe(hash)
|
|
48
|
+
})
|
|
@@ -225,6 +225,15 @@ describe('encode', () => {
|
|
|
225
225
|
expect(() => Cbor.encode(num)).toThrow(Cbor.NumberTooLargeError)
|
|
226
226
|
})
|
|
227
227
|
|
|
228
|
+
test('number too large error names the encodable range', () => {
|
|
229
|
+
expect(() => Cbor.encode(0x100000000)).toThrow(
|
|
230
|
+
'Number is outside the encodable integer range (-4294967296 to 4294967295): 4294967296',
|
|
231
|
+
)
|
|
232
|
+
expect(() => Cbor.encode(-0x100000001)).toThrow(
|
|
233
|
+
'Number is outside the encodable integer range (-4294967296 to 4294967295): -4294967297',
|
|
234
|
+
)
|
|
235
|
+
})
|
|
236
|
+
|
|
228
237
|
test('bigint throws', () => {
|
|
229
238
|
expect(() => Cbor.encode(BigInt(42))).toThrow(Cbor.UnsupportedBigIntError)
|
|
230
239
|
})
|
|
@@ -510,6 +519,23 @@ describe('decode', () => {
|
|
|
510
519
|
expect(() => Cbor.decode('0x123')).toThrow()
|
|
511
520
|
})
|
|
512
521
|
|
|
522
|
+
test('error: nesting deeper than the depth limit', () => {
|
|
523
|
+
// `0x81` opens a one-element array.
|
|
524
|
+
expect(
|
|
525
|
+
Cbor.decode(new Uint8Array([...new Uint8Array(1_023).fill(0x81), 0x01])),
|
|
526
|
+
).toBeDefined()
|
|
527
|
+
expect(() =>
|
|
528
|
+
Cbor.decode(new Uint8Array([...new Uint8Array(1_024).fill(0x81), 0x01])),
|
|
529
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
530
|
+
`[Cbor.DepthLimitExceededError: CBOR depth limit of \`1024\` exceeded.]`,
|
|
531
|
+
)
|
|
532
|
+
expect(() =>
|
|
533
|
+
Cbor.decode(new Uint8Array(100_000).fill(0x81)),
|
|
534
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
535
|
+
`[Cbor.DepthLimitExceededError: CBOR depth limit of \`1024\` exceeded.]`,
|
|
536
|
+
)
|
|
537
|
+
})
|
|
538
|
+
|
|
513
539
|
test('large string (> 0xffff)', () => {
|
|
514
540
|
const str = 'a'.repeat(0x10000)
|
|
515
541
|
const encoded = Cbor.encode(str)
|
|
@@ -46,6 +46,19 @@ describe('fromRpc', () => {
|
|
|
46
46
|
status: expected,
|
|
47
47
|
})
|
|
48
48
|
})
|
|
49
|
+
|
|
50
|
+
test('behavior: unknown status named like an `Object.prototype` key', () => {
|
|
51
|
+
for (const status of ['__proto__', 'constructor', 'toString'])
|
|
52
|
+
expect(
|
|
53
|
+
FrameReceipt.fromRpc({
|
|
54
|
+
executionGasUsed: '0x0',
|
|
55
|
+
gasUsed: '0x0',
|
|
56
|
+
logs: [],
|
|
57
|
+
stateGasUsed: '0x0',
|
|
58
|
+
status: status as never,
|
|
59
|
+
}).status,
|
|
60
|
+
).toBeUndefined()
|
|
61
|
+
})
|
|
49
62
|
})
|
|
50
63
|
|
|
51
64
|
describe('toRpc', () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { test } from '@fast-check/vitest'
|
|
1
|
+
import { fc, test } from '@fast-check/vitest'
|
|
2
2
|
import { type Bytes, Hex, Rlp } from 'ox'
|
|
3
3
|
import { describe, expect } from 'vp/test'
|
|
4
4
|
|
|
@@ -36,8 +36,62 @@ describe('Rlp round-trip', () => {
|
|
|
36
36
|
expect(asHex).toEqual(Hex.fromBytes(asBytes))
|
|
37
37
|
},
|
|
38
38
|
)
|
|
39
|
+
|
|
40
|
+
test.prop(
|
|
41
|
+
{
|
|
42
|
+
edit: fc.tuple(
|
|
43
|
+
fc.nat(),
|
|
44
|
+
fc.nat(0xff),
|
|
45
|
+
fc.constantFrom('cut', 'set', 'add', 'char'),
|
|
46
|
+
),
|
|
47
|
+
tree: arbitraryRecursiveRlpHex(),
|
|
48
|
+
},
|
|
49
|
+
{ numRuns },
|
|
50
|
+
)(
|
|
51
|
+
'hex and bytes decode paths agree on mutated encodings, errors included',
|
|
52
|
+
({ edit: [at, byte, kind], tree }) => {
|
|
53
|
+
const body = Rlp.from(tree, { as: 'Hex' }).slice(2)
|
|
54
|
+
const index = (at % (body.length / 2 + 1)) * 2
|
|
55
|
+
const pair = byte.toString(16).padStart(2, '0')
|
|
56
|
+
const mutated = `0x${(() => {
|
|
57
|
+
if (kind === 'cut') return body.slice(0, index)
|
|
58
|
+
if (kind === 'set')
|
|
59
|
+
return `${body.slice(0, index)}${pair}${body.slice(index + 2)}`
|
|
60
|
+
if (kind === 'add')
|
|
61
|
+
return `${body.slice(0, index)}${pair}${body.slice(index)}`
|
|
62
|
+
return `${body.slice(0, index)}g${body.slice(index + 1)}`
|
|
63
|
+
})()}` as Hex.Hex
|
|
64
|
+
expect(outcome(() => Rlp.toHex(mutated))).toEqual(
|
|
65
|
+
outcome(() => normalizeBytesToHex(Rlp.toBytes(mutated))),
|
|
66
|
+
)
|
|
67
|
+
},
|
|
68
|
+
)
|
|
39
69
|
})
|
|
40
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Returns a decode result or its error, so that two decode paths can be
|
|
73
|
+
* compared on malformed input.
|
|
74
|
+
*
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
function outcome(fn: () => unknown) {
|
|
78
|
+
try {
|
|
79
|
+
return { value: fn() }
|
|
80
|
+
} catch (error) {
|
|
81
|
+
return { error: `${(error as Error).name}: ${(error as Error).message}` }
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Converts `Uint8Array` leaves to hex, as `Rlp.toHex` returns them.
|
|
87
|
+
*
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
function normalizeBytesToHex(value: RecursiveArray<Bytes.Bytes>): unknown {
|
|
91
|
+
if (Array.isArray(value)) return value.map(normalizeBytesToHex)
|
|
92
|
+
return Hex.fromBytes(value as Uint8Array)
|
|
93
|
+
}
|
|
94
|
+
|
|
41
95
|
/**
|
|
42
96
|
* Lower-case any hex string in a recursive tree. The encoder emits
|
|
43
97
|
* lowercase but the arbitrary may produce mixed casing in the future,
|
|
@@ -157,6 +157,70 @@ describe('Rlp.to', () => {
|
|
|
157
157
|
expect(Rlp.toHex(rlpBytes)).toEqual('0x')
|
|
158
158
|
})
|
|
159
159
|
|
|
160
|
+
test('behavior: hex leaves of a hex input', () => {
|
|
161
|
+
// Short and long leaves, nested, in short and long (> 4096 hex
|
|
162
|
+
// characters) inputs.
|
|
163
|
+
for (const length of [32, 4_096]) {
|
|
164
|
+
const value = [
|
|
165
|
+
'0x0a',
|
|
166
|
+
'0x',
|
|
167
|
+
`0x${'ab'.repeat(20)}`,
|
|
168
|
+
[[`0x${'cd'.repeat(length)}`], '0x7f', '0x80'],
|
|
169
|
+
`0x${'ef'.repeat(56)}`,
|
|
170
|
+
] as const
|
|
171
|
+
const encoded = Rlp.fromHex(value as never)
|
|
172
|
+
expect(Rlp.toHex(encoded)).toEqual(value)
|
|
173
|
+
// Leaves are lowercase, as `Hex.fromBytes` writes them.
|
|
174
|
+
expect(Rlp.toHex(`0x${encoded.slice(2).toUpperCase()}`)).toEqual(value)
|
|
175
|
+
}
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
test('behavior: hex input decodes and fails like byte input', () => {
|
|
179
|
+
// Decoding to bytes always goes through `Bytes.fromHex` and the cursor,
|
|
180
|
+
// which short hex input to hex skips.
|
|
181
|
+
const toHex = (value: unknown): unknown =>
|
|
182
|
+
Array.isArray(value) ? value.map(toHex) : Hex.fromBytes(value as never)
|
|
183
|
+
const outcome = (fn: () => unknown) => {
|
|
184
|
+
try {
|
|
185
|
+
return { value: fn() }
|
|
186
|
+
} catch (error) {
|
|
187
|
+
return {
|
|
188
|
+
error: `${(error as Error).name}: ${(error as Error).message}`,
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
for (const value of [
|
|
193
|
+
'0x',
|
|
194
|
+
'0x00',
|
|
195
|
+
'0x7F',
|
|
196
|
+
'0x8180',
|
|
197
|
+
'0xC88363617483646F67',
|
|
198
|
+
'0xc0',
|
|
199
|
+
'0xzz',
|
|
200
|
+
'0x8',
|
|
201
|
+
'0x0\u0130',
|
|
202
|
+
'0x82',
|
|
203
|
+
'0x8201',
|
|
204
|
+
'0xb8',
|
|
205
|
+
'0xb801ff',
|
|
206
|
+
'0xb838',
|
|
207
|
+
'0xb90001',
|
|
208
|
+
'0xbc',
|
|
209
|
+
'0x8100',
|
|
210
|
+
'0x817f',
|
|
211
|
+
'0xc20102',
|
|
212
|
+
'0xc1c0c0',
|
|
213
|
+
'0xc3010203ff',
|
|
214
|
+
'0xc28201',
|
|
215
|
+
'0xff',
|
|
216
|
+
'0x0101',
|
|
217
|
+
`0x${'c1'.repeat(1_025)}`,
|
|
218
|
+
] as const)
|
|
219
|
+
expect(outcome(() => Rlp.toHex(value as Hex.Hex))).toEqual(
|
|
220
|
+
outcome(() => toHex(Rlp.toBytes(value as Hex.Hex))),
|
|
221
|
+
)
|
|
222
|
+
})
|
|
223
|
+
|
|
160
224
|
describe('prefix < 0x80', () => {
|
|
161
225
|
test('bytes -> bytes', () => {
|
|
162
226
|
expect(Rlp.toBytes(Rlp.fromBytes(Bytes.fromHex('0x00')))).toEqual(
|
|
@@ -224,7 +224,7 @@ describe('fromHttp', () => {
|
|
|
224
224
|
|
|
225
225
|
Status: 400
|
|
226
226
|
URL: https://oxlib.sh/rpc
|
|
227
|
-
Body:
|
|
227
|
+
Body: {"id":0,"method":"eth_accounts","jsonrpc":"2.0"}
|
|
228
228
|
|
|
229
229
|
Details: Bad Request]
|
|
230
230
|
`)
|
|
@@ -244,7 +244,7 @@ describe('fromHttp', () => {
|
|
|
244
244
|
|
|
245
245
|
Status: 400
|
|
246
246
|
URL: https://oxlib.sh/rpc
|
|
247
|
-
Body:
|
|
247
|
+
Body: {"id":0,"method":"eth_accounts","jsonrpc":"2.0"}
|
|
248
248
|
|
|
249
249
|
Details: bad]
|
|
250
250
|
`)
|
|
@@ -317,6 +317,19 @@ describe('fromHttp', () => {
|
|
|
317
317
|
}
|
|
318
318
|
})
|
|
319
319
|
|
|
320
|
+
test('behavior: timeout rejects when `fetchFn` ignores the signal', async () => {
|
|
321
|
+
const transport = RpcTransport.fromHttp('https://example.com', {
|
|
322
|
+
fetchFn: () => new Promise<Response>(() => {}),
|
|
323
|
+
timeout: 50,
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
await expect(() =>
|
|
327
|
+
transport.request({ method: 'eth_accounts' }),
|
|
328
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
329
|
+
`[Promise.TimeoutError: Operation timed out.]`,
|
|
330
|
+
)
|
|
331
|
+
})
|
|
332
|
+
|
|
320
333
|
test('behavior: timeout covers a response body that stalls after its headers', async () => {
|
|
321
334
|
const server = await createHttpServer(async (_, res) => {
|
|
322
335
|
res.writeHead(200, { 'Content-Type': 'application/json' })
|