Skip to content

Commit

Permalink
add tests to ensure the ttl is correctly computed
Browse files Browse the repository at this point in the history
  • Loading branch information
2color committed Mar 26, 2024
1 parent 569a076 commit 5e0f4cd
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/verified-fetch/test/utils/parse-url-string.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,40 @@ describe('parseUrlString', () => {
})
})

describe('TTL', () => {
const oneHourInSeconds = 3600
const oneHourInNanoseconds = BigInt(3600 * 1e9)

it('should return the correct TTL from the DNS Answer ', async () => {
ipns.resolveDNSLink.withArgs('newdomain.com').resolves({
cid: CID.parse('QmQJ8fxavY54CUsxMSx9aE9Rdcmvhx8awJK2jzJp4iAqCr'),
path: '',
answer: {
TTL: oneHourInSeconds,
type: 16,
name: 'n/a',
data: 'n/a'
}
})

const result = await parseUrlString({ urlString: 'ipns://newdomain.com/', ipns, logger })
expect(result.ttl).to.equal(oneHourInSeconds)
})

it('should return the correct TTL from the IPNS answer', async () => {
const testPeerId = await createEd25519PeerId()

ipns.resolve.withArgs(matchPeerId(testPeerId)).resolves({
cid: CID.parse('QmQJ8fxavY54CUsxMSx9aE9Rdcmvhx8awJK2jzJp4iAqCr'),
path: '',
record: ipnsRecordStub({ peerId: testPeerId, ttl: oneHourInNanoseconds })
})

const result = await parseUrlString({ urlString: `ipns://${testPeerId}`, ipns, logger })
expect(result.ttl).to.equal(3600)
})
})

describe('/ipfs/<CID> URLs', () => {
it('should parse an IPFS Path with a CID only', async () => {
await assertMatchUrl(
Expand Down

0 comments on commit 5e0f4cd

Please sign in to comment.