Merge branch 'yu/azimuth-rpc' into naive/aggregator

This commit is contained in:
yosoyubik 2021-05-14 09:46:36 +02:00
parent 9b62454bca
commit 154baceb8b
8 changed files with 1381 additions and 241 deletions

View File

@ -0,0 +1,235 @@
:: Azimuth JSON-RPC API
::
/- rpc=json-rpc
/+ naive,
azimuth-rpc,
json-rpc,
*server,
default-agent,
verb,
dbug,
version,
agentio
|%
:: FIXME: import tx-status, pend-tx from aggregator
::
+$ tx-status
$: status=?(%unknown %pending %sent %confirmed %failed)
tx=(unit @ux)
==
::
+$ pend-tx [force=? =raw-tx:naive]
::
+$ card card:agent:gall
::
+$ state-0 [%0 ~]
--
::
%+ verb |
%- agent:dbug
::
=| state-0
=* state -
::
^- agent:gall
=<
|_ =bowl:gall
+* this .
do ~(. +> bowl)
def ~(. (default-agent this %|) bowl)
::
++ on-init
^- (quip card _this)
~& > 'init'
:_ this
[%pass /bind %arvo %e %connect [~ [%v1 %azimuth ~]] dap.bowl]~
::
++ on-save !>(state)
++ on-load
|= old=vase
^- (quip card _this)
[~ this(state !<(state-0 old))]
::
++ on-poke
|= [=mark =vase]
^- (quip card _this)
|^
?> (team:title our.bowl src.bowl)
?+ mark (on-poke:def mark vase)
%handle-http-request
=+ !<([id=@ta req=inbound-request:eyre] vase)
:_ this
(handle-http-request id req)
::
%azimuth-action
=+ !<([%disconnect bind=binding:eyre] vase)
~& >>> "disconnecting at {<bind>}"
:_ this
[[%pass /bind %arvo %e %disconnect bind]]~
==
::
++ handle-http-request
|= [id=@ta =inbound-request:eyre]
^- (list card)
|^
=* req request.inbound-request
=* headers header-list.req
=/ req-line (parse-request-line url.req)
?. =(method.req %'POST')
:: TODO: method not supported
::
(give-simple-payload:app id not-found:gen)
?~ rpc-request=(validate-request:json-rpc body.req parse-method)
:: TODO: malformed request
::
(give-simple-payload:app id not-found:gen)
=/ [data=(unit cage) response=simple-payload:http]
(process-rpc-request:do u.rpc-request)
%+ weld
(give-simple-payload:app id response)
?~ data ~
:_ ~
^- card
[%pass / %agent [our.bowl %dice] %poke u.data]
:: TODO: validate that format is e.g. 'getPoint'
:: TODO: maybe use getPoint and translate to %get-point
::
++ parse-method |=(t=@t `term`t)
--
--
::
++ on-watch
|= =path
^- (quip card _this)
?> (team:title our.bowl src.bowl)
?+ path (on-watch:def path)
[%http-response *] [~ this]
==
::
++ on-arvo
|= [=wire =sign-arvo]
^- (quip card _this)
?+ sign-arvo (on-arvo:def wire sign-arvo)
[%eyre %bound *]
~? !accepted.sign-arvo
[dap.bowl 'bind rejected!' binding.sign-arvo]
[~ this]
==
::
++ on-leave on-leave:def
++ on-peek on-peek:def
++ on-agent on-agent:def
++ on-fail on-fail:def
--
::
|_ =bowl:gall
++ process-rpc-request
|= request:rpc
^- [(unit cage) simple-payload:http]
=; [data=(unit cage) =response:rpc]
:- data
%- json-response:gen
(response-to-json:json-rpc response)
=, azimuth-rpc
?. ?=([%map *] params)
[~ ~(parse error id)]
?+ method [~ ~(method error id)]
%get-point [~ (get-point id +.params point:scry)]
%transfer-point (transfer-point id +.params)
%configure-keys (configure-keys id +.params)
%spawn (spawn id +.params)
%escape (escape id +.params)
%cancel-escape (cancel-escape id +.params)
%adopt (adopt id +.params)
%detach (detach id +.params)
%reject (reject id +.params)
%set-management-proxy (management-proxy id +.params)
%set-spawn-proxy (spawn-proxy id +.params)
%set-transfer-proxy (transfer-proxy id +.params)
%pending [~ (all:pending id +.params all:pending:scry)]
%pending-by-ship [~ (ship:pending id +.params ship:pending:scry)]
%pending-by-address [~ (addr:pending id +.params addr:pending:scry)]
%status [~ (status id +.params tx-status:scry)]
:: %history [~ (history id +.params all:history:scry)]
==
::
++ scry
|%
++ point
|= =ship
.^ (unit point:naive)
%gx
(~(scry agentio bowl) %azimuth /nas/[(scot %p ship)]/noun)
==
::
++ pending
|%
++ all
.^ (list pend-tx)
%gx
(~(scry agentio bowl) %dice /pending/noun)
==
::
++ ship
|= =^ship
.^ (list pend-tx)
%gx
(~(scry agentio bowl) %dice /pending/[(scot %p ship)]/noun)
==
::
++ addr
|= =address:naive
.^ (list pend-tx)
%gx
%+ ~(scry agentio bowl) %dice
/pending/[(scot %ux address)]/noun
==
--
::
++ history
|%
++ all
:: FIXME: use proper type from aggregator/index
::
.^ (list tx:naive)
%gx
(~(scry agentio bowl) %dice /history/noun)
==
::
++ ship
|= =^ship
:: FIXME: use proper type from aggregator/index
::
.^ (list tx:naive)
%gx
(~(scry agentio bowl) %dice /history/[(scot %p ship)]/noun)
==
::
++ addr
|= =address:naive
:: FIXME: use proper type from aggregator/index
::
.^ (list tx:naive)
%gx
(~(scry agentio bowl) %dice /history/[(scot %ux address)]/noun)
==
--
::
++ tx-status
|= keccak=@ux
.^ ^tx-status
%gx
(~(scry agentio bowl) %dice /tx/[(scot %ux keccak)]/status/noun)
==
::
++ nonce
|= [=ship =address:naive]
:: FIXME: use proper type from aggregator/index
.^ @
%gx
%+ ~(scry agentio bowl)
%dice
/nonce/[(scot %p ship)]/[(scot %ux address)]/atom
==
--
--

View File

@ -256,11 +256,19 @@
++ on-leave on-leave:def
++ on-peek
|= =path
?: =(/x/nas path)
``nas+!>(nas.state)
?: =(/x/logs path)
^- (unit (unit cage))
?+ path (on-peek:def path)
[%x %logs ~]
``logs+!>(logs.state)
~
::
[%x %nas ~]
``nas+!>(nas.state)
::
[%x %nas @t ~]
?~ ship=(rush i.t.t.path ;~(pfix sig fed:ag))
``noun+!>(*(unit point:naive))
``noun+!>((~(get by points.nas.state) u.ship))
==
::
++ on-agent
|= [=wire =sign:agent:gall]

View File

@ -0,0 +1,4 @@
::
:- %say
|= [* [=binding:eyre ~] ~]
[%azimuth-action %disconnect binding]

View File

@ -0,0 +1,416 @@
:: azimuth-rpc: command parsing and utilities
::
/- rpc=json-rpc
/+ naive
::
=> :: Utilities
::
|%
:: FIXME: import tx-status, pend-tx from aggregator
::
+$ tx-status
$: status=?(%unknown %pending %sent %confirmed %failed)
tx=(unit @ux)
==
::
+$ pend-tx [force=? =raw-tx:naive]
::
++ from-json
|%
++ keys
|= params=(map @t json)
^- (unit [encrypt=@ auth=@ crypto-suite=@ breach=?])
?~ data=(~(get by params) 'data') ~
%. u.data
=, dejs-soft:format
%- ot
:~ ['encrypt' so]
['auth' so]
['crypto-suite' so]
['breach' bo]
==
::
++ address-transfer
|= params=(map @t json)
^- (unit [@ux ?])
?~ data=(~(get by params) 'data') ~
=; ans=(unit [add=(unit @ux) r=?])
?~ ans ~
?~ add.u.ans ~
(some [u.add.u.ans r.u.ans])
%. u.data
=, dejs-soft:format
%- ot
~[['address' (cu to-hex so)] ['reset' bo]]
::
++ address-ship
|= params=(map @t json)
^- (unit [@ux @p])
?~ data=(~(get by params) 'data') ~
=; ans=(unit [add=(unit @ux) ship=@p])
?~ ans ~
?~ add.u.ans ~
(some [u.add.u.ans ship.u.ans])
%. u.data
=, dejs-soft:format
%- ot
:~ ['address' (cu to-hex so)]
['ship' (su ;~(pfix sig fed:ag))]
==
::
++ address
|= params=(map @t json)
^- (unit @ux)
?~ data=(~(get by params) 'data') ~
=; ans=(unit (unit @ux))
?~(ans ~ u.ans)
=, dejs-soft:format
%. u.data
(ot ['address' (cu to-hex so)]~)
::
++ ship
|= params=(map @t json)
^- (unit @p)
?~ data=(~(get by params) 'data') ~
=, dejs-soft:format
%. u.data
(ot ['ship' (su ;~(pfix sig fed:ag))]~)
::
++ sig
|= params=(map @t json)
^- (unit @)
?~ sig=(~(get by params) 'sig') ~
(so:dejs-soft:format u.sig)
::
++ from
|= params=(map @t json)
^- (unit [@p proxy:naive])
?~ from=(~(get by params) 'from') ~
=, dejs-soft:format
%. u.from
%- ot
:~ ['ship' (su ;~(pfix sig fed:ag))]
['proxy' (cu proxy:naive so)]
==
::
++ keccak
|= params=(map @t json)
^- (unit @ux)
?~ keccak=(~(get by params) 'keccak') ~
=; ans=(unit (unit @ux))
?~(ans ~ u.ans)
=, dejs-soft:format
((cu to-hex so) u.keccak)
--
::
++ to-json
|%
++ pending
|= pending=(list pend-tx)
^- json
=, enjs:format
:- %a
%+ turn pending
|= pend-tx
^- json
=, enjs:format
%- pairs
:~ ['force' b+force]
::
:- 'raw-tx'
%- pairs
:~ ['sig' (numb sig.raw-tx)]
['tx' (tx:to-json tx.raw-tx)]
== ==
::
++ tx
|= =tx:naive
^- json
=, enjs:format
|^
%- pairs
:~ ['tx' (parse-tx +.tx)]
::
:- 'from'
%- pairs
~[['ship' (ship ship.from.tx)] ['proxy' s+proxy.from.tx]]
==
::
++ parse-tx
|= tx=skim-tx:naive
^- json
%- pairs
:~ ['type' s+-.tx]
::
:- 'data'
%- pairs
?- -.tx
%transfer-point (en-transfer +.tx)
%spawn (en-spawn +.tx)
%configure-keys (en-keys +.tx)
%escape ~[(en-ship parent.tx)]
%cancel-escape ~[(en-ship parent.tx)]
%adopt ~[(en-ship ship.tx)]
%reject ~[(en-ship ship.tx)]
%detach ~[(en-ship ship.tx)]
%set-management-proxy ~[(en-address address.tx)]
%set-spawn-proxy ~[(en-address address.tx)]
%set-transfer-proxy ~[(en-address address.tx)]
== ==
::
++ en-ship |=(s=@p ship+(ship s))
++ en-address |=(a=@ux address+s+(crip "0x{((x-co:co 20) a)}"))
++ en-spawn |=([s=@p a=@ux] ~[(en-ship s) (en-address a)])
++ en-transfer |=([a=@ux r=?] ~[(en-address a) reset+b+r])
++ en-keys
|= [encrypt=@ auth=@ crypto-suite=@ breach=?]
^- (list [@t json])
:~ ['encrypt' (numb encrypt)]
['auth' (numb auth)]
['crypto-suite' (numb crypto-suite)]
['breach' b+breach]
==
--
::
++ txs
|= txs=(list tx:naive)
^- json
a+(turn txs |=(=tx:naive (tx:to-json tx)))
::
++ point
|= =point:naive
^- json
=, enjs:format
%- pairs
:~ ['dominion' s+dominion.point]
::
:- 'ownership'
%- pairs
=* own own.point
^- (list [@t json])
:~ ['owner' (ownership owner.own)]
['spawnProxy' (ownership spawn-proxy.own)]
['managementProxy' (ownership management-proxy.own)]
['votingProxy' (ownership voting-proxy.own)]
['transferProxy' (ownership transfer-proxy.own)]
==
::
:- 'network'
%- pairs
=* net net.point
:* ['rift' (numb rift.net)]
::
:- 'keys'
%- pairs
:~ ['life' (numb life.keys.net)]
['suite' (numb suite.keys.net)]
['auth' (numb auth.keys.net)]
['crypt' (numb crypt.keys.net)]
==
::
['rift' (numb rift.net)]
:- 'sponsor'
%- pairs
~[['has' b+has.sponsor.net] ['who' (ship who.sponsor.net)]]
::
?~ escape.net ~
['escape' (ship u.escape.net)]~
== ==
::
++ ownership
|= [=address:naive =nonce:naive]
^- json
=, enjs:format
%- pairs
:~ ['address' s+(crip "0x{((x-co:co 20) address)}")]
['nonce' (numb nonce)]
==
::
++ tx-status
|= =^tx-status
^- json
=, enjs:format
%- pairs
:~ ['status' s+status.tx-status]
::
:- 'tx'
?~ tx.tx-status ~
s+(crip "0x{((x-co:co 20) u.tx.tx-status)}")
==
--
::
++ to-hex
|= =cord
^- (unit @ux)
=/ parsed=(unit (pair @ud @ux)) (de:base16:mimes:html cord)
?~ parsed
::~|(%non-hex-cord !!)
~
(some q.u.parsed)
::
++ rpc-res
|%
++ sponsor
|= [id=@t params=(map @t json)]
^- [(unit cage) response:rpc]
?. =((lent ~(tap by params)) 3)
[~ ~(params error id)]
=/ sig=(unit @) (sig:from-json params)
=/ from=(unit [@p proxy:naive]) (from:from-json params)
=/ data=(unit [@ux @p]) (address-ship:from-json params)
?. &(?=(^ sig) ?=(^ from) ?=(^ data))
[~ ~(parse error id)]
:_ [%result id s+'ok']
%- some
noun+!>([u.sig u.from u.data])
::
++ proxy
|= [id=@t params=(map @t json)]
^- [(unit cage) response:rpc]
?. =((lent ~(tap by params)) 3)
[~ ~(params error id)]
=/ sig=(unit @) (sig:from-json params)
=/ from=(unit [@p proxy:naive]) (from:from-json params)
=/ data=(unit @ux) (address:from-json params)
?. &(?=(^ sig) ?=(^ from) ?=(^ data))
[~ ~(parse error id)]
:_ [%result id s+'ok']
%- some
noun+!>([u.sig u.from u.data])
::
--
::
++ error
|_ id=@t
:: https://www.jsonrpc.org/specification#error_object
::
++ parse [%error id '-32700' 'Failed to parsed']
++ request [%error id '-32600' 'Invalid Request']
++ method [%error id '-32601' 'Method not found']
++ params [%error id '-32602' 'Invalid params']
++ internal [%error id '-32603' 'Internal error']
++ not-found [%error id '-32000' 'Resource not found']
--
--
|%
++ get-point
|= [id=@t params=(map @t json) scry=$-(ship (unit point:naive))]
^- response:rpc
?. =((lent ~(tap by params)) 1)
~(params error id)
?~ ship=(~(get by params) 'ship')
~(params error id)
?~ ship=(rush (so:dejs:format u.ship) ;~(pfix sig fed:ag))
~(params error id)
?~ point=(scry u.ship)
~(params error id)
[%result id (point:to-json u.point)]
::
++ transfer-point
|= [id=@t params=(map @t json)]
^- [(unit cage) response:rpc]
?. =((lent ~(tap by params)) 3)
[~ ~(params error id)]
=/ sig=(unit @) (sig:from-json params)
=/ from=(unit [ship @t]) (from:from-json params)
=/ data=(unit [@ux ?]) (address-transfer:from-json params)
?: |(?=(~ sig) ?=(~ from) ?=(~ data))
[~ ~(parse error id)]
:_ [%result id s+'ok']
%- some
noun+!>([u.sig u.from u.data])
::
++ configure-keys
|= [id=@t params=(map @t json)]
^- [(unit cage) response:rpc]
?. =((lent ~(tap by params)) 3)
[~ ~(params error id)]
=/ sig=(unit @) (sig:from-json params)
=/ from=(unit [ship @t]) (from:from-json params)
=/ data=(unit [encrypt=@ auth=@ crypto-suite=@ breach=?])
(keys:from-json params)
?. &(?=(^ sig) ?=(^ from) ?=(^ data))
[~ ~(parse error id)]
:_ [%result id s+'ok']
%- some
noun+!>([u.sig u.from u.data])
::
++ spawn sponsor:rpc-res
++ escape sponsor:rpc-res
++ cancel-escape sponsor:rpc-res
++ adopt sponsor:rpc-res
++ detach sponsor:rpc-res
++ reject sponsor:rpc-res
++ management-proxy proxy:rpc-res
++ spawn-proxy proxy:rpc-res
++ transfer-proxy proxy:rpc-res
:: - readNonce(from=[ship proxy]) -> @ :: automatically increment for pending wraps
::
++ read-nonce
|= [id=@t params=(map @t json) scry=$-([ship proxy:naive] (unit @))]
^- response:rpc
?. =((lent ~(tap by params)) 3)
~(params error id)
?~ from=(from:from-json params)
~(parse error id)
?~ nonce=(scry u.from)
~(params error id)
[%result id (numb:enjs:format u.nonce)]
::
++ pending
:: FIXME: send raw-tx (i.e. tx with signature) instead?
::
|%
:: - readPendingRoll() -> (list pend-tx)
::
++ all
|= [id=@t params=(map @t json) pending=(list pend-tx)]
^- response:rpc
?. =((lent ~(tap by params)) 0)
~(params error id)
[%result id (pending:to-json pending)]
:: - readPendingByShip(ship) -> (list pend-tx)
::
++ ship
|= [id=@t params=(map @t json) scry=$-(@p (list pend-tx))]
^- response:rpc
?. =((lent ~(tap by params)) 1)
~(params error id)
?~ ship=(ship:from-json params)
~(parse error id)
[%result id (pending:to-json (scry u.ship))]
:: - readPendingByAddress(address) -> (list pend-tx)
::
++ addr
|= [id=@t params=(map @t json) scry=$-(@ux (list pend-tx))]
^- response:rpc
?. =((lent ~(tap by params)) 1)
~(params error id)
?~ address=(address:from-json params)
~(parse error id)
[%result id (pending:to-json (scry u.address))]
--
::
++ status
|= [id=@t params=(map @t json) scry=$-(@ tx-status)]
^- response:rpc
?. =((lent ~(tap by params)) 1)
~(params error id)
?~ keccak=(keccak:from-json params)
~(parse error id)
[%result id (tx-status:to-json (scry u.keccak))]
::
:: ++ history
:: |= $: id=@t
:: params=(map @t json)
:: :: FIXME: use proper type from aggregator/index
:: ::
:: scry=$-([@p proxy:naive] (list tx:naive))
:: ==
:: ^- response:rpc
:: ?. =((lent ~(tap by params)) 1)
:: ~(params error id)
:: ?~ from=(from:from-json params)
:: ~(parse error id)
:: [%result id (txs:to-json (scry u.from))]
--

View File

@ -25,7 +25,64 @@
^- json
?- -.params
%list [%a +.params]
%map [%o +.params]
%object [%o (~(gas by *(map @t json)) +.params)]
== ==
::
++ response-to-json
|= =response
^- json
:: TODO: consider all cases
::
?+ -.response ~|([%unsupported-rpc-response response] !!)
%result
:- %o
%- molt
^- (list [@t json])
:: FIXME: return 'id' as string, number or NULL
::
:~ ['jsonrpc' s+'2.0']
['id' s+id.response]
['result' res.response]
==
::
%error
:- %o
%- molt
^- (list [@t json])
:~ ['jsonrpc' s+'2.0']
['id' ?~(id.response ~ s+id.response)]
['code' n+code.response]
['message' s+message.response]
==
==
::
++ validate-request
|= [body=(unit octs) parse-method=$-(@t term)]
^- (unit request)
?~ body ~
?~ jon=(de-json:html q.u.body) ~
:: ignores non-object responses
::
:: ?. ?=([%o *] json) ~|([%format-not-valid json] !!)
?. ?=([%o *] u.jon) ~
%- some
%. u.jon
=, dejs:format
:: TODO: If parsing fails, return a proper error (not 500)
::
%- ot
:~ :: FIXME: parse 'id' as string, number or NULL
::
['id' so]
['jsonrpc' (su (jest '2.0'))]
['method' (cu parse-method so)]
::
:- 'params'
|= =json
^- request-params
?+ -.json !!
%a [%list ((ar same) json)]
%o [%map ((om same) json)]
== ==
--

View File

@ -0,0 +1,177 @@
/+ naive, ethereum
:: Types
|%
+$ address address:ethereum
+$ nonce @ud
+$ proxy ?(%own %spawn %manage %vote %transfer)
+$ skp [=ship pk=@ =proxy]
::
+$ l2-tx
$% [%spawn child=ship =address]
[%transfer-point =address reset=?]
[%configure-keys suite=@ud encrypt=@ auth=@ breach=?]
[%escape parent=ship]
[%cancel-escape parent=ship]
[%adopt child=ship]
[%reject child=ship]
[%detach child=ship]
[%set-management-proxy =address]
[%set-spawn-proxy =address]
[%set-transfer-proxy =address]
==
--
::
|%
::
++ gen-tx
|= [=nonce =skp tx=l2-tx] ^- octs
=/ raw=octs
?- -.tx
%spawn (get-spawn:bits ship.skp proxy.skp +.tx)
%transfer-point (get-transfer:bits ship.skp proxy.skp +.tx)
%configure-keys (get-keys:bits ship.skp proxy.skp +.tx)
%escape (get-escape:bits %escape ship.skp proxy.skp +.tx)
%cancel-escape (get-escape:bits %cancel-escape ship.skp proxy.skp +.tx)
%adopt (get-escape:bits %adopt ship.skp proxy.skp +.tx)
%reject (get-escape:bits %reject ship.skp proxy.skp +.tx)
%detach (get-escape:bits %detach ship.skp proxy.skp +.tx)
%set-management-proxy (get-ship-address:bits %set-management-proxy ship.skp proxy.skp +.tx)
%set-spawn-proxy (get-ship-address:bits %set-spawn-proxy ship.skp proxy.skp +.tx)
%set-transfer-proxy (get-ship-address:bits %set-transfer-proxy ship.skp proxy.skp +.tx)
==
%^ sign-tx pk.skp nonce raw
::
:: TODO: does this uniquely produce the pubkey?
++ verifier
^- ^verifier:naive
|= [dat=octs v=@ r=@ s=@]
?: (gth v 3) ~ :: TODO: move to jet
=/ result
%- mule
|.
=, secp256k1:secp:crypto
%- address-from-pub:key:ethereum
%- serialize-point
(ecdsa-raw-recover (keccak-256:keccak:crypto dat) v r s)
?- -.result
%| ~
%& `p.result
==
::
++ sign-tx
|= [pk=@ =nonce tx=octs] ^- octs
=/ prepared-data (prepare-for-sig 1.337 nonce tx)
=/ sign-data
=/ len (rsh [3 2] (scot %ui p.prepared-data))
%- keccak-256:keccak:crypto
%: cad:naive 3
26^'\19Ethereum Signed Message:\0a'
(met 3 len)^len
prepared-data
~
==
=+ (ecdsa-raw-sign:secp256k1:secp:crypto sign-data pk)
(cad:naive 3 1^v 32^s 32^r tx ~)
::
++ prepare-for-sig
|= [chain-id=@ud =nonce tx=octs]
^- octs
=/ chain-t (rsh [3 2] (scot %ui chain-id))
%: cad:naive 3
14^'UrbitIDV1Chain'
(met 3 chain-t)^chain-t
1^':'
4^nonce
tx
~
==
::
++ bits
::
|%
::
:: TODO: Shouldn't need to pass all these arguments along - they should already be in the subject somewhere
::
++ get-spawn
|= [=ship =proxy child=ship =address] ^- octs
%: cad:naive 3
(from-proxy:bits proxy)
4^ship
1^%1 :: %spawn
4^child
20^address
~
==
::
++ get-transfer
|= [=ship =proxy =address reset=?] ^- octs
%: cad:naive 3
(from-proxy:bits proxy)
4^ship
1^(can 0 7^%0 1^reset ~) :: %transfer-point
20^address
~
==
::
++ get-keys
|= [=ship =proxy suite=@ud encrypt=@ auth=@ breach=?] ^- octs
%: cad:naive 3
(from-proxy:bits proxy)
4^ship
1^(can 0 7^%2 1^breach ~) :: %configure-keys
32^encrypt
32^auth
4^suite
~
==
::
++ get-escape
|= [action=@tas from=ship proxy=@tas other=ship] ^- octs
=/ op
?+ action !!
%escape %3
%cancel-escape %4
%adopt %5
%reject %6
%detach %7
==
%: cad:naive 3
(from-proxy proxy)
4^from
1^(can 0 7^op 1^0 ~)
4^other
~
==
::
++ get-ship-address
|= [action=@tas from=ship proxy=@tas =address] ^- octs
=/ op
?+ action !!
%set-management-proxy %8
%set-spawn-proxy %9
%set-transfer-proxy %10
==
%: cad:naive 3
(from-proxy proxy)
4^from
1^(can 0 7^op 1^0 ~)
20^address
~
==
::
++ from-proxy
|= prx=@tas
^- [@ @]
=/ proxy
?+ prx !!
%own %0
%spawn %1
%manage %2
%vote %3
%transfer %4
==
1^(can 0 3^proxy 5^0 ~)
::
--
::
--

View File

@ -3,12 +3,14 @@
|%
+$ request
$: id=@t
jsonrpc=@t
method=@t
params=request-params
==
::
+$ request-params
$% [%list (list json)]
[%map (map @t json)]
[%object (list (pair @t json))]
==
+$ response

View File

@ -1,24 +1,7 @@
/+ *test, naive, ethereum
|%
++ address @ux
++ n |=([=^state:naive =^input:naive] (%*(. naive lac |) verifier 1.337 +<))
:: TODO: does this uniquely produce the pubkey?
/+ *test, naive, ethereum, azimuth, *naive-transactions
::
++ verifier
^- ^verifier:naive
|= [dat=octs v=@ r=@ s=@]
?: (gth v 3) ~ :: TODO: move to jet
=/ result
%- mule
|.
=, secp256k1:secp:crypto
%- address-from-pub:key:ethereum
%- serialize-point
(ecdsa-raw-recover (keccak-256:keccak:crypto dat) v r s)
?- -.result
%| ~
%& `p.result
==
|%
++ n |=([=^state:naive =^input:naive] (%*(. naive lac |) verifier 1.337 +<))
::
++ addr address-from-prv:key:ethereum
::
@ -32,7 +15,14 @@
++ init-bud
|= =^state:naive
^- [effects:naive ^state:naive]
(n state (owner-changed:l1 ~bud (addr ~bud)))
(n state (owner-changed:l1 ~bud (addr %bud-key-0)))
::
:: ~wes is for testing sponsors of stars
::
++ init-wes
|= =^state:naive
^- [effects:naive ^state:naive]
(n state (owner-changed:l1 ~wes (addr %wes-key-0)))
::
:: ~dopbud is for testing L1 ownership with L2 spawn proxy
::
@ -54,7 +44,18 @@
=^ f3 state (n state (owner-changed:l1 ~marbud deposit-address:naive))
[:(welp f1 f2 f3) state]
::
:: ~sambud is for testing L1 stars attempting L2 actions
:: ~litbud is for testing L2 sponsorship
::
++ init-litbud
|= =^state:naive
^- [effects:naive ^state:naive]
:: ~bud should already be spawned, though trying to init ~bud again shouldn't matter i think?
:: =^ f1 state (init-bud state)
=^ f2 state (n state (owner-changed:l1 ~litbud (addr %litbud-key-0)))
=^ f3 state (n state (owner-changed:l1 ~litbud deposit-address:naive))
[:(welp f2 f3) state]
::
:: ~sambud is for testing L1 stars
::
++ init-sambud
|= =^state:naive
@ -63,34 +64,6 @@
=^ f2 state (n state (owner-changed:l1 ~sambud (addr %sambud-key-0)))
[:(welp f1 f2) state]
::
++ sign-tx
|= [pk=@ nonce=@ud tx=octs] ^- octs
=/ prepared-data (prepare-for-sig 1.337 nonce tx)
=/ sign-data
=/ len (rsh [3 2] (scot %ui p.prepared-data))
%- keccak-256:keccak:crypto
%: cad:naive 3
26^'\19Ethereum Signed Message:\0a'
(met 3 len)^len
prepared-data
~
==
=+ (ecdsa-raw-sign:secp256k1:secp:crypto sign-data pk)
(cad:naive 3 1^v 32^s 32^r tx ~)
::
++ prepare-for-sig
|= [chain-id=@ud nonce=@ud tx=octs]
^- octs
=/ chain-t (rsh [3 2] (scot %ui chain-id))
%: cad:naive 3
14^'UrbitIDV1Chain'
(met 3 chain-t)^chain-t
1^':'
4^nonce
tx
~
==
::
++ l1
|%
::
@ -121,7 +94,7 @@
(log lost-sponsor:log-names:naive *@ux lost parent ~)
::
++ changed-keys
|= [=ship encr=@ auth=@ suite=@ life=@]
|= [=ship suite=@ encr=@ auth=@ life=@]
=/ keys=@ux
%: can 8
1^life
@ -162,162 +135,44 @@
::
--
::
++ l2
--
::
:: Common values used for tests
::
|%
::
++ spawn
|= [nonce=@ud parent=ship pk=@ proxy=@tas child=ship =address] ^- octs
%^ sign-tx pk nonce
%: cad:naive 3
(from-proxy:bits proxy)
4^parent
1^%1 :: %spawn
4^child
20^address
~
==
++ encr (shax 'You will forget that you ever read this sentence.')
++ auth (shax 'You cant know that this sentence is true.')
++ suit 1
::
++ transfer-point
|= [nonce=@ud =ship pk=@ =address proxy=@tas reset=?] ^- octs
%^ sign-tx pk nonce
%: cad:naive 3
(from-proxy:bits proxy)
4^ship
1^(can 0 7^%0 1^reset ~) :: %transfer-point
20^address
~
==
++ marbud-own [~marbud %marbud-key-0 %own]
++ marbud-spn [~marbud %marbud-skey %spawn]
++ marbud-mgt [~marbud %marbud-mkey %manage]
::
++ configure-keys
|= $: nonce=@ud =ship pk=@ proxy=@tas
breach=@ encrypt=@ auth=@ crypto-suite=@
==
^- octs
%^ sign-tx pk nonce
%: cad:naive 3
(from-proxy:bits proxy)
4^ship
1^(can 0 7^%2 1^breach ~) :: %configure-keys
32^encrypt
32^auth
4^crypto-suite
~
==
++ dopbud-own [~dopbud %dopbud-key-0 %own]
::
++ escape
|= [nonce=@ud child=ship pk=@ proxy=@tas parent=ship] ^- octs
%^ sign-tx pk nonce
(take-escape:bits %escape child proxy parent)
++ litbud-own [~litbud %litbud-key-0 %own]
::
++ cancel-escape
|= [nonce=@ud child=ship pk=@ proxy=@tas parent=ship] ^- octs
%^ sign-tx pk nonce
(take-escape:bits %cancel-escape child proxy parent)
++ lt-own [~linnup-torsyx %lt-key-0 %own]
++ lt-xfr [~linnup-torsyx %lt-key-0 %transfer]
--
::
++ adopt
|= [nonce=@ud child=ship pk=@ proxy=@tas parent=ship] ^- octs
%^ sign-tx pk nonce
(take-escape:bits %adopt parent proxy child)
::
++ reject
|= [nonce=@ud child=ship pk=@ proxy=@tas parent=ship] ^- octs
%^ sign-tx pk nonce
(take-escape:bits %reject parent proxy child)
::
++ detach
|= [nonce=@ud child=ship pk=@ proxy=@tas parent=ship] ^- octs
%^ sign-tx pk nonce
(take-escape:bits %detach parent proxy child)
::
++ set-management-proxy
|= [nonce=@ud =ship pk=@ proxy=@tas =address] ^- octs
%^ sign-tx pk nonce
^- octs
(take-ship-address:bits %set-management-proxy ship proxy address)
::
++ set-spawn-proxy
|= [nonce=@ud =ship pk=@ proxy=@tas =address] ^- octs
%^ sign-tx pk nonce
(take-ship-address:bits %set-spawn-proxy ship proxy address)
::
++ set-transfer-proxy
|= [nonce=@ud =ship pk=@ proxy=@tas =address] ^- octs
%^ sign-tx pk nonce
(take-ship-address:bits %set-transfer-proxy ship proxy address)
::
++ bits
:: Tests
::
|%
::
:: TODO: Shouldn't need to pass all these arguments along - they should already be in the subject somewhere
::
++ take-escape
|= [action=@tas from=ship proxy=@tas other=ship] ^- octs
=/ op
?+ action !!
%escape %3
%cancel-escape %4
%adopt %5
%reject %6
%detach %7
==
%: cad:naive 3
(from-proxy proxy)
4^from
1^(can 0 7^op 1^0 ~)
4^other
~
==
::
++ take-ship-address
|= [action=@tas from=ship proxy=@tas =address] ^- octs
=/ op
?+ action !!
%set-management-proxy %8
%set-spawn-proxy %9
%set-transfer-proxy %10
==
%: cad:naive 3
(from-proxy proxy)
4^from
1^(can 0 7^op 1^0 ~)
20^address
~
==
::
++ from-proxy
|= prx=@tas
^- [@ @]
=/ proxy
?+ prx !!
%own %0
%spawn %1
%manage %2
%vote %3
%transfer %4
==
1^(can 0 3^proxy 5^0 ~)
::
--
::
--
::
--
::
|%
++ test-log ^- tang
%+ expect-eq
!>
:- [%point ~bud %owner 0x123]~
:- [%point ~bud %owner (addr %bud-key-0)]~
:_ [~ ~] :_ [~ ~]
:- ~bud
%*(. *point:naive dominion %l1, owner.own 0x123^0, who.sponsor.net ~bud)
%*(. *point:naive dominion %l1, owner.own (addr %bud-key-0)^0, who.sponsor.net ~bud)
::
!>
%^ naive verifier 1.337 :- *^state:naive
:* %log *@ux *@ux
owner-changed:log-names:naive (@ux ~bud) 0x123 ~
owner-changed:log-names:naive (@ux ~bud) (addr %bud-key-0) ~
==
::
++ test-deposit ^- tang
@ -330,84 +185,153 @@
dominion:(~(got by points.state) ~marbud)
::
++ test-batch ^- tang
=/ marbud-transfer [%transfer-point (addr %marbud-key-0) |]
=/ marbud-transfer-2 [%transfer-point (addr %marbud-key-1) |]
::
%+ expect-eq
!> [0x234 2]
!> [(addr %marbud-key-1) 2]
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (n state %bat q:(transfer-point:l2 0 ~marbud %marbud-key-0 (addr %marbud-key-0) %own |))
=^ f state (n state %bat q:(transfer-point:l2 1 ~marbud %marbud-key-0 0x234 %own |))
=^ f state (n state %bat q:(gen-tx 0 marbud-own marbud-transfer))
=^ f state (n state %bat q:(gen-tx 1 marbud-own marbud-transfer-2))
owner.own:(~(got by points.state) ~marbud)
::
++ test-l1-changed-spawn-proxy ^- tang
%+ expect-eq
!> [0x123 0]
!> [(addr %bud-skey) 0]
::
!>
=| =^state:naive
=^ f state (init-bud state)
=^ f state (n state (changed-spawn-proxy:l1 ~bud 0x123))
=^ f state (n state (changed-spawn-proxy:l1 ~bud (addr %bud-skey)))
spawn-proxy.own:(~(got by points.state) ~bud)
::
++ test-l1-changed-transfer-proxy ^- tang
%+ expect-eq
!> [0x123 0]
!> [(addr %bud-key-1) 0]
::
!>
=| =^state:naive
=^ f state (init-bud state)
=^ f state (n state (changed-transfer-proxy:l1 ~bud 0x123))
=^ f state (n state (changed-transfer-proxy:l1 ~bud (addr %bud-key-1)))
transfer-proxy.own:(~(got by points.state) ~bud)
::
++ test-l1-changed-management-proxy ^- tang
%+ expect-eq
!> [0x123 0]
!> [(addr %bud-mkey) 0]
::
!>
=| =^state:naive
=^ f state (init-bud state)
=^ f state (n state (changed-management-proxy:l1 ~bud 0x123))
=^ f state (n state (changed-management-proxy:l1 ~bud (addr %bud-mkey)))
management-proxy.own:(~(got by points.state) ~bud)
::
++ test-l1-changed-voting-proxy ^- tang
%+ expect-eq
!> [0x123 0]
!> [(addr %bud-vkey) 0]
::
!>
=| =^state:naive
=^ f state (init-bud state)
=^ f state (n state (changed-voting-proxy:l1 ~bud 0x123))
=^ f state (n state (changed-voting-proxy:l1 ~bud (addr %bud-vkey)))
voting-proxy.own:(~(got by points.state) ~bud)
::
++ test-l2-set-spawn-proxy ^- tang
++ test-l1-changed-keys ^- tang
=/ life 1
=/ new-keys [~bud suit encr auth life]
::
%+ expect-eq
!> [0x123 0]
!> [suit auth encr]
::
!>
=| =^state:naive
=^ f state (init-bud state)
=^ f state (n state (changed-keys:l1 new-keys))
|1:keys.net:(~(got by points.state) ~bud)
::
++ test-l1-star-escape-requested ^- tang
%+ expect-eq
!> [~ ~wes]
::
!>
=| =^state:naive
=^ f state (init-wes state)
=^ f state (init-sambud state)
=^ f state (n state (escape-requested:l1 ~sambud ~wes))
escape.net:(~(got by points.state) ~sambud)
::
++ test-l1-star-escape-canceled ^- tang
%+ expect-eq
!> ~
::
!>
=| =^state:naive
=^ f state (init-wes state)
=^ f state (init-sambud state)
=^ f state (n state (escape-requested:l1 ~sambud ~wes))
=^ f state (n state (escape-canceled:l1 ~sambud ~wes))
escape.net:(~(got by points.state) ~sambud)
::
++ test-l1-star-adopt-accept ^- tang
%+ expect-eq
!> [~ %.y ~wes]
::
!>
=| =^state:naive
=^ f state (init-wes state)
=^ f state (init-sambud state)
=^ f state (n state (escape-requested:l1 ~sambud ~wes))
=^ f state (n state (escape-accepted:l1 ~sambud ~wes))
[escape.net sponsor.net]:(~(got by points.state) ~sambud)
::
++ test-l1-star-lost-sponsor ^- tang
%+ expect-eq
!> [~ %.n ~bud]
::
!>
=| =^state:naive
=^ f state (init-sambud state)
=^ f state (n state (lost-sponsor:l1 ~sambud ~bud))
[escape.net sponsor.net]:(~(got by points.state) ~sambud)
::
:: TODO: sponsorship tests for l1 planets, and L1/L2 sponsorship tests
::
++ test-l2-set-spawn-proxy ^- tang
=/ marbud-sproxy [%set-spawn-proxy (addr %marbud-skey)]
::
%+ expect-eq
!> [(addr %marbud-skey) 0]
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (n state %bat q:(set-spawn-proxy:l2 0 ~marbud %marbud-key-0 %own 0x123))
=^ f state (n state %bat q:(gen-tx 0 marbud-own marbud-sproxy))
spawn-proxy.own:(~(got by points.state) ~marbud)
::
++ test-l2-set-transfer-proxy ^- tang
=/ marbud-tproxy [%set-transfer-proxy (addr %marbud-tkey)]
::
%+ expect-eq
!> [0x123 0]
!> [(addr %marbud-tkey) 0]
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (n state %bat q:(set-transfer-proxy:l2 0 ~marbud %marbud-key-0 %own 0x123))
=^ f state (n state %bat q:(gen-tx 0 marbud-own marbud-tproxy))
transfer-proxy.own:(~(got by points.state) ~marbud)
::
++ test-l2-set-management-proxy ^- tang
=/ marbud-mproxy [%set-management-proxy (addr %marbud-mkey)]
::
%+ expect-eq
!> [0x123 0]
!> [(addr %marbud-mkey) 0]
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (n state %bat q:(set-management-proxy:l2 0 ~marbud %marbud-key-0 %own 0x123))
=^ f state (n state %bat q:(gen-tx 0 marbud-own marbud-mproxy))
management-proxy.own:(~(got by points.state) ~marbud)
::
++ test-l2-spawn-proxy-deposit ^- tang
@ -420,46 +344,271 @@
dominion:(~(got by points.state) ~dopbud)
::
++ test-marbud-l2-spawn ^- tang
=/ marbud-sproxy [%set-spawn-proxy (addr %marbud-skey)]
=/ lt-spawn [%spawn ~linnup-torsyx (addr %lt-key-0)]
::
;: weld
%+ expect-eq
!> [`@ux`(addr %ll-key-0) 0]
:: Tests l2 spawning with ownership
!> [`@ux`(addr %lt-key-0) 0]
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (n state %bat q:(spawn:l2 0 ~marbud %marbud-key-0 %own ~linnup-torsyx (addr %ll-key-0)))
=^ f state (n state %bat q:(gen-tx 0 marbud-own lt-spawn))
transfer-proxy.own:(~(got by points.state) ~linnup-torsyx)
::
++ test-marbud-l2-spawn-w-proxy ^- tang
%+ expect-eq
!> [`@ux`(addr %ll-key-0) 0]
:: Tests l2 spawning with spawn proxy
!> [`@ux`(addr %lt-key-0) 0]
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (n state %bat q:(set-spawn-proxy:l2 0 ~marbud %marbud-key-0 %own (addr %marbud-spawn-0)))
=^ f state (n state %bat q:(spawn:l2 0 ~marbud %marbud-spawn-0 %spawn ~linnup-torsyx (addr %ll-key-0)))
=^ f state (n state %bat q:(gen-tx 0 marbud-own marbud-sproxy))
=^ f state (n state %bat q:(gen-tx 0 marbud-spn lt-spawn))
transfer-proxy.own:(~(got by points.state) ~linnup-torsyx)
==
::
++ test-marbud-l2-double-spawn ^- tang
:: Attempts to spawn the same planet twice, once with ownership and once with spawn proxy
=/ marbud-sproxy [%set-spawn-proxy (addr %marbud-skey)]
=/ lt-spawn-0 [%spawn ~linnup-torsyx (addr %lt-key-0)]
=/ lt-spawn-1 [%spawn ~linnup-torsyx (addr %lt-key-1)]
::
%- expect-fail
|.
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (n state %bat q:(gen-tx 0 marbud-own marbud-sproxy))
=^ f state (n state %bat q:(gen-tx 1 marbud-own lt-spawn-0))
=^ f state (n state %bat q:(gen-tx 0 marbud-spn lt-spawn-1))
state
::
++ test-marbud-l2-change-keys ^- tang
=/ new-keys [%configure-keys suit encr auth |]
=/ marbud-mproxy [%set-management-proxy (addr %marbud-mkey)]
::
;: weld
%+ expect-eq
!> [suit auth encr]
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (n state %bat q:(gen-tx 0 marbud-own new-keys))
|1:keys.net:(~(got by points.state) ~marbud)
::
%+ expect-eq
!> [suit auth encr]
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (n state %bat q:(gen-tx 0 marbud-own marbud-mproxy))
=^ f state (n state %bat q:(gen-tx 0 marbud-mgt new-keys))
|1:keys.net:(~(got by points.state) ~marbud)
::
:: TODO: make sure nobody else can change these keys
==
::
:: TODO: transfer breach via transfer proxy
++ test-marbud-l2-proxies-transfer ^- tang
=/ marbud-t1 [~marbud %marbud-key-1 %transfer]
=/ new-keys [%configure-keys suit encr auth |]
=/ marbud-sproxy [%set-spawn-proxy (addr %marbud-skey)]
=/ marbud-mproxy [%set-management-proxy (addr %marbud-mkey)]
=/ marbud-tproxy [%set-transfer-proxy (addr %marbud-key-1)]
=/ marbud-transfer-breach [%transfer-point (addr %marbud-key-1) &]
=/ marbud-transfer-no-breach [%transfer-point (addr %marbud-key-1) |]
::
;: weld
%+ expect-eq
:: Tests that proxies are reset on transfer with breach
::
!>
:* [(addr %marbud-key-1) 3] :: ownership
[0 0] :: spawn-proxy
[0 0] :: management-proxy
[0 0] :: voting-proxy
[0 1] :: transfer-proxy
==
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (n state %bat q:(gen-tx 0 marbud-own marbud-sproxy))
=^ f state (n state %bat q:(gen-tx 1 marbud-own marbud-mproxy))
=^ f state (n state %bat q:(gen-tx 2 marbud-own marbud-tproxy))
=^ f state (n state %bat q:(gen-tx 0 marbud-t1 marbud-transfer-breach))
^- [[@ @] [@ @] [@ @] [@ @] [@ @]]
own:(~(got by points.state) ~marbud)
::
%+ expect-eq
:: Tests that networking keys are reset on transfer with breach
!>
[0 0 0]
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (n state %bat q:(gen-tx 0 marbud-own new-keys))
=^ f state (n state %bat q:(gen-tx 1 marbud-own [%transfer-point (addr %marbud-key-0) &]))
|1:keys.net:(~(got by points.state) ~marbud)
::
%+ expect-eq
:: Tests that proxies are not reset when transfering without breach
!>
:* [(addr %marbud-key-1) 3] :: ownership
[(addr %marbud-skey) 0] :: spawn-proxy
[(addr %marbud-mkey) 0] :: management-proxy
[0 0] :: voting-proxy
[0 1] :: transfer-proxy
==
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (n state %bat q:(gen-tx 0 marbud-own marbud-sproxy))
=^ f state (n state %bat q:(gen-tx 1 marbud-own marbud-mproxy))
=^ f state (n state %bat q:(gen-tx 2 marbud-own marbud-tproxy))
=^ f state (n state %bat q:(gen-tx 0 marbud-t1 marbud-transfer-no-breach))
^- [[@ @] [@ @] [@ @] [@ @] [@ @]]
own:(~(got by points.state) ~marbud)
::
%+ expect-eq
:: Tests that networking keys are not reset when transfering without breach
!>
[suit auth encr]
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (n state %bat q:(gen-tx 0 marbud-own new-keys))
=^ f state (n state %bat q:(gen-tx 1 marbud-own [%transfer-point (addr %marbud-key-0) |]))
|1:keys.net:(~(got by points.state) ~marbud)
==
::
:: TODO: life+rift changes via transfer proxy
::
++ test-marbud-keys-life-rift ^- tang
=/ new-keys-no-reset [%configure-keys suit encr auth |]
=/ new-keys-yes-reset [%configure-keys suit encr auth &]
=/ zero-keys-no-reset [%configure-keys 0 0 0 |]
=/ zero-keys-yes-reset [%configure-keys 0 0 0 &]
::
;: weld
%+ expect-eq
:: breach=%.n
!> [0 1] :: [rift life]
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (n state %bat q:(gen-tx 0 marbud-own new-keys-no-reset))
[rift.net life.keys.net]:(~(got by points.state) ~marbud)
::
%+ expect-eq
:: breach=%.y
!> [1 1]
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (n state %bat q:(gen-tx 0 marbud-own new-keys-yes-reset))
[rift.net life.keys.net]:(~(got by points.state) ~marbud)
::
%+ expect-eq
:: networking keys set incremenets life, reset=%.y
:: then zero keys and transfer, should increment rift but not life
::
!> [2 2]
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (n state %bat q:(gen-tx 0 marbud-own new-keys-yes-reset)) :: inc life and rift
=^ f state (n state %bat q:(gen-tx 1 marbud-own zero-keys-no-reset)) :: inc life
=^ f state (n state %bat q:(gen-tx 2 marbud-own zero-keys-yes-reset)) :: inc rift
[rift.net life.keys.net]:(~(got by points.state) ~marbud)
::
==
::
++ test-marbud-transfer-life-rift ^- tang
=/ new-keys-no-reset [%configure-keys suit encr auth |]
=/ new-keys-yes-reset [%configure-keys suit encr auth &]
=/ zero-keys-no-reset [%configure-keys 0 0 0 |]
=/ zero-keys-yes-reset [%configure-keys 0 0 0 &]
=/ marbud-transfer-no-breach [%transfer-point (addr %marbud-key-1) |]
=/ marbud-transfer-yes-breach [%transfer-point (addr %marbud-key-1) &]
::
;: weld
%+ expect-eq
:: networking keys not set, reset=%.n
::
!> [0 0] :: [rift life]
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (n state %bat q:(gen-tx 0 marbud-own marbud-transfer-no-breach))
[rift.net life.keys.net]:(~(got by points.state) ~marbud)
::
%+ expect-eq
:: networking keys not set, reset=%.y
::
!> [0 0]
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (n state %bat q:(gen-tx 0 marbud-own marbud-transfer-no-breach))
[rift.net life.keys.net]:(~(got by points.state) ~marbud)
::
%+ expect-eq
:: networking keys set incremenets life, reset=%.y
:: then zero keys and transfer, should increment rift but not life
:: TODO: transferring and reset with already zeroed keys ought to incr rift but not life, right?
:: but currently the transfer w/ reset increments both life and rift, despite keys already being 0
::
!> [2 2]
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (n state %bat q:(gen-tx 0 marbud-own new-keys-yes-reset)) :: inc life and rift
=^ f state (n state %bat q:(gen-tx 1 marbud-own zero-keys-no-reset)) :: inc life
=^ f state (n state %bat q:(gen-tx 2 marbud-own marbud-transfer-yes-breach)) :: inc rift
[rift.net life.keys.net]:(~(got by points.state) ~marbud)
::
==
::
++ test-dopbud-l2-spawn ^- tang
=/ pp-spawn [%spawn ~palsep-picdun (addr %pp-key-0)]
::
%+ expect-eq
!> [`@ux`(addr %pp-key-0) 0]
::
!>
=| =^state:naive
=^ f state (init-dopbud state)
=^ f state (n state %bat q:(spawn:l2 0 ~dopbud %dopbud-key-0 %own ~palsep-picdun (addr %pp-key-0)))
=^ f state (n state %bat q:(gen-tx 0 dopbud-own pp-spawn))
transfer-proxy.own:(~(got by points.state) ~palsep-picdun)
::
++ test-dopbud-l2-spawn-after-transfer ^- tang
=/ pp-spawn [%spawn ~palsep-picdun (addr %pp-key-0)]
=/ lr-spawn [%spawn ~laclur-rachul (addr %lr-key-0)]
=/ dopbud-own-1 [~dopbud %dopbud-key-1 %own]
::
%+ expect-eq
!> [`@ux`(addr %lr-key-0) 0]
::
!>
=| =^state:naive
=^ f state (init-dopbud state)
=^ f state (n state %bat q:(spawn:l2 0 ~dopbud %dopbud-key-0 %own ~palsep-picdun (addr %pp-key-0)))
=^ f state (n state %bat q:(gen-tx 0 dopbud-own pp-spawn))
=^ f state (n state (owner-changed:l1 ~dopbud (addr %dopbud-key-1)))
=^ f state (n state %bat q:(spawn:l2 1 ~dopbud %dopbud-key-1 %own ~laclur-rachul (addr %lr-key-0)))
=^ f state (n state %bat q:(gen-tx 1 dopbud-own-1 lr-spawn))
transfer-proxy.own:(~(got by points.state) ~laclur-rachul)
::
:: ++ test-sambud-double-spawn ^- tang
@ -493,27 +642,119 @@
:: state
::
++ test-linnup-torsyx-l2-transfer-ownership ^- tang
=/ lt-spawn [%spawn ~linnup-torsyx (addr %lt-key-0)]
=/ lt-transfer-yes-breach [%transfer-point (addr %lt-key-0) &]
::
%+ expect-eq
!> [`@ux`(addr %lt-key-0) 0]
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (n state %bat q:(spawn:l2 0 ~marbud %marbud-key-0 %own ~linnup-torsyx (addr %lt-key-0)))
=^ f state (n state %bat q:(transfer-point:l2 0 ~linnup-torsyx %lt-key-0 (addr %lt-key-0) %transfer &))
=^ f state (n state %bat q:(gen-tx 0 marbud-own lt-spawn))
=^ f state (n state %bat q:(gen-tx 0 lt-xfr lt-transfer-yes-breach))
owner.own:(~(got by points.state) ~linnup-torsyx)
::
++ test-palsep-picdun-l2-transfer-ownership ^- tang
=/ pp-xfr [~palsep-picdun %pp-key-0 %transfer]
=/ pp-spawn [%spawn ~palsep-picdun (addr %pp-key-0)]
=/ pp-transfer-yes-breach [%transfer-point (addr %pp-key-0) &]
%+ expect-eq
!> [`@ux`(addr %pp-key-0) 0]
::
!>
=| =^state:naive
=^ f state (init-dopbud state)
=^ f state (n state %bat q:(spawn:l2 0 ~dopbud %dopbud-key-0 %own ~palsep-picdun (addr %pp-key-0)))
=^ f state (n state %bat q:(transfer-point:l2 0 ~palsep-picdun %pp-key-0 (addr %pp-key-0) %transfer &))
=^ f state (n state %bat q:(gen-tx 0 dopbud-own pp-spawn))
=^ f state (n state %bat q:(gen-tx 0 pp-xfr pp-transfer-yes-breach))
owner.own:(~(got by points.state) ~palsep-picdun)
::
++ test-linnup-torsyx-l2-escape-request ^- tang
:: TODO: Are you supposed to be able to request escape to a non-existent star?
=/ lt-spawn [%spawn ~linnup-torsyx (addr %lt-key-0)]
=/ lt-transfer-yes-breach [%transfer-point (addr %lt-key-0) &]
::
%+ expect-eq
!> [~ ~litbud]
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (init-litbud state)
=^ f state (n state %bat q:(gen-tx 0 marbud-own lt-spawn))
=^ f state (n state %bat q:(gen-tx 0 lt-xfr lt-transfer-yes-breach))
=^ f state (n state %bat q:(gen-tx 0 lt-own [%escape ~litbud]))
escape.net:(~(got by points.state) ~linnup-torsyx)
::
++ test-linnup-torsyx-l2-cancel-escape-request ^- tang
=/ lt-spawn [%spawn ~linnup-torsyx (addr %lt-key-0)]
=/ lt-transfer-yes-breach [%transfer-point (addr %lt-key-0) &]
::
%+ expect-eq
!> ~
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (init-litbud state)
=^ f state (n state %bat q:(gen-tx 0 marbud-own lt-spawn))
=^ f state (n state %bat q:(gen-tx 0 lt-xfr lt-transfer-yes-breach))
=^ f state (n state %bat q:(gen-tx 0 lt-own [%escape ~litbud]))
=^ f state (n state %bat q:(gen-tx 1 lt-own [%cancel-escape ~litbud]))
escape.net:(~(got by points.state) ~linnup-torsyx)
::
++ test-linnup-torsyx-l2-adopt-accept ^- tang
=/ lt-spawn [%spawn ~linnup-torsyx (addr %lt-key-0)]
=/ lt-transfer-yes-breach [%transfer-point (addr %lt-key-0) &]
::
%+ expect-eq
!> [~ %.y ~litbud]
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (init-litbud state)
=^ f state (n state %bat q:(gen-tx 0 marbud-own lt-spawn))
=^ f state (n state %bat q:(gen-tx 0 lt-xfr lt-transfer-yes-breach))
=^ f state (n state %bat q:(gen-tx 0 lt-own [%escape ~litbud]))
=^ f state (n state %bat q:(gen-tx 0 litbud-own [%adopt ~linnup-torsyx]))
[escape.net sponsor.net]:(~(got by points.state) ~linnup-torsyx)
::
++ test-linnup-torsyx-l2-adopt-reject ^- tang
:: TODO: at the moment the default sponsor is always ~zod, but it should probably
:: be ~marbud here
=/ lt-spawn [%spawn ~linnup-torsyx (addr %lt-key-0)]
=/ lt-transfer-yes-breach [%transfer-point (addr %lt-key-0) &]
::
%+ expect-eq
!> ~
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (init-litbud state)
=^ f state (n state %bat q:(gen-tx 0 marbud-own lt-spawn))
=^ f state (n state %bat q:(gen-tx 0 lt-xfr lt-transfer-yes-breach))
=^ f state (n state %bat q:(gen-tx 0 lt-own [%escape ~litbud]))
=^ f state (n state %bat q:(gen-tx 0 litbud-own [%reject ~linnup-torsyx]))
escape.net:(~(got by points.state) ~linnup-torsyx)
::
++ test-linnup-torsyx-l2-detach ^- tang
=/ lt-spawn [%spawn ~linnup-torsyx (addr %lt-key-0)]
=/ lt-transfer-yes-breach [%transfer-point (addr %lt-key-0) &]
::
%+ expect-eq
!> [~ %.n ~marbud]
::
!>
=| =^state:naive
=^ f state (init-marbud state)
=^ f state (init-litbud state)
=^ f state (n state %bat q:(gen-tx 0 marbud-own lt-spawn))
=^ f state (n state %bat q:(gen-tx 0 lt-xfr lt-transfer-yes-breach))
=^ f state (n state %bat q:(gen-tx 1 marbud-own [%detach ~linnup-torsyx]))
[escape.net sponsor.net]:(~(got by points.state) ~linnup-torsyx)
::
:: TODO: signature format changed; regenerate
::
:: ++ test-metamask-signature ^- tang