From 799625796ad7ad42c6963572aef80168685b4545 Mon Sep 17 00:00:00 2001 From: Abhishek Shah Date: Mon, 18 Mar 2024 15:01:01 +0530 Subject: [PATCH] manually invoke git, then run add-pallet --- tests/add.rs | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/tests/add.rs b/tests/add.rs index 03f7d022..d89ff29f 100644 --- a/tests/add.rs +++ b/tests/add.rs @@ -1,8 +1,8 @@ use assert_cmd::Command; use std::fs; use tempdir::TempDir; +use toml_edit::DocumentMut; -#[ignore = "test fails due to no git commit on `pop new parachain`"] #[test] fn add_parachain_pallet_template() { let temp_dir = TempDir::new("add-pallet-test").unwrap(); @@ -12,12 +12,19 @@ fn add_parachain_pallet_template() { .current_dir(&temp_dir) .args(&["new", "parachain", "testchain"]) .assert() - .success(); + .success(); + // Git setup + use duct::cmd; + cmd!("git", "add", ".").dir(&temp_dir.path().join("testchain")).run().unwrap(); + cmd!("git", "commit", "--no-gpg-sign", "-m", "Initialized testchain") + .dir(&temp_dir.path().join("testchain")) + .run() + .unwrap(); // Add pallet-parachain-template Command::cargo_bin("pop") .unwrap() - .args(&["add", "pallet", "template", "-r", "runtime/src/lib.rs"]) - .current_dir(&temp_dir.path().join("testchain")) + .args(&["add", "pallet", "template", "-r", "testchain/runtime/src/lib.rs"]) + .current_dir(&temp_dir.path()) .assert() .success(); @@ -25,7 +32,7 @@ fn add_parachain_pallet_template() { fs::read_to_string(&temp_dir.path().join("testchain/runtime/src/lib.rs")).unwrap(); let runtime_manifest = fs::read_to_string(&temp_dir.path().join("testchain/runtime/Cargo.toml")).unwrap(); - + // Check runtime entries assert_eq!(runtime_contents.matches("pub use pallet_parachain_template;").count(), 1); assert_eq!( runtime_contents @@ -34,6 +41,14 @@ fn add_parachain_pallet_template() { 1 ); assert_eq!(runtime_contents.matches("Template: pallet_parachain_template").count(), 1); - - assert_eq!(runtime_manifest.matches("pallet-parachain-template").count(), 3); + // Check runtime manifest entries + let toml = runtime_manifest.parse::().unwrap(); + assert!(toml["dependencies"]["pallet-parachain-template"].is_value()); + let std = toml["features"]["std"].as_value().unwrap().as_array().unwrap(); + assert_eq!( + std.iter() + .filter(|val| val.as_str().unwrap() == "pallet-parachain-template/std") + .count(), + 1 + ); }