-
Notifications
You must be signed in to change notification settings - Fork 38
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
chore: add tests to verify allowable data layouts #58
Conversation
Thank you for submitting this PR!
Getting other community members to do a review would be great help too on complex PRs (you can ask in the chats/forums). If you are unsure about something, just leave us a comment.
We currently aim to provide initial feedback/triaging within two business days. Please keep an eye on any labelling actions, as these will indicate priorities and status of your contribution. |
/cc @mvdan for review |
OK, I figured out what to do with this, see summary in ipld/specs#297 (comment) The important difference is that I've been thinking of I've also ditched my custom printer and gone with There are two differences in the tests here and in JS where we do proper Data Model form checks:
We should do both of those things in go-ipld-prime-proto. @mvdan ptal at my Go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM. Using a map and then json sounds fine to me. You still have a bit of code, but there are less footguns when it comes to getting the encoding wrong. And the map gives you the "nil vs absent" difference that you want, I assume.
At the Go level, I left some comments below. They're mostly about making the tests a bit nicer to use and maintain, not really about what they do. The only other point that comes to mind is that each of the tests is just running verifyRoundTrip
on different input/output, so you would save a lot of boilerplate by using table-driven tests: https://github.com/golang/go/wiki/TableDrivenTests. Up to you if it's worth it at this point, though.
I assume my approval isn't counting because I don't have enough permissions in the ipfs org. I'm not sure if that matters :) |
Thanks for the link to TableDrivenTests -- I went googling "data driven testing golang" for this one because I felt the need. The problem I'm having is that some of these pieces of data can't be created as a top level |
Hm, I'm pretty sure you don't need multiple steps there; you could just do:
If you really did need multiple steps, such as when creating a cycle, you could use a constructor func:
|
OK, I've got it sorted now. It's all the pointers that get in the way of pulling these things into a top-level variable. But I've solved that by also making the things that become pointers top level variables so I can
How does it look now @mvdan? |
Yeah, you can't do
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM
@aschmahmann I suspect you might be the one to ping about getting this merged now? This doesn't change the implementation, just adds tests that explore the edges of the forms for the protobuf data. These are mirrored in the new dag-pb JavaScript implementation @ https://github.com/ipld/js-dag-pb/blob/master/test/test-compat.js and a new Go implementation currently @ https://github.com/rvagg/go-dagpb/blob/master/compat_test.go |
discovered I have commit access and can just merge this myself |
chore: add tests to verify allowable data layouts This commit was moved from ipfs/go-merkledag@8f475e5
Trying to pin down a precise schema for DAG-PB.
Ref: ipld/specs#297
Relevant findings:
nil
.Links:[]
is not possible, zero-lengthLinks
becomesnil
, this isn't the case forName
orHash
when they are zero length. This also means{ Data: nil, Links: [] } === { Data: nil, Links: nil } === {}
.{ Data: nil, Links: nil }
). I'm not really sure what to do with that information but it's worth noting. I'm sure others already know this but perhaps this should go into the DAG-PB spec if it's allowable by other components of the IPLD stack. So there would be a canonical CID for an empty PB block for any given multihash. That would bebafybeihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku
orQmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n
for SHA2-256. And yep, the latter in Google gives us patch add-link fails to write result to blockstore kubo#1925. That issue also has a discussion where it's stated that zero-length byte arrays should be encoded asnil
when marshalling, but it looks like that never happened here at least.Some of this is at odds with js-ipld-dag-pb, but I'll take that discussion to ipld/specs#297, nothing needs to change here.