Skip to content

Commit 86b822c

Browse files
committed
Minor fixes described in changeset
1 parent c10edb6 commit 86b822c

File tree

5 files changed

+40
-3
lines changed

5 files changed

+40
-3
lines changed

.changeset/olive-pots-brush.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/functions-toolkit': patch
3+
---
4+
5+
Support `0x` in decodeResult, fixed simulator shutdown when error is encountered, added explicitly supported versions to README

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Up-to-date documentation on Chainlink Functions can be found [here](https://docs
66

77
> :warning: Chainlink Functions requires signing a terms of service agreement before creating a billing subscription. See this [getting started](https://docs.chain.link/chainlink-functions/getting-started) section in the docs.
88
9+
# Prerequisites
10+
11+
Install Node.js version `18.18.0` or higher *and* Deno version `1.36.0` or higher.
12+
913
# How to use this package
1014

1115
The following classes expose functionality one would expect from their name.
@@ -23,6 +27,7 @@ The `SubscriptionManager` class is used to manage the Chainlink billing [subscri
2327

2428
The typical subscriptions-related operations are
2529

30+
- [Prerequisites](#prerequisites)
2631
- [How to use this package](#how-to-use-this-package)
2732
- [Functions Billing Subscription Management](#functions-billing-subscription-management)
2833
- [Subscription Initialization](#subscription-initialization)

src/decodeResult.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const decodeResult = (
66
resultHexstring: string,
77
expectedReturnType: ReturnType,
88
): DecodedResult => {
9-
if (!isValidHexadecimal(resultHexstring)) {
9+
if (!isValidHexadecimal(resultHexstring) && resultHexstring.slice(0, 2) !== '0x') {
1010
throw Error(`'${resultHexstring}' is not a valid hexadecimal string`)
1111
}
1212
expectedReturnType = expectedReturnType.toLowerCase() as ReturnType
@@ -29,6 +29,9 @@ export const decodeResult = (
2929
`'${resultHexstring}' has '${resultHexBits}' bits which is too large for uint256`,
3030
)
3131
}
32+
if (resultHexstring === '0x') {
33+
return BigInt(0)
34+
}
3235
decodedOutput = BigInt('0x' + resultHexstring.slice(2).slice(-64))
3336
break
3437
case ReturnType.int256:
@@ -37,9 +40,15 @@ export const decodeResult = (
3740
`'${resultHexstring}' has '${resultHexBits}' bits which is too large for int256`,
3841
)
3942
}
43+
if (resultHexstring === '0x') {
44+
return BigInt(0)
45+
}
4046
decodedOutput = signedInt256toBigInt('0x' + resultHexstring.slice(2).slice(-64))
4147
break
4248
case ReturnType.string:
49+
if (resultHexstring === '0x') {
50+
return ''
51+
}
4352
decodedOutput = Buffer.from(resultHexstring.slice(2), 'hex').toString()
4453
break
4554
case ReturnType.bytes:

src/simulateScript/deno-sandbox/sandbox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,6 @@ try {
452452
}) as () => Promise<unknown>
453453
const result = await userScript()
454454

455-
__2___.close()
456-
457455
if (!(result instanceof ArrayBuffer) && !(result instanceof Uint8Array)) {
458456
throw Error('returned value not an ArrayBuffer or Uint8Array')
459457
}
@@ -495,4 +493,6 @@ try {
495493
},
496494
}),
497495
)
496+
} finally {
497+
__2___.close()
498498
}

test/unit/decode_result.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@ import { decodeResult, ReturnType } from '../../src/index'
22

33
describe('decodeResult', () => {
44
it.each([
5+
{
6+
result: '0x',
7+
expectedDataType: ReturnType.string,
8+
decodedResult: '',
9+
label: 'decodes empty string',
10+
},
11+
{
12+
result: '0x',
13+
expectedDataType: ReturnType.uint256,
14+
decodedResult: BigInt(0),
15+
label: 'decodes empty uint256',
16+
},
17+
{
18+
result: '0x',
19+
expectedDataType: ReturnType.int256,
20+
decodedResult: BigInt(0),
21+
label: 'decodes empty int256',
22+
},
523
{
624
result: '0x48656c6c6f2c20576f726c6421',
725
expectedDataType: ReturnType.string,

0 commit comments

Comments
 (0)