Skip to content

Commit

Permalink
Fix CloseAccount js test (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
CriesofCarrots authored Jul 15, 2020
1 parent 339100e commit 4683535
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
6 changes: 3 additions & 3 deletions token/js/cli/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
mintTo,
multisig,
burn,
closeAccount,
failOnCloseAccount,
nativeToken,
} from './token-test';

Expand All @@ -43,8 +43,8 @@ async function main() {
await multisig();
console.log('Run test: burn');
await burn();
console.log('Run test: closeAccount');
await closeAccount();
console.log('Run test: failOnCloseAccount');
await failOnCloseAccount();
console.log('Run test: nativeToken');
await nativeToken();
console.log('Success\n');
Expand Down
12 changes: 5 additions & 7 deletions token/js/cli/token-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ export async function multisig(): Promise<void> {
}
}

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

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

await testToken.closeAccount(close, dest.publicKey, owner, []);
assert(didThrow(testToken.closeAccount, [close, dest.publicKey, owner, []]));

info = await connection.getAccountInfo(close);
if (info != null) {
throw new Error('Account not closed');
}
info = await connection.getAccountInfo(dest.publicKey);
if (info != null) {
assert(info.lamports == balanceNeeded + close_balance);
assert(info.lamports == close_balance);
} else {
throw new Error('Account not found');
}
Expand Down

0 comments on commit 4683535

Please sign in to comment.