From 3135307e9e004d58c8d6537ac96a4c85904ce8e7 Mon Sep 17 00:00:00 2001 From: Daniel N <2color@users.noreply.github.com> Date: Wed, 22 Jan 2025 13:11:23 +0100 Subject: [PATCH] test: add test for custom ttl --- packages/ipns/test/publish.spec.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/ipns/test/publish.spec.ts b/packages/ipns/test/publish.spec.ts index 93ad9252..45f1f748 100644 --- a/packages/ipns/test/publish.spec.ts +++ b/packages/ipns/test/publish.spec.ts @@ -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()