Skip to content

Commit

Permalink
chore: update new program id
Browse files Browse the repository at this point in the history
  • Loading branch information
quanghuynguyen1902 committed Jan 31, 2023
1 parent cf1067c commit 89b2365
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ pub mod sender_reject_proposal;
pub mod receiver_reject_proposal;
pub mod cancel_proposal;
pub mod close_proposal;
pub mod update_nft;

pub use create_proposal::*;
pub use receiver_approve_proposal::*;
pub use sender_approve_proposal::*;
pub use sender_reject_proposal::*;
pub use receiver_reject_proposal::*;
pub use cancel_proposal::*;
pub use close_proposal::*;
pub use close_proposal::*;
pub use update_nft::*;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use anchor_lang::prelude::*;

use crate::constants::*;
use crate::error::*;
use crate::schemas::Proposal;


#[derive(Accounts)]
pub struct UpdateNft<'info> {
#[account(
mut,
constraint = *receiver.key == proposal.receiver
@ ErrorCodes::ReceiverInvalidStateAccount
)]
pub proposal: Account<'info, Proposal>,

#[account(mut)]
pub receiver: Signer<'info>,
pub system_program: Program<'info, System>,
}

pub fn handler(
ctx: Context<UpdateNft>, nft: Pubkey
) -> Result<()> {
let proposal = &mut ctx.accounts.proposal;
if proposal.sender_status == 1 && proposal.receiver_status == 1 {
proposal.nft = nft;
}
Ok(())
}


7 changes: 6 additions & 1 deletion programs/superteam-dao-contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::error::*;
use instructions::*;
use schemas::*;

declare_id!("7cir3NiJkRvAHY5DFtnBWWDWXUMPjnJcVgwiQ9YBUS5o");
declare_id!("9fHpouSqNrqBKLka9WeUXkRuh2Qt97nvqtP1Km99LKXb");

#[program]
pub mod superteam_dao_contract {
Expand Down Expand Up @@ -55,5 +55,10 @@ pub mod superteam_dao_contract {
Ok(())
}

pub fn update_nft(ctx: Context<UpdateNft>, nft: Pubkey) -> Result<()> {
update_nft::handler(ctx, nft);
Ok(())
}


}
2 changes: 2 additions & 0 deletions programs/superteam-dao-contract/src/schemas/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub struct Proposal {
pub receiver: Pubkey,
pub sender: Pubkey,
pub submitter: Pubkey,
pub nft: Pubkey,
pub receiver_status: u8,
pub sender_status: u8,
pub spl: Pubkey,
Expand All @@ -26,6 +27,7 @@ impl Proposal {
PUBKEY_SIZE + // recipient
PUBKEY_SIZE + // sender
PUBKEY_SIZE + // submitter
PUBKEY_SIZE + // nft
1 + // receiver_status-0-pending-1-approve-2-reject
1 + // sender_status-0-pending-1-approve-2-reject
PUBKEY_SIZE + // spl
Expand Down
81 changes: 54 additions & 27 deletions tests/superteam-dao-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,34 @@ describe("superteam-dao-contract", () => {
console.log("[proposal account] sender approve : ", dataApplicantProposal);
});

it("[receiver] approve proposal", async () => {
await program.methods.receiverApproveProposal()
.accounts({
proposal: applicantProposal,
receiver: receiver.publicKey,
systemProgram: SystemProgram.programId,
})
.signers([receiver])
.rpc();

const dataApplicantProposal = await program.account.proposal.fetch(applicantProposal);
console.log("[proposal account] sender approve : ", dataApplicantProposal);
});

it("[receiver] update nft", async () => {
await program.methods.updateNft(new PublicKey("3J11Q7h5PhxvbKorARKHnG3rkqoqJqLGisCt8WWZYUBT"))
.accounts({
proposal: applicantProposal,
receiver: receiver.publicKey,
systemProgram: SystemProgram.programId,
})
.signers([receiver])
.rpc();

const dataApplicantProposal = await program.account.proposal.fetch(applicantProposal);
console.log("[proposal account] update nft approve : ", dataApplicantProposal);
});

it("[submitter] cancel proposal", async () => {
const balanceBefore = await provider.connection.getBalance(payer.publicKey);
console.log("[payer balance before close proposal]: ", balanceBefore);
Expand Down Expand Up @@ -180,32 +208,32 @@ describe("superteam-dao-contract", () => {
//
// });

it("get proposal by transaction, sender, receiver ", async () => {
let transaction = "3danKMRy4oyf4mD7Sun3FtnHxQGsHyxJwxBzHN1CWzaRdK6vjwEUH6gv5yNN2Cp6SPnUxwSHYbuimkNyX2zm24bZ"
const proposalBySender = await program.account.proposal.all([
{
memcmp: {
offset: 8, // Discriminator.
bytes: receiver.publicKey.toBase58(),
},
},
{
memcmp: {
offset: 40, // Discriminator.
bytes: sender.publicKey.toBase58(),
},
},
{
memcmp: {
offset: 118, // Discriminator.
bytes: bs58.encode(Buffer.from(transaction)),
},
}
]);

console.log(proposalBySender);

});
// it("get proposal by transaction, sender, receiver ", async () => {
// let transaction = "3danKMRy4oyf4mD7Sun3FtnHxQGsHyxJwxBzHN1CWzaRdK6vjwEUH6gv5yNN2Cp6SPnUxwSHYbuimkNyX2zm24bZ"
// const proposalBySender = await program.account.proposal.all([
// {
// memcmp: {
// offset: 8, // Discriminator.
// bytes: receiver.publicKey.toBase58(),
// },
// },
// {
// memcmp: {
// offset: 40, // Discriminator.
// bytes: sender.publicKey.toBase58(),
// },
// },
// {
// memcmp: {
// offset: 118, // Discriminator.
// bytes: bs58.encode(Buffer.from(transaction)),
// },
// }
// ]);
//
// console.log(proposalBySender);
//
// });

it("get proposal by receiver ", async () => {
const proposal = await program.account.proposal.all([
Expand All @@ -232,7 +260,6 @@ describe("superteam-dao-contract", () => {
]);

console.log(proposal);

});

it("get proposal by submitter ", async () => {
Expand Down

0 comments on commit 89b2365

Please sign in to comment.