diff --git a/programs/mpl-staking/tests/test_claim.rs b/programs/mpl-staking/tests/test_claim.rs index 202f99fa..9b6e38a2 100644 --- a/programs/mpl-staking/tests/test_claim.rs +++ b/programs/mpl-staking/tests/test_claim.rs @@ -25,6 +25,7 @@ struct CLaimSetup { voter_authority_ata: Pubkey, realm_authority: Keypair, payer: Keypair, + mngo_voting_mint: VotingMintConfigCookie, } async fn setup(realm_name: &str) -> Result { @@ -240,6 +241,7 @@ async fn setup(realm_name: &str) -> Result { deposit_mining, voter_authority_ata, realm_authority, + mngo_voting_mint, }) } @@ -453,7 +455,7 @@ async fn claim_is_allowed() -> Result<(), TransportError> { #[tokio::test] async fn claim_without_dao_vote_fail() -> Result<(), TransportError> { - // Create realm wi th invalid seed + // Create realm with invalid seed let claim_setup = setup("Realm").await?; // DAO with invalid seed vote @@ -499,3 +501,148 @@ async fn claim_without_dao_vote_fail() -> Result<(), TransportError> { Ok(()) } + +// TODO +#[tokio::test] +async fn claim_after_other_user_proposal_vote() -> Result<(), TransportError> { + let claim_setup = setup(REALM_NAME).await?; + let addin = &claim_setup.context.addin; + + let voter2_authority = &claim_setup.context.users[3].key; + let token_owner_record2 = claim_setup + .realm + .create_token_owner_record(voter2_authority.pubkey(), &claim_setup.payer) + .await; + let (deposit_mining_voter2, _) = find_deposit_mining_addr( + &claim_setup.context.rewards.program_id, + &voter2_authority.pubkey(), + &claim_setup.rewards_pool, + ); + let voter_authority_ata = claim_setup + .context + .rewards + .solana + .create_spl_ata( + &voter2_authority.pubkey(), + &claim_setup.mngo_voting_mint.mint.pubkey.unwrap(), + &claim_setup.payer, + ) + .await; + + let voter2 = addin + .create_voter( + &claim_setup.registrar, + &token_owner_record2, + voter2_authority, + &claim_setup.payer, + &claim_setup.rewards_pool, + &deposit_mining_voter2, + &claim_setup.context.rewards.program_id, + ) + .await; + + claim_setup + .context + .addin + .create_deposit_entry( + &claim_setup.registrar, + &voter2, + &voter2, + &claim_setup.mngo_voting_mint, + 0, + LockupKind::None, + LockupPeriod::None, + ) + .await?; + claim_setup + .context + .addin + .create_deposit_entry( + &claim_setup.registrar, + &voter2, + &voter2, + &claim_setup.mngo_voting_mint, + 1, + LockupKind::Constant, + LockupPeriod::ThreeMonths, + ) + .await?; + + let depositer_token_account = claim_setup.context.users[3].token_accounts[0]; + claim_setup + .context + .addin + .deposit( + &claim_setup.registrar, + &voter2, + &claim_setup.mngo_voting_mint, + voter2_authority, + depositer_token_account, + 0, + 10000, + ) + .await?; + + claim_setup + .context + .addin + .stake( + &claim_setup.registrar, + &voter2, + voter2.authority.pubkey(), + &claim_setup.context.rewards.program_id, + 0, + 1, + 10000, + ) + .await?; + + // voter2 cast vote into voter1_proposal + claim_setup + .realm + .cast_vote( + claim_setup.mint_governance.address, + &claim_setup.proposal, + &voter2, + &voter2_authority, + &claim_setup.payer, + claim_setup + .context + .addin + .update_voter_weight_record_instruction(&claim_setup.registrar, &voter2), + ) + .await + .unwrap(); + + let vote_record = get_vote_record_address( + &Pubkey::from_str(GOVERNANCE_PROGRAM_ID).unwrap(), + &claim_setup.proposal.address, + &claim_setup.proposal.owner_token_owner_record, + ); + + claim_setup + .context + .addin + .claim( + &claim_setup.rewards_pool, + &claim_setup.reward_mint, + &claim_setup.deposit_mining, + &claim_setup.voter_authority, + &claim_setup.voter_authority_ata, + &claim_setup.context.rewards.program_id, + &claim_setup.registrar, + &claim_setup.mint_governance.address, + &claim_setup.proposal.address, + &vote_record, + ) + .await?; + + let claimed_amount = claim_setup + .context + .solana + .token_account_balance(voter_authority_ata) + .await; + assert_eq!(100, claimed_amount); + + Ok(()) +}