Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Governance: voter-weight-addin cleanup #2512

Merged
merged 9 commits into from
Oct 19, 2021
Next Next commit
chore: Ensure voter-weight-addin is built for tests
fix: build addin during test run

fix: build voter weight addin for tests using the addin only

chore: use mutex to build addin only once

chore: move build guard to separate file

chore: update governance version for chat
  • Loading branch information
SebastianBor committed Oct 16, 2021
commit fa95fdcc2eefaee9fb74224fe679deed4fe6a867
7 changes: 4 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion governance/chat/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ serde = "1.0.127"
serde_derive = "1.0.103"
solana-program = "1.8.0"
spl-token = { version = "3.2", path = "../../../token/program", features = [ "no-entrypoint" ] }
spl-governance= { version = "2.1.0", path ="../../program", features = [ "no-entrypoint" ]}
spl-governance= { version = "2.1.2", path ="../../program", features = [ "no-entrypoint" ]}
thiserror = "1.0"


Expand Down
4 changes: 2 additions & 2 deletions governance/program/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spl-governance"
version = "2.1.1"
version = "2.1.2"
description = "Solana Program Library Governance Program"
authors = ["Solana Maintainers <maintainers@solana.foundation>"]
repository = "https://github.com/solana-labs/solana-program-library"
Expand All @@ -26,12 +26,12 @@ thiserror = "1.0"
[dev-dependencies]
assert_matches = "1.5.0"
base64 = "0.13"
lazy_static = "1.4.0"
proptest = "1.0"
solana-program-test = "1.8.0"
solana-sdk = "1.8.0"
spl-governance-test-sdk = { version = "0.1.0", path ="../test-sdk"}
spl-governance-v1 = {package="spl-governance", version = "1.1.1", features = [ "no-entrypoint" ] }


[lib]
crate-type = ["cdylib", "lib"]
Binary file not shown.
25 changes: 25 additions & 0 deletions governance/program/tests/program_test/addins.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use lazy_static::lazy_static;
use solana_program_test::find_file;
use std::{process::Command, sync::Mutex};

lazy_static! {
pub static ref VOTER_WEIGHT_ADDIN_BUILD_GUARD: Mutex::<u8> = Mutex::new(0);
}

pub fn ensure_voter_weight_addin_is_built() {
if find_file("spl_governance_voter_weight_addin.so").is_none() {
let guard = VOTER_WEIGHT_ADDIN_BUILD_GUARD.lock().unwrap();
if find_file("spl_governance_voter_weight_addin.so").is_none() {
assert!(Command::new("cargo")
.args(&[
"build-bpf",
"--manifest-path",
"../voter-weight-addin/program/Cargo.toml",
])
.status()
.expect("Failed to build voter-weight-addin program")
.success());
}
std::mem::drop(guard);
SebastianBor marked this conversation as resolved.
Show resolved Hide resolved
}
}
14 changes: 10 additions & 4 deletions governance/program/tests/program_test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ use spl_governance::{
tools::bpf_loader_upgradeable::get_program_data_address,
};

pub mod addins;
pub mod cookies;

use crate::program_test::cookies::{
Expand All @@ -63,10 +64,13 @@ use spl_governance_test_sdk::{
ProgramTestBench, TestBenchProgram,
};

use self::cookies::{
GovernanceCookie, GovernedAccountCookie, GovernedMintCookie, GovernedProgramCookie,
GovernedTokenCookie, ProposalCookie, ProposalInstructionCookie, RealmCookie,
TokenOwnerRecordCookie, VoteRecordCookie,
use self::{
addins::ensure_voter_weight_addin_is_built,
cookies::{
GovernanceCookie, GovernedAccountCookie, GovernedMintCookie, GovernedProgramCookie,
GovernedTokenCookie, ProposalCookie, ProposalInstructionCookie, RealmCookie,
TokenOwnerRecordCookie, VoteRecordCookie,
},
};

pub struct GovernanceProgramTest {
Expand All @@ -84,6 +88,8 @@ impl GovernanceProgramTest {

#[allow(dead_code)]
pub async fn start_with_voter_weight_addin() -> Self {
ensure_voter_weight_addin_is_built();

Self::start_impl(true).await
}

Expand Down
2 changes: 1 addition & 1 deletion governance/voter-weight-addin/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ serde = "1.0.127"
serde_derive = "1.0.103"
solana-program = "1.7.11"
spl-token = { version = "3.2", path = "../../../token/program", features = [ "no-entrypoint" ] }
spl-governance= { version = "2.1.1", path ="../../program", features = [ "no-entrypoint" ]}
spl-governance= { version = "2.1.2", path ="../../program", features = [ "no-entrypoint" ]}
spl-governance-chat= { version = "0.1.0", path ="../../chat/program", features = [ "no-entrypoint" ]}
thiserror = "1.0"

Expand Down