feat: add getEstimatedFee to Transaction (#23579)

This commit is contained in:
Marc Jaramillo
2022-03-11 09:05:22 -08:00
committed by GitHub
parent 4f18d73281
commit 2bff36dfba
2 changed files with 32 additions and 0 deletions

View File

@ -3,6 +3,7 @@ import {Buffer} from 'buffer';
import nacl from 'tweetnacl';
import {expect} from 'chai';
import {Connection} from '../src/connection';
import {Keypair} from '../src/keypair';
import {PublicKey} from '../src/publickey';
import {Transaction, TransactionInstruction} from '../src/transaction';
@ -11,6 +12,7 @@ import {SystemProgram} from '../src/system-program';
import {Message} from '../src/message';
import invariant from '../src/util/assert';
import {toBuffer} from '../src/util/to-buffer';
import {helpers} from './mocks/rpc-http';
describe('Transaction', () => {
describe('compileMessage', () => {
@ -112,6 +114,28 @@ describe('Transaction', () => {
});
});
it('getEstimatedFee', async () => {
const connection = new Connection('https://api.testnet.solana.com');
const accountFrom = Keypair.generate();
const accountTo = Keypair.generate();
const {blockhash} = await helpers.latestBlockhash({connection});
const transaction = new Transaction({
feePayer: accountFrom.publicKey,
recentBlockhash: blockhash,
}).add(
SystemProgram.transfer({
fromPubkey: accountFrom.publicKey,
toPubkey: accountTo.publicKey,
lamports: 10,
}),
);
const fee = await transaction.getEstimatedFee(connection);
expect(fee).to.eq(5000);
});
it('partialSign', () => {
const account1 = Keypair.generate();
const account2 = Keypair.generate();