Skip to content

Commit

Permalink
fix: add index param to feed writer (#905)
Browse files Browse the repository at this point in the history
* fix: add index param

* test: adjust

---------

Co-authored-by: Levente Kiss <levente.kiss@solarpunk.bzz>
  • Loading branch information
LevilkTheReal and Levente Kiss authored Apr 24, 2024
1 parent 1d29ce9 commit 077dcb7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/feed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ export async function updateFeed(
reference: BytesReference,
postageBatchId: BatchId,
options?: FeedUploadOptions,
index: Index = 'latest',
): Promise<Reference> {
const ownerHex = makeHexEthAddress(signer.address)
const nextIndex = index === 'latest' ? await findNextIndex(requestOptions, ownerHex, topic, options) : index
const nextIndex = options?.index || (await findNextIndex(requestOptions, ownerHex, topic, options))

const identifier = makeFeedIdentifier(topic, nextIndex)
const at = options?.at ?? Date.now() / 1000.0
Expand Down
10 changes: 5 additions & 5 deletions test/integration/feed/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai'
import { makeContentAddressedChunk } from '../../../src/chunk/cac'
import { makePrivateKeySigner } from '../../../src/chunk/signer'
import { downloadFeedUpdate, findNextIndex, Index, updateFeed } from '../../../src/feed'
import { downloadFeedUpdate, FeedUploadOptions, findNextIndex, updateFeed } from '../../../src/feed'
import * as chunkAPI from '../../../src/modules/chunk'
import { fetchLatestFeedUpdate } from '../../../src/modules/feed'
import type { BeeRequestOptions, BytesReference, PrivateKeyBytes, Signer, Topic } from '../../../src/types'
Expand All @@ -27,11 +27,11 @@ async function tryUploadFeedUpdate(
options: BeeRequestOptions,
signer: Signer,
topic: Topic,
index: Index,
reference: BytesReference,
feedOptions?: FeedUploadOptions,
) {
try {
await updateFeed(options, signer, topic, reference, getPostageBatch(), undefined, index)
await updateFeed(options, signer, topic, reference, getPostageBatch(), feedOptions)
} catch (e: any) {
if (e?.response?.status === 409) {
// ignore conflict errors when uploading the same feed update twice
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('feed', () => {
this.timeout(21000)

const uploadedChunk = await uploadChunk(BEE_KY_OPTIONS, 0)
await tryUploadFeedUpdate(BEE_KY_OPTIONS, signer, topic, 0, uploadedChunk)
await tryUploadFeedUpdate(BEE_KY_OPTIONS, signer, topic, uploadedChunk, { index: 0 })

const feedUpdate = await fetchLatestFeedUpdate(BEE_KY_OPTIONS, owner, topic)

Expand All @@ -79,7 +79,7 @@ describe('feed', () => {

for (let i = 0; i < numUpdates; i++) {
const referenceI = new Uint8Array([i, ...referenceBytes.slice(1)]) as Bytes<32>
await tryUploadFeedUpdate(BEE_KY_OPTIONS, signer, multipleUpdateTopic, i, referenceI)
await tryUploadFeedUpdate(BEE_KY_OPTIONS, signer, multipleUpdateTopic, referenceI, { index: i })
}

for (let i = 0; i < numUpdates; i++) {
Expand Down

0 comments on commit 077dcb7

Please sign in to comment.