Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 4683535

Browse files
Fix CloseAccount js test (#128)
1 parent 339100e commit 4683535

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

token/js/cli/main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
mintTo,
1717
multisig,
1818
burn,
19-
closeAccount,
19+
failOnCloseAccount,
2020
nativeToken,
2121
} from './token-test';
2222

@@ -43,8 +43,8 @@ async function main() {
4343
await multisig();
4444
console.log('Run test: burn');
4545
await burn();
46-
console.log('Run test: closeAccount');
47-
await closeAccount();
46+
console.log('Run test: failOnCloseAccount');
47+
await failOnCloseAccount();
4848
console.log('Run test: nativeToken');
4949
await nativeToken();
5050
console.log('Success\n');

token/js/cli/token-test.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ export async function multisig(): Promise<void> {
388388
}
389389
}
390390

391-
export async function closeAccount(): Promise<void> {
391+
export async function failOnCloseAccount(): Promise<void> {
392392
const connection = await getConnection();
393393
const owner = new Account();
394394
const close = await testToken.createAccount(owner.publicKey);
@@ -401,6 +401,7 @@ export async function closeAccount(): Promise<void> {
401401
throw new Error('Account not found');
402402
}
403403

404+
// Initialize destination account to isolate source of failure
404405
const balanceNeeded =
405406
await connection.getMinimumBalanceForRentExemption(0);
406407
const dest = await newAccountWithLamports(connection, balanceNeeded);
@@ -412,14 +413,11 @@ export async function closeAccount(): Promise<void> {
412413
throw new Error('Account not found');
413414
}
414415

415-
await testToken.closeAccount(close, dest.publicKey, owner, []);
416+
assert(didThrow(testToken.closeAccount, [close, dest.publicKey, owner, []]));
417+
416418
info = await connection.getAccountInfo(close);
417419
if (info != null) {
418-
throw new Error('Account not closed');
419-
}
420-
info = await connection.getAccountInfo(dest.publicKey);
421-
if (info != null) {
422-
assert(info.lamports == balanceNeeded + close_balance);
420+
assert(info.lamports == close_balance);
423421
} else {
424422
throw new Error('Account not found');
425423
}

0 commit comments

Comments
 (0)