Skip to content

Commit

Permalink
Merge pull request #651 from application-research/snissn/pinmgrtestpanic
Browse files Browse the repository at this point in the history
fields must be capital letters
  • Loading branch information
snissn authored Dec 4, 2022
2 parents b885c4d + 7997472 commit 0297b01
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 8 additions & 6 deletions pinner/pinmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ type AddrInfoString struct {
Addrs []string
}
type PinningOperationSerialize struct {
po PinningOperation
peers []AddrInfoString
Po PinningOperation
Peers []AddrInfoString
}

func encode_msgpack(po *PinningOperation) ([]byte, error) {
Expand All @@ -377,18 +377,20 @@ func encode_msgpack(po *PinningOperation) ([]byte, error) {
newpeer := AddrInfoString{ID: peers[i].ID, Addrs: newaddrs}
serialPeers = append(serialPeers, newpeer)
}
savedObject := PinningOperationSerialize{po: *po, peers: serialPeers}
return msgpack.Marshal(&savedObject)
savedObject := PinningOperationSerialize{Po: *po, Peers: serialPeers}
bytes, err := msgpack.Marshal(&savedObject)
po.Peers = peers
return bytes, err
}
func decode_msgpack(po_bytes []byte) (*PinningOperation, error) {
var next *PinningOperationSerialize
err := msgpack.Unmarshal(po_bytes, &next)
if err != nil {
log.Fatal(err)
}
po := next.po
po := next.Po
newPeers := []*peer.AddrInfo{}
peers := next.peers
peers := next.Peers
for i := 0; i < len(peers); i++ {
newaddrs := []ma.Multiaddr{}
for j := 0; j < len(peers[i].Addrs); j++ {
Expand Down
8 changes: 6 additions & 2 deletions pinner/pinmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,19 @@ func TestEncodeDecode(t *testing.T) {
fmt.Println(err)
}
peer := []*peer.AddrInfo{{ID: peer.ID("12D3KooWCsxFFH242NZ4bjRMJEVc61La6Ha4yGVNXeEEwpf8KWCX"), Addrs: []ma.Multiaddr{addr}}}
po := &PinningOperation{Peers: peer}
po := &PinningOperation{Peers: peer, Name: "pinning operation name"}
bytes, err := encode_msgpack(po)
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 0297b01

Please sign in to comment.