Skip to content

Commit

Permalink
test that before and after encode / decode is same value. also restor…
Browse files Browse the repository at this point in the history
…e Peer after serialize
  • Loading branch information
snissn committed Dec 4, 2022
1 parent c24e1c4 commit 7997472
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pinner/pinmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,9 @@ func encode_msgpack(po *PinningOperation) ([]byte, error) {
serialPeers = append(serialPeers, newpeer)
}
savedObject := PinningOperationSerialize{Po: *po, Peers: serialPeers}
return msgpack.Marshal(&savedObject)
bytes, err := msgpack.Marshal(&savedObject)
po.Peers = peers
return bytes, err
}
func decode_msgpack(po_bytes []byte) (*PinningOperation, error) {
var next *PinningOperationSerialize
Expand Down
6 changes: 5 additions & 1 deletion pinner/pinmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,14 @@ func TestEncodeDecode(t *testing.T) {
if err != nil {
fmt.Println(err)
}
po, err = decode_msgpack(bytes)
newpo, err := decode_msgpack(bytes)
if err != nil {
fmt.Println(err)
}
assert.Equal(t, newpo.Name, po.Name, "name doesnt match")
assert.Equal(t, newpo.Peers[0].Addrs[0].String(), po.Peers[0].Addrs[0].String(), "addr doesnt match")
assert.Equal(t, newpo.Peers[0].ID, po.Peers[0].ID, "ID doesnt match")

})
}
func newPinData(name string, userid int, contid int) PinningOperation {
Expand Down

0 comments on commit 7997472

Please sign in to comment.