fix: rent in connection tests, and remove invalid Loader.load

This commit is contained in:
Tyera Eulberg
2019-12-11 00:13:15 -07:00
committed by Michael Vines
parent cf31ba8924
commit d5cd16bef4

View File

@ -2,8 +2,6 @@
import { import {
Account, Account,
Connection, Connection,
BpfLoader,
Loader,
SystemProgram, SystemProgram,
sendAndConfirmTransaction, sendAndConfirmTransaction,
SOL_LAMPORTS, SOL_LAMPORTS,
@ -846,13 +844,16 @@ test('account change notification', async () => {
mockCallback, mockCallback,
); );
const balanceNeeded = await connection.getMinimumBalanceForRentExemption(0);
await connection.requestAirdrop(owner.publicKey, SOL_LAMPORTS); await connection.requestAirdrop(owner.publicKey, SOL_LAMPORTS);
try { try {
await Loader.load(connection, owner, programAccount, BpfLoader.programId, [ let transaction = SystemProgram.transfer(
1, owner.publicKey,
2, programAccount.publicKey,
3, balanceNeeded,
]); );
await sendAndConfirmTransaction(connection, transaction, owner);
} catch (err) { } catch (err) {
await connection.removeAccountChangeListener(subscriptionId); await connection.removeAccountChangeListener(subscriptionId);
throw err; throw err;
@ -875,8 +876,8 @@ test('account change notification', async () => {
await connection.removeAccountChangeListener(subscriptionId); await connection.removeAccountChangeListener(subscriptionId);
expect(mockCallback.mock.calls[0][0].lamports).toBe(1); expect(mockCallback.mock.calls[0][0].lamports).toBe(balanceNeeded);
expect(mockCallback.mock.calls[0][0].owner).toEqual(BpfLoader.programId); expect(mockCallback.mock.calls[0][0].owner).toEqual(SystemProgram.programId);
}); });
test('program account change notification', async () => { test('program account change notification', async () => {
@ -891,27 +892,32 @@ test('program account change notification', async () => {
// const mockCallback = jest.fn(); // const mockCallback = jest.fn();
const balanceNeeded = await connection.getMinimumBalanceForRentExemption(0);
let notified = false; let notified = false;
const subscriptionId = connection.onProgramAccountChange( const subscriptionId = connection.onProgramAccountChange(
BpfLoader.programId, SystemProgram.programId,
keyedAccountInfo => { keyedAccountInfo => {
if (keyedAccountInfo.accountId !== programAccount.publicKey.toString()) { if (keyedAccountInfo.accountId !== programAccount.publicKey.toString()) {
//console.log('Ignoring another account', keyedAccountInfo); //console.log('Ignoring another account', keyedAccountInfo);
return; return;
} }
expect(keyedAccountInfo.accountInfo.lamports).toBe(1); expect(keyedAccountInfo.accountInfo.lamports).toBe(balanceNeeded);
expect(keyedAccountInfo.accountInfo.owner).toEqual(BpfLoader.programId); expect(keyedAccountInfo.accountInfo.owner).toEqual(
SystemProgram.programId,
);
notified = true; notified = true;
}, },
); );
await connection.requestAirdrop(owner.publicKey, SOL_LAMPORTS); await connection.requestAirdrop(owner.publicKey, SOL_LAMPORTS);
try { try {
await Loader.load(connection, owner, programAccount, BpfLoader.programId, [ let transaction = SystemProgram.transfer(
1, owner.publicKey,
2, programAccount.publicKey,
3, balanceNeeded,
]); );
await sendAndConfirmTransaction(connection, transaction, owner);
} catch (err) { } catch (err) {
await connection.removeProgramAccountChangeListener(subscriptionId); await connection.removeProgramAccountChangeListener(subscriptionId);
throw err; throw err;