File tree Expand file tree Collapse file tree 4 files changed +33
-13
lines changed
__tests__/unit/crypto/transactions
transactions/builders/transactions Expand file tree Collapse file tree 4 files changed +33
-13
lines changed Original file line number Diff line number Diff line change 11import "jest-extended" ;
22
33import { TransactionType } from "../../../../../../packages/crypto/src/enums" ;
4- import { MaximumPaymentCountExceededError } from "../../../../../../packages/crypto/src/errors" ;
4+ import {
5+ MaximumPaymentCountExceededError ,
6+ MinimumPaymentCountSubceededError ,
7+ } from "../../../../../../packages/crypto/src/errors" ;
58import { BuilderFactory , MultiPaymentTransaction } from "../../../../../../packages/crypto/src/transactions" ;
69import { MultiPaymentBuilder } from "../../../../../../packages/crypto/src/transactions/builders/transactions/multi-payment" ;
710import { BigNumber } from "../../../../../../packages/crypto/src/utils" ;
@@ -59,4 +62,18 @@ describe("Multi Payment Transaction", () => {
5962 expect ( ( ) => builder . addPayment ( "address" , "2" ) ) . toThrow ( MaximumPaymentCountExceededError ) ;
6063 } ) ;
6164 } ) ;
65+
66+ describe ( "getStruct" , ( ) => {
67+ it ( "should throw if payments is undefined" , ( ) => {
68+ builder . data . asset . payments = undefined ;
69+
70+ expect ( ( ) => builder . getStruct ( ) ) . toThrow ( MinimumPaymentCountSubceededError ) ;
71+ } ) ;
72+
73+ it ( "should throw if payments count is less than min required" , ( ) => {
74+ builder . addPayment ( "address" , "1" ) ;
75+
76+ expect ( ( ) => builder . getStruct ( ) ) . toThrow ( MinimumPaymentCountSubceededError ) ;
77+ } ) ;
78+ } ) ;
6279} ) ;
Original file line number Diff line number Diff line change @@ -748,17 +748,6 @@ describe("Multi Payment Transaction", () => {
748748 expect ( error ) . toBeUndefined ( ) ;
749749 } ) ;
750750
751- it ( "should be invalid with 0 or 1 payment" , ( ) => {
752- multiPayment . sign ( "passphrase" ) ;
753- const { error : errorZeroPayment } = Ajv . validate ( transactionSchema . $id , multiPayment . getStruct ( ) ) ;
754- expect ( errorZeroPayment ) . not . toBeUndefined ( ) ;
755-
756- multiPayment . addPayment ( address , "100" ) . sign ( "passphrase" ) ;
757-
758- const { error : errorOnePayment } = Ajv . validate ( transactionSchema . $id , multiPayment . getStruct ( ) ) ;
759- expect ( errorOnePayment ) . not . toBeUndefined ( ) ;
760- } ) ;
761-
762751 it ( "should not accept more than `multiPaymentLimit` payments" , ( ) => {
763752 const limit = configManager . getMilestone ( ) . multiPaymentLimit ;
764753
Original file line number Diff line number Diff line change @@ -132,6 +132,12 @@ export class MaximumPaymentCountExceededError extends CryptoError {
132132 }
133133}
134134
135+ export class MinimumPaymentCountSubceededError extends CryptoError {
136+ constructor ( ) {
137+ super ( `Number of payments subceeded the required minimum of 2.` ) ;
138+ }
139+ }
140+
135141export class VendorFieldLengthExceededError extends CryptoError {
136142 constructor ( limit : number ) {
137143 super ( `Length of vendor field exceeded the allowed maximum ${ limit } .` ) ;
Original file line number Diff line number Diff line change 1- import { MaximumPaymentCountExceededError } from "../../../errors" ;
1+ import { MaximumPaymentCountExceededError , MinimumPaymentCountSubceededError } from "../../../errors" ;
22import { ITransactionData } from "../../../interfaces" ;
33import { configManager } from "../../../managers" ;
44import { BigNumber } from "../../../utils" ;
@@ -35,6 +35,14 @@ export class MultiPaymentBuilder extends TransactionBuilder<MultiPaymentBuilder>
3535 }
3636
3737 public getStruct ( ) : ITransactionData {
38+ if (
39+ ! this . data . asset . payments ||
40+ ! Array . isArray ( this . data . asset . payments ) ||
41+ this . data . asset . payments . length <= 1
42+ ) {
43+ throw new MinimumPaymentCountSubceededError ( ) ;
44+ }
45+
3846 const struct : ITransactionData = super . getStruct ( ) ;
3947 struct . senderPublicKey = this . data . senderPublicKey ;
4048 struct . vendorField = this . data . vendorField ;
You can’t perform that action at this time.
0 commit comments