Skip to content

Commit

Permalink
modify add-pallet test
Browse files Browse the repository at this point in the history
  • Loading branch information
weezy20 committed Mar 18, 2024
1 parent 1bb0385 commit 33c2a95
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 791 deletions.
39 changes: 27 additions & 12 deletions tests/add.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
use assert_cmd::Command;
use std::fs;
use std::path::PathBuf;
use tempdir::TempDir;

#[ignore = "TomlEditor expects to find a parachain project structure initialized with git"]
#[ignore = "test fails to run"]
#[test]
fn add_parachain_pallet_template() {
let temp_dir = TempDir::new("add-pallet-test").unwrap();
let output = temp_dir.path().join("test_lib.rs");
let source_file = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/add/lib.rs");
println!("source file : {:?}", source_file);
fs::copy(&source_file, &output).unwrap();
// Setup new parachain
Command::cargo_bin("pop")
.unwrap()
.args(&["add", "pallet", "template", "-r", "test_lib.rs"])
.current_dir(&temp_dir)
.args(&["new", "parachain", "testchain"])
.assert()
.success();
let contents = fs::read_to_string(&output).unwrap();

assert_eq!(contents.matches("pub use pallet_parachain_template;").count(), 1);
assert_eq!(contents.matches("impl pallet_parachain_template::Config for Runtime {").count(), 1);
assert_eq!(contents.matches("Template: pallet_parachain_template").count(), 1);
println!("{:?}", temp_dir.path().display());
// 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"))
.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();

assert_eq!(runtime_contents.matches("pub use pallet_parachain_template;").count(), 1);
assert_eq!(
runtime_contents
.matches("impl pallet_parachain_template::Config for Runtime {")
.count(),
1
);
assert_eq!(runtime_contents.matches("Template: pallet_parachain_template").count(), 1);

assert_eq!(runtime_manifest.matches("pallet-parachain-template").count(), 3);
}
Loading

0 comments on commit 33c2a95

Please sign in to comment.