Test failure: Util › Generate content id #7

Closed
opened 2022-11-04 15:21:31 +00:00 by dboreham · 6 comments
Contributor
  ● Util › Generate content id.

    expect(received).toBe(expected) // Object.is equality

    Expected: "bafyreic3p6otn5mf236vkw4p2lxzeij5gmoi3rmcujc3puolhjdtsfwipi"
    Received: "bafyreif7z4lbftuxkj7nu4bl7xihitqvhus3wmoqdkjo7lwv24j6fkfskm"

      42 |   test('Generate content id.', async () => {
      43 |     const cid = await Util.getContentId(watcher.record);
    > 44 |     expect(cid).toBe(watcherId)
         |                 ^
      45 |   });
      46 | }
      47 |

      at src/util.test.ts:44:17
      at fulfilled (src/util.test.ts:5:58)
``` ● Util › Generate content id. expect(received).toBe(expected) // Object.is equality Expected: "bafyreic3p6otn5mf236vkw4p2lxzeij5gmoi3rmcujc3puolhjdtsfwipi" Received: "bafyreif7z4lbftuxkj7nu4bl7xihitqvhus3wmoqdkjo7lwv24j6fkfskm" 42 | test('Generate content id.', async () => { 43 | const cid = await Util.getContentId(watcher.record); > 44 | expect(cid).toBe(watcherId) | ^ 45 | }); 46 | } 47 | at src/util.test.ts:44:17 at fulfilled (src/util.test.ts:5:58) ```
Member

fails for me too (the only one)

fails for me too (the only one)
Member

This is the issue I assumed to be due to switching from sha2-512 to sha2-256 in https://github.com/vulcanize/chiba-clonk/pull/45/files

But, that was a change from sha2-512 to sha2-256 in a pending PR. The old go-ipld-cbor codec that we replaced in that PR was already using sha2-256.

Also, if it were due to a change like this I would expect all tests that are testing CIDs to fail.

I think what happened instead is that the content itself was changed when changing the attribute types in https://github.com/cerc-io/laconicd/pull/40 (watcher registration object was changed) and the corresponding changes were not made here.

Just thoughts right now I still need to test things.

This is the issue I assumed to be due to switching from sha2-512 to sha2-256 in https://github.com/vulcanize/chiba-clonk/pull/45/files But, that was a change from sha2-512 to sha2-256 in a pending PR. The old go-ipld-cbor codec that we replaced in that PR was already using sha2-256. Also, if it were due to a change like this I would expect all tests that are testing CIDs to fail. I think what happened instead is that the content itself was changed when changing the attribute types in https://github.com/cerc-io/laconicd/pull/40 (watcher registration object was changed) and the corresponding changes were not made here. Just thoughts right now I still need to test things.
Member

Due to the amount of overlap between the two CIDs we can conclude that it is not due to the wrong CID version, multihash prefix, or multicontent prefix being used. It either must be due to differences in the contentg itself, or the IPLD codecs or their encapsulating methods are encoding/decoding incorrectly.

Due to the amount of overlap between the two CIDs we can conclude that it is not due to the wrong CID version, multihash prefix, or multicontent prefix being used. It either must be due to differences in the contentg itself, or the IPLD codecs or their encapsulating methods are encoding/decoding incorrectly.
Member

So I’m thinking the problem is:
In the cbor.FromJSON function inside of CIDFromJSONBytes, the JSON is decoded and converted to a CBOR object before it is marshalled into DAG CBOR. It is then these marshalled DAG CBOR bytes that are hashed into a CID.

CIDFromJSONBytesUsingIpldPrime does not appear to be doing this, it appears to be computing the CID off the raw input JSON bytes without converting and encoding it as DAG CBOR first.

So I’m thinking the problem is: In the `cbor.FromJSON` function inside of `CIDFromJSONBytes`, the JSON is [decoded](https://github.com/ipfs/go-ipld-cbor/blob/master/node.go#L461) and converted to a [CBOR object](https://github.com/ipfs/go-ipld-cbor/blob/master/node.go#L466) before it is [marshalled into DAG CBOR](https://github.com/ipfs/go-ipld-cbor/blob/master/node.go#L117). It is then these marshalled DAG CBOR bytes that are hashed into a CID. `CIDFromJSONBytesUsingIpldPrime` does not appear to be doing this, it appears to be computing the CID off the raw input JSON bytes without converting and encoding it as DAG CBOR first.
Member

I think we need to reimplement a helper function like cbor.FromJSON

But instead of using the go-ipld-cbor marshaller here

We would use the go-ipld-prime marshal function

Its possible it is a simple drop in replacement

I think we need to reimplement a helper function like `cbor.FromJSON` But instead of using the [go-ipld-cbor marshaller here](https://github.com/ipfs/go-ipld-cbor/blob/master/node.go#L117) We would use the [go-ipld-prime marshal function](https://github.com/ipld/go-ipld-prime/blob/master/codec/dagcbor/marshal.go#L36) Its possible it is a simple drop in replacement
ABastionOfSanity commented 2023-01-30 22:08:15 +00:00 (Migrated from github.com)
Closed by: https://github.com/cerc-io/laconicd/pull/88
Sign in to join this conversation.
4 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: cerc-io/laconic-sdk#7