diff --git a/token/js/cli/main.js b/token/js/cli/main.js index a886a6353f4..ee36e4f5a5f 100644 --- a/token/js/cli/main.js +++ b/token/js/cli/main.js @@ -16,7 +16,7 @@ import { mintTo, multisig, burn, - closeAccount, + failOnCloseAccount, nativeToken, } from './token-test'; @@ -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'); diff --git a/token/js/cli/token-test.js b/token/js/cli/token-test.js index 5cc8baa6609..67e9f3ece55 100644 --- a/token/js/cli/token-test.js +++ b/token/js/cli/token-test.js @@ -388,7 +388,7 @@ export async function multisig(): Promise { } } -export async function closeAccount(): Promise { +export async function failOnCloseAccount(): Promise { const connection = await getConnection(); const owner = new Account(); const close = await testToken.createAccount(owner.publicKey); @@ -401,6 +401,7 @@ export async function closeAccount(): Promise { 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); @@ -412,14 +413,11 @@ export async function closeAccount(): Promise { 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'); }