urbit/pkg/arvo/tests/sys/vane/ames.hoon

338 lines
8.8 KiB
Plaintext
Raw Normal View History

2019-05-25 05:03:33 +03:00
/+ *test
2020-04-19 02:53:45 +03:00
/= ames /sys/vane/ames
:: construct some test fixtures
2019-05-25 05:03:33 +03:00
::
2019-11-27 11:25:56 +03:00
=/ vane (ames !>(..zuse))
2019-05-28 06:39:42 +03:00
::
2019-08-14 00:30:15 +03:00
=/ nec vane
2019-11-27 09:15:05 +03:00
=/ bud vane
2020-12-01 17:51:14 +03:00
=/ comet vane
::
2020-12-01 17:51:14 +03:00
=. our.nec ~nec
=. now.nec ~1111.1.1
=. eny.nec 0xdead.beef
=. life.ames-state.nec 2
2020-12-01 22:14:36 +03:00
=. rof.nec |=(* ``[%noun !>(*(list turf))])
2019-08-14 00:30:15 +03:00
=. crypto-core.ames-state.nec (pit:nu:crub:crypto 512 (shaz 'nec'))
=/ nec-pub pub:ex:crypto-core.ames-state.nec
=/ nec-sec sec:ex:crypto-core.ames-state.nec
2020-12-01 17:51:14 +03:00
::
=. our.bud ~bud
=. now.bud ~1111.1.1
=. eny.bud 0xbeef.dead
=. life.ames-state.bud 3
2020-12-01 22:14:36 +03:00
=. rof.bud |=(* ``[%noun !>(*(list turf))])
2020-12-01 17:51:14 +03:00
=. crypto-core.ames-state.bud (pit:nu:crub:crypto 512 (shaz 'bud'))
2019-11-27 09:15:05 +03:00
=/ bud-pub pub:ex:crypto-core.ames-state.bud
=/ bud-sec sec:ex:crypto-core.ames-state.bud
::
2020-12-01 17:51:14 +03:00
=. our.comet ~bosrym-podwyl-magnes-dacrys--pander-hablep-masrym-marbud
=. now.comet ~1111.1.1
=. eny.comet 0xbeef.cafe
2020-12-01 22:14:36 +03:00
=. rof.comet |=(* ``[%noun !>(*(list turf))])
2020-12-01 17:51:14 +03:00
=. crypto-core.ames-state.comet
%- nol:nu:crub:crypto
0w9N.5uIvA.Jg0cx.NCD2R.o~MtZ.uEQOB.9uTbp.6LHvg.0yYTP.
3q3td.T4UF0.d5sDL.JGpZq.S3A92.QUuWg.IHdw7.izyny.j9W92
=/ comet-pub pub:ex:crypto-core.ames-state.comet
=/ comet-sec sec:ex:crypto-core.ames-state.comet
::
2019-08-14 00:30:15 +03:00
=/ nec-sym (derive-symmetric-key:vane bud-pub nec-sec)
2019-11-27 09:15:05 +03:00
=/ bud-sym (derive-symmetric-key:vane nec-pub bud-sec)
2019-08-14 00:30:15 +03:00
?> =(nec-sym bud-sym)
::
2020-12-01 17:51:14 +03:00
=/ comet-sym (derive-symmetric-key:vane bud-pub comet-sec)
::
2019-08-14 00:30:15 +03:00
=. peers.ames-state.nec
%+ ~(put by peers.ames-state.nec) ~bud
2019-11-27 11:25:56 +03:00
=| =peer-state:ames
2019-06-26 02:27:50 +03:00
=. -.peer-state
2019-08-14 00:30:15 +03:00
:* symmetric-key=bud-sym
2019-06-26 02:27:50 +03:00
life=3
2019-08-14 00:30:15 +03:00
public-key=bud-pub
sponsor=~nec
2019-06-26 02:27:50 +03:00
==
2019-11-27 11:25:56 +03:00
=. route.peer-state `[direct=%.y `lane:ames`[%& ~nec]]
2019-06-26 02:29:17 +03:00
[%known peer-state]
::
2019-08-14 00:30:15 +03:00
=. peers.ames-state.bud
%+ ~(put by peers.ames-state.bud) ~nec
2019-11-27 11:25:56 +03:00
=| =peer-state:ames
2019-06-26 02:27:50 +03:00
=. -.peer-state
2019-08-14 00:30:15 +03:00
:* symmetric-key=nec-sym
2019-06-26 02:27:50 +03:00
life=2
2019-08-14 00:30:15 +03:00
public-key=nec-pub
2019-06-26 02:27:50 +03:00
sponsor=~nec
==
2019-11-27 11:25:56 +03:00
=. route.peer-state `[direct=%.y `lane:ames`[%| `@`%lane-bar]]
2019-06-26 02:29:17 +03:00
[%known peer-state]
2019-06-29 00:26:40 +03:00
:: metamorphose
::
2020-02-12 03:12:37 +03:00
=> .(nec +:(call:(nec) ~[//unix] ~ ** %born ~))
=> .(bud +:(call:(bud) ~[//unix] ~ ** %born ~))
2019-06-29 00:26:40 +03:00
:: helper core
::
=>
2019-06-21 04:36:16 +03:00
|%
++ move-to-packet
2019-11-27 11:25:56 +03:00
|= =move:ames
^- [=lane:ames =blob:ames]
2019-06-21 04:36:16 +03:00
::
?> ?=([%give %send *] +.move)
[lane blob]:+>+.move
::
++ is-move-send
2019-11-27 11:25:56 +03:00
|= =move:ames
2019-06-21 04:36:16 +03:00
^- ?
?=([%give %send *] card.move)
2019-06-26 01:26:52 +03:00
::
++ snag-packet
2019-11-27 11:25:56 +03:00
|= [index=@ud moves=(list move:ames)]
^- [=lane:ames =blob:ames]
2019-06-26 01:26:52 +03:00
::
%- move-to-packet
%+ snag index
(skim moves is-move-send)
2019-06-29 00:26:40 +03:00
::
++ call
2019-11-27 11:25:56 +03:00
|= [vane=_nec =duct =task:ames]
^- [moves=(list move:ames) _nec]
2019-06-29 00:26:40 +03:00
::
=/ vane-core (vane(now `@da`(add ~s1 now.vane)))
::
2020-02-12 03:12:37 +03:00
(call:vane-core duct ~ ** task)
2019-06-29 00:26:40 +03:00
::
++ take
2019-11-27 11:25:56 +03:00
|= [vane=_nec =wire =duct =sign:ames]
^- [moves=(list move:ames) _nec]
2019-06-29 00:26:40 +03:00
::
=/ vane-core (vane(now `@da`(add ~s1 now.vane)))
::
2020-02-12 03:12:37 +03:00
(take:vane-core wire duct ~ ** sign)
2019-06-21 04:36:16 +03:00
--
2019-06-29 00:26:40 +03:00
:: test core
::
2019-05-25 05:03:33 +03:00
|%
++ test-packet-encoding ^- tang
::
2019-11-27 11:25:56 +03:00
=/ =packet:ames
2019-08-14 00:30:15 +03:00
:* [sndr=~nec rcvr=~bud]
2020-12-01 17:51:14 +03:00
sndr-tick=0b10
rcvr-tick=0b11
2019-05-25 05:03:33 +03:00
origin=~
2020-12-01 17:51:14 +03:00
content=0xdead.beef
2019-05-25 05:03:33 +03:00
==
::
2019-06-29 00:26:40 +03:00
=/ encoded (encode-packet:vane packet)
=/ decoded (decode-packet:vane encoded)
2019-05-25 05:03:33 +03:00
::
%+ expect-eq
!> packet
!> decoded
2019-05-28 06:39:42 +03:00
::
2020-12-01 17:51:14 +03:00
++ test-origin-encoding ^- tang
::
=/ =packet:ames
:* [sndr=~nec rcvr=~bud]
sndr-tick=0b10
rcvr-tick=0b11
origin=`0xbeef.cafe.beef
content=0xdead.beef
==
::
=/ encoded (encode-packet:vane packet)
=/ decoded (decode-packet:vane encoded)
::
%+ expect-eq
!> packet
!> decoded
::
++ test-shut-packet-encoding ^- tang
::
=/ =shut-packet:ames
:+ bone=17 message-num=18
[%& num-fragments=1 fragment-num=1 fragment=`@`0xdead.beef]
::
=/ =packet:ames
(encode-shut-packet:ames shut-packet nec-sym ~marnec ~marbud-marbud 3 17)
::
=/ decoded (decode-shut-packet:ames packet nec-sym 3 17)
::
%+ expect-eq
!> shut-packet
!> decoded
::
++ test-shut-packet-associated-data ^- tang
::
=/ =shut-packet:ames
:+ bone=17 message-num=18
[%& num-fragments=1 fragment-num=1 fragment=`@`0xdead.beef]
::
=/ =packet:ames
(encode-shut-packet:ames shut-packet nec-sym ~marnec ~marbud-marbud 3 1)
::
%- expect-fail
|.((decode-shut-packet:ames packet nec-sym 3 17))
::
2019-05-28 06:39:42 +03:00
++ test-alien-encounter ^- tang
2019-06-26 04:34:43 +03:00
::
2019-11-27 11:25:56 +03:00
=/ lane-foo=lane:ames [%| `@ux``@`%lane-foo]
2019-05-28 06:39:42 +03:00
::
2019-07-29 14:05:52 +03:00
=/ =plea:ames [%g /talk [%first %post]]
::
2019-11-27 11:25:56 +03:00
=/ =shut-packet:ames
2020-12-01 17:51:14 +03:00
:* bone=1
message-num=1
2019-07-29 14:05:52 +03:00
[%& num-fragments=1 fragment-num=0 (jam plea)]
==
::
2019-11-27 11:25:56 +03:00
=/ =packet:ames
2020-12-01 17:51:14 +03:00
%: encode-shut-packet:vane
shut-packet
nec-sym
~bus
~bud
sndr-life=4
rcvr-life=3
2019-05-28 06:39:42 +03:00
==
::
2019-11-27 11:25:56 +03:00
=/ =blob:ames (encode-packet:vane packet)
2019-08-14 00:30:15 +03:00
=^ moves1 bud (call bud ~[//unix] %hear lane-foo blob)
=^ moves2 bud
2019-11-27 11:25:56 +03:00
=/ =point:ames
:* rift=1
life=4
2019-08-14 00:30:15 +03:00
keys=[[life=4 [crypto-suite=1 `@`nec-pub]] ~ ~]
sponsor=`~bus
==
%- take
2019-08-14 00:30:15 +03:00
:^ bud /public-keys ~[//unix]
2019-11-27 11:25:56 +03:00
^- sign:ames
2019-11-20 01:45:41 +03:00
[%j %public-keys %full [n=[~bus point] ~ ~]]
=^ moves3 bud (call bud ~[//unix] %hear lane-foo blob)
2019-05-28 06:39:42 +03:00
::
;: weld
%+ expect-eq
2019-11-20 01:45:41 +03:00
!> [~[//unix] %pass /public-keys %j %public-keys [~bus ~ ~]]~
2019-06-26 04:34:43 +03:00
!> moves1
2019-05-28 06:39:42 +03:00
::
%+ expect-eq
2019-08-14 00:30:15 +03:00
!> %- sy
:~ :^ ~[//unix] %pass /bone/~bus/1
[%g %plea ~bus %g /talk [%first %post]]
::
:^ ~[//unix] %pass /qos
[%d %flog %text "; ~bus is your neighbor"]
==
2019-11-20 01:45:41 +03:00
!> (sy ,.moves3)
2019-05-28 06:39:42 +03:00
==
::
2020-12-01 17:51:14 +03:00
++ test-comet-encounter ^- tang
::
=/ lane-foo=lane:ames [%| `@ux``@`%lane-foo]
::
=/ =open-packet:ames
:* public-key=`@`comet-pub
sndr=our.comet
sndr-life=1
rcvr=~bud
rcvr-life=3
==
=/ packet
(encode-open-packet:vane open-packet crypto-core.ames-state.comet)
=/ blob (encode-packet:vane packet)
::
=^ moves0 bud (call bud ~[//unix] %hear lane-foo blob)
::
=/ =plea:ames [%g /talk [%first %post]]
=/ =shut-packet:ames
:* bone=1
message-num=1
[%& num-fragments=1 fragment-num=0 (jam plea)]
==
=/ =packet:ames
%: encode-shut-packet:vane
shut-packet
comet-sym
our.comet
~bud
sndr-life=1
rcvr-life=3
==
=/ blob (encode-packet:vane packet)
=^ moves1 bud (call bud ~[//unix] %hear lane-foo blob)
::
;: weld
%+ expect-eq
!> ~
!> moves0
::
%+ expect-eq
!> :~ :* ~[//unix] %pass /qos %d %flog %text
"; {<our.comet>} is your neighbor"
==
:* ~[//unix] %pass /bone/(scot %p our.comet)/1
%g %plea our.comet plea
== ==
!> moves1
==
::
++ test-message-flow ^- tang
2019-08-14 00:30:15 +03:00
:: ~nec -> %plea -> ~bud
::
2019-08-14 00:30:15 +03:00
=^ moves1 nec (call nec ~[/g/talk] %plea ~bud %g /talk [%get %post])
=^ moves2 bud (call bud ~[//unix] %hear (snag-packet 0 moves1))
:: ~bud -> %done -> ~nec
::
2019-08-14 00:30:15 +03:00
=^ moves3 bud (take bud /bone/~nec/1 ~[//unix] %g %done ~)
=^ moves4 nec (call nec ~[//unix] %hear (snag-packet 0 moves3))
:: ~bud -> %boon -> ~nec
::
2019-08-14 00:30:15 +03:00
=^ moves5 bud (take bud /bone/~nec/1 ~[//unix] %g %boon [%post 'first1!!'])
=^ moves6 nec (call nec ~[//unix] %hear (snag-packet 0 moves5))
:: ~nec -> %done -> ~bud (just make sure ~bud doesn't crash on ack)
::
=^ moves7 bud (call bud ~[//unix] %hear (snag-packet 0 moves6))
::
;: weld
%+ expect-eq
2019-08-14 00:30:15 +03:00
!> :~ [~[//unix] %pass /qos %d %flog %text "; ~nec is your neighbor"]
[~[//unix] %pass /bone/~nec/1 %g %plea ~nec %g /talk [%get %post]]
==
2019-08-14 00:30:15 +03:00
!> moves2
::
%+ expect-eq
2019-08-14 00:30:15 +03:00
!> %- sy
2019-11-20 01:45:41 +03:00
:~ [~[/ames] %pass /pump/~bud/0 %b %rest ~1111.1.1..00.00.02]
[~[//unix] %pass /qos %d %flog %text "; ~bud is your neighbor"]
2019-08-14 00:30:15 +03:00
[~[/g/talk] %give %done error=~]
==
!> (sy ,.moves4)
::
%+ expect-eq
!> [~[/g/talk] %give %boon [%post 'first1!!']]
!> (snag 0 `(list move:ames)`moves6)
==
2019-06-21 04:36:16 +03:00
::
++ test-nack ^- tang
2019-08-14 00:30:15 +03:00
:: ~nec -> %plea -> ~bud
::
=^ moves1 nec (call nec ~[/g/talk] %plea ~bud %g /talk [%get %post])
=^ moves2 bud (call bud ~[//unix] %hear (snag-packet 0 moves1))
:: ~bud -> nack -> ~nec
::
2019-11-27 11:25:56 +03:00
=/ =error:ames [%flub [%leaf "sinusoidal repleneration"]~]
2019-08-14 00:30:15 +03:00
=^ moves3 bud (take bud /bone/~nec/1 ~[/bud] %g %done `error)
=^ moves4 nec (call nec ~[//unix] %hear (snag-packet 0 moves3))
:: ~bud -> nack-trace -> ~nec
::
=^ moves5 nec (call nec ~[//unix] %hear (snag-packet 1 moves3))
:: ~nec -> ack nack-trace -> ~bud
2019-06-21 04:36:16 +03:00
::
2019-08-14 00:30:15 +03:00
=^ moves6 bud (call bud ~[//unix] %hear (snag-packet 0 moves5))
2019-06-21 04:36:16 +03:00
::
%+ expect-eq
2019-08-14 00:30:15 +03:00
!> [~[/g/talk] %give %done `error]
2019-11-27 11:25:56 +03:00
!> (snag 1 `(list move:ames)`moves5)
2019-05-25 05:03:33 +03:00
--