Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add index param #905

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/feed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
const feedUpdate = await fetchLatestFeedUpdate(requestOptions, owner, topic, options)

return makeHexString(feedUpdate.feedIndexNext, FEED_INDEX_HEX_LENGTH)
} catch (e: any) {

Check warning on line 62 in src/feed/index.ts

View workflow job for this annotation

GitHub Actions / check (16.x)

Unexpected any. Specify a different type
if (e?.response?.status === 404) {
return bytesToHex(makeBytes(8))
}
Expand All @@ -74,10 +74,9 @@
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
Loading