fix: Update signature status result type

This commit is contained in:
Tyera Eulberg 2019-04-10 13:15:41 -07:00 committed by Michael Vines
parent f2b38bcc56
commit 7f72bbeba3
3 changed files with 16 additions and 16 deletions

View File

@ -124,13 +124,13 @@ const ConfirmTransactionRpcResult = jsonRpcResult('boolean');
* Expected JSON RPC response for the "getSignatureStatus" message * Expected JSON RPC response for the "getSignatureStatus" message
*/ */
const GetSignatureStatusRpcResult = jsonRpcResult( const GetSignatureStatusRpcResult = jsonRpcResult(
struct.enum([ struct.union([
'AccountInUse', 'null',
'Confirmed', struct.union([
'GenericFailure', struct({Ok: 'null'}),
'ProgramRuntimeError', struct({Err: 'string'})
'SignatureNotFound', ])
]), ])
); );
/** /**

View File

@ -28,7 +28,7 @@ export async function sendAndConfirmTransaction(
let statusRetries = 6; let statusRetries = 6;
for (;;) { for (;;) {
status = await connection.getSignatureStatus(signature); status = await connection.getSignatureStatus(signature);
if (status !== 'SignatureNotFound') { if (status) {
break; break;
} }
@ -39,7 +39,7 @@ export async function sendAndConfirmTransaction(
await sleep((500 * DEFAULT_TICKS_PER_SLOT) / NUM_TICKS_PER_SECOND); await sleep((500 * DEFAULT_TICKS_PER_SLOT) / NUM_TICKS_PER_SECOND);
} }
if (status === 'Confirmed') { if ('Ok' in status) {
break; break;
} }
if (--sendRetries <= 0) { if (--sendRetries <= 0) {
@ -51,7 +51,7 @@ export async function sendAndConfirmTransaction(
); );
} }
if (status !== 'AccountInUse' && status !== 'SignatureNotFound') { if ('Err' in status && !status.includes('AccountInUse')) {
throw new Error(`Transaction ${signature} failed (${status})`); throw new Error(`Transaction ${signature} failed (${status})`);
} }

View File

@ -341,8 +341,8 @@ test('transaction', async () => {
result: 'Confirmed', result: 'Confirmed',
}, },
]); ]);
await expect(connection.getSignatureStatus(signature)).resolves.toBe( await expect(connection.getSignatureStatus(signature)).resolves.toEqual(
'Confirmed', {'Ok': null},
); );
mockRpc.push([ mockRpc.push([
@ -410,8 +410,8 @@ test('multi-instruction transaction', async () => {
expect(++i).toBeLessThan(10); expect(++i).toBeLessThan(10);
await sleep(500); await sleep(500);
} }
await expect(connection.getSignatureStatus(signature)).resolves.toBe( await expect(connection.getSignatureStatus(signature)).resolves.toEqual(
'Confirmed', {'Ok': null},
); );
expect(await connection.getBalance(accountFrom.publicKey)).toBe(12); expect(await connection.getBalance(accountFrom.publicKey)).toBe(12);
@ -466,7 +466,7 @@ test('account change notification', async () => {
await connection.removeAccountChangeListener(subscriptionId); await connection.removeAccountChangeListener(subscriptionId);
expect(mockCallback.mock.calls[0][0].lamports).toBe(41); expect(mockCallback.mock.calls[0][0].lamports).toBe(42);
expect(mockCallback.mock.calls[0][0].owner).toEqual(BpfLoader.programId); expect(mockCallback.mock.calls[0][0].owner).toEqual(BpfLoader.programId);
expect(mockCallback.mock.calls[0][0].executable).toBe(false); expect(mockCallback.mock.calls[0][0].executable).toBe(false);
expect(mockCallback.mock.calls[0][0].data).toEqual(Buffer.from([1, 2, 3])); expect(mockCallback.mock.calls[0][0].data).toEqual(Buffer.from([1, 2, 3]));
@ -523,7 +523,7 @@ test('program account change notification', async () => {
expect(mockCallback.mock.calls[0][0].accountId).toEqual( expect(mockCallback.mock.calls[0][0].accountId).toEqual(
programAccount.publicKey.toString(), programAccount.publicKey.toString(),
); );
expect(mockCallback.mock.calls[0][0].accountInfo.lamports).toBe(41); expect(mockCallback.mock.calls[0][0].accountInfo.lamports).toBe(42);
expect(mockCallback.mock.calls[0][0].accountInfo.owner).toEqual( expect(mockCallback.mock.calls[0][0].accountInfo.owner).toEqual(
BpfLoader.programId, BpfLoader.programId,
); );