Skip to content

Commit

Permalink
CI fix/Claim test fix (#25)
Browse files Browse the repository at this point in the history
ci and test fix
  • Loading branch information
rwwwx authored Aug 19, 2024
1 parent 01dedb1 commit 61855c5
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 53 deletions.
48 changes: 0 additions & 48 deletions .github/workflows/ci-lint.yml

This file was deleted.

93 changes: 93 additions & 0 deletions .github/workflows/ci-rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Rust CI

on:
push:
branches:
- master
pull_request:

env:
CARGO_TERM_COLOR: always
SOLANA_VERSION: "1.14.12"
RUST_STABLE_VERSION: "1.66.1"

defaults:
run:
working-directory: ./

jobs:
lint:
name: Linter
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install stable Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ env.RUST_STABLE_VERSION }}
components: clippy
cache: true

- name: Install nightly Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly
components: rustfmt
cache: true

- name: Set default Rust toolchain
run: |
rustup show
rustup override set ${{ env.RUST_STABLE_VERSION }}
- name: Run fmt
run: cargo +nightly fmt -- --check

- name: Run clippy
run: cargo clippy --all-targets --all-features --workspace -- -D warnings --allow=clippy::result_large_err --allow=clippy::await_holding_refcell_ref

tests:
name: Tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install Linux dependencies
run: sudo apt-get update && sudo apt-get install -y pkg-config build-essential libudev-dev

- name: Install stable Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ env.RUST_STABLE_VERSION }}
cache: true

- name: Cache Solana binaries
uses: actions/cache@v2
with:
path: ~/.cache/solana
key: ${{ runner.os }}-${{ env.RUST_STABLE_VERSION }}

- name: Install Solana
run: |
sh -c "$(curl -sSfL https://release.solana.com/v${{ env.SOLANA_VERSION }}/install)"
echo "$HOME/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH"
solana --version
echo "Generating keypair..."
solana-keygen new -o "$HOME/.config/solana/id.json" --no-passphrase --silent
- name: Switch toolchain
run: |
rustup override set ${{ env.RUST_STABLE_VERSION }}
solana-install init ${{ env.SOLANA_VERSION }}
- name: Append to Cargo.toml
run: |
echo "[profile.dev]" >> Cargo.toml
echo "debug = 0" >> Cargo.toml
- name: Run tests
run: cargo test-bpf
9 changes: 7 additions & 2 deletions programs/voter-stake-registry/src/instructions/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ use spl_governance::state::{
};
use std::{borrow::Borrow, str::FromStr};

// TODO: replace placeholder with the actual DAO pubkey
pub const DAO_PUBKEY: &str = "some_dao_pubkey";
// TODO: Replace placeholder with the actual DAO pubkey.
// TODO: Current `DAO_PUBKEY` is invalid and used only for `test_claim.rs` test,
// pls put actual DAO pubkey, when will we deploy.
// TODO: Also don't forget to change `GOVERNANCE_PROGRAM_ID` and `REALM_NAME` constants in
// `program_test/mod.rs` to derive valid PDA.
// Link to ticket: https://linear.app/mplx/issue/MTG-546/replace-dao-pubkey-constant-with-actual-public-key-in-staking-contract
pub const DAO_PUBKEY: &str = "89wVNeyqqDaWKWtS4rbunYdsxxbe5V3VRx6g8GWNMTMt";

#[derive(Accounts)]
pub struct Claim<'info> {
Expand Down
6 changes: 6 additions & 0 deletions programs/voter-stake-registry/tests/program_test/addin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,9 @@ impl AddinCookie {
owner_reward_ata: &Pubkey,
rewards_program: &Pubkey,
registrar: &RegistrarCookie,
governance: &Pubkey,
proposal: &Pubkey,
vote_record: &Pubkey,
) -> std::result::Result<(), BanksClientError> {
let data = anchor_lang::InstructionData::data(&mpl_staking::instruction::Claim {
realm_governing_mint_pubkey: registrar.realm_governing_token_mint_pubkey,
Expand All @@ -799,6 +802,9 @@ impl AddinCookie {
deposit_mining: *reward_mining,
mining_owner: mining_owner.pubkey(),
registrar: registrar.address,
governance: *governance,
proposal: *proposal,
vote_record: *vote_record,
user_reward_token_account: *owner_reward_ata,
token_program: spl_token::id(),
rewards_program: *rewards_program,
Expand Down
9 changes: 7 additions & 2 deletions programs/voter-stake-registry/tests/program_test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ pub mod rewards;
pub mod solana;
pub mod utils;

// TODO: Change values of this constants to derive correct PDA for `DAO_PUBKEY` constant in
// `claim.rs` file.
// Link to ticket: https://linear.app/mplx/issue/MTG-546/replace-dao-pubkey-constant-with-actual-public-key-in-staking-contract
pub const GOVERNANCE_PROGRAM_ID: &str = "GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw";
pub const REALM_NAME: &str = "VSR Rewards 21";

trait AddPacked {
fn add_packable_account<T: Pack>(
&mut self,
Expand Down Expand Up @@ -120,8 +126,7 @@ impl TestContext {
// intentionally set to half the limit, to catch potential problems early
test.set_compute_max_units(120000);

let governance_program_id =
Pubkey::from_str("GovernanceProgramTest1111111111111111111111").unwrap();
let governance_program_id = Pubkey::from_str(GOVERNANCE_PROGRAM_ID).unwrap();
test.add_program(
"spl_governance_3_1_1",
governance_program_id,
Expand Down
6 changes: 6 additions & 0 deletions programs/voter-stake-registry/tests/program_test/solana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ impl SolanaCookie {

transaction.sign(&all_signers, context.last_blockhash);

context.last_blockhash = context
.banks_client
.get_latest_blockhash()
.await
.expect("Cannot get latest blockhash!");

context
.banks_client
.process_transaction_with_commitment(
Expand Down
52 changes: 51 additions & 1 deletion programs/voter-stake-registry/tests/test_claim.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use anchor_spl::token::TokenAccount;
use mplx_staking_states::state::{LockupKind, LockupPeriod};
use program_test::*;
use solana_program::pubkey::Pubkey;
use solana_program_test::*;
use solana_sdk::{signature::Keypair, signer::Signer, transport::TransportError};
use spl_governance::state::vote_record::get_vote_record_address;
use std::str::FromStr;

mod program_test;

Expand All @@ -15,7 +18,7 @@ async fn successeful_claim() -> Result<(), TransportError> {
let realm = context
.governance
.create_realm(
"testrealm",
REALM_NAME,
realm_authority.pubkey(),
&context.mints[0],
payer,
Expand Down Expand Up @@ -180,6 +183,50 @@ async fn successeful_claim() -> Result<(), TransportError> {
.distribute_rewards(&rewards_pool, &distribution_authority)
.await?;

let mint_governance = realm
.create_mint_governance(
context.mints[0].pubkey.unwrap(),
&context.mints[0].authority,
&voter,
voter_authority,
payer,
context
.addin
.update_voter_weight_record_instruction(&registrar, &voter),
)
.await;

let proposal = realm
.create_proposal(
mint_governance.address,
voter_authority,
&voter,
payer,
context
.addin
.update_voter_weight_record_instruction(&registrar, &voter),
)
.await
.unwrap();
realm
.cast_vote(
mint_governance.address,
&proposal,
&voter,
voter_authority,
payer,
context
.addin
.update_voter_weight_record_instruction(&registrar, &voter),
)
.await
.unwrap();
let vote_record = get_vote_record_address(
&Pubkey::from_str(GOVERNANCE_PROGRAM_ID).unwrap(),
&proposal.address,
&proposal.owner_token_owner_record,
);

context
.addin
.claim(
Expand All @@ -190,6 +237,9 @@ async fn successeful_claim() -> Result<(), TransportError> {
&voter_authority_ata,
&context.rewards.program_id,
&registrar,
&mint_governance.address,
&proposal.address,
&vote_record,
)
.await?;

Expand Down

0 comments on commit 61855c5

Please sign in to comment.