Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a delegated singer test #82

Merged
merged 1 commit into from
Oct 4, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
- name: Test
env:
DRIFT_GATEWAY_KEY: ${{ secrets.DRIFT_GATEWAY_KEY }}
TEST_DELEGATED_SIGNER: ${{ secrets.TEST_DELEGATED_SIGNER }}
TEST_RPC_ENDPOINT: ${{ secrets.DEVNET_RPC_ENDPOINT }}
# --test-threads, limit parallelism to prevent hitting RPC rate-limits
run: |
Expand Down
41 changes: 40 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ struct GatewayConfig {
/// http keep-alive timeout in seconds
#[argh(option, default = "3600")]
keep_alive_timeout: u32,
/// use delegated signing mode, provide the delegator's pubkey
/// use delegated signing mode, provide the delegator's pubkey (i.e the main account)
/// 'DRIFT_GATEWAY_KEY' should be set to the delegate's private key
#[argh(option)]
delegate: Option<String>,
/// run the gateway in read-only mode for given authority pubkey
Expand Down Expand Up @@ -420,6 +421,44 @@ mod tests {
AppState::new(&rpc_endpoint, true, wallet, None, None, false).await
}

// likely safe to ignore during development, mainy regression tests for CI
#[actix_web::test]
async fn delegated_signing_ok() {
let _ = env_logger::try_init();
let delegated_seed =
std::env::var("TEST_DELEGATED_SIGNER").expect("delegated signing key set");
let wallet = create_wallet(
Some(delegated_seed),
None,
Some(
"GiMXQkJXLVjScmQDkoLJShBJpTh9SDPvT2AZQq8NyEBf"
.try_into()
.unwrap(),
),
);

let rpc_endpoint = std::env::var("TEST_RPC_ENDPOINT")
.unwrap_or_else(|_| "https://api.devnet.solana.com".to_string());
let state = AppState::new(&rpc_endpoint, true, wallet, None, None, false).await;

let app = test::init_service(
App::new()
.app_data(web::Data::new(state))
.service(cancel_orders),
)
.await;
tokio::time::sleep(Duration::from_secs(1)).await;

let req = test::TestRequest::default()
.method(Method::DELETE)
.uri("/orders")
.to_request();

let resp = test::call_service(&app, req).await;
dbg!(resp.response().body());
assert!(resp.status().is_success());
}

#[actix_web::test]
async fn get_market_info_works() {
let controller = setup_controller(None).await;
Expand Down
Loading