test: reenable account change subscription test
This commit is contained in:
parent
35ee38b0f1
commit
db50893fa1
|
@ -23,6 +23,7 @@ import invariant from '../src/util/assert';
|
||||||
import {DEFAULT_TICKS_PER_SLOT, NUM_TICKS_PER_SECOND} from '../src/timing';
|
import {DEFAULT_TICKS_PER_SLOT, NUM_TICKS_PER_SECOND} from '../src/timing';
|
||||||
import {MOCK_PORT, url} from './url';
|
import {MOCK_PORT, url} from './url';
|
||||||
import {
|
import {
|
||||||
|
AccountInfo,
|
||||||
BLOCKHASH_CACHE_TIMEOUT_MS,
|
BLOCKHASH_CACHE_TIMEOUT_MS,
|
||||||
BlockResponse,
|
BlockResponse,
|
||||||
BlockSignatures,
|
BlockSignatures,
|
||||||
|
@ -3550,70 +3551,36 @@ describe('Connection', function () {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// it('account change notification', async () => {
|
it('account change notification', async () => {
|
||||||
// if (mockServer) {
|
if (mockServer) {
|
||||||
// console.log('non-live test skipped');
|
console.log('non-live test skipped');
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
|
const connection = new Connection(url, 'confirmed');
|
||||||
|
const owner = Keypair.generate();
|
||||||
|
|
||||||
// const connection = new Connection(url, 'confirmed');
|
let subscriptionId;
|
||||||
// const owner = Keypair.generate();
|
try {
|
||||||
// const programAccount = Keypair.generate();
|
const notificationPromise = new Promise<AccountInfo<Buffer>>(
|
||||||
|
resolve => {
|
||||||
// const mockCallback = jest.fn();
|
subscriptionId = connection.onAccountChange(
|
||||||
|
owner.publicKey,
|
||||||
// const subscriptionId = connection.onAccountChange(
|
resolve,
|
||||||
// programAccount.publicKey,
|
'confirmed',
|
||||||
// mockCallback,
|
);
|
||||||
// 'confirmed',
|
},
|
||||||
// );
|
);
|
||||||
|
connection.requestAirdrop(owner.publicKey, LAMPORTS_PER_SOL);
|
||||||
// const balanceNeeded = Math.max(
|
const notificationPayload = await notificationPromise;
|
||||||
// await connection.getMinimumBalanceForRentExemption(0),
|
expect(notificationPayload.lamports).to.eq(LAMPORTS_PER_SOL);
|
||||||
// 1,
|
expect(notificationPayload.owner.equals(SystemProgram.programId)).to.be
|
||||||
// );
|
.true;
|
||||||
|
} finally {
|
||||||
// let signature = await connection.requestAirdrop(
|
if (subscriptionId != null) {
|
||||||
// owner.publicKey,
|
connection.removeAccountChangeListener(subscriptionId);
|
||||||
// LAMPORTS_PER_SOL,
|
}
|
||||||
// );
|
}
|
||||||
// await connection.confirmTransaction(signature);
|
});
|
||||||
// try {
|
|
||||||
// const transaction = new Transaction().add(
|
|
||||||
// SystemProgram.transfer({
|
|
||||||
// fromPubkey: owner.publicKey,
|
|
||||||
// toPubkey: programAccount.publicKey,
|
|
||||||
// lamports: balanceNeeded,
|
|
||||||
// }),
|
|
||||||
// );
|
|
||||||
// await sendAndConfirmTransaction(connection, transaction, [owner], {
|
|
||||||
// commitment: 'confirmed',
|
|
||||||
// });
|
|
||||||
// } catch (err) {
|
|
||||||
// await connection.removeAccountChangeListener(subscriptionId);
|
|
||||||
// throw err;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Wait for mockCallback to receive a call
|
|
||||||
// let i = 0;
|
|
||||||
// for (;;) {
|
|
||||||
// if (mockCallback.mock.calls.length > 0) {
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (++i === 30) {
|
|
||||||
// throw new Error('Account change notification not observed');
|
|
||||||
// }
|
|
||||||
// // Sleep for a 1/4 of a slot, notifications only occur after a block is
|
|
||||||
// // processed
|
|
||||||
// await sleep((250 * DEFAULT_TICKS_PER_SLOT) / NUM_TICKS_PER_SECOND);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// await connection.removeAccountChangeListener(subscriptionId);
|
|
||||||
|
|
||||||
// expect(mockCallback.mock.calls[0][0].lamports).to.eq(balanceNeeded);
|
|
||||||
// expect(mockCallback.mock.calls[0][0].owner).to.eq(SystemProgram.programId);
|
|
||||||
// });
|
|
||||||
|
|
||||||
it('program account change notification', async () => {
|
it('program account change notification', async () => {
|
||||||
connection._commitment = 'confirmed';
|
connection._commitment = 'confirmed';
|
||||||
|
|
Loading…
Reference in New Issue