Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log model stream id #1176

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/ancillary/__tests__/anchor-request-params-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const TIMESTAMP_ISO = '2023-01-25T17:32:42.971Z'

const FAKE_CACAO='test' // the p.domain of the cacao in our test blob

const FAKE_MODEL='kjzl6hvfrbw6c5ws6n17gx7zgb6veprsbb0b2m1x7x026rorhhu0mtuqz4d5zjn'

const LEGACY_REQUEST_EXAMPLE = mockRequest({
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -66,6 +68,15 @@ const CAR_FILE_REQUEST_EXAMPLE_SIGNED_GENESIS_WITH_CACAO = mockRequest({
),
})

const CAR_FILE_REQUEST_EXAMPLE_WITH_MODEL = mockRequest({
headers: {
'Content-Type': 'application/vnd.ipld.car',
},
body: bases['base64url'].decode(
'uOqJlcm9vdHOB2CpYJQABcRIgQtL_mq5jv6WdKws8V3DwrUhSUnms7JUdb0aT_3sFXDFndmVyc2lvbgGqAQFxEiBC0v-armO_pZ0rCzxXcPCtSFJSeazslR1vRpP_ewVcMaNjdGlw2CpYJgABhQESIFXEyGyqkZ6hvYy558-KIMaMkhW5OEvuCqxXzx3z5_a-aHN0cmVhbUlkWCjOAQMBhQESIFXEyGyqkZ6hvYy558-KIMaMkhW5OEvuCqxXzx3z5_a-aXRpbWVzdGFtcHgYMjAyMy0xMC0yM1QxNjo0MzowOS43MTlaugIBhQESIFXEyGyqkZ6hvYy558-KIMaMkhW5OEvuCqxXzx3z5_a-omdwYXlsb2Fk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VyaWZpY2F0aW9uTWV0aG9keGlkaWQ6a2V5Ono2TWtnaHZHSExvYkxFZGoxYmdSTGhTNExQR0pBdmJNQTF0bjJ6Y1J5cW1ZVTVMQyN6Nk1rZ2h2R0hMb2JMRWRqMWJnUkxoUzRMUEdKQXZiTUExdG4yemNSeXFtWVU1TENmaGVhZGVypGNzZXBlbW9kZWxlbW9kZWxYKM4BAgGFARIgI_-XRam_FzV3nlPWMV3YjqwzrNP3leux4_Fjpjd_sDNmdW5pcXVlTCkRWqdoKgigCq5F02tjb250cm9sbGVyc4F4OGRpZDprZXk6ejZNa3N3bXg2QjhCa3FhMUJ6a3NvdmNjWUhOZGtxc3U5R0hHUmJjMW1ucWg5UlJ4'
),
})


const CAR_FILE_INVALID = mockRequest({
headers: {
Expand Down Expand Up @@ -125,6 +136,16 @@ describe('AnchoRequestParamsParser', () => {

const params: RequestAnchorParams = (validation as Right<RequestAnchorParams>).right
expect(params.cacaoDomain).toEqual(FAKE_CACAO)
expect((params as RequestAnchorParamsV2).genesisFields.model).toBeUndefined()
})


test('parses CAR file with model properly', () => {
const validation = parser.parse(CAR_FILE_REQUEST_EXAMPLE_WITH_MODEL as ExpReq)
expect(isRight(validation)).toEqual(true)

const params: RequestAnchorParams = (validation as Right<RequestAnchorParams>).right
expect((params as RequestAnchorParamsV2).genesisFields.model.toString()).toEqual(FAKE_MODEL)
})

test('isleft indicates invalid car file', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/services/request-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class RequestService {
did,
schema: genesisFields?.schema,
family: genesisFields?.family,
model: genesisFields?.model,
model: genesisFields?.model?.toString() ?? '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually wait, I'm not sure this will actually log the right thing. Have you tested this with a real MID stream's genesis commit? I think you need to do StreamID.fromBytes(genesisFields.model).toString()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% positive though, so if you tested it with just calling toString on the Uint8Array and it printed the proper model streamid string we expect, then it's fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, so the thing is, because we decode it actually model is an object.

so, the structure of 'model' depends on whether it was run thru decode or not



carFile.get(genesisJWS.link).header.model

Uint8Array(40)


decode(IpfsGenesis, carFile.get(genesisJWS.link)).header.model

{ _tag: Symbol(@ceramicnetwork/streamid/StreamID),

_type: 2,

_cid: CID }


and in our case, it is using decode

const genesis = decode(IpfsGenesis, genesisRecord)



const genesis = decode(IpfsGenesis, genesisRecord)
return genesis.header

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stbrody fyi ^^ so i commited your change, will merge when it completes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, we use the codec to deserialize the genesis commit, so it's already a StreamID instance by the time we get here. Sounds good.

stream: request.streamId,
origin: request.origin,
cacao: 'cacaoDomain' in params ? params.cacaoDomain : '',
Expand Down