WHYWDNSL67TTB2AGAUACXERJ6X54YMNYVC32KJQFEXFFRYA4K3HQC TestData = testrecs:test_hash_response(),TestObj = proplists:get_value(obj, TestData),Bin = proplists:get_value(binary, TestData),Header = wire:decode_response_header(Bin),?assert(proplists:get_value(msgLen, Header) == maps:get(<<"msgLen">>, TestObj)),?assert(proplists:get_value(msgType, Header) == maps:get(<<"msgType">>, TestObj)),
[{binary, Bin}, {obj, TestObj}] = examples:hash_response(),[{header, Header}, {ttl, Ttl}, {hashes, Hashes}] = wire:decode_hash_response(Bin),?assert(proplists:get_value(msgLen, Header) =:= maps:get(<<"msgLen">>, TestObj)),?assert(proplists:get_value(msgType, Header) =:= maps:get(<<"msgType">>, TestObj)),
% ping_test(Config) ->% Host = get_value(hostname, Config, "localhost"),% {ok, NewSbotClient} = ssb_client:start_link(Host, remote_long_pk()),% Now = erlang:system_time(millisecond),% Time = ssb_client:send(NewSbotClient, ping()),% End = binary_to_integer(jiffy:decode(Time)),% ?assert((End - Now) < 5),% Config.
cancel_request_test() ->[{binary, Bin}, {obj, TestObj}] = examples:cancel_request(),[{header, Header}, {ttl, Ttl}, {cancelid, CancelId}] = wire:decode_cancel_request(Bin),?assert(proplists:get_value(msgLen, Header) =:= maps:get(<<"msgLen">>, TestObj)),?assert(proplists:get_value(msgType, Header) =:= maps:get(<<"msgType">>, TestObj)),CancelId = hex:hexstr_to_bin(binary_to_list(maps:get(<<"cancelid">>, TestObj))),ReqId = hex:hexstr_to_bin(binary_to_list(maps:get(<<"reqid">>, TestObj))),?assert(proplists:get_value(requestId, Header) =:= ReqId),?assert(Ttl =:= 1).
% whoami_test(Config) ->% Host = get_value(hostname, Config, "localhost"),% {ok, NewSbotClient} = ssb_client:start_link(Host, remote_long_pk()),% {WhoAmI} = jiffy:decode(ssb_client:send(NewSbotClient, whoami_req())),% ?assert(keys:pub_key_disp() == ?pgv(<<"id">>, WhoAmI)),% Config.% remote_long_pk() ->% base64:decode(keys:pub_key()).% ping() ->% Flags = rpc_processor:create_flags(1,0,2),% Body = jiffy:encode({[{<<"name">>,[<<"gossip">>,<<"ping">>]},% {<<"args">>,[{[{<<"timeout">>, 300000}]}]},% {<<"type">>,<<"duplex">>}]}),% Header = rpc_processor:create_header(Flags, size(Body), 1),% utils:combine(Header, Body).% whoami_req() ->% Flags = rpc_processor:create_flags(1,0,2),% Body = jiffy:encode({[{<<"name">>,[?whoami]},% {<<"args">>,[]},% {<<"type">>,<<"async">>}]}),% Header = rpc_processor:create_header(Flags, size(Body), 1),% utils:combine(Header, Body).
channel_time_range_request_test() ->[{binary, Bin}, {obj, TestObj}] = examples:channel_time_range_request(),Decoded = wire:decode_channel_time_range_request(Bin),[{header, Header}, {ttl, Ttl},{channel, Channel},{timestart, TimeStart},{timeend, TimeEnd},{limit, Limit}] = Decoded,?assert(proplists:get_value(msgLen, Header) =:= maps:get(<<"msgLen">>, TestObj)),?assert(proplists:get_value(msgType, Header) =:= maps:get(<<"msgType">>, TestObj)),ReqId = hex:hexstr_to_bin(binary_to_list(maps:get(<<"reqid">>, TestObj))),?assert(proplists:get_value(requestId, Header) =:= ReqId),?assert(Channel =:= maps:get(<<"channel">>, TestObj)),?assert(TimeStart =:= maps:get(<<"timeStart">>, TestObj)),?assert(TimeEnd =:= maps:get(<<"timeEnd">>, TestObj)),?assert(Limit =:= maps:get(<<"limit">>, TestObj)),?assert(Ttl =:= 1).
-module(testrecs).-export([test_hash_response/0]).test_hash_response() ->D = <<"{\"name\":\"hashresponse\",\"type\":\"response\",\"id\":2,\"binary\":\"6b020000000095050429010320265674e8aac2dfddd78f86fe5a3dd68d976ca3f5ba23645ec7381480921d0d10705340e5528f2ef03a6797b72b1bb9f37f9009ad408247387c4bcc4d2a3371af700793dd51d4cb3c18a6df46f88bfe1665fba9b277487ddecd1e031441d69d\",\"obj\":{\"msgLen\":107,\"msgType\":2,\"reqid\":\"95050429\",\"ttl\":1,\"hashes\":[\"20265674e8aac2dfddd78f86fe5a3dd68d976ca3f5ba23645ec7381480921d0d\",\"10705340e5528f2ef03a6797b72b1bb9f37f9009ad408247387c4bcc4d2a3371\",\"af700793dd51d4cb3c18a6df46f88bfe1665fba9b277487ddecd1e031441d69d\"]}}">>,J = jsone:decode(D),#{ <<"binary">> := Bin, <<"obj">> := Obj } = J,[{binary, hex:hexstr_to_bin(binary_to_list(Bin))},{obj, Obj}].% {% "name": "hash response",% "type": "response",% "id": 2,% "binary": "6b020000000095050429010320265674e8aac2dfddd78f86fe5a3dd68d976ca3f5ba23645ec7381480921d0d10705340e5528f2ef03a6797b72b1bb9f37f9009ad408247387c4bcc4d2a3371af700793dd51d4cb3c18a6df46f88bfe1665fba9b277487ddecd1e031441d69d",% "obj": {% "msgLen": 107,% "msgType": 2,% "reqid": "95050429",% "ttl": 1,% "hashes": [% "20265674e8aac2dfddd78f86fe5a3dd68d976ca3f5ba23645ec7381480921d0d",% "10705340e5528f2ef03a6797b72b1bb9f37f9009ad408247387c4bcc4d2a3371",% "af700793dd51d4cb3c18a6df46f88bfe1665fba9b277487ddecd1e031441d69d"% ]% }% }
decode_hash_response(Data) ->Header = decode_response_header(Data),Payload = proplists:get_value(payload, Header),{Ttl, Rest} = decode_varint(Payload),{HashCount, Rest2} = decode_varint(Rest),Hashes = [Hash || <<Hash:32/binary>> <= Rest2],case length(Hashes) =:= HashCount offalse -> erlang:error("invalid hash_count");true -> [{header, proplists:delete(payload, Header)},{ttl, Ttl},{hashes, Hashes}]end.decode_cancel_request(Data) ->Header = decode_response_header(Data),Payload = proplists:get_value(payload, Header),{Ttl, <<CancelId:4/binary>>} = decode_varint(Payload),[ {header, proplists:delete(payload, Header)}, {ttl, Ttl}, {cancelid, CancelId}].decode_channel_time_range_request(Data) ->Header = decode_response_header(Data),Payload = proplists:get_value(payload, Header),{Ttl, Rest} = decode_varint(Payload),{ChannelLen, Rest2} = decode_varint(Rest),<<Channel:ChannelLen/binary, Rest3/binary>> = Rest2,{TimeStart, Rest4} = decode_varint(Rest3),{TimeEnd, Rest5} = decode_varint(Rest4),{Limit, <<>>} = decode_varint(Rest5),[ {header, proplists:delete(payload, Header)}, {ttl, Ttl}, {channel, Channel}, {timestart, TimeStart}, {timeend, TimeEnd}, {limit, Limit}].