Skip to content

Commit

Permalink
fix: message assertions and improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
anilhelvaci committed Oct 5, 2024
1 parent d3f2453 commit 57e25e6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
46 changes: 22 additions & 24 deletions a3p-integration/proposals/z:acceptance/test-lib/sync-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ const retryUntilCondition = async (
throw Error(`${message} condition failed after ${maxRetries} retries.`);
};

/**
* @param {RetryOptions} options
*/
const overrideDefaultOptions = options => {
const defaultValues = {
maxRetries: 6,
retryIntervalMs: 3500,
log: console.log,
errorMessage: 'Error',
};

return { ...defaultValues, ...options };
};

///////////// Making sure a core-eval resulted successfully deploying a contract /////////////

const makeGetInstances = follow => async () => {
Expand All @@ -110,12 +124,8 @@ export const waitUntilContractDeployed = (
) => {
const { follow, setTimeout } = ambientAuthority;
const getInstances = makeGetInstances(follow);
const {
maxRetries = 6,
retryIntervalMs = 3500,
log = console.log,
errorMessage = 'Error',
} = options;
const { maxRetries, retryIntervalMs, errorMessage, log } =
overrideDefaultOptions(options);

return retryUntilCondition(
getInstances,
Expand Down Expand Up @@ -157,12 +167,8 @@ export const waitUntilAccountFunded = (
) => {
const { query, setTimeout } = ambientAuthority;
const queryCosmosBalance = makeQueryCosmosBalance(query);
const {
maxRetries = 6,
retryIntervalMs = 3500,
log = console.log,
errorMessage = 'Error',
} = options;
const { maxRetries, retryIntervalMs, errorMessage, log } =
overrideDefaultOptions(options);

return retryUntilCondition(
async () => queryCosmosBalance(destAcct),
Expand Down Expand Up @@ -216,12 +222,8 @@ export const waitUntilOfferResult = (
) => {
const { follow, setTimeout } = ambientAuthority;
const queryWallet = makeQueryWallet(follow);
const {
maxRetries = 6,
retryIntervalMs = 3500,
log = console.log,
errorMessage = 'Error',
} = options;
const { maxRetries, retryIntervalMs, errorMessage, log } =
overrideDefaultOptions(options);

return retryUntilCondition(
async () => queryWallet(addr),
Expand Down Expand Up @@ -260,12 +262,8 @@ export const waitUntilInvitationReceived = (
) => {
const { follow, setTimeout } = ambientAuthority;
const queryWallet = makeQueryWallet(follow);
const {
maxRetries = 6,
retryIntervalMs = 3500,
log = console.log,
errorMessage = 'Error',
} = options;
const { maxRetries, retryIntervalMs, errorMessage, log } =
overrideDefaultOptions(options);

return retryUntilCondition(
async () => queryWallet(addr),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ test.serial('wait until account funded, insufficient balance', async t => {
},
};
setTimeout(() => setResult(desiredResult), 3000); // set desired value after third retry
await t.throwsAsync(waitP);
await t.throwsAsync(waitP, { message: /Account not funded yet/ });
});

test.serial(
Expand All @@ -159,7 +159,7 @@ test.serial(
},
);

await t.throwsAsync(waitP);
await t.throwsAsync(waitP, { message: /Wrong update type/ });
},
);

Expand All @@ -180,7 +180,7 @@ test.serial('wait until offer result, wrong id - should throw', async t => {
},
);

await t.throwsAsync(waitP);
await t.throwsAsync(waitP, { message: /Wrong offer id/ });
});

test.serial('wait until offer result, no "status" - should throw', async t => {
Expand All @@ -200,7 +200,7 @@ test.serial('wait until offer result, no "status" - should throw', async t => {
},
);

await t.throwsAsync(waitP);
await t.throwsAsync(waitP, { message: /No "status" object/ });
});

test.serial(
Expand All @@ -225,7 +225,7 @@ test.serial(
},
);

await t.throwsAsync(waitP);
await t.throwsAsync(waitP, { message: /"numWantsSatisfied" is not 1/ });
},
);

Expand Down Expand Up @@ -333,7 +333,7 @@ test.serial(
},
);

await t.throwsAsync(waitP);
await t.throwsAsync(waitP, { message: /wrong "updated" value/ });
},
);

Expand All @@ -350,7 +350,7 @@ test.serial(
maxRetries: 5,
retryIntervalMs: 1000,
log: t.log,
errorMessage: 'falty "currentAmount" object',
errorMessage: 'faulty "currentAmount" object',
},
);

Expand All @@ -359,7 +359,7 @@ test.serial(
2000,
);

await t.throwsAsync(waitP);
await t.throwsAsync(waitP, { message: /faulty "currentAmount" object/ });
},
);

Expand All @@ -380,7 +380,7 @@ test.serial(
},
);

await t.throwsAsync(waitP);
await t.throwsAsync(waitP, { message: /brand string do not match/ });
},
);

Expand Down
2 changes: 1 addition & 1 deletion a3p-integration/proposals/z:acceptance/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"strictNullChecks": true,
"noImplicitThis": true,
// XXX synthetic-chain has some errors
"skipLibCheck": true,
"skipLibCheck": true
}
}

0 comments on commit 57e25e6

Please sign in to comment.