Skip to content

Commit

Permalink
manually invoke git, then run add-pallet
Browse files Browse the repository at this point in the history
  • Loading branch information
weezy20 committed Mar 18, 2024
1 parent 3c55dac commit 7996257
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions tests/add.rs
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -12,20 +12,27 @@ 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();

let runtime_contents =
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
Expand All @@ -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::<DocumentMut>().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
);
}

0 comments on commit 7996257

Please sign in to comment.