Skip to content

Commit

Permalink
Add block encoding test
Browse files Browse the repository at this point in the history
  • Loading branch information
oed committed Mar 23, 2024
1 parent 8c05944 commit 1596e70
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
1 change: 1 addition & 0 deletions test/__fixtures__/signing.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const fixtures = {
bytes.fromHex('a2677061796c6f6164582401701220debd7adb3ce56544d22a6f6b93396f6980a8067c2cc134f0f7801b6331092b956a7369676e61747572657381a26970726f746563746564507b22616c67223a2245533235364b227d697369676e6174757265584043c3dd4c4e40e4dddad24b4edb035d5329ae987952c4d17d4a2dfc22fcec31a4990badf2430f9b24da4a7fe51e2453c7edc0f363b8cb8361bfbe27a3a7b36a5e'),
],
multipleSig: bytes.fromHex('a2677061796c6f6164582401701220debd7adb3ce56544d22a6f6b93396f6980a8067c2cc134f0f7801b6331092b956a7369676e61747572657382a26970726f746563746564507b22616c67223a2245533235364b227d697369676e617475726558404a26065d6ed88be2b16e92252cd9aed25121adac95ef2a5a002e3d180710feaa53b2d656f3d333e82a7c5655045fea95b2062373ef7ed73bcb703625c4eb2bd6a26970726f746563746564507b22616c67223a2245533235364b227d697369676e6174757265584043c3dd4c4e40e4dddad24b4edb035d5329ae987952c4d17d4a2dfc22fcec31a4990badf2430f9b24da4a7fe51e2453c7edc0f363b8cb8361bfbe27a3a7b36a5e'),
withPayload: bytes.fromHex('a2677061796c6f61645901717b2274657374223a227061796c6f6164222c22614c696e6b223a22697066733a2f2f6261667962656967367876356e777068666d76636e656b74706e6f6a747333336a716375616d37626d7965327062353461646e727463636a6c7375222c22617272223a5b22697066733a2f2f6261667962656967367876356e777068666d76636e656b74706e6f6a747333336a716375616d37626d7965327062353461646e727463636a6c7375222c226974656d31222c226974656d32225d2c226e6573746564223a7b22614c696e6b223a22697066733a2f2f6261667962656967367876356e777068666d76636e656b74706e6f6a747333336a716375616d37626d7965327062353461646e727463636a6c7375222c22617272223a5b22697066733a2f2f6261667962656967367876356e777068666d76636e656b74706e6f6a747333336a716375616d37626d7965327062353461646e727463636a6c7375222c226974656d31222c226974656d32225d7d7d6a7369676e61747572657381a26970726f746563746564507b22616c67223a2245533235364b227d697369676e61747572655840218f001e1401d27e50a4ed68a6c7bcddde87ad759fa1f3e35ba89fe6f541ec3932df08f6f9d693f08d711d7e6ce0f6ee0b7a30668dabafc0be9c642c7ed1c4fb'),
},
}
/*eslint-enable */
25 changes: 5 additions & 20 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
/* eslint-env jest */

import * as dagJose from '../src/index.js'
import { createDagJWS } from './signing.test.js'
import { fixtures as sFixtures } from './__fixtures__/signing.fixtures'
import { fixtures as eFixtures } from './__fixtures__/encryption.fixtures'
import { convert as toLegacyIpld } from 'blockcodec-to-ipld-format'
import IPLD from 'ipld'
import ipldInMem from 'ipld-in-memory'
import { CID } from 'multiformats/cid'
import { ES256KSigner } from 'did-jwt'

describe('dag-jose codec', () => {
describe('DagJWS', () => {
Expand All @@ -26,6 +20,9 @@ describe('dag-jose codec', () => {

encoded = dagJose.encode(sFixtures.dagJws.multipleSig)
expect(encoded).toEqual(sFixtures.blockEncoded.multipleSig)

encoded = dagJose.encode(sFixtures.dagJws.withPayload)
expect(encoded).toEqual(sFixtures.blockEncoded.withPayload)
})

it('Decode bytes', () => {
Expand All @@ -35,21 +32,9 @@ describe('dag-jose codec', () => {

decoded = dagJose.decode(sFixtures.blockEncoded.multipleSig)
expect(decoded).toEqual(sFixtures.dagJws.multipleSig)
})

it.skip('IPLD integration', async () => {
const ipld = await ipldInMem(IPLD)
const format = toLegacyIpld(dagJose)
ipld.addFormat(format)
const signer = ES256KSigner(sFixtures.keys[0].priv)
const cidPayload = CID.parse('bagcqcera73rupyla6bauseyk75rslfys3st25spm75ykhvgusqvv2zfqtucq')
const dagJws = await createDagJWS(cidPayload, signer)
const cid = await ipld.put(dagJws, format.codec)
expect(cid.toString()).toEqual(
'bagcqcera5p4hvkei322lg3hp3dvrmndlojwcst3gvq2nhledmv4plt2ore2q'
)
const data = await ipld.get(cid)
expect(data).toEqual(sFixtures.dagJws.oneSig[0])
decoded = dagJose.decode(sFixtures.blockEncoded.withPayload)
expect(decoded).toEqual(sFixtures.dagJws.withPayload)
})
})

Expand Down

0 comments on commit 1596e70

Please sign in to comment.