Skip to content

Commit

Permalink
cli: Fund configured wallet when testing (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
armaniferrante committed Apr 9, 2021
1 parent 80ddf04 commit 0e02301
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
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
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
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

0 comments on commit 0e02301

Please sign in to comment.