@@ -413,8 +413,9 @@ public void publicAddressToShieldedAddressNotConsumeBandwidth() {
413413 public void publicAddressToShieldedInvalidFromAmount () throws ZksnarkException {
414414 dbManager .getDynamicPropertiesStore ().saveAllowZksnarkTransaction (1 );
415415 long fee = dbManager .getDynamicPropertiesStore ().getShieldedTransactionFee ();
416- long [] transferAmount = {0 , -100 };
417- for (long amount : transferAmount ) {
416+
417+ try {
418+ long amount = 0 ;
418419 ZenTransactionBuilder builder = new ZenTransactionBuilder (wallet );
419420 //From amount
420421 builder .setTransparentInput (ByteArray .fromHexString (PUBLIC_ADDRESS_ONE ), amount );
@@ -424,26 +425,53 @@ public void publicAddressToShieldedInvalidFromAmount() throws ZksnarkException {
424425 IncomingViewingKey incomingViewingKey = fullViewingKey .inViewingKey ();
425426 PaymentAddress paymentAddress = incomingViewingKey .address (new DiversifierT ().random ()).get ();
426427 builder .addOutput (fullViewingKey .getOvk (), paymentAddress , AMOUNT - fee , new byte [512 ]);
427- try {
428- TransactionCapsule transactionCap = builder .build ();
429-
430- Any contract =
431- transactionCap .getInstance ().toBuilder ().getRawDataBuilder ().getContract (0 )
432- .getParameter ();
433- ShieldedTransferActuator actuator = new ShieldedTransferActuator (contract , dbManager ,
434- transactionCap );
435- TransactionResultCapsule ret = new TransactionResultCapsule ();
436-
437- actuator .validate ();
438- actuator .execute (ret );
439- Assert .assertTrue (false );
440- } catch (ContractValidateException e ) {
441- Assert .assertTrue (e instanceof ContractValidateException );
442- Assert .assertEquals (
443- "from_amount should not be less than 0" , e .getMessage ());
444- } catch (Exception e ) {
445- Assert .assertTrue (false );
446- }
428+ TransactionCapsule transactionCap = builder .build ();
429+
430+ Any contract =
431+ transactionCap .getInstance ().toBuilder ().getRawDataBuilder ().getContract (0 )
432+ .getParameter ();
433+ ShieldedTransferActuator actuator = new ShieldedTransferActuator (contract , dbManager ,
434+ transactionCap );
435+ TransactionResultCapsule ret = new TransactionResultCapsule ();
436+
437+ actuator .validate ();
438+ actuator .execute (ret );
439+ Assert .assertTrue (false );
440+ } catch (ContractValidateException e ) {
441+ Assert .assertTrue (e instanceof ContractValidateException );
442+ Assert .assertEquals ("from_amount must be greater than 0" , e .getMessage ());
443+ } catch (Exception e ) {
444+ Assert .assertTrue (false );
445+ }
446+
447+ try {
448+ long amount = -100 ;
449+ ZenTransactionBuilder builder = new ZenTransactionBuilder (wallet );
450+ //From amount
451+ builder .setTransparentInput (ByteArray .fromHexString (PUBLIC_ADDRESS_ONE ), amount );
452+ //TO amount
453+ SpendingKey spendingKey = SpendingKey .random ();
454+ FullViewingKey fullViewingKey = spendingKey .fullViewingKey ();
455+ IncomingViewingKey incomingViewingKey = fullViewingKey .inViewingKey ();
456+ PaymentAddress paymentAddress = incomingViewingKey .address (new DiversifierT ().random ()).get ();
457+ builder .addOutput (fullViewingKey .getOvk (), paymentAddress , AMOUNT - fee , new byte [512 ]);
458+ TransactionCapsule transactionCap = builder .build ();
459+
460+ Any contract =
461+ transactionCap .getInstance ().toBuilder ().getRawDataBuilder ().getContract (0 )
462+ .getParameter ();
463+ ShieldedTransferActuator actuator = new ShieldedTransferActuator (contract , dbManager ,
464+ transactionCap );
465+ TransactionResultCapsule ret = new TransactionResultCapsule ();
466+
467+ actuator .validate ();
468+ actuator .execute (ret );
469+ Assert .assertTrue (false );
470+ } catch (ContractValidateException e ) {
471+ Assert .assertTrue (e instanceof ContractValidateException );
472+ Assert .assertEquals ("from_amount should not be less than 0" , e .getMessage ());
473+ } catch (Exception e ) {
474+ Assert .assertTrue (false );
447475 }
448476 }
449477
@@ -453,41 +481,71 @@ public void publicAddressToShieldedInvalidFromAmount() throws ZksnarkException {
453481 @ Test
454482 public void publicAddressToShieldedInvalidToAmount () {
455483 dbManager .getDynamicPropertiesStore ().saveAllowZksnarkTransaction (1 );
456- long [] transferAmount = {0 , -100 };
457- for (long amount : transferAmount ) {
458- ZenTransactionBuilder builder = new ZenTransactionBuilder (wallet );
459- try {
460- //From amount
461- SpendingKey sk = SpendingKey .random ();
462- ExpandedSpendingKey expsk = sk .expandedSpendingKey ();
463- PaymentAddress address = sk .defaultAddress ();
464- Note note = new Note (address , AMOUNT );
465- IncrementalMerkleVoucherContainer voucher = createSimpleMerkleVoucherContainer (note .cm ());
466- byte [] anchor = voucher .root ().getContent ().toByteArray ();
467- dbManager .getMerkleContainer ().putMerkleTreeIntoStore (anchor ,
468- voucher .getVoucherCapsule ().getTree ());
469- builder .addSpend (expsk , note , anchor , voucher );
470- //TO amount
471- builder .setTransparentOutput (ByteArray .fromHexString (PUBLIC_ADDRESS_TWO ), amount );
472- TransactionCapsule transactionCap = builder .build ();
473-
474- Any contract =
475- transactionCap .getInstance ().toBuilder ().getRawDataBuilder ().getContract (0 )
476- .getParameter ();
477- ShieldedTransferActuator actuator = new ShieldedTransferActuator (contract , dbManager ,
478- transactionCap );
479- TransactionResultCapsule ret = new TransactionResultCapsule ();
480-
481- actuator .validate ();
482- actuator .execute (ret );
483- Assert .assertTrue (false );
484- } catch (ContractValidateException e ) {
485- Assert .assertTrue (e instanceof ContractValidateException );
486- Assert .assertEquals (
487- "to_amount should not be less than 0" , e .getMessage ());
488- } catch (Exception e ) {
489- Assert .assertTrue (false );
490- }
484+ ZenTransactionBuilder builder = new ZenTransactionBuilder (wallet );
485+ try {
486+ long amount = 0 ;
487+ //From amount
488+ SpendingKey sk = SpendingKey .random ();
489+ ExpandedSpendingKey expsk = sk .expandedSpendingKey ();
490+ PaymentAddress address = sk .defaultAddress ();
491+ Note note = new Note (address , AMOUNT );
492+ IncrementalMerkleVoucherContainer voucher = createSimpleMerkleVoucherContainer (note .cm ());
493+ byte [] anchor = voucher .root ().getContent ().toByteArray ();
494+ dbManager .getMerkleContainer ().putMerkleTreeIntoStore (anchor ,
495+ voucher .getVoucherCapsule ().getTree ());
496+ builder .addSpend (expsk , note , anchor , voucher );
497+ //TO amount
498+ builder .setTransparentOutput (ByteArray .fromHexString (PUBLIC_ADDRESS_TWO ), amount );
499+ TransactionCapsule transactionCap = builder .build ();
500+
501+ Any contract =
502+ transactionCap .getInstance ().toBuilder ().getRawDataBuilder ().getContract (0 )
503+ .getParameter ();
504+ ShieldedTransferActuator actuator = new ShieldedTransferActuator (contract , dbManager ,
505+ transactionCap );
506+ TransactionResultCapsule ret = new TransactionResultCapsule ();
507+
508+ actuator .validate ();
509+ actuator .execute (ret );
510+ Assert .assertTrue (false );
511+ } catch (ContractValidateException e ) {
512+ Assert .assertTrue (e instanceof ContractValidateException );
513+ Assert .assertEquals ("to_amount must be greater than 0" , e .getMessage ());
514+ } catch (Exception e ) {
515+ Assert .assertTrue (false );
516+ }
517+
518+ try {
519+ long amount = -100 ;
520+ //From amount
521+ SpendingKey sk = SpendingKey .random ();
522+ ExpandedSpendingKey expsk = sk .expandedSpendingKey ();
523+ PaymentAddress address = sk .defaultAddress ();
524+ Note note = new Note (address , AMOUNT );
525+ IncrementalMerkleVoucherContainer voucher = createSimpleMerkleVoucherContainer (note .cm ());
526+ byte [] anchor = voucher .root ().getContent ().toByteArray ();
527+ dbManager .getMerkleContainer ().putMerkleTreeIntoStore (anchor ,
528+ voucher .getVoucherCapsule ().getTree ());
529+ builder .addSpend (expsk , note , anchor , voucher );
530+ //TO amount
531+ builder .setTransparentOutput (ByteArray .fromHexString (PUBLIC_ADDRESS_TWO ), amount );
532+ TransactionCapsule transactionCap = builder .build ();
533+
534+ Any contract =
535+ transactionCap .getInstance ().toBuilder ().getRawDataBuilder ().getContract (0 )
536+ .getParameter ();
537+ ShieldedTransferActuator actuator = new ShieldedTransferActuator (contract , dbManager ,
538+ transactionCap );
539+ TransactionResultCapsule ret = new TransactionResultCapsule ();
540+
541+ actuator .validate ();
542+ actuator .execute (ret );
543+ Assert .assertTrue (false );
544+ } catch (ContractValidateException e ) {
545+ Assert .assertTrue (e instanceof ContractValidateException );
546+ Assert .assertEquals ("to_amount should not be less than 0" , e .getMessage ());
547+ } catch (Exception e ) {
548+ Assert .assertTrue (false );
491549 }
492550 }
493551
@@ -622,6 +680,7 @@ public void transferFromPublicAndShieldAddressFailure() {
622680 */
623681 @ Test
624682 public void PublicToShieldAddressAndShieldToPublicAddressSuccess () {
683+ Args .getInstance ().setAllowShieldedTransactionApi (true );
625684 dbManager .getDynamicPropertiesStore ().saveAllowZksnarkTransaction (1 );
626685 long fee = dbManager .getDynamicPropertiesStore ().getShieldedTransactionFee ();
627686
@@ -980,6 +1039,7 @@ public void publicAddressAToShieldAddressNoToAddressFailure() {
9801039 */
9811040 @ Test
9821041 public void PublicToShieldAddressAndShieldToPublicAddressWithZoreValueSuccess () {
1042+ Args .getInstance ().setAllowShieldedTransactionApi (true );
9831043 dbManager .getDynamicPropertiesStore ().saveAllowZksnarkTransaction (1 );
9841044 long fee = dbManager .getDynamicPropertiesStore ().getShieldedTransactionFee ();
9851045
0 commit comments