shrub/tests/sys/vane/alef.hoon

292 lines
7.2 KiB
Plaintext
Raw Normal View History

2019-05-25 05:03:33 +03:00
/+ *test
/= alef /: /===/sys/vane/alef
/!noun/
::
2019-05-28 06:39:42 +03:00
=/ vane (alef !>(..zuse))
::
2019-06-21 04:36:16 +03:00
|%
++ move-to-packet
|= =move:alef
^- [=lane:alef =blob:alef]
::
?> ?=([%give %send *] +.move)
[lane blob]:+>+.move
::
++ is-move-send
|= =move:alef
^- ?
?=([%give %send *] card.move)
2019-06-26 01:26:52 +03:00
::
++ snag-packet
|= [index=@ud moves=(list move:alef)]
^- [=lane:alef =blob:alef]
::
%- move-to-packet
%+ snag index
(skim moves is-move-send)
2019-06-21 04:36:16 +03:00
--
2019-05-25 05:03:33 +03:00
|%
++ test-packet-encoding ^- tang
::
=/ =packet:alef
:* [sndr=~nec rcvr=~doznec-doznec]
encrypted=%.n
origin=~
content=[12 13]
==
::
=/ encoded (encode-packet:alef packet)
=/ decoded (decode-packet:alef encoded)
::
%+ expect-eq
!> packet
!> decoded
2019-05-28 06:39:42 +03:00
::
++ test-alien-encounter ^- tang
::
=/ =packet:alef
:* [sndr=~nec rcvr=~doznec-doznec]
encrypted=%.y
origin=~
2019-05-28 06:59:53 +03:00
content=%double-secret
2019-05-28 06:39:42 +03:00
==
=/ =blob:alef (encode-packet:alef packet)
::
=/ event-args
[our=~doznec-doznec eny=0xdead.beef now=~2222.2.2 *sley]
::
=/ lane-foo=lane:alef [%| `@ux``@`%lane-foo]
::
2019-05-28 06:39:42 +03:00
=/ res
(call:(vane event-args) ~[//unix] *type %hear lane-foo blob)
::
;: weld
%+ expect-eq
2019-06-25 02:52:22 +03:00
!> [~[//unix] %pass /alien %j %public-keys ~nec]~
2019-05-28 06:39:42 +03:00
!> -.res
::
%+ expect-eq
!> [%alien [lane-foo packet]~ ~ ~]
2019-05-28 06:39:42 +03:00
!> (~(got by peers.ames-state.+.res) ~nec)
==
::
++ test-send-rcv-message ^- tang
::
=/ alice vane
=/ bob vane
::
=. crypto-core.ames-state.alice (pit:nu:crub:crypto 512 (shaz 'alice'))
=. crypto-core.ames-state.bob (pit:nu:crub:crypto 512 (shaz 'bob'))
::
=/ alice-pub pub:ex:crypto-core.ames-state.alice
=/ alice-sec sec:ex:crypto-core.ames-state.alice
=/ bob-pub pub:ex:crypto-core.ames-state.bob
=/ bob-sec sec:ex:crypto-core.ames-state.bob
::
=/ alice-sym (derive-symmetric-key:alef bob-pub alice-sec)
=/ bob-sym (derive-symmetric-key:alef alice-pub bob-sec)
::
?> =(alice-sym bob-sym)
::
=. life.ames-state.alice 2
=. peers.ames-state.alice
%+ ~(put by peers.ames-state.alice) ~doznec-doznec
:- %known
^- peer-state:alef
:- :* symmetric-key=bob-sym
life=3
public-key=bob-pub
sponsor=~marzod
==
:* [~ direct=%.y `lane:alef`[%& ~nec]]
*ossuary:alef
*(map bone:alef message-pump-state:alef)
*(map bone:alef message-still-state:alef)
2019-06-19 02:38:20 +03:00
*(set [bone:alef message-num:alef])
==
::
=. life.ames-state.bob 3
=. peers.ames-state.bob
%+ ~(put by peers.ames-state.bob) ~nec
:- %known
^- peer-state:alef
:- :* symmetric-key=alice-sym
life=2
public-key=alice-pub
sponsor=~nec
==
:* [~ direct=%.y `lane:alef`[%| `@`%lane-bar]]
*ossuary:alef
*(map bone:alef message-pump-state:alef)
*(map bone:alef message-still-state:alef)
2019-06-19 02:38:20 +03:00
*(set [bone:alef message-num:alef])
==
::
=/ alice-core (alice ~nec 0xdead.beef ~2222.2.2 *sley)
::
=/ res1
%- call:alice-core
2019-06-21 00:46:31 +03:00
[~[/alice] ** %memo ~doznec-doznec /g/talk [%get %post]]
::
::~& res1=-.res1
2019-06-11 23:37:30 +03:00
::
=/ bob-core (bob ~doznec-doznec 0xbeef.dead ~2222.2.3 *sley)
::
=/ res2
%- call:bob-core
2019-06-26 01:26:52 +03:00
[~[/bob] ** %hear (snag-packet 0 -.res1)]
::
::~& res2=-.res2
2019-06-11 23:37:30 +03:00
::
=. bob-core (+.res2 ~doznec-doznec 0xbeef.dead ~2222.2.4 *sley)
::
=/ res3
%- take:bob-core
2019-06-20 10:21:37 +03:00
[/bone/~nec/1 ~[/bob] ** %g %done ~]
::
::~& res3=-.res3
::
=. alice-core (+.res1 ~nec 0xdead.beef ~2222.2.5 *sley)
::
=/ res4
%- call:alice-core
2019-06-26 01:26:52 +03:00
[~[/alice] ** %hear (snag-packet 0 -.res3)]
2019-06-21 00:46:31 +03:00
::
=. bob-core (+.res3 ~doznec-doznec 0xbeef.dead ~2222.2.6 *sley)
::
=/ res5
%- take:bob-core
[/bone/~nec/1 ~[/bob] ** %g %memo /g/talk [%post 'first1!!']]
::
2019-06-26 01:26:52 +03:00
::~& res5=-.res5
::
=. alice-core (+.res4 ~nec 0xdead.beef ~2222.2.7 *sley)
::
=/ res6
%- call:alice-core
2019-06-26 01:26:52 +03:00
[~[/alice] ** %hear (snag-packet 0 -.res5)]
::
2019-06-26 01:26:52 +03:00
::~& res6=-.res6
::
=. bob-core (+.res5 ~doznec-doznec 0xbeef.dead ~2222.2.8 *sley)
::
=/ res7
%- call:bob-core
2019-06-26 01:26:52 +03:00
[~[/bob] ** %hear (snag-packet 0 -.res6)]
::
2019-06-26 01:26:52 +03:00
::~& res7=-.res7
::
%+ expect-eq
2019-06-20 10:21:37 +03:00
!> :~ :+ ~[/alice] %give [%done error=~]
:+ ~[/alice] %pass
[/pump/~doznec-doznec/0 %b %rest ~2222.2.2..00.00.05]
==
!> -.res4
2019-06-21 04:36:16 +03:00
::
++ test-nack ^- tang
::
=/ alice vane
=/ bob vane
::
=. crypto-core.ames-state.alice (pit:nu:crub:crypto 512 (shaz 'alice'))
=. crypto-core.ames-state.bob (pit:nu:crub:crypto 512 (shaz 'bob'))
::
=/ alice-pub pub:ex:crypto-core.ames-state.alice
=/ alice-sec sec:ex:crypto-core.ames-state.alice
=/ bob-pub pub:ex:crypto-core.ames-state.bob
=/ bob-sec sec:ex:crypto-core.ames-state.bob
::
=/ alice-sym (derive-symmetric-key:alef bob-pub alice-sec)
=/ bob-sym (derive-symmetric-key:alef alice-pub bob-sec)
::
?> =(alice-sym bob-sym)
::
=. life.ames-state.alice 2
=. peers.ames-state.alice
%+ ~(put by peers.ames-state.alice) ~doznec-doznec
:- %known
^- peer-state:alef
:- :* symmetric-key=bob-sym
life=3
public-key=bob-pub
sponsor=~marzod
2019-06-21 04:36:16 +03:00
==
:* [~ direct=%.y `lane:alef`[%& ~nec]]
2019-06-21 04:36:16 +03:00
*ossuary:alef
*(map bone:alef message-pump-state:alef)
*(map bone:alef message-still-state:alef)
*(set [bone:alef message-num:alef])
==
::
=. life.ames-state.bob 3
=. peers.ames-state.bob
%+ ~(put by peers.ames-state.bob) ~nec
:- %known
^- peer-state:alef
:- :* symmetric-key=alice-sym
life=2
public-key=alice-pub
sponsor=~nec
2019-06-21 04:36:16 +03:00
==
:* [~ direct=%.y `lane:alef`[%| `@`%lane-bar]]
2019-06-21 04:36:16 +03:00
*ossuary:alef
*(map bone:alef message-pump-state:alef)
*(map bone:alef message-still-state:alef)
*(set [bone:alef message-num:alef])
==
::
=/ alice-core (alice ~nec 0xdead.beef ~2222.2.2 *sley)
::
=/ res1
%- call:alice-core
[~[/alice] ** %memo ~doznec-doznec /g/talk [%get %post]]
::
::~& res1=-.res1
::
=/ bob-core (bob ~doznec-doznec 0xbeef.dead ~2222.2.3 *sley)
::
=/ res2
%- call:bob-core
2019-06-26 01:26:52 +03:00
[~[/bob] ** %hear (snag-packet 0 -.res1)]
2019-06-21 04:36:16 +03:00
::
::~& res2=-.res2
::
=. bob-core (+.res2 ~doznec-doznec 0xbeef.dead ~2222.2.4 *sley)
::
=/ =error:alef [%flub [%leaf "sinusoidal repleneration"]~]
::
=/ res3
%- take:bob-core
[/bone/~nec/1 ~[/bob] ** %g %done `error]
::
2019-06-26 01:26:52 +03:00
::~& res3=-.res3
2019-06-21 04:36:16 +03:00
::
=. alice-core (+.res1 ~nec 0xdead.beef ~2222.2.5 *sley)
2019-06-26 01:26:52 +03:00
:: process first (nack) packet
2019-06-21 04:36:16 +03:00
::
=/ res4
%- call:alice-core
2019-06-26 01:26:52 +03:00
[~[/alice] ** %hear (snag-packet 0 -.res3)]
2019-06-21 04:36:16 +03:00
::
2019-06-26 01:26:52 +03:00
::~& res4=-.res4
2019-06-21 04:36:16 +03:00
::
=. alice-core (+.res4 ~nec 0xdead.beef ~2222.2.6 *sley)
2019-06-26 01:26:52 +03:00
:: process second (naxplanation message) packet
2019-06-21 04:36:16 +03:00
::
=/ res5
%- call:alice-core
2019-06-26 01:26:52 +03:00
[~[/alice] ** %hear (snag-packet 1 -.res3)]
2019-06-21 04:36:16 +03:00
::
2019-06-26 01:26:52 +03:00
::~& res5=-.res5
2019-06-21 04:36:16 +03:00
::
=. bob-core (+.res3 ~doznec-doznec 0xbeef.dead ~2222.2.7 *sley)
::
=/ res6
%- call:bob-core
2019-06-26 01:26:52 +03:00
[~[/bob] ** %hear (snag-packet 0 -.res5)]
2019-06-21 04:36:16 +03:00
::
2019-06-26 01:26:52 +03:00
::~& res6=-.res6
2019-06-21 04:36:16 +03:00
::
~
2019-05-25 05:03:33 +03:00
--