From eb797cb4a1f0698abb37776411cdcc66a4cf898f Mon Sep 17 00:00:00 2001 From: timlucmiptev Date: Sat, 30 Jan 2021 12:27:57 +0200 Subject: [PATCH] WIP: standardize tests --- TEST.md | 11 ++-- tests/btc-wallet-store.hoon | 35 ---------- tests/{ => lib}/bip158.hoon | 0 tests/lib/btc-wallet-store.hoon | 111 ++++++++++++++++++++++++++++++++ tests/{ => lib}/btc.hoon | 0 5 files changed, 115 insertions(+), 42 deletions(-) delete mode 100644 tests/btc-wallet-store.hoon rename tests/{ => lib}/bip158.hoon (100%) create mode 100644 tests/lib/btc-wallet-store.hoon rename tests/{ => lib}/btc.hoon (100%) diff --git a/TEST.md b/TEST.md index e4f3c24228..4a98f06b19 100644 --- a/TEST.md +++ b/TEST.md @@ -8,23 +8,20 @@ ## BTC libs ``` |commit %home -=test -build-file %/tests/btc/hoon +=test -build-file %/tests/lib/btc/hoon run:test ``` ## BIP158 ``` |commit %home -=test -build-file %/tests/bip158/hoon +=test -build-file %/tests/lib/bip158/hoon run:test ``` ## btc-wallet-store ``` |commit %home -=test -build-file %/tests/btc-wallet-store/hoon -run:test +=test -build-file %/tests/lib/btc-wallet-store/hoon +((slog test-vectors:test) ~) ``` - - -5e4affa5aed691d53d548a2705d602b45c9ae553bf44a4689e96a90c2f5e07b6 diff --git a/tests/btc-wallet-store.hoon b/tests/btc-wallet-store.hoon deleted file mode 100644 index 09977e3893..0000000000 --- a/tests/btc-wallet-store.hoon +++ /dev/null @@ -1,35 +0,0 @@ -/+ *btc-wallet-store, btc -=/ blank-utxo=utxo:btc - :* pos=0 - [wid=32 dat=0xc493.f6f1.4668.5f76.b44f.0c77.ca88.120c.b8bc.89f5.34fe.69b6.8288.27b9.74e6.8849] - height=3 - value=0 - ~ - == -|% -++ utxo-vals `(list sats:btc)`~[200.000 500.000 30 235.000] -++ eny1 0v3uc.iuebi.5qilc.l8d87.c1k6n.7iksq.nkobs.8s5he.raq40.9ff0b.5tj3u.kjtg7.aq59e.hatv7.oioam.mlsr4.pqqcd.cnbjn.pnpi2.1m5rt.k4scg -++ eny2 0v1gt.mc4ca.lfs0m.q1dal.lqobu.mmlbd.2umnp.lj9dr.4pf4s.pvclr.dps96.4a6i8.rt6n9.krp0r.11kqu.ckqe4.1tmat.gr754.463aj.a4b41.jj7qg -++ blank-walt - =| w=walt - w(bipt %84, confs 6) -++ sample-utxo-set - ^- (list insel) - :~ [blank-utxo(value (snag 0 utxo-vals)) %0 0] - [blank-utxo(value (snag 1 utxo-vals)) %0 2] - [blank-utxo(value (snag 2 utxo-vals)) %0 1] - [blank-utxo(value (snag 3 utxo-vals)) %1 2] - == -:: -++ run - :: random UTXO selection - =/ outputs=(list txo) - :~ [[%bech32 'bc1q59u5epktervh6fxqay2dlph0wxu9hjnx6v8n66'] value=200.100 ~] - [[%bech32 'bc1qlwd7mw33uea5m8r2lsnsrkc7gp2qynrxsfxpfm'] value=200.000 ~] - == - ?. =(1 (lent (need (~(single-random-draw sut [blank-walt eny1 923 ~ 100 outputs]) sample-utxo-set)))) - ~|("Didn't select correct number of UTXOs" !!) - ?. =(2 (lent (need (~(single-random-draw sut [blank-walt eny2 923 ~ 100 outputs]) sample-utxo-set)))) - ~|("Didn't select correct number of UTXOs" !!) - "All tests passed" --- diff --git a/tests/bip158.hoon b/tests/lib/bip158.hoon similarity index 100% rename from tests/bip158.hoon rename to tests/lib/bip158.hoon diff --git a/tests/lib/btc-wallet-store.hoon b/tests/lib/btc-wallet-store.hoon new file mode 100644 index 0000000000..463f257eb2 --- /dev/null +++ b/tests/lib/btc-wallet-store.hoon @@ -0,0 +1,111 @@ +/+ *test, *btc-wallet-store, btc +|% ++$ vector + $: =xpub:btc + eny=@uv + block=@ud + feyb=sats + ins=(list insel) + outs=(list txo) + expect=[selected=(unit (list insel)) chng=(unit sats:btc)] + == +++ mk-utxo + |= value=sats:btc + ^- utxo:btc + :* pos=0 + [wid=32 dat=0xc493.f6f1.4668.5f76.b44f.0c77.ca88.120c.b8bc.89f5.34fe.69b6.8288.27b9.74e6.8849] + height=3 + value + recvd=~ + == +:: +++ fprint 4^0xdead.beef +:: +++ vectors + =| w=walt + ^- (list vector) + :~ :* 'zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs' + 0v3uc.iuebi.5qilc.l8d87.c1k6n.7iksq.nkobs.8s5he.raq40.9ff0b.5tj3u.kjtg7.aq59e.hatv7.oioam.mlsr4.pqqcd.cnbjn.pnpi2.1m5rt.k4scg + 999 + 10 + :~ [(mk-utxo 200.000) %0 1] + [(mk-utxo 500.000) %0 2] + [(mk-utxo 204) %0 3] + [(mk-utxo 235.000) %1 2] + == + :~ [[%bech32 'bc1q59u5epktervh6fxqay2dlph0wxu9hjnx6v8n66'] 200.100 ~] + [[%bech32 'bc1qlwd7mw33uea5m8r2lsnsrkc7gp2qynrxsfxpfm'] 200.000 ~] + == + :* `~[[(mk-utxo 500.000) %0 2]] + `98.400 + == + == + :: + :* 'zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs' + 0v1gt.mc4ca.lfs0m.q1dal.lqobu.mmlbd.2umnp.lj9dr.4pf4s.pvclr.dps96.4a6i8.rt6n9.krp0r.11kqu.ckqe4.1tmat.gr754.463aj.a4b41.jj7qg + 999 + 10 + :~ [(mk-utxo 200.000) %0 1] + [(mk-utxo 500.000) %0 2] + [(mk-utxo 204) %0 3] + [(mk-utxo 235.000) %1 2] + == + :~ [[%bech32 'bc1q59u5epktervh6fxqay2dlph0wxu9hjnx6v8n66'] 200.100 ~] + [[%bech32 'bc1qlwd7mw33uea5m8r2lsnsrkc7gp2qynrxsfxpfm'] 200.000 ~] + == + :* `~[[(mk-utxo 235.000) %1 2] [(mk-utxo 200.000) %0 1]] + `64.000 + == + == + :: + :* 'zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs' + 0v1gt.mc4ca.lfs0m.q1dal.lqobu.mmlbd.2umnp.lj9dr.4pf4s.pvclr.dps96.4a6i8.rt6n9.krp0r.11kqu.ckqe4.1tmat.gr754.463aj.a4b41.jj7qg + 999 + 10 + ~[[(mk-utxo 500.000) %0 2]] + :~ [[%bech32 'bc1q59u5epktervh6fxqay2dlph0wxu9hjnx6v8n66'] 299.797 ~] + [[%bech32 'bc1qlwd7mw33uea5m8r2lsnsrkc7gp2qynrxsfxpfm'] 200.000 ~] + == + :* *(unit (list insel)) + *(unit sats:btc) + == + == + == +:: +++ dust-vectors %.n +:: +++ test-vectors + ^- tang + |^ ;: weld + %+ category "single-random-draw" + (zing (turn vectors check-single-random-draw)) + :: + %+ category "select with change" + (zing (turn vectors check-change)) + :: + == + :: + ++ check-single-random-draw + |= v=vector + =/ w=walt (from-xpub xpub.v fprint ~ ~ ~) + %+ expect-eq + !>(selected.expect.v) + !>((~(single-random-draw sut [w eny.v block.v ~ feyb.v outs.v]) ins.v)) + :: + ++ check-change + |= v=vector + =/ w=walt (from-xpub xpub.v fprint ~ ~ ~) + =/ addis=(list [address:btc addi]) + %+ turn ins.v + |= i=insel + :- (~(mk-address wad w chyg.i) idx.i) + [%.y %0 0 (sy ~[utxo.i])] + ?~ addis ~ + =. w w(wach (my addis + %+ expect-eq + !>(chng.expect.v) + !>(+:~(with-change sut [w eny.v block.v ~ feyb.v outs.v])) + -- + :: don't allow dust outputs + :: +-- diff --git a/tests/btc.hoon b/tests/lib/btc.hoon similarity index 100% rename from tests/btc.hoon rename to tests/lib/btc.hoon