Skip to content

Commit dd786f6

Browse files
authored
fix: fix minimum postage batch amount being off by one (#1021)
* fix: fix minimum postage batch amount being off by one * test: adjust batch amounts in tests
1 parent cf697e2 commit dd786f6

File tree

7 files changed

+21
-19
lines changed

7 files changed

+21
-19
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ After making changes, link the package to your project by running `npm link` in
374374

375375
### Test
376376

377+
[Code coverage](https://bah5acgza26tlmya36bdiu5cdfs3hh22hqthkhfv6cvq2ugxqrv5aw267ydlq.bzz.limo/)
378+
377379
Tests are currently run against a mainnet Bee nodes. This is temporary and this section will be revised in the future.
378380

379381
## License

src/bee.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,7 @@ export class Bee {
16151615
}
16161616

16171617
const chainState = await this.getChainState()
1618-
const minimumAmount = BigInt(chainState.currentPrice) * 17280n
1618+
const minimumAmount = BigInt(chainState.currentPrice) * 17280n + 1n
16191619

16201620
if (BigInt(amountString) < minimumAmount) {
16211621
throw new BeeArgumentError(
@@ -1672,7 +1672,7 @@ export class Bee {
16721672
throw new BeeArgumentError('New depth has to be greater than the original depth', depth)
16731673
}
16741674

1675-
await this.topUpBatch(batch.batchID, BigInt(batch.amount) * 2n ** BigInt(delta - 1), options)
1675+
await this.topUpBatch(batch.batchID, BigInt(batch.amount) * 2n ** BigInt(delta - 1) + 1n, options)
16761676

16771677
return this.diluteBatch(batch.batchID, depth, options)
16781678
}

src/utils/stamps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export function getStampDuration(
122122
* @param blockTime The block time in seconds.
123123
*/
124124
export function getAmountForDuration(duration: Duration, pricePerBlock: number, blockTime: number): bigint {
125-
return (BigInt(duration.toSeconds()) / BigInt(blockTime)) * BigInt(pricePerBlock)
125+
return (BigInt(duration.toSeconds()) / BigInt(blockTime)) * BigInt(pricePerBlock) + 1n
126126
}
127127

128128
/**

test/integration/stamp.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ test('GET batches', async () => {
2121
})
2222

2323
test('POST stamps', async () => {
24-
const response = await bee.createPostageBatch('780000000', 17, { waitForUsable: true })
24+
const response = await bee.createPostageBatch('580000000', 17, { waitForUsable: true })
2525
expect(response.toHex()).toHaveLength(64)
2626

27-
await bee.topUpBatch(response, '780000000')
27+
await bee.topUpBatch(response, '580000000')
2828

2929
await System.waitFor(
3030
async () => {

test/integration/stamp.ux.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ test('Utils.getDepthForSize', () => {
1414
})
1515

1616
test('Utils.getAmountForDuration', () => {
17-
expect(Utils.getAmountForDuration(Duration.fromHours(25), 24000, 5)).toBe((414720000n / 24n) * 25n)
18-
expect(Utils.getAmountForDuration(Duration.fromDays(1), 24000, 5)).toBe(414720000n)
19-
expect(Utils.getAmountForDuration(Duration.fromWeeks(1), 24000, 5)).toBe(414720000n * 7n)
20-
expect(Utils.getAmountForDuration(Duration.fromYears(1), 24000, 5)).toBe(414720000n * 365n)
17+
expect(Utils.getAmountForDuration(Duration.fromHours(25), 24000, 5)).toBe((414720000n / 24n) * 25n + 1n)
18+
expect(Utils.getAmountForDuration(Duration.fromDays(1), 24000, 5)).toBe(414720000n + 1n)
19+
expect(Utils.getAmountForDuration(Duration.fromWeeks(1), 24000, 5)).toBe(414720000n * 7n + 1n)
20+
expect(Utils.getAmountForDuration(Duration.fromYears(1), 24000, 5)).toBe(414720000n * 365n + 1n)
2121
})
2222

2323
test('bee.getStorageCost', async () => {
@@ -61,7 +61,7 @@ test('bee.getExtensionCost', async () => {
6161
Size.fromGigabytes(18),
6262
Duration.fromYears(1),
6363
)
64-
expect(cost.toDecimalString()).toBe('209.0182760562950144')
64+
expect(cost.toDecimalString()).toBe('209.0182760579727360')
6565
})
6666
})
6767

@@ -80,23 +80,23 @@ test('bee.buyStorage with extensions', async () => {
8080
// create stamp
8181
'GET /chainstate',
8282
'GET /chainstate',
83-
'POST /stamps/458922240/22',
83+
'POST /stamps/458922241/22',
8484
'GET /stamps/b330000000000000000000000000000000000000000000000000000000000000',
8585
// create stamp, do not wait for usable
8686
'GET /chainstate',
8787
'GET /chainstate',
88-
'POST /stamps/458922240/22',
88+
'POST /stamps/458922241/22',
8989
// extend duration
9090
'GET /stamps/b330000000000000000000000000000000000000000000000000000000000000',
9191
'GET /chainstate',
92-
'PATCH /stamps/topup/b330000000000000000000000000000000000000000000000000000000000000/458922240',
92+
'PATCH /stamps/topup/b330000000000000000000000000000000000000000000000000000000000000/458922241',
9393
// extend size +1 depth
9494
'GET /stamps/b330000000000000000000000000000000000000000000000000000000000000',
95-
'PATCH /stamps/topup/b330000000000000000000000000000000000000000000000000000000000000/458922240',
95+
'PATCH /stamps/topup/b330000000000000000000000000000000000000000000000000000000000000/458922241',
9696
'PATCH /stamps/dilute/b330000000000000000000000000000000000000000000000000000000000000/23',
9797
// extend size +2 depth
9898
'GET /stamps/b330000000000000000000000000000000000000000000000000000000000000',
99-
'PATCH /stamps/topup/b330000000000000000000000000000000000000000000000000000000000000/917844480',
99+
'PATCH /stamps/topup/b330000000000000000000000000000000000000000000000000000000000000/917844481',
100100
'PATCH /stamps/dilute/b330000000000000000000000000000000000000000000000000000000000000/24',
101101
// error case
102102
'GET /stamps/b330000000000000000000000000000000000000000000000000000000000000',

test/integration/stamper.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ test('Stamper', async () => {
77

88
const stamper = Stamper.fromBlank(
99
Types.asString(process.env.JEST_BEE_FULL_PK),
10-
'ae0b4d8548d17fb70672c5e7a9717de5f855d3f398a3cc2f0e445e2eecca2622',
10+
'b24b3f3ac5c7727cb9ad17b15167e75df33708f201c947f3cc6658348c2df31d',
1111
17,
1212
)
1313

test/mocks.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ responses.set(
2828
)
2929

3030
responses.set(
31-
'POST /stamps/458922240/22',
31+
'POST /stamps/458922241/22',
3232
JSON.stringify({ batchID: 'b330000000000000000000000000000000000000000000000000000000000000' }),
3333
)
3434

@@ -50,14 +50,14 @@ responses.set(
5050
)
5151

5252
responses.set(
53-
'PATCH /stamps/topup/b330000000000000000000000000000000000000000000000000000000000000/458922240',
53+
'PATCH /stamps/topup/b330000000000000000000000000000000000000000000000000000000000000/458922241',
5454
JSON.stringify({
5555
batchID: 'b330000000000000000000000000000000000000000000000000000000000000',
5656
}),
5757
)
5858

5959
responses.set(
60-
'PATCH /stamps/topup/b330000000000000000000000000000000000000000000000000000000000000/917844480',
60+
'PATCH /stamps/topup/b330000000000000000000000000000000000000000000000000000000000000/917844481',
6161
JSON.stringify({
6262
batchID: 'b330000000000000000000000000000000000000000000000000000000000000',
6363
}),

0 commit comments

Comments
 (0)