Skip to content

Commit 3135307

Browse files
committed
test: add test for custom ttl
1 parent c3a8ce3 commit 3135307

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

packages/ipns/test/publish.spec.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,35 @@ describe('publish', () => {
4848
expect(ipnsEntry).to.have.property('ttl', 3_600_000_000_000n) // 1 hour
4949
})
5050

51-
it('should publish an IPNS record with a custom ttl params', async function () {
51+
it('should publish an IPNS record with a custom lifetime params', async function () {
5252
const key = await generateKeyPair('Ed25519')
5353
const lifetime = 123000
54+
// lifetime is used to calculate the validity timestamp
5455
const ipnsEntry = await name.publish(key, cid, {
5556
lifetime
5657
})
5758

5859
expect(ipnsEntry).to.have.property('sequence', 1n)
59-
expect(ipnsEntry).to.have.property('ttl', 3_600_000_000_000n)
60+
61+
// Ignore the milliseconds after the dot 2025-01-22T12:07:33.650000000Z
62+
const expectedValidity = new Date(Date.now() + lifetime).toISOString().split('.')[0]
63+
64+
expect(ipnsEntry.validity.split('.')[0]).to.equal(expectedValidity)
65+
66+
expect(heliaRouting.put.called).to.be.true()
67+
expect(customRouting.put.called).to.be.true()
68+
})
69+
70+
it('should publish an IPNS record with a custom ttl params', async function () {
71+
const key = await generateKeyPair('Ed25519')
72+
const ttl = 1000 // override the default ttl
73+
74+
const ipnsEntry = await name.publish(key, cid, {
75+
ttl
76+
})
77+
78+
expect(ipnsEntry).to.have.property('sequence', 1n)
79+
expect(ipnsEntry).to.have.property('ttl', BigInt(ttl * 1e+6))
6080

6181
expect(heliaRouting.put.called).to.be.true()
6282
expect(customRouting.put.called).to.be.true()

0 commit comments

Comments
 (0)