Skip to content

Commit

Permalink
Updated units for estimateFunctionsRequestCost
Browse files Browse the repository at this point in the history
  • Loading branch information
KuphJr committed Sep 10, 2023
1 parent 4a7b088 commit 6b59d3b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ const estimatedCostInJuels: BigInt = await subscriptionManager.estimateFunctions
donId, // ID of the DON to which the Functions request will be sent
subscriptionId, // Subscription ID
callbackGasLimit, // Total gas used by the consumer contract's callback
gasPriceGwei, // Gas price in gWei
gasPriceWei, // Gas price in wei
})
```

Expand Down
8 changes: 4 additions & 4 deletions src/SubscriptionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ export class SubscriptionManager {
donId,
subscriptionId,
callbackGasLimit,
gasPriceGwei,
gasPriceWei,
}: EstimateCostConfig): Promise<BigInt> {
if (typeof donId !== 'string') {
throw Error('donId has invalid type')
Expand All @@ -488,8 +488,8 @@ export class SubscriptionManager {
throw Error('Invalid callbackGasLimit')
}

if (typeof gasPriceGwei !== 'bigint' || gasPriceGwei <= 0) {
throw Error('Invalid gasPriceGwei')
if (typeof gasPriceWei !== 'bigint' || gasPriceWei <= 0) {
throw Error('Invalid gasPriceWei')
}

let functionsCoordinatorAddress: string
Expand Down Expand Up @@ -520,7 +520,7 @@ export class SubscriptionManager {
subscriptionId,
[],
callbackGasLimit,
gasPriceGwei,
gasPriceWei,
)
return BigInt(estimatedCostInJuels.toString())
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export type EstimateCostConfig = {
donId: string
subscriptionId: BigInt | number | string
callbackGasLimit: number
gasPriceGwei: BigInt
gasPriceWei: BigInt
}

export type SubscriptionInfo = {
Expand Down
18 changes: 9 additions & 9 deletions test/integration/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1212,11 +1212,11 @@ describe('Functions toolkit classes', () => {
const estimatedCostInJuels = await subscriptionManager.estimateFunctionsRequestCost({
subscriptionId,
callbackGasLimit: 300_000,
gasPriceGwei: 1n,
gasPriceWei: 100000000000n, // 100 gWei
donId,
})

expect(estimatedCostInJuels.toString()).toBe(BigInt('389230000').toString())
expect(estimatedCostInJuels.toString()).toBe(BigInt('38923000000000000000').toString())
})

it('Throws an error for missing donId', async () => {
Expand All @@ -1235,7 +1235,7 @@ describe('Functions toolkit classes', () => {
donId: undefined,
subscriptionId,
callbackGasLimit: 300_000,
gasPriceGwei: 1n,
gasPriceWei: 100000000000n,
})
}).rejects.toThrowError(/donId has invalid type/)
})
Expand All @@ -1253,7 +1253,7 @@ describe('Functions toolkit classes', () => {
donId,
subscriptionId: 0,
callbackGasLimit: 300_000,
gasPriceGwei: 1n,
gasPriceWei: 100000000000n,
})
}).rejects.toThrowError(/Error fetching information for subscription ID/)
})
Expand All @@ -1274,12 +1274,12 @@ describe('Functions toolkit classes', () => {
donId,
subscriptionId,
callbackGasLimit: -1,
gasPriceGwei: 1n,
gasPriceWei: 100000000000n,
})
}).rejects.toThrowError(/Invalid callbackGasLimit/)
})

it('Throws an error for invalid gasPriceGwei', async () => {
it('Throws an error for invalid gasPriceWei', async () => {
const subscriptionManager = new SubscriptionManager({
signer: allowlistedUser_A,
linkTokenAddress,
Expand All @@ -1295,9 +1295,9 @@ describe('Functions toolkit classes', () => {
donId,
subscriptionId,
callbackGasLimit: 300_000,
gasPriceGwei: -1n,
gasPriceWei: -1n,
})
}).rejects.toThrowError(/Invalid gasPriceGwei/)
}).rejects.toThrowError(/Invalid gasPriceWei/)
})

it('Throws an error for incorrect donId', async () => {
Expand All @@ -1316,7 +1316,7 @@ describe('Functions toolkit classes', () => {
donId: 'wrong',
subscriptionId,
callbackGasLimit: 300_000,
gasPriceGwei: 1n,
gasPriceWei: 100000000000n,
})
}).rejects.toThrowError(
/Error encountered when attempting to fetch the FunctionsCoordinator address/,
Expand Down

0 comments on commit 6b59d3b

Please sign in to comment.