From ebe3d2d59d34f8d3c4d04ed42b4e8f958b2a6829 Mon Sep 17 00:00:00 2001 From: Pierre Date: Mon, 21 Feb 2022 17:20:11 +1100 Subject: [PATCH] fix: simulateTransaction accounts items can be null (#23229) * fix: simulated accounts can be null * Use Missing rather than token program id Co-authored-by: Arrowana <8245419+Arrowana@users.noreply.github.com> --- web3.js/src/connection.ts | 18 ++++++++++-------- web3.js/test/connection.test.ts | 10 ++++++++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/web3.js/src/connection.ts b/web3.js/src/connection.ts index e97db4a06e..056a60019f 100644 --- a/web3.js/src/connection.ts +++ b/web3.js/src/connection.ts @@ -469,7 +469,7 @@ export type SimulatedTransactionAccountInfo = { export type SimulatedTransactionResponse = { err: TransactionError | string | null; logs: Array | null; - accounts?: SimulatedTransactionAccountInfo[] | null; + accounts?: (SimulatedTransactionAccountInfo | null)[] | null; unitsConsumed?: number; }; @@ -480,13 +480,15 @@ const SimulatedTransactionResponseStruct = jsonRpcResultAndContext( accounts: optional( nullable( array( - pick({ - executable: boolean(), - owner: string(), - lamports: number(), - data: array(string()), - rentEpoch: optional(number()), - }), + nullable( + pick({ + executable: boolean(), + owner: string(), + lamports: number(), + data: array(string()), + rentEpoch: optional(number()), + }), + ), ), ), ), diff --git a/web3.js/test/connection.test.ts b/web3.js/test/connection.test.ts index 6e37326878..aa2aba618b 100644 --- a/web3.js/test/connection.test.ts +++ b/web3.js/test/connection.test.ts @@ -3044,10 +3044,16 @@ describe('Connection', () => { const results2 = await connection.simulateTransaction( message, [account1], - [account1.publicKey], + [ + account1.publicKey, + new PublicKey('Missing111111111111111111111111111111111111'), + ], ); - expect(results2.value.accounts).lengthOf(1); + expect(results2.value.accounts).lengthOf(2); + if (results2.value.accounts) { + expect(results2.value.accounts[1]).to.be.null; + } }).timeout(10000); it('transaction', async () => {