Skip to content

Commit f832c5f

Browse files
committed
fix CredentialIDs error messages
1 parent 244ef67 commit f832c5f

File tree

8 files changed

+43
-32
lines changed

8 files changed

+43
-32
lines changed

packages/xrpl/src/models/transactions/common.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ export function validateCredentialType<
775775
* @param isStringID Toggle for if array contains IDs instead of AuthorizeCredential objects
776776
* @param maxCredentials The maximum length of the credentials array.
777777
* PermissionedDomainSet transaction uses 10, other transactions use 8.
778+
* @param fieldName
778779
* @throws Validation Error if the formatting is incorrect
779780
*/
780781
// eslint-disable-next-line max-params, max-lines-per-function -- separating logic further will add unnecessary complexity
@@ -783,41 +784,42 @@ export function validateCredentialsList(
783784
transactionType: string,
784785
isStringID: boolean,
785786
maxCredentials: number,
787+
fieldName = 'CredentialIDs',
786788
): void {
787789
if (credentials == null) {
788790
return
789791
}
790792
if (!isArray(credentials)) {
791793
throw new ValidationError(
792-
`${transactionType}: invalid field CredentialIDs, expected a valid array`,
794+
`${transactionType}: invalid field ${fieldName}, expected a valid array`,
793795
)
794796
}
795797
if (credentials.length > maxCredentials) {
796798
throw new ValidationError(
797-
`${transactionType}: Credentials length cannot exceed ${maxCredentials} elements`,
799+
`${transactionType}: ${fieldName} length cannot exceed ${maxCredentials} elements`,
798800
)
799801
} else if (credentials.length === 0) {
800802
throw new ValidationError(
801-
`${transactionType}: Credentials cannot be an empty array`,
803+
`${transactionType}: ${fieldName} cannot be an empty array`,
802804
)
803805
}
804806
credentials.forEach((credential) => {
805807
if (isStringID) {
806808
if (!isString(credential)) {
807809
throw new ValidationError(
808-
`${transactionType}: Invalid Credentials ID list format`,
810+
`${transactionType}: Invalid ${fieldName} list format`,
809811
)
810812
}
811813
} else if (!isAuthorizeCredential(credential)) {
812814
throw new ValidationError(
813-
`${transactionType}: Invalid Credentials format`,
815+
`${transactionType}: Invalid ${fieldName} format`,
814816
)
815817
}
816818
})
817819
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- checked above
818820
if (containsDuplicates(credentials as string[] | AuthorizeCredential[])) {
819821
throw new ValidationError(
820-
`${transactionType}: Credentials cannot contain duplicate elements`,
822+
`${transactionType}: ${fieldName} cannot contain duplicate elements`,
821823
)
822824
}
823825
}

packages/xrpl/src/models/transactions/depositPreauth.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ export function validateDepositPreauth(tx: Record<string, unknown>): void {
7070
tx.TransactionType,
7171
false,
7272
MAX_AUTHORIZED_CREDENTIALS,
73+
'AuthorizeCredentials',
7374
)
7475
} else if (tx.UnauthorizeCredentials !== undefined) {
7576
validateCredentialsList(
7677
tx.UnauthorizeCredentials,
7778
tx.TransactionType,
7879
false,
7980
MAX_AUTHORIZED_CREDENTIALS,
81+
'UnauthorizeCredentials',
8082
)
8183
}
8284
}

packages/xrpl/src/models/transactions/permissionedDomainSet.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ export function validatePermissionedDomainSet(
4646
false,
4747
// PermissionedDomainSet uses at most 10 accepted credentials. This is different from Credential-feature transactions.
4848
MAX_ACCEPTED_CREDENTIALS,
49+
'AcceptedCredentials',
4950
)
5051
}

packages/xrpl/test/models/accountDelete.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ describe('AccountDelete', function () {
7575
]
7676

7777
const errorMessage =
78-
'AccountDelete: Credentials length cannot exceed 8 elements'
78+
'AccountDelete: CredentialIDs length cannot exceed 8 elements'
7979
assertInvalid(validAccountDelete, errorMessage)
8080
})
8181

8282
it(`throws w/ empty CredentialIDs`, function () {
8383
validAccountDelete.CredentialIDs = []
8484

85-
const errorMessage = 'AccountDelete: Credentials cannot be an empty array'
85+
const errorMessage = 'AccountDelete: CredentialIDs cannot be an empty array'
8686
assertInvalid(validAccountDelete, errorMessage)
8787
})
8888

@@ -92,7 +92,7 @@ describe('AccountDelete', function () {
9292
'EA85602C1B41F6F1F5E83C0E6B87142FB8957BD209469E4CC347BA2D0C26F662',
9393
]
9494

95-
const errorMessage = 'AccountDelete: Invalid Credentials ID list format'
95+
const errorMessage = 'AccountDelete: Invalid CredentialIDs list format'
9696
assertInvalid(validAccountDelete, errorMessage)
9797
})
9898

@@ -103,7 +103,7 @@ describe('AccountDelete', function () {
103103
]
104104

105105
const errorMessage =
106-
'AccountDelete: Credentials cannot contain duplicate elements'
106+
'AccountDelete: CredentialIDs cannot contain duplicate elements'
107107
assertInvalid(validAccountDelete, errorMessage)
108108
})
109109
})

packages/xrpl/test/models/depositPreauth.test.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,29 +112,31 @@ describe('DepositPreauth', function () {
112112

113113
it('throws when AuthorizeCredentials is not an array', function () {
114114
const errorMessage =
115-
'DepositPreauth: invalid field CredentialIDs, expected a valid array'
115+
'DepositPreauth: invalid field AuthorizeCredentials, expected a valid array'
116116
depositPreauth.AuthorizeCredentials = validCredential
117117

118118
assertInvalid(depositPreauth, errorMessage)
119119
})
120120

121121
it('throws when UnauthorizeCredentials is not an array', function () {
122122
const errorMessage =
123-
'DepositPreauth: invalid field CredentialIDs, expected a valid array'
123+
'DepositPreauth: invalid field UnauthorizeCredentials, expected a valid array'
124124
depositPreauth.UnauthorizeCredentials = validCredential
125125

126126
assertInvalid(depositPreauth, errorMessage)
127127
})
128128

129129
it('throws when AuthorizeCredentials is empty array', function () {
130-
const errorMessage = 'DepositPreauth: Credentials cannot be an empty array'
130+
const errorMessage =
131+
'DepositPreauth: AuthorizeCredentials cannot be an empty array'
131132
depositPreauth.AuthorizeCredentials = []
132133

133134
assertInvalid(depositPreauth, errorMessage)
134135
})
135136

136137
it('throws when UnauthorizeCredentials is empty array', function () {
137-
const errorMessage = 'DepositPreauth: Credentials cannot be an empty array'
138+
const errorMessage =
139+
'DepositPreauth: UnauthorizeCredentials cannot be an empty array'
138140
depositPreauth.UnauthorizeCredentials = []
139141

140142
assertInvalid(depositPreauth, errorMessage)
@@ -143,7 +145,7 @@ describe('DepositPreauth', function () {
143145
it('throws when AuthorizeCredentials is too long', function () {
144146
const sampleCredentials: AuthorizeCredential[] = []
145147
const errorMessage =
146-
'DepositPreauth: Credentials length cannot exceed 8 elements'
148+
'DepositPreauth: AuthorizeCredentials length cannot exceed 8 elements'
147149
for (let index = 0; index < 9; index++) {
148150
sampleCredentials.push({
149151
Credential: {
@@ -159,7 +161,7 @@ describe('DepositPreauth', function () {
159161
it('throws when UnauthorizeCredentials is too long', function () {
160162
const sampleCredentials: AuthorizeCredential[] = []
161163
const errorMessage =
162-
'DepositPreauth: Credentials length cannot exceed 8 elements'
164+
'DepositPreauth: UnauthorizeCredentials length cannot exceed 8 elements'
163165
for (let index = 0; index < 9; index++) {
164166
sampleCredentials.push({
165167
Credential: {
@@ -177,7 +179,7 @@ describe('DepositPreauth', function () {
177179
{ Credential: 'Invalid Shape' },
178180
{ Credential: 'Another Invalid Shape' },
179181
]
180-
const errorMessage = 'DepositPreauth: Invalid Credentials format'
182+
const errorMessage = 'DepositPreauth: Invalid AuthorizeCredentials format'
181183

182184
depositPreauth.AuthorizeCredentials = invalidCredentials
183185
assertInvalid(depositPreauth, errorMessage)
@@ -188,7 +190,7 @@ describe('DepositPreauth', function () {
188190
{ Credential: 'Invalid Shape' },
189191
{ Credential: 'Another Invalid Shape' },
190192
]
191-
const errorMessage = 'DepositPreauth: Invalid Credentials format'
193+
const errorMessage = 'DepositPreauth: Invalid UnauthorizeCredentials format'
192194

193195
depositPreauth.UnauthorizeCredentials = invalidCredentials
194196
assertInvalid(depositPreauth, errorMessage)
@@ -197,7 +199,7 @@ describe('DepositPreauth', function () {
197199
it('throws when AuthorizeCredentials has duplicates', function () {
198200
const invalidCredentials = [validCredential, validCredential]
199201
const errorMessage =
200-
'DepositPreauth: Credentials cannot contain duplicate elements'
202+
'DepositPreauth: AuthorizeCredentials cannot contain duplicate elements'
201203

202204
depositPreauth.AuthorizeCredentials = invalidCredentials
203205
assertInvalid(depositPreauth, errorMessage)
@@ -206,7 +208,7 @@ describe('DepositPreauth', function () {
206208
it('throws when UnauthorizeCredentials has duplicates', function () {
207209
const invalidCredentials = [validCredential, validCredential]
208210
const errorMessage =
209-
'DepositPreauth: Credentials cannot contain duplicate elements'
211+
'DepositPreauth: UnauthorizeCredentials cannot contain duplicate elements'
210212

211213
depositPreauth.UnauthorizeCredentials = invalidCredentials
212214
assertInvalid(depositPreauth, errorMessage)

packages/xrpl/test/models/escrowFinish.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ describe('EscrowFinish', function () {
105105
]
106106

107107
const errorMessage =
108-
'EscrowFinish: Credentials length cannot exceed 8 elements'
108+
'EscrowFinish: CredentialIDs length cannot exceed 8 elements'
109109

110110
assertInvalid(escrow, errorMessage)
111111
})
112112

113113
it(`throws w/ empty CredentialIDs`, function () {
114114
escrow.CredentialIDs = []
115115

116-
const errorMessage = 'EscrowFinish: Credentials cannot be an empty array'
116+
const errorMessage = 'EscrowFinish: CredentialIDs cannot be an empty array'
117117

118118
assertInvalid(escrow, errorMessage)
119119
})
@@ -124,7 +124,7 @@ describe('EscrowFinish', function () {
124124
'EA85602C1B41F6F1F5E83C0E6B87142FB8957BD209469E4CC347BA2D0C26F662',
125125
]
126126

127-
const errorMessage = 'EscrowFinish: Invalid Credentials ID list format'
127+
const errorMessage = 'EscrowFinish: Invalid CredentialIDs list format'
128128

129129
assertInvalid(escrow, errorMessage)
130130
})
@@ -136,7 +136,7 @@ describe('EscrowFinish', function () {
136136
]
137137

138138
const errorMessage =
139-
'EscrowFinish: Credentials cannot contain duplicate elements'
139+
'EscrowFinish: CredentialIDs cannot contain duplicate elements'
140140

141141
assertInvalid(escrow, errorMessage)
142142
})

packages/xrpl/test/models/payment.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,15 @@ describe('Payment', function () {
255255
'EA85602C1B41F6F1F5E83C0E6B87142FB8957BD209469E4CC347BA2D0C26F662',
256256
]
257257

258-
const errorMessage = 'Payment: Credentials length cannot exceed 8 elements'
258+
const errorMessage =
259+
'Payment: CredentialIDs length cannot exceed 8 elements'
259260
assertInvalid(payment, errorMessage)
260261
})
261262

262263
it(`throws w/ empty CredentialIDs`, function () {
263264
payment.CredentialIDs = []
264265

265-
const errorMessage = 'Payment: Credentials cannot be an empty array'
266+
const errorMessage = 'Payment: CredentialIDs cannot be an empty array'
266267
assertInvalid(payment, errorMessage)
267268
})
268269

@@ -272,7 +273,7 @@ describe('Payment', function () {
272273
'EA85602C1B41F6F1F5E83C0E6B87142FB8957BD209469E4CC347BA2D0C26F662',
273274
]
274275

275-
const errorMessage = 'Payment: Invalid Credentials ID list format'
276+
const errorMessage = 'Payment: Invalid CredentialIDs list format'
276277
assertInvalid(payment, errorMessage)
277278
})
278279

@@ -283,7 +284,7 @@ describe('Payment', function () {
283284
]
284285

285286
const errorMessage =
286-
'Payment: Credentials cannot contain duplicate elements'
287+
'Payment: CredentialIDs cannot contain duplicate elements'
287288
assertInvalid(payment, errorMessage)
288289
})
289290
})

packages/xrpl/test/models/permissionedDomainSet.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ describe('PermissionedDomainSet', function () {
5757

5858
assertInvalid(
5959
tx,
60-
'PermissionedDomainSet: Credentials length cannot exceed 10 elements',
60+
'PermissionedDomainSet: AcceptedCredentials length cannot exceed 10 elements',
6161
)
6262
})
6363

6464
it('throws when AcceptedCredentials is empty', function () {
6565
tx.AcceptedCredentials = []
6666
assertInvalid(
6767
tx,
68-
'PermissionedDomainSet: Credentials cannot be an empty array',
68+
'PermissionedDomainSet: AcceptedCredentials cannot be an empty array',
6969
)
7070
})
7171

@@ -81,12 +81,15 @@ describe('PermissionedDomainSet', function () {
8181
tx.AcceptedCredentials = [sampleCredential, sampleCredential]
8282
assertInvalid(
8383
tx,
84-
'PermissionedDomainSet: Credentials cannot contain duplicate elements',
84+
'PermissionedDomainSet: AcceptedCredentials cannot contain duplicate elements',
8585
)
8686
})
8787

8888
it('throws when AcceptedCredentials contains invalid format', function () {
8989
tx.AcceptedCredentials = [{ Field1: 'Value1', Field2: 'Value2' }]
90-
assertInvalid(tx, 'PermissionedDomainSet: Invalid Credentials format')
90+
assertInvalid(
91+
tx,
92+
'PermissionedDomainSet: Invalid AcceptedCredentials format',
93+
)
9194
})
9295
})

0 commit comments

Comments
 (0)