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 1
1
import "jest-extended" ;
2
2
3
3
import { 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" ;
5
8
import { BuilderFactory , MultiPaymentTransaction } from "../../../../../../packages/crypto/src/transactions" ;
6
9
import { MultiPaymentBuilder } from "../../../../../../packages/crypto/src/transactions/builders/transactions/multi-payment" ;
7
10
import { BigNumber } from "../../../../../../packages/crypto/src/utils" ;
@@ -59,4 +62,18 @@ describe("Multi Payment Transaction", () => {
59
62
expect ( ( ) => builder . addPayment ( "address" , "2" ) ) . toThrow ( MaximumPaymentCountExceededError ) ;
60
63
} ) ;
61
64
} ) ;
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
+ } ) ;
62
79
} ) ;
Original file line number Diff line number Diff line change @@ -748,17 +748,6 @@ describe("Multi Payment Transaction", () => {
748
748
expect ( error ) . toBeUndefined ( ) ;
749
749
} ) ;
750
750
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
-
762
751
it ( "should not accept more than `multiPaymentLimit` payments" , ( ) => {
763
752
const limit = configManager . getMilestone ( ) . multiPaymentLimit ;
764
753
Original file line number Diff line number Diff line change @@ -132,6 +132,12 @@ export class MaximumPaymentCountExceededError extends CryptoError {
132
132
}
133
133
}
134
134
135
+ export class MinimumPaymentCountSubceededError extends CryptoError {
136
+ constructor ( ) {
137
+ super ( `Number of payments subceeded the required minimum of 2.` ) ;
138
+ }
139
+ }
140
+
135
141
export class VendorFieldLengthExceededError extends CryptoError {
136
142
constructor ( limit : number ) {
137
143
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" ;
2
2
import { ITransactionData } from "../../../interfaces" ;
3
3
import { configManager } from "../../../managers" ;
4
4
import { BigNumber } from "../../../utils" ;
@@ -35,6 +35,14 @@ export class MultiPaymentBuilder extends TransactionBuilder<MultiPaymentBuilder>
35
35
}
36
36
37
37
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
+
38
46
const struct : ITransactionData = super . getStruct ( ) ;
39
47
struct . senderPublicKey = this . data . senderPublicKey ;
40
48
struct . vendorField = this . data . vendorField ;
You can’t perform that action at this time.
0 commit comments