fix: default preflightCommitment to Connection.commitment when sending tx (#15299)

This commit is contained in:
Tyera Eulberg 2021-02-12 18:29:26 -07:00 committed by GitHub
parent 08f94a2bd2
commit b09865e5a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -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;

View File

@ -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 () => {