Skip to content

Commit 35c7e1c

Browse files
fix: use depth over postageBatchId in calculateTopUpForBzz (#1155)
* fix: use depth over postageBatchId in calculateTopUpForBzz * test: update test coverage --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 4da7425 commit 35c7e1c

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

src/bee.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,20 +2369,19 @@ export class Bee {
23692369
/**
23702370
* Calculates the `amount` and expected duration extension for topping up a postage batch with a given BZZ value.
23712371
*
2372-
* @param postageBatchId
2372+
* @param depth Depth of the postage batch to top up.
23732373
* @param bzz The amount of BZZ to spend on the top-up.
23742374
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
23752375
* @returns An object with `amount` (to pass to {@link topUpBatch}) and `duration` (the expected TTL extension).
23762376
*/
23772377
async calculateTopUpForBzz(
2378-
postageBatchId: BatchId | Uint8Array | string,
2378+
depth: number,
23792379
bzz: BZZ,
23802380
requestOptions?: BeeRequestOptions,
23812381
): Promise<{ amount: bigint; duration: Duration }> {
2382-
const batch = await this.getPostageBatch(postageBatchId, requestOptions)
23832382
const chainState = await this.getChainState(requestOptions)
23842383
const blockTime = this.network === 'gnosis' ? 5 : 15
2385-
const amount = bzz.toPLURBigInt() / 2n ** BigInt(batch.depth)
2384+
const amount = bzz.toPLURBigInt() / 2n ** BigInt(depth)
23862385
const duration = getStampDuration(amount, chainState.currentPrice, blockTime)
23872386

23882387
return { amount, duration }

test/coverage/coverage-summary.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{"total": {"lines":{"total":2525,"covered":2054,"skipped":0,"pct":81.34},"statements":{"total":2570,"covered":2095,"skipped":0,"pct":81.51},"functions":{"total":619,"covered":489,"skipped":0,"pct":78.99},"branches":{"total":822,"covered":557,"skipped":0,"pct":67.76},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}}
1+
{"total": {"lines":{"total":2524,"covered":2054,"skipped":0,"pct":81.37},"statements":{"total":2569,"covered":2095,"skipped":0,"pct":81.54},"functions":{"total":619,"covered":489,"skipped":0,"pct":78.99},"branches":{"total":822,"covered":558,"skipped":0,"pct":67.88},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}}
22
,"/home/runner/work/bee-js/bee-js/src/bee-dev.ts": {"lines":{"total":14,"covered":5,"skipped":0,"pct":35.71},"functions":{"total":2,"covered":0,"skipped":0,"pct":0},"statements":{"total":14,"covered":5,"skipped":0,"pct":35.71},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
3-
,"/home/runner/work/bee-js/bee-js/src/bee.ts": {"lines":{"total":459,"covered":377,"skipped":0,"pct":82.13},"functions":{"total":133,"covered":108,"skipped":0,"pct":81.2},"statements":{"total":462,"covered":380,"skipped":0,"pct":82.25},"branches":{"total":172,"covered":112,"skipped":0,"pct":65.11}}
3+
,"/home/runner/work/bee-js/bee-js/src/bee.ts": {"lines":{"total":458,"covered":377,"skipped":0,"pct":82.31},"functions":{"total":133,"covered":108,"skipped":0,"pct":81.2},"statements":{"total":461,"covered":380,"skipped":0,"pct":82.42},"branches":{"total":172,"covered":113,"skipped":0,"pct":65.69}}
44
,"/home/runner/work/bee-js/bee-js/src/index.ts": {"lines":{"total":16,"covered":16,"skipped":0,"pct":100},"functions":{"total":10,"covered":7,"skipped":0,"pct":70},"statements":{"total":25,"covered":25,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
55
,"/home/runner/work/bee-js/bee-js/src/chunk/bmt.ts": {"lines":{"total":16,"covered":15,"skipped":0,"pct":93.75},"functions":{"total":3,"covered":3,"skipped":0,"pct":100},"statements":{"total":17,"covered":16,"skipped":0,"pct":94.11},"branches":{"total":2,"covered":1,"skipped":0,"pct":50}}
66
,"/home/runner/work/bee-js/bee-js/src/chunk/cac.ts": {"lines":{"total":21,"covered":20,"skipped":0,"pct":95.23},"functions":{"total":3,"covered":3,"skipped":0,"pct":100},"statements":{"total":21,"covered":20,"skipped":0,"pct":95.23},"branches":{"total":10,"covered":8,"skipped":0,"pct":80}}

0 commit comments

Comments
 (0)