Skip to content
This repository was archived by the owner on Feb 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions programs/gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ num-derive = "0.3"
num-traits = "0.2"
solana-gateway = "0.2.2"
solana-program = "1.14.16"
spl-governance = { version = "2.2.4", features = ["no-entrypoint"] }
spl-governance-tools= "0.1.2"
spl-governance-addin-api = "0.1.2"
spl-governance = { version = "3.1.1", features = ["no-entrypoint"] }
spl-governance-tools= "0.1.3"
spl-governance-addin-api = "0.1.3"
spl-token = { version = "3.3", features = [ "no-entrypoint" ] }

[dev-dependencies]
borsh = "0.9.1"
solana-sdk = "1.14.16"
solana-program-test = "1.14.16"
spl-governance-addin-mock = "0.1.2"
spl-governance-addin-mock = "0.1.3"
Binary file modified programs/gateway/tests/fixtures/spl_governance.so
Binary file not shown.
Binary file not shown.
63 changes: 41 additions & 22 deletions programs/gateway/tests/program_test/governance_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ use spl_governance::{
},
state::{
enums::{
GovernanceAccountType, MintMaxVoteWeightSource, ProposalState, VoteThresholdPercentage,
GovernanceAccountType, MintMaxVoterWeightSource, ProposalState, VoteThreshold,
VoteTipping,
},
governance::get_governance_address,
proposal::{get_proposal_address, ProposalV2},
realm::{get_realm_address, RealmConfig, RealmV2},
token_owner_record::{get_token_owner_record_address, TokenOwnerRecordV2},
realm::{get_realm_address, GoverningTokenConfigAccountArgs, RealmConfig, RealmV2},
realm_config::GoverningTokenType,
token_owner_record::{
get_token_owner_record_address, TokenOwnerRecordV2, TOKEN_OWNER_RECORD_LAYOUT_VERSION,
},
},
};

Expand Down Expand Up @@ -64,7 +67,7 @@ impl GovernanceTest {

#[allow(dead_code)]
pub fn add_program(program_test: &mut ProgramTest) {
program_test.add_program("spl_governance_deposit_allowed", Self::program_id(), None);
program_test.add_program("spl_governance", Self::program_id(), None);
}

#[allow(dead_code)]
Expand Down Expand Up @@ -93,21 +96,27 @@ impl GovernanceTest {
let realm_name = format!("Realm #{}", self.next_id).to_string();

let min_community_weight_to_create_governance = 1;
let community_mint_max_vote_weight_source = MintMaxVoteWeightSource::FULL_SUPPLY_FRACTION;
let community_mint_max_voter_weight_source = MintMaxVoterWeightSource::FULL_SUPPLY_FRACTION;

let realm_key = get_realm_address(&self.program_id, &realm_name);

let community_token_config_args = GoverningTokenConfigAccountArgs {
voter_weight_addin: self.community_voter_weight_addin,
max_voter_weight_addin: None,
token_type: GoverningTokenType::default(),
};

let create_realm_ix = create_realm(
&self.program_id,
&realm_authority.pubkey(),
&community_mint_cookie.address,
&self.bench.payer.pubkey(),
Some(council_mint_cookie.address),
self.community_voter_weight_addin,
Some(community_token_config_args),
None,
realm_name.clone(),
min_community_weight_to_create_governance,
community_mint_max_vote_weight_source.clone(),
community_mint_max_voter_weight_source.clone(),
);

self.bench
Expand All @@ -125,12 +134,13 @@ impl GovernanceTest {
council_mint: Some(council_mint_cookie.address),
reserved: [0; 6],
min_community_weight_to_create_governance,
community_mint_max_vote_weight_source,
use_community_voter_weight_addin: false,
use_max_community_voter_weight_addin: false,
legacy1: 0,
legacy2: 0,
community_mint_max_voter_weight_source,
},
voting_proposal_count: 0,

reserved_v2: [0; 128],
legacy1: 0,
};

Ok(RealmCookie {
Expand Down Expand Up @@ -208,13 +218,19 @@ impl GovernanceTest {
&realm_cookie.realm_authority.pubkey(),
None,
spl_governance::state::governance::GovernanceConfig {
vote_threshold_percentage: VoteThresholdPercentage::YesVote(60),
min_community_weight_to_create_proposal: 1,
min_transaction_hold_up_time: 0,
max_voting_time: 600,
vote_tipping: VoteTipping::Disabled,
proposal_cool_off_time: 0,
min_council_weight_to_create_proposal: 1,

community_vote_threshold: VoteThreshold::YesVotePercentage(60),
voting_base_time: 600,
community_vote_tipping: VoteTipping::Strict,
council_vote_threshold: VoteThreshold::YesVotePercentage(60),
council_veto_vote_threshold: VoteThreshold::Disabled,
council_vote_tipping: VoteTipping::Disabled,
community_veto_vote_threshold: VoteThreshold::Disabled,
voting_cool_off_time: 0,
deposit_exempt_proposal_count: 10,
},
);

Expand All @@ -225,14 +241,14 @@ impl GovernanceTest {
)
.await?;

let proposal_index: u32 = 0;
let proposal_governing_token_mint = realm_cookie.account.community_mint;
let proposal_seed = Pubkey::new_unique();

let proposal_key = get_proposal_address(
&self.program_id,
&governance_key,
&proposal_governing_token_mint,
&proposal_index.to_le_bytes(),
&proposal_seed,
);

let create_proposal_ix = create_proposal(
Expand All @@ -249,7 +265,7 @@ impl GovernanceTest {
spl_governance::state::proposal::VoteType::SingleChoice,
vec!["Yes".to_string()],
true,
0_u32,
&proposal_seed,
);

let sign_off_proposal_ix = sign_off_proposal(
Expand All @@ -276,7 +292,7 @@ impl GovernanceTest {
vote_type: spl_governance::state::proposal::VoteType::SingleChoice,
options: vec![],
deny_vote_weight: Some(1),
veto_vote_weight: None,
veto_vote_weight: 0,
abstain_vote_weight: None,
start_voting_at: None,
draft_at: 1,
Expand All @@ -289,10 +305,12 @@ impl GovernanceTest {
execution_flags: spl_governance::state::enums::InstructionExecutionFlags::None,
max_vote_weight: None,
max_voting_time: None,
vote_threshold_percentage: None,

reserved: [0; 64],
name: String::from("Proposal #1"),
description_link: String::from("Proposal #1 link"),
reserved1: 0,
vote_threshold: None,
};

Ok(ProposalCookie {
Expand Down Expand Up @@ -362,11 +380,11 @@ impl GovernanceTest {
governing_token_owner: token_owner_cookie.address,
governing_token_deposit_amount: tokens_to_deposit,
unrelinquished_votes_count: 0,
total_votes_count: 0,
outstanding_proposal_count: 0,
reserved: [0; 7],
reserved: [0; 6],
governance_delegate: None,
reserved_v2: [0; 128],
version: TOKEN_OWNER_RECORD_LAYOUT_VERSION,
};

Ok(TokenOwnerRecordCookie {
Expand All @@ -384,6 +402,7 @@ impl GovernanceTest {
) -> Result<(), TransportError> {
let relinquish_vote_ix = relinquish_vote(
&self.program_id,
&token_owner_record_cookie.account.realm,
&proposal_cookie.account.governance,
&proposal_cookie.address,
&token_owner_record_cookie.address,
Expand Down
4 changes: 2 additions & 2 deletions programs/nft-voter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ anchor-spl = { version = "0.26.0", features = ["token"] }
itertools = "0.10.2"
mpl-token-metadata = { version = "=1.1.0", features = ["no-entrypoint"] }
solana-program = "1.14.16"
spl-governance = { version = "2.2.2", features = ["no-entrypoint"] }
spl-governance-tools= "=0.1.2"
spl-governance = { version = "3.1.1", features = ["no-entrypoint"] }
spl-governance-tools= "0.1.3"
spl-token = { version = "3.5", features = [ "no-entrypoint" ] }

# The explicit versions are required to compile Anchor <= 0.27.0
Expand Down
3 changes: 0 additions & 3 deletions programs/nft-voter/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,4 @@ pub enum NftVoterError {

#[msg("VoterWeightRecord must be expired")]
VoterWeightRecordMustBeExpired,

#[msg("Cannot configure collection with voting proposals")]
CannotConfigureCollectionWithVotingProposals,
}
1 change: 1 addition & 0 deletions programs/nft-voter/src/instructions/cast_nft_vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ pub fn cast_nft_vote<'a, 'b, 'c, 'info>(
&id(),
&ctx.accounts.system_program.to_account_info(),
&rent,
0,
)?;
}

Expand Down
9 changes: 6 additions & 3 deletions programs/nft-voter/src/instructions/configure_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ pub fn configure_collection(
NftVoterError::InvalidRealmAuthority
);

// spl-gov doesn't track voting_proposal_count any longer and we can't enforce the check here
// It's not ideal but acceptable. The proper solution would require proposal queuing in spl-gov
//
// Changes to the collections config can accidentally tip the scales for outstanding proposals and hence we disallow it
if realm.voting_proposal_count > 0 {
return err!(NftVoterError::CannotConfigureCollectionWithVotingProposals);
}
// if realm.voting_proposal_count > 0 {
// return err!(NftVoterError::CannotConfigureCollectionWithVotingProposals);
// }

let collection = &ctx.accounts.collection;

Expand Down
2 changes: 1 addition & 1 deletion programs/nft-voter/src/instructions/relinquish_nft_vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub fn relinquish_nft_vote(ctx: Context<RelinquishNftVote>) -> Result<()> {
&governing_token_owner,
)?;

dispose_account(nft_vote_record_info, &ctx.accounts.beneficiary);
dispose_account(nft_vote_record_info, &ctx.accounts.beneficiary)?;
}

// Reset VoterWeightRecord and set expiry to expired to prevent it from being used
Expand Down
59 changes: 0 additions & 59 deletions programs/nft-voter/tests/configure_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,62 +411,3 @@ async fn test_configure_collection_with_invalid_max_voter_weight_mint_error(

Ok(())
}

#[tokio::test]
async fn test_configure_collection_with_voting_proposal_error() -> Result<(), TransportError> {
// Arrange
let mut nft_voter_test = NftVoterTest::start_new().await;

let realm_cookie = nft_voter_test.governance.with_realm().await?;

let registrar_cookie = nft_voter_test.with_registrar(&realm_cookie).await?;

let nft_collection_cookie = nft_voter_test.token_metadata.with_nft_collection().await?;

let max_voter_weight_record_cookie = nft_voter_test
.with_max_voter_weight_record(&registrar_cookie)
.await?;

nft_voter_test
.with_collection(
&registrar_cookie,
&nft_collection_cookie,
&max_voter_weight_record_cookie,
Some(ConfigureCollectionArgs {
weight: 10,
size: 20,
}),
)
.await?;

nft_voter_test
.governance
.with_proposal(&realm_cookie)
.await?;

nft_voter_test.bench.advance_clock().await;

// Act

let err = nft_voter_test
.with_collection(
&registrar_cookie,
&nft_collection_cookie,
&max_voter_weight_record_cookie,
Some(ConfigureCollectionArgs {
weight: 10,
size: 20,
}),
)
.await
.err()
.unwrap();

// Assert
assert_nft_voter_err(
err,
NftVoterError::CannotConfigureCollectionWithVotingProposals,
);

Ok(())
}
Binary file modified programs/nft-voter/tests/fixtures/spl_governance.so
Binary file not shown.
Loading