@@ -37,18 +37,18 @@ export function TestOnLocalnet () {
3737 Test ( 'Programs' , // Test SimplicityHL commitment and redemption transactions.
3838 // Empty program, always passes:
3939 TestProgram ( "unit program" , 'fn main () {}' , {
40- p2tr : 'ert1p9jcvyzkdwdqtf49kta4xpc5g35xkfcexwfsl8v70w2gwttelncyspjlnrz' ,
40+ address : 'ert1p9jcvyzkdwdqtf49kta4xpc5g35xkfcexwfsl8v70w2gwttelncyspjlnrz' ,
4141 commitFee : 27n
4242 } ) ,
4343 // Correct assertion, always passes:
4444 TestProgram ( "assert true" , 'fn main () { assert!(true) }' , {
45- p2tr : 'ert1per0vg2wvc4ua2rsndm8j6062r7z7ys7q6wcvwumepgz8t5m6hfhsrd8d8q' ,
45+ address : 'ert1per0vg2wvc4ua2rsndm8j6062r7z7ys7q6wcvwumepgz8t5m6hfhsrd8d8q' ,
4646 commitFee : 27n
4747 } ) ,
4848 // Incorrect assertion, always fails:
4949 TestProgram ( "assert false fails" , 'fn main () { assert!(false) }' , {
5050 shouldFail : true ,
51- p2tr : 'ert1p7p4rgaw5dmhxt6qutf2v3rtuy6afghfgktmmedkpju5uamxdz5js3hdug9' ,
51+ address : 'ert1p7p4rgaw5dmhxt6qutf2v3rtuy6afghfgktmmedkpju5uamxdz5js3hdug9' ,
5252 commitFee : 27n
5353 } ) ,
5454 // Test basic language features. Guards against general failure of all jets
@@ -59,13 +59,13 @@ export function TestOnLocalnet () {
5959 let ab: u8 = <(u4, u4)>::into((0b1011, 0b1101));
6060 assert!(jet::eq_8(ab, 0b10111101));
6161 }` , {
62- p2tr : 'ert1pmy9edmq0yfrc477jvcc835umyajlgjsnyujplt8nppr45zrwl7qs02gj3x' ,
62+ address : 'ert1pmy9edmq0yfrc477jvcc835umyajlgjsnyujplt8nppr45zrwl7qs02gj3x' ,
6363 commitFee : 27n , } ) ,
6464 // Witness signing:
6565 TestProgram ( "pay to pubkey" , `fn main () {
6666 jet::bip_0340_verify((param::PK, jet::sig_all_hash()), witness::SIG)
6767 }` , {
68- p2tr : 'ert1pa69jdawgz5wu5uc8ce2cv7lcqf64kadyl4wsrddparl25erfj2vq9824m9' ,
68+ address : 'ert1pa69jdawgz5wu5uc8ce2cv7lcqf64kadyl4wsrddparl25erfj2vq9824m9' ,
6969 argTypes : { PK : "u256" } ,
7070 witTypes : { SIG : "[u8; 64]" } ,
7171 provideArgs : ( ) => ( {
@@ -75,10 +75,6 @@ export function TestOnLocalnet () {
7575 SIG : SimplicityHL . Arg . Signature ( ALICE . signSchnorr ( sighash ) ) ,
7676 } ) ,
7777 commitFee : 27n , } ) ) ,
78- // Shutdown the localnet.
79- // TODO: wrapper ElementsRegtest(async () => { do things }); then autokilled
80- ( ) => sleep ( 1000 ) ,
81- Run . Kill ( 9 )
8278 ) ;
8379}
8480
@@ -89,9 +85,36 @@ export function TestOnTestnet () {
8985 TestSend ( ) , // Test the basic transaction primitive
9086 Test ( 'Programs' ,
9187 TestProgram ( "unit program" , 'fn main () {}' , {
92- p2tr : 'tex1p9jcvyzkdwdqtf49kta4xpc5g35xkfcexwfsl8v70w2gwttelncyshxjk56' ,
93- commitFee : 27n } ) ) ,
94- ) ;
88+ address : 'tex1p9jcvyzkdwdqtf49kta4xpc5g35xkfcexwfsl8v70w2gwttelncyshxjk56' ,
89+ commitFee : 27n } ) ,
90+ TestProgram ( "assert true" , 'fn main () { assert!(true) }' , {
91+ address : 'tex1per0vg2wvc4ua2rsndm8j6062r7z7ys7q6wcvwumepgz8t5m6hfhs4e2gsc' ,
92+ commitFee : 27n } ) ,
93+ TestProgram ( "assert false fails" , 'fn main () { assert!(false) }' , {
94+ shouldFail : true ,
95+ address : 'tex1p7p4rgaw5dmhxt6qutf2v3rtuy6afghfgktmmedkpju5uamxdz5js8rqela' ,
96+ commitFee : 27n } ) ,
97+ TestProgram ( "basic jets work" , `fn main () {
98+ let ab: u16 = <(u8, u8)>::into((0x10, 0x01));
99+ assert!(jet::eq_16(ab, 0x1001));
100+ let ab: u8 = <(u4, u4)>::into((0b1011, 0b1101));
101+ assert!(jet::eq_8(ab, 0b10111101));
102+ }` , {
103+ address : 'tex1pmy9edmq0yfrc477jvcc835umyajlgjsnyujplt8nppr45zrwl7qse79hx7' ,
104+ commitFee : 27n , } ) ,
105+ TestProgram ( "pay to pubkey" , `fn main () {
106+ jet::bip_0340_verify((param::PK, jet::sig_all_hash()), witness::SIG)
107+ }` , {
108+ address : 'tex1pa69jdawgz5wu5uc8ce2cv7lcqf64kadyl4wsrddparl25erfj2vqnn8sva' ,
109+ argTypes : { PK : "u256" } ,
110+ witTypes : { SIG : "[u8; 64]" } ,
111+ provideArgs : ( ) => ( {
112+ PK : SimplicityHL . Arg . Pubkey ( ALICE . xOnlyPublicKey ( ) )
113+ } ) ,
114+ provideWits : ( sighash : Uint8Array < ArrayBufferLike > ) => ( {
115+ SIG : SimplicityHL . Arg . Signature ( ALICE . signSchnorr ( sighash ) ) ,
116+ } ) ,
117+ commitFee : 27n , } ) ) ) ;
95118}
96119
97120// Test the spend helper.
@@ -114,11 +137,11 @@ function TestProgram (name: string, src: string, {
114137 /** Program runs that should fail. */
115138 shouldFail = false as boolean ,
116139 /** Expected deploy fee. */
117- commitFee = null as null | number ,
140+ commitFee = 100n ,
118141 /** Expected commitment Merkle root of program. */
119142 cmr = null as null | string ,
120143 /** Expected pay-to-taproot address of program. */
121- p2tr = null as null | string ,
144+ address = null as null | string ,
122145 /** Expected compile-time signature of program. */
123146 argTypes = { } as Record < string , string > ,
124147 /** Expected runtime signature of program. */
@@ -129,8 +152,8 @@ function TestProgram (name: string, src: string, {
129152 provideWits = null as null | Fn < [ Uint8Array < ArrayBufferLike > ] , Async < object > > ,
130153} = { } ) {
131154
132- return Fn . Name ( `${ name } (${ p2tr || 'unspecified P2TR' } )` , testProgram , {
133- shouldFail, name, src, commitFee, cmr, p2tr , argTypes, witTypes, provideArgs, provideWits,
155+ return Fn . Name ( `${ name } (${ address || 'unspecified P2TR' } )` , testProgram , {
156+ shouldFail, name, src, commitFee, cmr, address , argTypes, witTypes, provideArgs, provideWits,
134157 } ) ;
135158
136159 // Test the SimplicityHL program specified above on the given chain.
@@ -140,7 +163,7 @@ function TestProgram (name: string, src: string, {
140163 // Compile this program with these arguments for this chain.
141164 const program = await SimplicityHL . Program ( src , {
142165 // Expected program address, optional. Makes it safer.
143- address : p2tr ,
166+ address,
144167 // Represents config such as HRP, prefix bytes...
145168 // TODO expose
146169 chain : chain . ID ,
@@ -153,11 +176,16 @@ function TestProgram (name: string, src: string, {
153176 } ) ;
154177
155178 // Fund program from deployer:
156- const commitSource = await chain . getUtxo ( chain . P2WPKH ( ALICE . publicKey ( ) ) . address ) ;
157- const commitAmount = ( Btc . toSat ( commitSource . amount ) / 10n ) - commitFee ;
179+ const sender = chain . P2WPKH ( ALICE . publicKey ( ) ) . address ;
180+ const commitSource = await chain . getUtxo ( sender , x => x . amount >= commitFee ) ;
181+ const commitAmount = commitSource . value - commitFee ;
158182 const commitTxid = await SimplicityHL . Spend ( ) // TODO wrap as program.commit() ?
159- . asset ( commitSource . asset ) . input ( commitSource , ALICE )
160- . output ( program . p2tr , commitAmount ) . fee ( commitFee ) . broadcast ( chain ) ;
183+ . asset ( commitSource . asset )
184+ . input ( commitSource , ALICE )
185+ . output ( program . p2tr , commitAmount )
186+ . fee ( commitFee )
187+ . broadcast ( chain ) ;
188+
161189 debug ( 'Commit TX:' , commitTxid ) ;
162190
163191 // Note current recipient balance:
@@ -172,7 +200,7 @@ function TestProgram (name: string, src: string, {
172200 debug ( 'Redeem from:' , prev ) ;
173201 let index = null ;
174202 const vout = prev . vout . find ( ( x : Btc . Utxo , i : number ) => {
175- if ( toSPKA ( x ) === p2tr ) {
203+ if ( toSPKA ( x ) === program . p2tr ) {
176204 index = i ;
177205 return true ;
178206 }
@@ -182,9 +210,9 @@ function TestProgram (name: string, src: string, {
182210 debug ( 'Redeem UTXO:' , redeemSource ) ;
183211
184212 // To get SIGHASH_ALL for signing, first the rest of the transaction must be specified:
185- const redeemFee = 1000n ;
186- const redeemAmount = commitAmount - redeemFee ;
187- const sighashOpts = { asset, utxos : [ redeemSource ] , recipient, amount : redeemAmount , fee : redeemFee } ;
213+ const redeemFee = 200n ;
214+ const redeemAmount = 200n ;
215+ const sighashOpts = { asset, utxos : [ redeemSource ] , recipient, amount : redeemAmount , fee : redeemFee } ;
188216 debug ( 'Redeem opts:' , sighashOpts ) ;
189217 const sighash = program . redeemSighash ( sighashOpts ) ;
190218 ok ( sighash instanceof Uint8Array , 'sighash expected to be returned from WASM as Uint8Array' )
@@ -205,12 +233,13 @@ function TestProgram (name: string, src: string, {
205233 // TX is expected to pass
206234 const redeemTxid = await chain . broadcast ( hex ) ;
207235 const redeemTx = await chain . waitForTx ( redeemTxid ) ;
236+ debug ( 'Redeemed:' , redeemTx ) ;
208237
209238 // Balance is expected to increase
210- debug ( await chain . getBalance ( recipient , 0 ) ) ;
211- debug ( await chain . getBalance ( recipient , 0 ) ) ;
212- debug ( await recipientBalance ( ) ) ;
213- debug ( await recipientBalance ( ) ) ;
239+ // debug(await chain.getBalance(recipient, 0));
240+ // debug(await chain.getBalance(recipient, 0));
241+ // debug(await recipientBalance());
242+ // debug(await recipientBalance());
214243 //equal(await recipientBalance(), balance + redeemAmount);
215244 }
216245
0 commit comments