Skip to content

Commit

Permalink
updated close account program change name to userId
Browse files Browse the repository at this point in the history
  • Loading branch information
adpthegreat committed Oct 23, 2024
1 parent d5a9036 commit d3734fe
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ declare_id!("2q4uoWExFAbZjeDe4n3miipsT9bX9vLnkSetCfZYF2VT");
#[program]
pub mod close_account {
use super::*;
pub fn create_user(ctx: Context<CreateUserContext>, name: u8) -> Result<()> {
pub fn create_user(ctx: Context<CreateUserContext>, name: u32) -> Result<()> {
ctx.accounts.user_account.user_bump = ctx.bumps.user_account;
ctx.accounts.user_account.user = ctx.accounts.user.key();
ctx.accounts.user_account.name = name;
Expand Down Expand Up @@ -39,6 +39,6 @@ pub struct CloseUserContext<'info> {
#[account]
pub struct UserAccount {
pub user_bump: u8,
pub name: u8,
pub name: u32,
pub user: Pubkey,
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ describe("Close an account", async () => {
);

it("Can create an account", async () => {
const userId = anchor.BN(76362)
await program.methods
.createUser("John Doe")
.createUser(userId)
.accounts({
user: payer.publicKey,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ describe("Close an account", () => {
);

it("can create an account", async () => {
const userId = anchor.BN(76362)

await program.methods
.createUser("John Doe")
.createUser(userId)
.accounts({
user: payer.publicKey,
})
Expand All @@ -38,7 +40,6 @@ describe("Close an account", () => {
.closeUser()
.accounts({
user: payer.publicKey
// userAccount: userAccountAddress,
})
.rpc();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Account, Pubkey, Result, u8, Signer } from "@solanaturbine/poseidon";
import { Account, Pubkey, Result, u8, Signer, u32 } from "@solanaturbine/poseidon";

export default class CloseAccount {
static PROGRAM_ID = new Pubkey(
"2q4uoWExFAbZjeDe4n3miipsT9bX9vLnkSetCfZYF2VT"
);

createUser(user: Signer, userAccount: UserAccount, name: u8): Result {
createUser(user: Signer, userAccount: UserAccount, userId: u32): Result {
userAccount.derive(["USER", user.key]).init();

userAccount.userBump = userAccount.getBump();

userAccount.user = user.key;

userAccount.name = name;
userAccount.userId = userId;
}
closeUser(userAccount: UserAccount, user: Signer): Result {
userAccount.derive(["USER", user.key]).close(user);
Expand All @@ -21,6 +21,6 @@ export default class CloseAccount {

export interface UserAccount extends Account {
userBump: u8;
name: u8;
userId: u32;
user: Pubkey;
}

0 comments on commit d3734fe

Please sign in to comment.