Browse Source

test: test and lint scripts (#99)

Danilo Guanabara 10 tháng trước cách đây
mục cha
commit
d597787517

+ 2 - 1
.prettierignore

@@ -6,4 +6,5 @@ node_modules
 dist
 dist
 build
 build
 test-ledger
 test-ledger
-clients/bolt-sdk/lib
+clients/bolt-sdk/lib
+cli/src/templates/**/*

+ 1 - 1
cli/src/rust_template.rs

@@ -47,7 +47,7 @@ pub(crate) fn create_system(name: &str) -> Result<()> {
 pub fn create_program(name: &str, template: ProgramTemplate) -> Result<()> {
 pub fn create_program(name: &str, template: ProgramTemplate) -> Result<()> {
     let program_path = Path::new("programs").join(name);
     let program_path = Path::new("programs").join(name);
     let common_files = vec![
     let common_files = vec![
-        ("Cargo.toml".into(), workspace_manifest().into()),
+        ("Cargo.toml".into(), workspace_manifest()),
         (program_path.join("Cargo.toml"), cargo_toml(name)),
         (program_path.join("Cargo.toml"), cargo_toml(name)),
         (program_path.join("Xargo.toml"), xargo_toml().into()),
         (program_path.join("Xargo.toml"), xargo_toml().into()),
     ];
     ];

+ 5 - 1
cli/src/templates/component/mod.rs

@@ -12,7 +12,11 @@ pub fn create_component_template_simple(name: &str, program_path: &Path) -> File
     let program_name = name.to_upper_camel_case();
     let program_name = name.to_upper_camel_case();
     vec![(
     vec![(
         program_path.join("src").join("lib.rs"),
         program_path.join("src").join("lib.rs"),
-        format!(include_str!("lib.rs"), program_id=program_id, program_name=program_name)
+        format!(
+            include_str!("lib.rs"),
+            program_id = program_id,
+            program_name = program_name
+        ),
     )]
     )]
 }
 }
 
 

+ 11 - 6
cli/src/templates/program/mod.rs

@@ -7,7 +7,11 @@ pub fn create_program_template_single(name: &str, program_path: &Path) -> Files
     let program_name = name.to_snake_case();
     let program_name = name.to_snake_case();
     vec![(
     vec![(
         program_path.join("src").join("lib.rs"),
         program_path.join("src").join("lib.rs"),
-        format!(include_str!("single.lib.rs"), program_id=program_id, program_name=program_name),
+        format!(
+            include_str!("single.lib.rs"),
+            program_id = program_id,
+            program_name = program_name
+        ),
     )]
     )]
 }
 }
 
 
@@ -19,16 +23,17 @@ pub fn create_program_template_multiple(name: &str, program_path: &Path) -> File
     vec![
     vec![
         (
         (
             src_path.join("lib.rs"),
             src_path.join("lib.rs"),
-            format!(include_str!("multiple.lib.rs"), program_id=program_id, program_name=program_name),
+            format!(
+                include_str!("multiple.lib.rs"),
+                program_id = program_id,
+                program_name = program_name
+            ),
         ),
         ),
         (
         (
             src_path.join("constants.rs"),
             src_path.join("constants.rs"),
             include_str!("constants.rs").into(),
             include_str!("constants.rs").into(),
         ),
         ),
-        (
-            src_path.join("error.rs"),
-            include_str!("error.rs").into(),
-        ),
+        (src_path.join("error.rs"), include_str!("error.rs").into()),
         (
         (
             src_path.join("instructions").join("mod.rs"),
             src_path.join("instructions").join("mod.rs"),
             include_str!("instructions/mod.rs").into(),
             include_str!("instructions/mod.rs").into(),

+ 5 - 1
cli/src/templates/system/mod.rs

@@ -8,6 +8,10 @@ pub fn create_system_template_simple(name: &str, program_path: &Path) -> Files {
     let program_name = name.to_snake_case();
     let program_name = name.to_snake_case();
     vec![(
     vec![(
         program_path.join("src").join("lib.rs"),
         program_path.join("src").join("lib.rs"),
-        format!(include_str!("lib.rs"), program_id=program_id, program_name=program_name)
+        format!(
+            include_str!("lib.rs"),
+            program_id = program_id,
+            program_name = program_name
+        ),
     )]
     )]
 }
 }

+ 23 - 4
cli/src/templates/workspace/mod.rs

@@ -3,7 +3,11 @@ use heck::ToSnakeCase;
 pub const ANCHOR_VERSION: &str = anchor_cli::VERSION;
 pub const ANCHOR_VERSION: &str = anchor_cli::VERSION;
 
 
 pub fn workspace_manifest() -> String {
 pub fn workspace_manifest() -> String {
-    format!(include_str!("workspace.toml"), VERSION=VERSION, ANCHOR_VERSION=ANCHOR_VERSION)
+    format!(
+        include_str!("workspace.toml"),
+        VERSION = VERSION,
+        ANCHOR_VERSION = ANCHOR_VERSION
+    )
 }
 }
 
 
 pub fn package_json(jest: bool) -> String {
 pub fn package_json(jest: bool) -> String {
@@ -36,13 +40,23 @@ pub fn ts_mocha(name: &str) -> String {
 
 
 pub fn cargo_toml(name: &str) -> String {
 pub fn cargo_toml(name: &str) -> String {
     let snake_case_name = name.to_snake_case();
     let snake_case_name = name.to_snake_case();
-    format!(include_str!("Cargo.toml"), name=name, snake_case_name=snake_case_name, VERSION=VERSION)
+    format!(
+        include_str!("Cargo.toml"),
+        name = name,
+        snake_case_name = snake_case_name,
+        VERSION = VERSION
+    )
 }
 }
 
 
 /// TODO: Remove serde dependency
 /// TODO: Remove serde dependency
 pub fn cargo_toml_with_serde(name: &str) -> String {
 pub fn cargo_toml_with_serde(name: &str) -> String {
     let snake_case_name = name.to_snake_case();
     let snake_case_name = name.to_snake_case();
-    format!(include_str!("Cargo.serde.toml"), name=name, snake_case_name=snake_case_name, VERSION=VERSION)
+    format!(
+        include_str!("Cargo.serde.toml"),
+        name = name,
+        snake_case_name = snake_case_name,
+        VERSION = VERSION
+    )
 }
 }
 
 
 pub fn xargo_toml() -> &'static str {
 pub fn xargo_toml() -> &'static str {
@@ -59,5 +73,10 @@ pub fn prettier_ignore() -> &'static str {
 pub(crate) fn types_cargo_toml() -> String {
 pub(crate) fn types_cargo_toml() -> String {
     let name = "bolt-types";
     let name = "bolt-types";
     let snake_case_name = name.to_snake_case();
     let snake_case_name = name.to_snake_case();
-    format!(include_str!("types.Cargo.toml"), name=name, snake_case_name=snake_case_name, VERSION=VERSION)
+    format!(
+        include_str!("types.Cargo.toml"),
+        name = name,
+        snake_case_name = snake_case_name,
+        VERSION = VERSION
+    )
 }
 }

+ 13 - 0
scripts/lint.sh

@@ -0,0 +1,13 @@
+set -e
+SCRIPT_DIR=$(dirname "$0")
+PROJECT_DIR="$SCRIPT_DIR/.."
+pushd "$PROJECT_DIR"
+echo "### Checking formatting..."
+cargo fmt -- --check --verbose
+
+echo "### Checking clippy..."
+cargo clippy -- --deny=warnings
+
+echo "### Checking yarn lint..."
+yarn lint
+popd

+ 5 - 1
scripts/test.sh

@@ -1,2 +1,6 @@
+SCRIPT_DIR=$(dirname "$0")
+PROJECT_DIR="$SCRIPT_DIR/.."
+pushd "$PROJECT_DIR"
 cp tests/keys/* target/deploy/
 cp tests/keys/* target/deploy/
-bolt test
+bolt test
+popd

+ 1 - 1
tests/bolt.ts

@@ -22,9 +22,9 @@ import {
   ApproveSystem,
   ApproveSystem,
   RemoveSystem,
   RemoveSystem,
   type Program,
   type Program,
+  anchor,
   web3,
   web3,
 } from "../clients/bolt-sdk";
 } from "../clients/bolt-sdk";
-import * as anchor from "@coral-xyz/anchor";
 
 
 enum Direction {
 enum Direction {
   Left = "Left",
   Left = "Left",