@@ -96,11 +96,17 @@ public class ShieldedReceiveTest {
9696
9797 private static Wallet wallet ;
9898
99- public enum TestColumn {CV , ZKPOOF , D_CM , PKD_CM , VALUE_CM , R_CM };
99+ public enum TestColumn {CV , ZKPOOF , D_CM , PKD_CM , VALUE_CM , R_CM }
100100
101- public enum TestSignMissingColumn { FROM_ADDRESS , FROM_AMOUNT , SPEND_DESCRITPION , RECEIVE_DESCRIPTION , TO_ADDRESS , TO_AMOUNT } ;
101+ ;
102102
103- public enum TestReceiveMissingColumn {CV , CM , EPK , C_ENC , C_OUT , ZKPROOF };
103+ public enum TestSignMissingColumn {FROM_ADDRESS , FROM_AMOUNT , SPEND_DESCRITPION , RECEIVE_DESCRIPTION , TO_ADDRESS , TO_AMOUNT }
104+
105+ ;
106+
107+ public enum TestReceiveMissingColumn {CV , CM , EPK , C_ENC , C_OUT , ZKPROOF }
108+
109+ ;
104110
105111 static {
106112 Args .setParam (new String []{"--output-directory" , dbPath }, "config-localtest.conf" );
@@ -358,7 +364,7 @@ private ZenTransactionBuilder generateBuilderWithoutColumnInDescription(
358364 */
359365 @ Test
360366 public void testReceiveDescriptionWithEmptyCV () throws BadItemException ,
361- ContractValidateException , ContractExeException , RuntimeException , ZksnarkException {
367+ ContractValidateException , ContractExeException , RuntimeException , ZksnarkException {
362368 librustzcashInitZksnarkParams ();
363369 dbManager .getDynamicPropertiesStore ().saveAllowZksnarkTransaction (1 );
364370 dbManager .getDynamicPropertiesStore ().saveTotalShieldedPoolValue (100 * 1000000l );
@@ -374,7 +380,7 @@ public void testReceiveDescriptionWithEmptyCV() throws BadItemException,
374380 transactionCapsule = wallet .createTransactionCapsuleWithoutValidate (
375381 builder .getContractBuilder ().build (), ContractType .ShieldedTransferContract );
376382 TransactionExtention transactionExtention = TransactionExtention .newBuilder ()
377- .setTransaction (transactionCapsule .getInstance ()).build ();
383+ .setTransaction (transactionCapsule .getInstance ()).build ();
378384
379385 dataToBeSigned = transactionCapsule .hashShieldTransaction (transactionCapsule );
380386 } catch (Exception ex ) {
@@ -1279,44 +1285,44 @@ private byte[] hashWithMissingColumn(TransactionCapsule tx, TestSignMissingColum
12791285 .unpack (ShieldedTransferContract .class );
12801286 ShieldedTransferContract .Builder newContract = ShieldedTransferContract .newBuilder ();
12811287
1282- if (column != null ) {
1288+ if (column != null ) {
12831289 switch (column ) {
12841290 case FROM_ADDRESS :
12851291 newContract .setFromAmount (shieldedTransferContract .getFromAmount ());
12861292 newContract
1287- .addAllReceiveDescription (shieldedTransferContract .getReceiveDescriptionList ());
1293+ .addAllReceiveDescription (shieldedTransferContract .getReceiveDescriptionList ());
12881294 newContract .setToAmount (shieldedTransferContract .getToAmount ());
12891295 //newContract.setTransparentFromAddress(shieldedTransferContract.getTransparentFromAddress());
12901296 newContract .setTransparentToAddress (shieldedTransferContract .getTransparentToAddress ());
12911297 for (SpendDescription spendDescription : shieldedTransferContract
1292- .getSpendDescriptionList ()) {
1298+ .getSpendDescriptionList ()) {
12931299 newContract
1294- .addSpendDescription (
1295- spendDescription .toBuilder ().clearSpendAuthoritySignature ().build ());
1300+ .addSpendDescription (
1301+ spendDescription .toBuilder ().clearSpendAuthoritySignature ().build ());
12961302 }
12971303 break ;
12981304 case FROM_AMOUNT :
12991305 //newContract.setFromAmount(shieldedTransferContract.getFromAmount());
13001306 newContract
1301- .addAllReceiveDescription (shieldedTransferContract .getReceiveDescriptionList ());
1307+ .addAllReceiveDescription (shieldedTransferContract .getReceiveDescriptionList ());
13021308 newContract .setToAmount (shieldedTransferContract .getToAmount ());
13031309 newContract
1304- .setTransparentFromAddress (shieldedTransferContract .getTransparentFromAddress ());
1310+ .setTransparentFromAddress (shieldedTransferContract .getTransparentFromAddress ());
13051311 newContract .setTransparentToAddress (shieldedTransferContract .getTransparentToAddress ());
13061312 for (SpendDescription spendDescription : shieldedTransferContract
1307- .getSpendDescriptionList ()) {
1313+ .getSpendDescriptionList ()) {
13081314 newContract
1309- .addSpendDescription (
1310- spendDescription .toBuilder ().clearSpendAuthoritySignature ().build ());
1315+ .addSpendDescription (
1316+ spendDescription .toBuilder ().clearSpendAuthoritySignature ().build ());
13111317 }
13121318 break ;
13131319 case SPEND_DESCRITPION :
13141320 newContract .setFromAmount (shieldedTransferContract .getFromAmount ());
13151321 newContract
1316- .addAllReceiveDescription (shieldedTransferContract .getReceiveDescriptionList ());
1322+ .addAllReceiveDescription (shieldedTransferContract .getReceiveDescriptionList ());
13171323 newContract .setToAmount (shieldedTransferContract .getToAmount ());
13181324 newContract
1319- .setTransparentFromAddress (shieldedTransferContract .getTransparentFromAddress ());
1325+ .setTransparentFromAddress (shieldedTransferContract .getTransparentFromAddress ());
13201326 newContract .setTransparentToAddress (shieldedTransferContract .getTransparentToAddress ());
13211327 //for (SpendDescription spendDescription : shieldedTransferContract.getSpendDescriptionList()) {
13221328 // newContract
@@ -1328,43 +1334,43 @@ private byte[] hashWithMissingColumn(TransactionCapsule tx, TestSignMissingColum
13281334 //newContract.addAllReceiveDescription(shieldedTransferContract.getReceiveDescriptionList());
13291335 newContract .setToAmount (shieldedTransferContract .getToAmount ());
13301336 newContract
1331- .setTransparentFromAddress (shieldedTransferContract .getTransparentFromAddress ());
1337+ .setTransparentFromAddress (shieldedTransferContract .getTransparentFromAddress ());
13321338 newContract .setTransparentToAddress (shieldedTransferContract .getTransparentToAddress ());
13331339 for (SpendDescription spendDescription : shieldedTransferContract
1334- .getSpendDescriptionList ()) {
1340+ .getSpendDescriptionList ()) {
13351341 newContract
1336- .addSpendDescription (
1337- spendDescription .toBuilder ().clearSpendAuthoritySignature ().build ());
1342+ .addSpendDescription (
1343+ spendDescription .toBuilder ().clearSpendAuthoritySignature ().build ());
13381344 }
13391345 break ;
13401346 case TO_ADDRESS :
13411347 newContract .setFromAmount (shieldedTransferContract .getFromAmount ());
13421348 newContract
1343- .addAllReceiveDescription (shieldedTransferContract .getReceiveDescriptionList ());
1349+ .addAllReceiveDescription (shieldedTransferContract .getReceiveDescriptionList ());
13441350 newContract .setToAmount (shieldedTransferContract .getToAmount ());
13451351 newContract
1346- .setTransparentFromAddress (shieldedTransferContract .getTransparentFromAddress ());
1352+ .setTransparentFromAddress (shieldedTransferContract .getTransparentFromAddress ());
13471353 //newContract.setTransparentToAddress(shieldedTransferContract.getTransparentToAddress());
13481354 for (SpendDescription spendDescription : shieldedTransferContract
1349- .getSpendDescriptionList ()) {
1355+ .getSpendDescriptionList ()) {
13501356 newContract
1351- .addSpendDescription (
1352- spendDescription .toBuilder ().clearSpendAuthoritySignature ().build ());
1357+ .addSpendDescription (
1358+ spendDescription .toBuilder ().clearSpendAuthoritySignature ().build ());
13531359 }
13541360 break ;
13551361 case TO_AMOUNT :
13561362 newContract .setFromAmount (shieldedTransferContract .getFromAmount ());
13571363 newContract
1358- .addAllReceiveDescription (shieldedTransferContract .getReceiveDescriptionList ());
1364+ .addAllReceiveDescription (shieldedTransferContract .getReceiveDescriptionList ());
13591365 //newContract.setToAmount(shieldedTransferContract.getToAmount());
13601366 newContract
1361- .setTransparentFromAddress (shieldedTransferContract .getTransparentFromAddress ());
1367+ .setTransparentFromAddress (shieldedTransferContract .getTransparentFromAddress ());
13621368 newContract .setTransparentToAddress (shieldedTransferContract .getTransparentToAddress ());
13631369 for (SpendDescription spendDescription : shieldedTransferContract
1364- .getSpendDescriptionList ()) {
1370+ .getSpendDescriptionList ()) {
13651371 newContract
1366- .addSpendDescription (
1367- spendDescription .toBuilder ().clearSpendAuthoritySignature ().build ());
1372+ .addSpendDescription (
1373+ spendDescription .toBuilder ().clearSpendAuthoritySignature ().build ());
13681374 }
13691375 break ;
13701376 default :
@@ -1748,7 +1754,7 @@ public void testSpendSignatureWithWrongColumn()
17481754 IncomingViewingKey ivk1 = fullViewingKey1 .inViewingKey ();
17491755 PaymentAddress paymentAddress1 = ivk1 .address (new DiversifierT ()).get ();
17501756 builder .addOutput (fullViewingKey1 .getOvk (), paymentAddress1 , 90 * 1000000 , new byte [512 ]);
1751-
1757+
17521758 // Create Sapling SpendDescriptions
17531759 for (SpendDescriptionInfo spend : builder .getSpends ()) {
17541760 SpendDescriptionCapsule spendDescriptionCapsule = builder .generateSpendProof (spend , ctx );
@@ -1869,17 +1875,19 @@ public void testLibrustzcashZip32XskMaster() throws ZksnarkException {
18691875 }
18701876
18711877 @ AllArgsConstructor
1872- class TransactionHash {
1878+ class TransactionHash {
1879+
18731880 @ Setter
18741881 @ Getter
18751882 byte [] hash ;
18761883 }
1884+
18771885 /**
18781886 * test use isolate method to build the signature
18791887 */
18801888 @ Test
18811889 public void testIsolateSignature ()
1882- throws ZksnarkException , BadItemException , ContractValidateException , ContractExeException {
1890+ throws ZksnarkException , BadItemException , ContractValidateException , ContractExeException {
18831891 librustzcashInitZksnarkParams ();
18841892 dbManager .getDynamicPropertiesStore ().saveAllowZksnarkTransaction (1 );
18851893 dbManager .getDynamicPropertiesStore ().saveTotalShieldedPoolValue (100 * 1000000l );
@@ -1892,37 +1900,38 @@ public void testIsolateSignature()
18921900
18931901 //build transaction without spend signature and get transactionHash
18941902 TransactionHash transactionHash = new TransactionHash (new byte [32 ]);
1895- TransactionCapsule transactionCapsule = buildShieldedTransactionWithoutSpendAuthSig (sk .defaultAddress (),
1896- sk .fullViewingKey ().getAk (),
1897- expsk .getNsk (),
1898- expsk .getOvk (),
1899- transactionHash ,
1900- builder ,
1901- ctx );
1903+ TransactionCapsule transactionCapsule = buildShieldedTransactionWithoutSpendAuthSig (
1904+ sk .defaultAddress (),
1905+ sk .fullViewingKey ().getAk (),
1906+ expsk .getNsk (),
1907+ expsk .getOvk (),
1908+ transactionHash ,
1909+ builder ,
1910+ ctx );
19021911
19031912 //filled with Sapling spendAuth in builder
19041913 List <SpendDescriptionInfo > spends = builder .getSpends ();
19051914 for (int i = 0 ; i < spends .size (); i ++) {
19061915 //replace with interface
19071916 SpendAuthSigParameters spendAuthSigParameters = SpendAuthSigParameters .newBuilder ()
1908- .setAsk (ByteString .copyFrom (expsk .getAsk ())) //ask => ak
1909- .setAlpha (ByteString .copyFrom (spends .get (i ).alpha ))
1910- .setTxHash (ByteString .copyFrom (transactionHash .getHash ()))
1911- .build ();
1917+ .setAsk (ByteString .copyFrom (expsk .getAsk ())) //ask => ak
1918+ .setAlpha (ByteString .copyFrom (spends .get (i ).alpha ))
1919+ .setTxHash (ByteString .copyFrom (transactionHash .getHash ()))
1920+ .build ();
19121921 BytesMessage spendAuthSig = wallet .createSpendAuthSig (spendAuthSigParameters );
19131922 builder .getContractBuilder ().getSpendDescriptionBuilder (i )
1914- .setSpendAuthoritySignature (spendAuthSig .getValue ());
1923+ .setSpendAuthoritySignature (spendAuthSig .getValue ());
19151924 }
19161925
19171926 Transaction .raw .Builder rawBuilder = transactionCapsule .getInstance ().toBuilder ()
1918- .getRawDataBuilder ()
1919- .clearContract ()
1920- .addContract (Transaction .Contract .newBuilder ()
1921- .setType (ContractType .ShieldedTransferContract )
1922- .setParameter (Any .pack (builder .getContractBuilder ().build ()))
1923- .build ());
1927+ .getRawDataBuilder ()
1928+ .clearContract ()
1929+ .addContract (Transaction .Contract .newBuilder ()
1930+ .setType (ContractType .ShieldedTransferContract )
1931+ .setParameter (Any .pack (builder .getContractBuilder ().build ()))
1932+ .build ());
19241933 Transaction transaction = transactionCapsule .getInstance ().toBuilder ().clearRawData ()
1925- .setRawData (rawBuilder ).build ();
1934+ .setRawData (rawBuilder ).build ();
19261935
19271936 TransactionCapsule transactionCap = new TransactionCapsule (transaction );
19281937 //validate
@@ -1935,23 +1944,23 @@ public void testIsolateSignature()
19351944 }
19361945
19371946 public TransactionCapsule buildShieldedTransactionWithoutSpendAuthSig (PaymentAddress address ,
1938- byte [] ak , byte [] nsk , byte [] ovk , TransactionHash dataHashToBeSigned ,
1939- ZenTransactionBuilder builder ,Pointer ctx )
1940- throws ZksnarkException , BadItemException , ContractValidateException {
1947+ byte [] ak , byte [] nsk , byte [] ovk , TransactionHash dataHashToBeSigned ,
1948+ ZenTransactionBuilder builder , Pointer ctx )
1949+ throws ZksnarkException , BadItemException , ContractValidateException {
19411950 // generate input
19421951 Note note = new Note (address , 100 * 1000000 );
19431952 IncrementalMerkleVoucherContainer voucher = createSimpleMerkleVoucherContainer (note .cm ());
19441953 byte [] anchor = voucher .root ().getContent ().toByteArray ();
19451954 dbManager .getMerkleContainer ()
1946- .putMerkleTreeIntoStore (anchor , voucher .getVoucherCapsule ().getTree ());
1955+ .putMerkleTreeIntoStore (anchor , voucher .getVoucherCapsule ().getTree ());
19471956
19481957 SpendDescriptionInfo skSpend = new SpendDescriptionInfo (ak ,
1949- nsk ,
1950- ovk ,
1951- note ,
1952- note .r , //?
1953- anchor ,
1954- voucher
1958+ nsk ,
1959+ ovk ,
1960+ note ,
1961+ note .r , //?
1962+ anchor ,
1963+ voucher
19551964 );
19561965 builder .addSpend (skSpend );
19571966
@@ -1971,16 +1980,16 @@ public TransactionCapsule buildShieldedTransactionWithoutSpendAuthSig(PaymentAdd
19711980 // Create Sapling OutputDescriptions
19721981 for (ReceiveDescriptionInfo receive : builder .getReceives ()) {
19731982 ReceiveDescriptionCapsule receiveDescriptionCapsule = builder
1974- .generateOutputProof (receive , ctx );
1983+ .generateOutputProof (receive , ctx );
19751984 builder .getContractBuilder ().addReceiveDescription (receiveDescriptionCapsule .getInstance ());
19761985 }
19771986
19781987 // Empty output script
19791988 TransactionCapsule transactionCapsule = wallet .createTransactionCapsuleWithoutValidate (
1980- builder .getContractBuilder ().build (), ContractType .ShieldedTransferContract );
1989+ builder .getContractBuilder ().build (), ContractType .ShieldedTransferContract );
19811990 //replace with interface
19821991 TransactionExtention transactionExtention = TransactionExtention .newBuilder ()
1983- .setTransaction (transactionCapsule .getInstance ()).build ();
1992+ .setTransaction (transactionCapsule .getInstance ()).build ();
19841993 BytesMessage transactionHash = wallet .getShieldTransactionHash (transactionExtention );
19851994
19861995 if (transactionHash == null ) {
@@ -1991,10 +2000,10 @@ public TransactionCapsule buildShieldedTransactionWithoutSpendAuthSig(PaymentAdd
19912000 // Create binding signatures
19922001 byte [] bindingSig = new byte [64 ];
19932002 Librustzcash .librustzcashSaplingBindingSig (
1994- new SaplingBindingSigParams (ctx ,
1995- builder .getValueBalance (),
1996- dataHashToBeSigned .getHash (),
1997- bindingSig )
2003+ new SaplingBindingSigParams (ctx ,
2004+ builder .getValueBalance (),
2005+ dataHashToBeSigned .getHash (),
2006+ bindingSig )
19982007 );
19992008 builder .getContractBuilder ().setBindingSignature (ByteString .copyFrom (bindingSig ));
20002009 return transactionCapsule ;
0 commit comments