Skip to content

Commit ee1c8ea

Browse files
committed
fix: another commit
1 parent b5a2307 commit ee1c8ea

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

packages/core/src/vcdm/encoding/rlp/RLP.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ class RLP implements VeChainDataModel<RLP> {
1313
protected constructor(data: RLPInput);
1414
protected constructor(data: Uint8Array);
1515
protected constructor(data: RLPInput | Uint8Array) {
16-
this.decoded =
17-
data instanceof Uint8Array ? EthereumjsRLP.decode(data) : data;
18-
this.encoded =
19-
data instanceof Uint8Array ? data : EthereumjsRLP.encode(data);
16+
// ArrayBuffer.isView so we support https://github.com/vitest-dev/vitest/issues/5183
17+
this.decoded = ArrayBuffer.isView(data)
18+
? EthereumjsRLP.decode(data)
19+
: data;
20+
this.encoded = ArrayBuffer.isView(data)
21+
? data
22+
: EthereumjsRLP.encode(data);
2023
}
2124

2225
/**
@@ -214,7 +217,8 @@ class RLP implements VeChainDataModel<RLP> {
214217

215218
// ScalarKind: Direct decoding using the provided method.
216219
if (kind instanceof ScalarKind) {
217-
if (!(packed instanceof Uint8Array)) {
220+
// ArrayBuffer.isView so we support https://github.com/vitest-dev/vitest/issues/5183
221+
if (!ArrayBuffer.isView(packed)) {
218222
throw new InvalidRLP(
219223
'RLP.unpackData()',
220224
`Unpacking error: Expected data type is Uint8Array.`,

packages/core/src/vcdm/encoding/rlp/kind/BufferKind.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class BufferKind extends ScalarKind {
1717
*/
1818
public data(data: RLPInput, context: string): DataOutput {
1919
// Ensure that the data is indeed a Buffer before encoding.
20-
if (!(data instanceof Uint8Array))
20+
// ArrayBuffer.isView so we support https://github.com/vitest-dev/vitest/issues/5183
21+
if (!ArrayBuffer.isView(data)) {
2122
throw new InvalidRLP(
2223
'BufferKind.data()',
2324
`Validation error: Expected a Uint8Array type in ${context}.`,
@@ -28,6 +29,7 @@ class BufferKind extends ScalarKind {
2829
}
2930
}
3031
);
32+
}
3133

3234
return {
3335
encode: () => data // Data is already a Buffer, so return as-is.

0 commit comments

Comments
 (0)