Skip to content

Commit

Permalink
add tests for init if and init competitor
Browse files Browse the repository at this point in the history
  • Loading branch information
wphan committed Oct 26, 2023
1 parent 83bf8b6 commit f81d1d3
Show file tree
Hide file tree
Showing 19 changed files with 373 additions and 1,200 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
drift-competitions
38 changes: 28 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defaults:
env:
CARGO_TERM_COLOR: always
RUST_TOOLCHAIN: 1.67.0
SOLANA_VERSION: '1.14.7'
SOLANA_VERSION: "1.14.7"

jobs:
fmt-clippy:
Expand Down Expand Up @@ -59,8 +59,8 @@ jobs:
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
node-version: "16.x"
registry-url: "https://registry.npmjs.org"
- name: Install yarn
run: yarn
- name: Run prettier
Expand All @@ -72,8 +72,8 @@ jobs:
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
node-version: "16.x"
registry-url: "https://registry.npmjs.org"
- name: Install yarn
run: yarn
- name: Run lint
Expand All @@ -82,7 +82,16 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v2
- name: Checkout main
uses: actions/checkout@v3

- name: Checkout competitions
uses: actions/checkout@v3
with:
repository: drift-labs/drift-competitions
ssh-key: ${{ secrets.DRIFT_COMMON_DEPLOY_KEY }}
path: drift-competitions
submodules: recursive

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
Expand All @@ -93,7 +102,7 @@ jobs:
- name: Cache build artefacts
uses: Swatinem/rust-cache@v1
with:
cache-on-failure: 'true'
cache-on-failure: "true"

- uses: ./.github/actions/setup-solana/

Expand All @@ -103,8 +112,8 @@ jobs:
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
node-version: "16.x"
registry-url: "https://registry.npmjs.org"

- name: Setup yarn
run: npm install -g yarn
Expand All @@ -121,7 +130,16 @@ jobs:
npm install --global mocha
- name: build sdk
run: cd ts/sdk/ && yarn && tsc && cd ../..
run: |
yarn
tsc
working-directory: ts/sdk

- name: build competitions sdk
run: |
yarn
yarn build
working-directory: drift-competitions/ts/sdk

- name: run anchor tests
run: anchor test
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "drift-competitions"]
path = drift-competitions
url = [email protected]:drift-labs/drift-competitions.git
4 changes: 4 additions & 0 deletions Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ wallet = "~/.config/solana/id.json"
address = "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH"
program = "./deps/drift.so"

[[test.genesis]]
address = "DraWMeQX9LfzQQSYoeBwHAgM5JcqFkgrX7GbTfjzVMVL"
program = "./deps/drift_competitions.so"

[scripts]
test = "yarn anchor-tests"
Binary file added deps/drift_competitions.so
Binary file not shown.
1 change: 1 addition & 0 deletions drift-competitions
Submodule drift-competitions added at 5be5cb
18 changes: 0 additions & 18 deletions programs/drift_vaults/src/cpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,6 @@ pub trait InitializeInsuranceFundStakeCPI {
fn drift_initialize_insurance_fund_stake(&self, market_index: u16) -> Result<()>;
}

pub trait AddInsuranceFundStakeCPI {
fn drift_add_insurance_fund_stake(&self, market_index: u16, amount: u64) -> Result<()>;
}

pub trait RequestRemoveInsuranceFundStakeCPI {
fn drift_request_remove_insurance_fund_stake(
&self,
market_index: u16,
amount: u64,
) -> Result<()>;

fn drift_cancel_request_remove_insurance_fund_stake(&self, market_index: u16) -> Result<()>;
}

pub trait RemoveInsuranceFundStakeCPI {
fn drift_remove_insurance_fund_stake(&self, market_index: u16) -> Result<()>;
}

pub trait InitializeCompetitorCPI {
fn drift_competition_initialize_competitor(&self) -> Result<()>;
}
137 changes: 0 additions & 137 deletions programs/drift_vaults/src/instructions/add_insurance_fund_stake.rs

This file was deleted.

12 changes: 6 additions & 6 deletions programs/drift_vaults/src/instructions/initialize_competitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use anchor_lang::prelude::*;
use drift::state::user::UserStats;
use drift_competitions::cpi::accounts::InitializeCompetitor as DriftCompetitionInitializeCompetitor;
use drift_competitions::program::DriftCompetitions;
// use drift_competitions::state::{Competition, Competitor};
use drift_competitions::state::{Competition, Competitor};

pub fn initialize_competitor<'info>(
ctx: Context<'_, '_, '_, 'info, InitializeCompetitor<'info>>,
Expand All @@ -17,7 +15,6 @@ pub fn initialize_competitor<'info>(
}

#[derive(Accounts)]
#[instruction(market_index: u16)]
pub struct InitializeCompetitor<'info> {
#[account(
mut,
Expand All @@ -33,11 +30,14 @@ pub struct InitializeCompetitor<'info> {
#[account(
mut,
seeds = [b"competitor", competition.key().as_ref(), vault.key().as_ref()],
bump
bump,
seeds::program = drift_competitions_program.key(),
)]
pub competitor: AccountLoader<'info, Competitor>,
/// CHECK: checked in drift cpi
pub competitor: AccountInfo<'info>,
#[account(mut)]
pub competition: AccountLoader<'info, Competition>,
/// CHECK: checked in drift cpi
pub competition: AccountInfo<'info>,
#[account(
mut,
constraint = is_user_stats_for_vault(&vault, &drift_user_stats.to_account_info())?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::Vault;
use anchor_lang::prelude::*;
use drift::cpi::accounts::InitializeInsuranceFundStake as DriftInitializeInsuranceFundStake;
use drift::program::Drift;
use drift::state::insurance_fund_stake::InsuranceFundStake;
use drift::state::spot_market::SpotMarket;

pub fn initialize_insurance_fund_stake<'info>(
Expand Down Expand Up @@ -34,12 +33,14 @@ pub struct InitializeInsuranceFundStake<'info> {
constraint = is_spot_market_for_vault(&vault, &drift_spot_market, market_index)?,
)]
pub drift_spot_market: AccountLoader<'info, SpotMarket>,
/// CHECK: checked in drift cpi
#[account(
mut,
seeds = [b"insurance_fund_stake", vault.key().as_ref(), market_index.to_le_bytes().as_ref()],
bump
bump,
seeds::program = drift_program.key(),
)]
pub insurance_fund_stake: AccountLoader<'info, InsuranceFundStake>,
pub insurance_fund_stake: AccountInfo<'info>,
#[account(
mut,
constraint = is_user_stats_for_vault(&vault, &drift_user_stats)?
Expand Down
6 changes: 0 additions & 6 deletions programs/drift_vaults/src/instructions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub use add_insurance_fund_stake::*;
pub use apply_profit_share::*;
pub use cancel_withdraw_request::*;
pub use deposit::*;
Expand All @@ -12,8 +11,6 @@ pub use manager_cancel_withdraw_request::*;
pub use manager_deposit::*;
pub use manager_request_withdraw::*;
pub use manager_withdraw::*;
pub use remove_insurance_fund_stake::*;
pub use request_remove_insurance_fund_stake::*;

pub use request_withdraw::*;
pub use reset_delegate::*;
Expand All @@ -22,7 +19,6 @@ pub use update_margin_trading_enabled::*;
pub use update_vault::*;
pub use withdraw::*;

mod add_insurance_fund_stake;
mod apply_profit_share;
mod cancel_withdraw_request;
pub mod constraints;
Expand All @@ -37,8 +33,6 @@ mod manager_cancel_withdraw_request;
mod manager_deposit;
mod manager_request_withdraw;
mod manager_withdraw;
mod remove_insurance_fund_stake;
mod request_remove_insurance_fund_stake;
mod request_withdraw;
mod reset_delegate;
mod update_delegate;
Expand Down
Loading

0 comments on commit f81d1d3

Please sign in to comment.