forked from project-serum/serum-dex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db82618
commit 43d1f8c
Showing
54 changed files
with
3,774 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# This is the parent Makefile used by Solana program crates. It's expected | ||
# this is included in child Makefiles with commands overriden as desired | ||
# (this is why all the targets here end with % wildcards). In addition to | ||
# override targets, one can customize the behavior, by override following | ||
# variables in a child Makefile. See `registry/Makefile` for an example of | ||
# a child. | ||
|
||
# | ||
# Path to your local solana keypair. | ||
# | ||
TEST_PAYER_FILEPATH="$(HOME)/.config/solana/id.json" | ||
# | ||
# The solana cluster to test against. Defaults to local. | ||
# | ||
TEST_CLUSTER=localnet | ||
# | ||
# The url of TEST_CLUSTER. | ||
# | ||
TEST_CLUSTER_URL="http://localhost:8899" | ||
# | ||
# One can optionally set this along with the test-program command | ||
# to avoid redeploying everytime tests are run. | ||
# | ||
TEST_PROGRAM_ID="" | ||
# | ||
# Default options used for the solana cli. | ||
# | ||
SOL_OPTIONS=--url $(TEST_CLUSTER_URL) --keypair $(TEST_PAYER_FILEPATH) | ||
# | ||
# Path to the BPF sdk to build solana programs. | ||
# | ||
BPF_SDK=$(shell pwd)/../bin/bpf-sdk | ||
# | ||
# The name of the directory holding your Solana program, relative to the Makefile. | ||
# | ||
PROGRAM_DIRNAME=program | ||
# | ||
# Parent dir for the Solana program's build target. | ||
# | ||
BUILD_DIR=$(shell pwd)/$(PROGRAM_DIRNAME)/target/bpfel-unknown-unknown/release | ||
# | ||
# The program's crate name. | ||
# | ||
LIB_NAME=<your-solana-program> | ||
|
||
.PHONY: buil% \ | ||
build-clien% \ | ||
build-progra% \ | ||
deplo% \ | ||
tes% \ | ||
test-progra% \ | ||
test-integratio% \ | ||
test-uni% \ | ||
clipp% \ | ||
custo% | ||
|
||
buil%: build-progra% build-clien% | ||
@ # no-op | ||
|
||
build-clien%: | ||
ifdef features | ||
@cargo build --features client,$(features) | ||
else | ||
@cargo build --features client | ||
endif | ||
|
||
build-progra%: | ||
@$(BPF_SDK)/rust/build.sh $(PROGRAM_DIRNAME) | ||
@cp $(BUILD_DIR)/$(LIB_NAME).so $(BUILD_DIR)/$(LIB_NAME)_debug.so | ||
@$(BPF_SDK)/dependencies/llvm-native/bin/llvm-objcopy --strip-all $(BUILD_DIR)/$(LIB_NAME).so $(BUILD_DIR)/$(LIB_NAME).so | ||
|
||
deplo%: buil% | ||
@$(eval TEST_PROGRAM_ID=$(shell solana deploy $(SOL_OPTIONS) $(BUILD_DIR)/$(LIB_NAME).so | jq .programId -r)) | ||
@echo "{\"programId\": \"$(TEST_PROGRAM_ID)\"}" | ||
|
||
test-progra%: | ||
RUST_BACKTRACE=1 \ | ||
TEST_PROGRAM_ID=$(TEST_PROGRAM_ID) \ | ||
TEST_PAYER_FILEPATH=$(TEST_PAYER_FILEPATH) \ | ||
TEST_CLUSTER=$(TEST_CLUSTER) \ | ||
TEST_REWARDS_PROGRAM_ID=$(TEST_REWARDS_PROGRAM_ID) \ | ||
cargo test --features test,client -- --nocapture $(args) | ||
|
||
tes%: deplo% test-progra% | ||
@ # no-op | ||
|
||
init-tes%: | ||
@make init | ||
@make test | ||
|
||
test-uni%: | ||
RUST_BACKTRACE=1 \ | ||
@cargo test --lib --features test,client -- --nocapture $(args) | ||
|
||
ini%: | ||
@yes | solana-keygen new --outfile $(TEST_PAYER_FILEPATH) | ||
@yes | solana airdrop $(SOL_OPTIONS) 100 | ||
|
||
clipp%: | ||
@cargo clippy --features client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#![cfg_attr(feature = "strict", deny(warnings))] | ||
|
||
#[cfg(feature = "client")] | ||
pub mod client; | ||
#[macro_use] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "serum-common-tests" | ||
version = "0.1.0" | ||
description = "Serum common test utilities" | ||
repository = "https://github.com/project-serum/serum-dex" | ||
edition = "2018" | ||
|
||
[features] | ||
strict = [] | ||
|
||
[dependencies] | ||
solana-client-gen = { path = "../../solana-client-gen", features = ["client"] } | ||
serum-common = { path = "../", features = ["client"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#![cfg_attr(feature = "strict", deny(warnings))] | ||
|
||
use serum_common::client::Cluster; | ||
use solana_client_gen::prelude::ClientGen; | ||
use solana_client_gen::prelude::*; | ||
use solana_client_gen::solana_client::rpc_config::RpcSendTransactionConfig; | ||
use solana_client_gen::solana_sdk::commitment_config::CommitmentConfig; | ||
|
||
// Creates | ||
// | ||
// * Mint authority (shared between SRM and MSRM) | ||
// * SRM mint | ||
// * SRM god account (funded wallet) | ||
// * MSRM mint | ||
// * MSRM god account (funded wallet) | ||
// * RPC client. | ||
// | ||
pub fn genesis<T: ClientGen>() -> Genesis<T> { | ||
let client = client::<T>(); | ||
|
||
let spl_mint_decimals = 3; | ||
|
||
// Initialize the SPL token representing SRM. | ||
let mint_authority = Keypair::from_bytes(&Keypair::to_bytes(client.payer().clone())).unwrap(); | ||
let srm_mint = Keypair::generate(&mut OsRng); | ||
let _ = serum_common::client::rpc::create_and_init_mint( | ||
client.rpc(), | ||
client.payer(), | ||
&srm_mint, | ||
&mint_authority.pubkey(), | ||
spl_mint_decimals, | ||
) | ||
.unwrap(); | ||
|
||
// Initialize the SPL token representing MSRM. | ||
let mint_authority = Keypair::from_bytes(&Keypair::to_bytes(client.payer().clone())).unwrap(); | ||
let msrm_mint = Keypair::generate(&mut OsRng); | ||
let _ = serum_common::client::rpc::create_and_init_mint( | ||
client.rpc(), | ||
client.payer(), | ||
&msrm_mint, | ||
&mint_authority.pubkey(), | ||
spl_mint_decimals, | ||
); | ||
|
||
// Create a funded SRM account. | ||
let god_balance_before = 1_000_000; | ||
let god = serum_common::client::rpc::mint_to_new_account( | ||
client.rpc(), | ||
client.payer(), | ||
&mint_authority, | ||
&srm_mint.pubkey(), | ||
god_balance_before, | ||
) | ||
.unwrap(); | ||
// Create a funded MSRM account. | ||
let god_msrm_balance_before = 1_000_000; | ||
let god_msrm = serum_common::client::rpc::mint_to_new_account( | ||
client.rpc(), | ||
client.payer(), | ||
&mint_authority, | ||
&msrm_mint.pubkey(), | ||
god_balance_before, | ||
) | ||
.unwrap(); | ||
|
||
let god_owner = Keypair::from_bytes(&Keypair::to_bytes(client.payer().clone())).unwrap(); | ||
|
||
Genesis { | ||
client, | ||
mint_authority, | ||
srm_mint, | ||
msrm_mint, | ||
god, | ||
god_msrm, | ||
god_balance_before, | ||
god_msrm_balance_before, | ||
god_owner, | ||
} | ||
} | ||
|
||
// Genesis defines the initial state of the world. | ||
pub struct Genesis<T: ClientGen> { | ||
// RPC client. | ||
pub client: T, | ||
// SRM mint authority. | ||
pub mint_authority: Keypair, | ||
// SRM. | ||
pub srm_mint: Keypair, | ||
// MSRM. | ||
pub msrm_mint: Keypair, | ||
// Account funded with a ton of SRM. | ||
pub god: Keypair, | ||
// Account funded with a ton of MSRM. | ||
pub god_msrm: Keypair, | ||
// Balance of the god account to start. | ||
pub god_balance_before: u64, | ||
// Balance of the god_msrm account to start. | ||
pub god_msrm_balance_before: u64, | ||
// Owner of both god accounts. | ||
pub god_owner: Keypair, | ||
} | ||
|
||
// Returns a solana-client-gen generated client from the environment. | ||
pub fn client<T: ClientGen>() -> T { | ||
let program_id = std::env::var("TEST_PROGRAM_ID").unwrap().parse().unwrap(); | ||
let payer_filepath = std::env::var("TEST_PAYER_FILEPATH").unwrap().clone(); | ||
let cluster: Cluster = std::env::var("TEST_CLUSTER").unwrap().parse().unwrap(); | ||
|
||
T::from_keypair_file(program_id, &payer_filepath, cluster.url()) | ||
.expect("invalid keypair file") | ||
.with_options(RequestOptions { | ||
commitment: CommitmentConfig::single(), | ||
tx: RpcSendTransactionConfig { | ||
skip_preflight: true, | ||
preflight_commitment: None, | ||
}, | ||
}) | ||
} |
Oops, something went wrong.