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

cli: Fund configured wallet when testing #164

Merged
merged 2 commits into from
Apr 9, 2021
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ incremented for features.

## [Unreleased]

## Features

* cli: Fund Anchor.toml configured wallet when testing ([#164](https://github.com/project-serum/anchor/pull/164)).

## [0.4.1] - 2021-04-06

* cli: Version verifiable docker builder ([#145](https://github.com/project-serum/anchor/pull/145)).
Expand Down
6 changes: 6 additions & 0 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anchor_syn::idl::Idl;
use anyhow::{anyhow, Error, Result};
use serde::{Deserialize, Serialize};
use serum_common::client::Cluster;
use solana_sdk::signature::Keypair;
use std::fs::{self, File};
use std::io::prelude::*;
use std::path::Path;
Expand Down Expand Up @@ -58,6 +59,11 @@ impl Config {

Ok(None)
}

pub fn wallet_kp(&self) -> Result<Keypair> {
solana_sdk::signature::read_keypair_file(&self.wallet.to_string())
.map_err(|_| anyhow!("Unable to read keypair file"))
}
}

// Pubkey serializes as a byte array so use this type a hack to serialize
Expand Down
6 changes: 4 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ fn test(skip_deploy: bool, skip_local_validator: bool, file: Option<String>) ->
};
match skip_local_validator {
true => None,
false => Some(start_test_validator(flags)?),
false => Some(start_test_validator(cfg, flags)?),
}
}
_ => {
Expand Down Expand Up @@ -1058,7 +1058,7 @@ pub struct IdlTestMetadata {
address: String,
}

fn start_test_validator(flags: Option<Vec<String>>) -> Result<Child> {
fn start_test_validator(cfg: &Config, flags: Option<Vec<String>>) -> Result<Child> {
fs::create_dir_all(".anchor")?;
let test_ledger_filename = ".anchor/test-ledger";
let test_ledger_log_filename = ".anchor/test-ledger-log.txt";
Expand All @@ -1076,6 +1076,8 @@ fn start_test_validator(flags: Option<Vec<String>>) -> Result<Child> {
let validator_handle = std::process::Command::new("solana-test-validator")
.arg("--ledger")
.arg(test_ledger_filename)
.arg("--mint")
.arg(cfg.wallet_kp()?.pubkey().to_string())
.args(flags.unwrap_or_default())
.stdout(Stdio::from(test_validator_stdout))
.stderr(Stdio::from(test_validator_stderr))
Expand Down