Skip to content

Commit

Permalink
Ammend tests for verification urls
Browse files Browse the repository at this point in the history
  • Loading branch information
cwkang1998 committed Oct 14, 2024
1 parent 952fba0 commit 70532da
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 80 deletions.
2 changes: 0 additions & 2 deletions crates/sncast/src/starknet_commands/verification/voyager.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use super::base::VerificationInterface;
use async_trait::async_trait;
use blockifier::blockifier::config;
use camino::Utf8PathBuf;
use sncast::{helpers::configuration::CastConfig, Network};
use std::env;

pub struct VoyagerVerificationInterface {
pub network: Network,
Expand Down
1 change: 0 additions & 1 deletion crates/sncast/src/starknet_commands/verification/walnut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use super::base::VerificationInterface;
use async_trait::async_trait;
use camino::Utf8PathBuf;
use sncast::{helpers::configuration::CastConfig, Network};
use std::env;

pub struct WalnutVerificationInterface {
pub network: Network,
Expand Down
2 changes: 1 addition & 1 deletion crates/sncast/tests/e2e/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ mod multicall;
mod script;
mod show_config;
mod tx_status;
mod verify;
mod verification;
24 changes: 24 additions & 0 deletions crates/sncast/tests/e2e/verification/helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::{fs::File, io::Write};

use anyhow::Result;
use tempfile::TempDir;

use crate::helpers::fixtures::copy_directory_to_tempdir;
use configuration::CONFIG_FILENAME;

pub fn copy_directory_to_tempdir_with_config(
src_dir: String,
cast_config_content: String,
) -> Result<TempDir> {
let temp_dir = copy_directory_to_tempdir(src_dir);

let mut file = File::create(temp_dir.path().join(CONFIG_FILENAME))
.expect("Unable to create a temporary accounts file");

file.write_all(cast_config_content.as_bytes())
.expect("Unable to write test data to a temporary file");

file.flush().expect("Unable to flush a temporary file");

Ok(temp_dir)
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mod helpers;
mod voyager;
mod walnut;
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::helpers::copy_directory_to_tempdir_with_config;
use crate::helpers::constants::{
ACCOUNT_FILE_PATH, CONTRACTS_DIR, MAP_CONTRACT_ADDRESS_SEPOLIA, MAP_CONTRACT_CLASS_HASH_SEPOLIA,
};
Expand All @@ -10,14 +11,12 @@ use wiremock::{Mock, MockServer, ResponseTemplate};

#[tokio::test]
async fn test_happy_case() {
let contract_path = copy_directory_to_tempdir(CONTRACTS_DIR.to_string() + "/map");

let mock_server = MockServer::start().await;

let verifier_response = "Contract successfully verified";

Mock::given(method("POST"))
.and(path("/v1/sn_sepolia/verify"))
.and(path("/class-verify-v2"))
.respond_with(
ResponseTemplate::new(200)
.append_header("content-type", "text/plain")
Expand All @@ -26,6 +25,22 @@ async fn test_happy_case() {
.mount(&mock_server)
.await;

let cast_config = format!(
r#"
[sncast.default]
url = "http://127.0.0.1:5055/rpc"
account = "user1"
verification-base-url = "{}"
"#,
mock_server.uri()
);

let contract_path = copy_directory_to_tempdir_with_config(
CONTRACTS_DIR.to_string() + "/map",
cast_config.to_string(),
)
.unwrap();

let args = vec![
"--accounts-file",
ACCOUNT_FILE_PATH,
Expand All @@ -40,10 +55,7 @@ async fn test_happy_case() {
"sepolia",
];

let snapbox = runner(&args)
.env("VOYAGER_API_URL", mock_server.uri())
.current_dir(contract_path.path())
.stdin("Y");
let snapbox = runner(&args).current_dir(contract_path.path()).stdin("Y");

let output = snapbox.assert().success();

Expand All @@ -61,14 +73,12 @@ async fn test_happy_case() {

#[tokio::test]
async fn test_happy_case_class_hash() {
let contract_path = copy_directory_to_tempdir(CONTRACTS_DIR.to_string() + "/map");

let mock_server = MockServer::start().await;

let verifier_response = "Contract successfully verified";

Mock::given(method("POST"))
.and(path("/v1/sn_sepolia/verify"))
.and(path("/class-verify-v2"))
.respond_with(
ResponseTemplate::new(200)
.append_header("content-type", "text/plain")
Expand All @@ -77,6 +87,22 @@ async fn test_happy_case_class_hash() {
.mount(&mock_server)
.await;

let cast_config = format!(
r#"
[sncast.default]
url = "http://127.0.0.1:5055/rpc"
account = "user1"
verification-base-url = "{}"
"#,
mock_server.uri()
);

let contract_path = copy_directory_to_tempdir_with_config(
CONTRACTS_DIR.to_string() + "/map",
cast_config.to_string(),
)
.unwrap();

let args = vec![
"--accounts-file",
ACCOUNT_FILE_PATH,
Expand All @@ -91,10 +117,7 @@ async fn test_happy_case_class_hash() {
"sepolia",
];

let snapbox = runner(&args)
.env("VOYAGER_API_URL", mock_server.uri())
.current_dir(contract_path.path())
.stdin("Y");
let snapbox = runner(&args).current_dir(contract_path.path()).stdin("Y");

let output = snapbox.assert().success();

Expand All @@ -112,14 +135,12 @@ async fn test_happy_case_class_hash() {

#[tokio::test]
async fn test_failed_verification() {
let contract_path = copy_directory_to_tempdir(CONTRACTS_DIR.to_string() + "/map");

let mock_server = MockServer::start().await;

let verifier_response = "An error occurred during verification: contract class isn't declared";

Mock::given(method("POST"))
.and(path("/v1/sn_sepolia/verify"))
.and(path("/class-verify-v2"))
.respond_with(
ResponseTemplate::new(400)
.append_header("content-type", "text/plain")
Expand All @@ -128,6 +149,22 @@ async fn test_failed_verification() {
.mount(&mock_server)
.await;

let cast_config = format!(
r#"
[sncast.default]
url = "http://127.0.0.1:5055/rpc"
account = "user1"
verification-base-url = "{}"
"#,
mock_server.uri()
);

let contract_path = copy_directory_to_tempdir_with_config(
CONTRACTS_DIR.to_string() + "/map",
cast_config.to_string(),
)
.unwrap();

let args = vec![
"--accounts-file",
ACCOUNT_FILE_PATH,
Expand All @@ -142,10 +179,7 @@ async fn test_failed_verification() {
"sepolia",
];

let snapbox = runner(&args)
.env("VOYAGER_API_URL", mock_server.uri())
.current_dir(contract_path.path())
.stdin("Y");
let snapbox = runner(&args).current_dir(contract_path.path()).stdin("Y");

let output = snapbox.assert().success();

Expand Down Expand Up @@ -260,14 +294,12 @@ async fn test_no_class_hash_or_contract_address_provided() {

#[tokio::test]
async fn test_happy_case_with_confirm_verification_flag() {
let contract_path = copy_directory_to_tempdir(CONTRACTS_DIR.to_string() + "/map");

let mock_server = MockServer::start().await;

let verifier_response = "Contract successfully verified";

Mock::given(method("POST"))
.and(path("/v1/sn_sepolia/verify"))
.and(path("/class-verify-v2"))
.respond_with(
ResponseTemplate::new(200)
.append_header("content-type", "text/plain")
Expand All @@ -276,6 +308,22 @@ async fn test_happy_case_with_confirm_verification_flag() {
.mount(&mock_server)
.await;

let cast_config = format!(
r#"
[sncast.default]
url = "http://127.0.0.1:5055/rpc"
account = "user1"
verification-base-url = "{}"
"#,
mock_server.uri()
);

let contract_path = copy_directory_to_tempdir_with_config(
CONTRACTS_DIR.to_string() + "/map",
cast_config.to_string(),
)
.unwrap();

let args = vec![
"--accounts-file",
ACCOUNT_FILE_PATH,
Expand All @@ -291,9 +339,7 @@ async fn test_happy_case_with_confirm_verification_flag() {
"--confirm-verification",
];

let snapbox = runner(&args)
.env("VOYAGER_API_URL", mock_server.uri())
.current_dir(contract_path.path());
let snapbox = runner(&args).current_dir(contract_path.path());

let output = snapbox.assert().success();

Expand All @@ -311,14 +357,12 @@ async fn test_happy_case_with_confirm_verification_flag() {

#[tokio::test]
async fn test_happy_case_specify_package() {
let tempdir = copy_directory_to_tempdir(CONTRACTS_DIR.to_string() + "/multiple_packages");

let mock_server = MockServer::start().await;

let verifier_response = "Contract successfully verified";

Mock::given(method("POST"))
.and(path("/v1/sn_sepolia/verify"))
.and(path("/class-verify-v2"))
.respond_with(
ResponseTemplate::new(200)
.append_header("content-type", "text/plain")
Expand All @@ -327,6 +371,22 @@ async fn test_happy_case_specify_package() {
.mount(&mock_server)
.await;

let cast_config = format!(
r#"
[sncast.default]
url = "http://127.0.0.1:5055/rpc"
account = "user1"
verification-base-url = "{}"
"#,
mock_server.uri()
);

let tempdir = copy_directory_to_tempdir_with_config(
CONTRACTS_DIR.to_string() + "/multiple_packages",
cast_config.to_string(),
)
.unwrap();

let args = vec![
"--accounts-file",
ACCOUNT_FILE_PATH,
Expand All @@ -343,10 +403,7 @@ async fn test_happy_case_specify_package() {
"main_workspace",
];

let snapbox = runner(&args)
.env("VOYAGER_API_URL", mock_server.uri())
.current_dir(tempdir.path())
.stdin("Y");
let snapbox = runner(&args).current_dir(tempdir.path()).stdin("Y");

let output = snapbox.assert().success();

Expand All @@ -364,14 +421,12 @@ async fn test_happy_case_specify_package() {

#[tokio::test]
async fn test_worskpaces_package_specified_virtual_fibonacci() {
let tempdir = copy_directory_to_tempdir(CONTRACTS_DIR.to_string() + "/virtual_workspace");

let mock_server = MockServer::start().await;

let verifier_response = "Contract successfully verified";

Mock::given(method("POST"))
.and(path("/v1/sn_sepolia/verify"))
.and(path("/class-verify-v2"))
.respond_with(
ResponseTemplate::new(200)
.append_header("content-type", "text/plain")
Expand All @@ -380,6 +435,22 @@ async fn test_worskpaces_package_specified_virtual_fibonacci() {
.mount(&mock_server)
.await;

let cast_config = format!(
r#"
[sncast.default]
url = "http://127.0.0.1:5055/rpc"
account = "user1"
verification-base-url = "{}"
"#,
mock_server.uri()
);

let tempdir = copy_directory_to_tempdir_with_config(
CONTRACTS_DIR.to_string() + "/virtual_workspace",
cast_config.to_string(),
)
.unwrap();

let args = vec![
"--accounts-file",
ACCOUNT_FILE_PATH,
Expand All @@ -396,10 +467,7 @@ async fn test_worskpaces_package_specified_virtual_fibonacci() {
"cast_fibonacci",
];

let snapbox = runner(&args)
.env("VOYAGER_API_URL", mock_server.uri())
.current_dir(tempdir.path())
.stdin("Y");
let snapbox = runner(&args).current_dir(tempdir.path()).stdin("Y");

let output = snapbox.assert().success();

Expand Down
Loading

0 comments on commit 70532da

Please sign in to comment.