Skip to content

Commit 5ca2e35

Browse files
authored
fix: add missing feedIndexNext fields (#991)
1 parent 69ca260 commit 5ca2e35

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

src/feed/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ export function makeFeedReader(requestOptions: BeeRequestOptions, topic: Topic,
178178
return {
179179
payload: update.payload,
180180
feedIndex,
181+
feedIndexNext: feedIndex.next(),
181182
}
182183
}
183184

@@ -198,6 +199,7 @@ export function makeFeedReader(requestOptions: BeeRequestOptions, topic: Topic,
198199
return {
199200
payload,
200201
feedIndex,
202+
feedIndexNext: feedIndex.next(),
201203
}
202204
}
203205

@@ -213,6 +215,7 @@ export function makeFeedReader(requestOptions: BeeRequestOptions, topic: Topic,
213215
return {
214216
reference: new Reference(payload.payload.toUint8Array()),
215217
feedIndex: payload.feedIndex,
218+
feedIndexNext: payload.feedIndexNext ?? payload.feedIndex.next(),
216219
}
217220
}
218221

src/utils/typed-bytes.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,11 @@ export class Topic extends Bytes {
195195
}
196196
}
197197

198+
const MAX_UINT64 = new Uint8Array(8).fill(0xff, 0, 8)
199+
198200
export class FeedIndex extends Bytes {
199201
static readonly LENGTH = 8
200-
static readonly MINUS_ONE = new FeedIndex(new Uint8Array(8).fill(0xff, 0, 8))
202+
static readonly MINUS_ONE = new FeedIndex(MAX_UINT64)
201203

202204
constructor(bytes: Uint8Array | string | Bytes) {
203205
super(bytes, 8)
@@ -210,4 +212,12 @@ export class FeedIndex extends Bytes {
210212
toBigInt(): bigint {
211213
return Binary.uint64ToNumber(this.bytes, 'BE')
212214
}
215+
216+
next(): FeedIndex {
217+
if (Binary.equals(this.bytes, MAX_UINT64)) {
218+
return FeedIndex.fromBigInt(0n)
219+
}
220+
221+
return FeedIndex.fromBigInt(this.toBigInt() + 1n)
222+
}
213223
}

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('670000000', 17, { waitForUsable: true })
24+
const response = await bee.createPostageBatch('780000000', 17, { waitForUsable: true })
2525
expect(response.toHex()).toHaveLength(64)
2626

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

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

test/unit/feed-index.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { FeedIndex } from '../../src'
2+
3+
test('FeedIndex.next', () => {
4+
expect(FeedIndex.fromBigInt(0n).next().toBigInt()).toBe(1n)
5+
6+
expect(FeedIndex.MINUS_ONE.next().toBigInt()).toBe(0n)
7+
expect(FeedIndex.MINUS_ONE.next().toBigInt()).toBe(0n) // no mutation
8+
9+
const feedIndex = FeedIndex.fromBigInt(137n)
10+
expect(feedIndex.next().next().next().toBigInt()).toBe(140n)
11+
expect(feedIndex.toBigInt()).toBe(137n) // no mutation
12+
})

0 commit comments

Comments
 (0)