Skip to content

Commit

Permalink
test: add test for custom ttl
Browse files Browse the repository at this point in the history
  • Loading branch information
2color committed Jan 22, 2025
1 parent c3a8ce3 commit 3135307
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions packages/ipns/test/publish.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,35 @@ describe('publish', () => {
expect(ipnsEntry).to.have.property('ttl', 3_600_000_000_000n) // 1 hour
})

it('should publish an IPNS record with a custom ttl params', async function () {
it('should publish an IPNS record with a custom lifetime params', async function () {
const key = await generateKeyPair('Ed25519')
const lifetime = 123000
// lifetime is used to calculate the validity timestamp
const ipnsEntry = await name.publish(key, cid, {
lifetime
})

expect(ipnsEntry).to.have.property('sequence', 1n)
expect(ipnsEntry).to.have.property('ttl', 3_600_000_000_000n)

// Ignore the milliseconds after the dot 2025-01-22T12:07:33.650000000Z
const expectedValidity = new Date(Date.now() + lifetime).toISOString().split('.')[0]

expect(ipnsEntry.validity.split('.')[0]).to.equal(expectedValidity)

expect(heliaRouting.put.called).to.be.true()
expect(customRouting.put.called).to.be.true()
})

it('should publish an IPNS record with a custom ttl params', async function () {
const key = await generateKeyPair('Ed25519')
const ttl = 1000 // override the default ttl

const ipnsEntry = await name.publish(key, cid, {
ttl
})

expect(ipnsEntry).to.have.property('sequence', 1n)
expect(ipnsEntry).to.have.property('ttl', BigInt(ttl * 1e+6))

expect(heliaRouting.put.called).to.be.true()
expect(customRouting.put.called).to.be.true()
Expand Down

0 comments on commit 3135307

Please sign in to comment.