-
Notifications
You must be signed in to change notification settings - Fork 84
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
Tests for #206 #209
Tests for #206 #209
Conversation
- compare to proto3 behaviour - test for pointers to empty struct and nil pointer Signed-off-by: Liamsi <Liamsi@users.noreply.github.com>
- use []byte{} not []byte(nil) Signed-off-by: Liamsi <Liamsi@users.noreply.github.com>
amino.go
Outdated
@@ -197,7 +197,7 @@ func (cdc *Codec) MarshalBinaryBare(o interface{}) ([]byte, error) { | |||
|
|||
// Encode Amino:binary bytes. | |||
var bz []byte | |||
buf := new(bytes.Buffer) | |||
buf := bytes.NewBuffer([]byte{}) |
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.
I don't think this is necessary, fyi. From the docs,
"The zero value for Buffer is an empty buffer ready to use."
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.
True, it is ready to use but the returned bytes will differ from what go-protobuf returns ([]byte(nil)
vs []byte{}
). Alternatively, we can make the tests treat these cases as equal instead of modifying it here.
The test Maybe it makes sense to also fold the other test into the new framework... I think the tests should ideally unmarshal as well and test for equality before and after... I noticed that we lack proper fuzz tests here in go-amino, so I modified the test cases there, but given how we missed this the first time (e.g. the new test cases would fail w/ the WriteEmpty changes before #206) and that the fuzz tests may still not be complete, I think we should also add unmarshal+and+test+for+equality here as well. |
OK, I've split up the tests and removed the remaining one which didn't really test a separate concern / unit of code. We can still improve them. I would suggest to add table driven test (as you usually do). we But let's get this merged and tested and switch to table-driven tests in a separate PR? I'll see why the |
For the failing fuzzer test: In protobuf this (repeated field containing a Context (failing fuzzer test):
If we look at protobuf's behaviour here: message EmptyMessage {}
// this will generate (part of) the same go-lang code as PointerSlicesStruct
message PtrSliceEmptyMsg {
repeated EmptyMessage ptr = 1;
} when trying to encode what causes the problem on amino's side: psl := p3.PtrSliceEmptyMsg{Ptr: []*p3.EmptyMessage{nil, &p3.EmptyMessage{}}}
pb, err := proto.Marshal(&psl)
|
nil
pointerThe intended behaviour is achieved by your PR @jaekwon 👍 Currently, the test fails with:
TestProto3CompatPtrs: (Click to expand)
The problem here seems orthogonal to what we were trying to do in the initial PR: If we skip (nil-pointer case) in amino we end up with
[]byte(nil)
. In protobuf we end up with[]byte{}
.This is fixed by e90abf1