Skip to content

Commit

Permalink
Make sep31 /info response fields optional (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
lijamie98 authored Sep 6, 2024
1 parent 4bf3d7a commit c0a91c9
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions @stellar/anchor-tests/src/tests/sep31/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export const hasExpectedAssetEnabled: Test = {
};

const hasExpectedTransactionFields: Test = {
assertion: "has configured transaction 'fields'",
assertion: "check optional transaction 'fields'",
sep: 31,
group: "GET /info",
dependencies: [hasValidInfoSchema],
Expand Down Expand Up @@ -184,31 +184,33 @@ const hasExpectedTransactionFields: Test = {
// this is checked before tests are run
throw new Error("improperly configured");
const result: Result = { networkCalls: [] };
const responseTransactionFields =
this.context.expects.sep31InfoObj.receive[config.assetCode].fields
.transaction;
const responseTransactionFieldNames = Object.keys(
responseTransactionFields,
);
const configuredTransactionFieldNames = Object.keys(
config.sepConfig["31"].transactionFields,
);
for (const fieldName of responseTransactionFieldNames) {
if (
!responseTransactionFields[fieldName].optional &&
!configuredTransactionFieldNames.includes(fieldName)
) {
result.failure = makeFailure(this.failureModes.UNEXPECTED_FIELD, {
field: fieldName,
});
return result;
if (this.context.expects.sep31InfoObj.receive[config.assetCode].fields) {
const responseTransactionFields =
this.context.expects.sep31InfoObj.receive[config.assetCode].fields
.transaction;
const responseTransactionFieldNames = Object.keys(
responseTransactionFields,
);
const configuredTransactionFieldNames = Object.keys(
config.sepConfig["31"].transactionFields,
);
for (const fieldName of responseTransactionFieldNames) {
if (
!responseTransactionFields[fieldName].optional &&
!configuredTransactionFieldNames.includes(fieldName)
) {
result.failure = makeFailure(this.failureModes.UNEXPECTED_FIELD, {
field: fieldName,
});
return result;
}
}
}
for (const fieldName of configuredTransactionFieldNames) {
if (!responseTransactionFieldNames.includes(fieldName)) {
result.failure = makeFailure(this.failureModes.FIELD_NOT_FOUND);
result.expected = fieldName;
return result;
for (const fieldName of configuredTransactionFieldNames) {
if (!responseTransactionFieldNames.includes(fieldName)) {
result.failure = makeFailure(this.failureModes.FIELD_NOT_FOUND);
result.expected = fieldName;
return result;
}
}
}
return result;
Expand Down

0 comments on commit c0a91c9

Please sign in to comment.