urbit/pkg/arvo/tests/lib/naive.hoon

94 lines
2.1 KiB
Plaintext
Raw Normal View History

2021-03-18 03:27:30 +03:00
/+ *test, naive, ethereum
|%
2021-03-18 04:07:21 +03:00
++ address @ux
2021-03-28 05:08:17 +03:00
++ n |=([=^state:naive =^input:naive] (naive verifier +<))
2021-03-18 23:32:32 +03:00
:: TODO: does this uniquely produce the pubkey?
::
2021-03-28 05:08:17 +03:00
++ verifier
2021-03-18 03:27:30 +03:00
^- ^verifier:naive
|= [dat=@ v=@ r=@ s=@]
2021-03-28 05:08:17 +03:00
=/ result
%- mule
|.
=, secp256k1:secp:crypto
%- address-from-pub:key:ethereum
%- serialize-point
(ecdsa-raw-recover dat v r s)
?- -.result
%| ~
%& `p.result
==
2021-03-18 04:07:21 +03:00
::
++ key address-from-prv:key:ethereum
++ log
|= [event=@t data=@t topics=(lest @)]
^- ^input:naive
2021-04-01 04:17:37 +03:00
[%log *@ux data (hash-log-name:naive event) topics]
2021-03-18 04:07:21 +03:00
::
::
++ owner-changed
|= [=ship =address]
(log 'OwnerChanged(uint32,address)' *@t ship address ~)
::
++ init-bud
|= =^state:naive
(n state (owner-changed ~bud 0x123))
::
++ init-l2-marbud
|= =^state:naive
=^ f1 state (init-bud state)
=^ f2 state (n state (owner-changed ~marbud (key ~marbud)))
=^ f3 state (n state (owner-changed ~marbud deposit-address:naive))
[:(welp f1 f2 f3) state]
::
++ sign-tx
2021-04-01 10:05:12 +03:00
|= [pk=@ nonce=@ud tx=@]
=+ (ecdsa-raw-sign:secp256k1:secp:crypto (dad:naive 5 nonce tx) pk)
2021-03-18 04:07:21 +03:00
(cat 3 (can 3 1^v 32^r 32^s ~) tx)
::
++ transfer-point
2021-04-01 10:05:12 +03:00
|= [nonce=@ud =ship =address reset=?]
%^ sign-tx ship nonce
2021-03-18 04:07:21 +03:00
%: can 3
2021-04-01 10:05:12 +03:00
1^0
4^ship
2021-03-18 04:07:21 +03:00
1^(can 0 7^%0 1^reset ~)
4^ship
20^address
~
==
2021-03-18 03:27:30 +03:00
--
::
|%
++ test-log
%+ expect-eq
!>
2021-04-01 10:05:12 +03:00
`[[[~bud %*(. *point:naive dominion %l1, owner.own 0x123^0)] ~ ~] ~ ~]
2021-03-18 03:27:30 +03:00
::
!>
2021-03-28 05:08:17 +03:00
%^ naive verifier *^state:naive
2021-04-01 04:17:37 +03:00
:* %log *@ux *@t
2021-03-18 03:27:30 +03:00
(hash-log-name:naive 'OwnerChanged(uint32,address)') (@ux ~bud) 0x123 ~
==
2021-03-18 04:07:21 +03:00
::
++ test-deposit
%+ expect-eq
!> %l2
::
!>
=| =^state:naive
=^ f state (init-l2-marbud state)
dominion:(~(got by points.state) ~marbud)
::
++ test-batch
%+ expect-eq
2021-04-01 10:05:12 +03:00
!> [0x234 2]
2021-03-18 04:07:21 +03:00
::
!>
=| =^state:naive
=^ f state (init-l2-marbud state)
2021-04-01 10:05:12 +03:00
=^ f state (n state %bat (transfer-point 0 ~marbud (key ~marbud) |))
=^ f state (n state %bat (transfer-point 1 ~marbud 0x234 |))
2021-03-18 04:07:21 +03:00
owner.own:(~(got by points.state) ~marbud)
2021-03-18 03:27:30 +03:00
--