From d5f0e15f47aaced0eaadaac82a0f641ca1d10176 Mon Sep 17 00:00:00 2001 From: Qiwei Yang Date: Tue, 12 Sep 2023 17:33:09 +0800 Subject: [PATCH] fix polkadot js got unknown error (#396) * fix error.toJSON undefined * fix: pass error to polkadot * add a test for reject unsigned extrinsic --- .../chopsticks/src/rpc/substrate/author.ts | 21 +++++++++---------- packages/e2e/src/author.test.ts | 6 ++++++ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/chopsticks/src/rpc/substrate/author.ts b/packages/chopsticks/src/rpc/substrate/author.ts index 8e5f3b43..4c293c0a 100644 --- a/packages/chopsticks/src/rpc/substrate/author.ts +++ b/packages/chopsticks/src/rpc/substrate/author.ts @@ -47,18 +47,17 @@ const handlers: Handlers = { done(id) } - context.chain - .submitExtrinsic(extrinsic) - .then(() => { - callback({ - Ready: null, - }) - }) - .catch((error: TransactionValidityError) => { - logger.error({ error }, 'ExtrinsicFailed') - callback(error?.toJSON() ?? error) - done(id) + try { + await context.chain.submitExtrinsic(extrinsic) + callback({ + Ready: null, }) + } catch (error) { + logger.error({ error }, 'ExtrinsicFailed') + const code = (error as TransactionValidityError).isInvalid ? 1010 : 1011 + done(id) + throw new ResponseError(code, (error as TransactionValidityError).toString()) + } return id }, author_unwatchExtrinsic: async (_context, [subid], { unsubscribe }) => { diff --git a/packages/e2e/src/author.test.ts b/packages/e2e/src/author.test.ts index 97378085..f8fa1ce9 100644 --- a/packages/e2e/src/author.test.ts +++ b/packages/e2e/src/author.test.ts @@ -86,6 +86,12 @@ describe('author rpc', async () => { await expect(tx.send()).rejects.toThrow('1010: {"invalid":{"badProof":null}}') }) + it('reject unsigned extrinsic', async () => { + const tx = api.tx.balances.transfer(bob.address, 100) + + await expect(tx.send()).rejects.toThrow('1011: {"unknown":{"noUnsignedValidator":null}}') + }) + it('failed apply extirinsic', async () => { const finalized = defer() const invalid = defer()