From b09865e5a064e72d84783e1e826ffd1b4b2a3c0b Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Fri, 12 Feb 2021 18:29:26 -0700 Subject: [PATCH] fix: default preflightCommitment to Connection.commitment when sending tx (#15299) --- web3.js/src/connection.js | 3 ++- web3.js/test/connection.test.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/web3.js/src/connection.js b/web3.js/src/connection.js index f8798a24c0..56d3367d58 100644 --- a/web3.js/src/connection.js +++ b/web3.js/src/connection.js @@ -3034,7 +3034,8 @@ export class Connection { const config: any = {encoding: 'base64'}; const args = [encodedTransaction, config]; const skipPreflight = options && options.skipPreflight; - const preflightCommitment = options && options.preflightCommitment; + const preflightCommitment = + (options && options.preflightCommitment) || this.commitment; if (skipPreflight) { config.skipPreflight = skipPreflight; diff --git a/web3.js/test/connection.test.js b/web3.js/test/connection.test.js index 9f4a9b961f..b237f00ed1 100644 --- a/web3.js/test/connection.test.js +++ b/web3.js/test/connection.test.js @@ -1361,6 +1361,25 @@ describe('Connection', () => { ).to.be.rejected; }); }); + + it('consistent preflightCommitment', async () => { + const connection = new Connection(url, 'singleGossip'); + const sender = new Account(); + const recipient = new Account(); + let signature = await connection.requestAirdrop( + sender.publicKey, + 2 * LAMPORTS_PER_SOL, + ); + await connection.confirmTransaction(signature, 'singleGossip'); + const transaction = new Transaction().add( + SystemProgram.transfer({ + fromPubkey: sender.publicKey, + toPubkey: recipient.publicKey, + lamports: LAMPORTS_PER_SOL, + }), + ); + await sendAndConfirmTransaction(connection, transaction, [sender]); + }); } it('get largest accounts', async () => {