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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
*/
const TransactionErrorResult = nullable(pick({}));
const TransactionErrorResult = nullable(union([pick({}), string()]));
/**
* Signature status for a transaction
@ -1536,7 +1536,7 @@ export type SignatureResult = {
/**
* Transaction error
*/
export type TransactionError = {};
export type TransactionError = {} | string;
/**
* Transaction confirmation status

View File

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