fix: allow strings in transaction error validation (#16348)

* fix: allow strings in transaction error validation

* chore: make log tests more robust
This commit is contained in:
Justin Starry
2021-04-04 18:02:36 +08:00
committed by GitHub
parent 3429785d9b
commit 4b7b402e74
2 changed files with 16 additions and 15 deletions

View File

@ -369,7 +369,7 @@ const GetLeaderScheduleResult = record(string(), array(number()));
/** /**
* Transaction error or null * Transaction error or null
*/ */
const TransactionErrorResult = nullable(pick({})); const TransactionErrorResult = nullable(union([pick({}), string()]));
/** /**
* Signature status for a transaction * Signature status for a transaction
@ -1536,7 +1536,7 @@ export type SignatureResult = {
/** /**
* Transaction error * Transaction error
*/ */
export type TransactionError = {}; export type TransactionError = {} | string;
/** /**
* Transaction confirmation status * Transaction confirmation status

View File

@ -2281,24 +2281,25 @@ describe('Connection', () => {
let listener: number | undefined; let listener: number | undefined;
const owner = new Account(); const owner = new Account();
const [logsRes, ctx] = await new Promise(resolve => { const [logsRes, ctx] = await new Promise(resolve => {
let received = false;
listener = connection.onLogs( listener = connection.onLogs(
'all', owner.publicKey,
(logs, ctx) => { (logs, ctx) => {
if (!logs.err) {
received = true;
resolve([logs, ctx]); resolve([logs, ctx]);
}
}, },
'processed', 'processed',
); );
// Sleep to allow the subscription time to be setup.
// // Send transactions until the log subscription receives an event
// Without this, there's a race condition between setting up the log (async () => {
// subscription and executing the transaction to trigger the log. while (!received) {
// If the transaction to trigger the log executes before the
// subscription is setup, the log event listener never fires and so the
// promise never resolves.
sleep(1000).then(() => {
// Execute a transaction so that we can pickup its logs. // Execute a transaction so that we can pickup its logs.
connection.requestAirdrop(owner.publicKey, 1); await connection.requestAirdrop(owner.publicKey, 1);
}); }
})();
}); });
expect(ctx.slot).to.be.greaterThan(0); expect(ctx.slot).to.be.greaterThan(0);
expect(logsRes.logs.length).to.eq(2); expect(logsRes.logs.length).to.eq(2);