|
há 1 ano atrás | |
---|---|---|
.. | ||
migrations | há 1 ano atrás | |
programs | há 1 ano atrás | |
tests | há 1 ano atrás | |
Anchor.toml | há 1 ano atrás | |
Cargo.toml | há 1 ano atrás | |
README.md | há 2 anos atrás | |
package.json | há 1 ano atrás | |
pnpm-lock.yaml | há 1 ano atrás | |
tsconfig.json | há 2 anos atrás |
We're creating a PDA
using create_user.rs
instruction.
#[account(
init,
seeds=[User::PREFIX.as_bytes(), user.key().as_ref()],
payer=user,
space=User::SIZE,
bump
)]
pub user_account: Box<Account<'info, User>>,
We're closing it using destroy_user.rs
instruction, which uses Anchor
AccoutClose
trait
.
user_account.close(user.to_account_info())?;
In our test destroy-an-account.ts we're using fetchNullable
since we expect
the account to be null
prior to creation and after closing.
const userAccountBefore = await program.account.user.fetchNullable(userAccountAddress, "processed");
assert.equal(userAccountBefore, null);
...
...
const userAccountAfter = await program.account.user.fetchNullable(userAccountAddress, "processed");
assert.notEqual(userAccountAfter, null);