Commit leo example tests (#2524)

* commit leo example tests

* improve leo example readme's and ci

* commit leo token example script
This commit is contained in:
Collin Chin 2023-08-14 15:26:55 -07:00 committed by GitHub
parent a601ccd5cc
commit 12570e4602
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 17 deletions

View File

@ -3,8 +3,8 @@ $LEO new foo || exit
ls -la ls -la
cd foo && ls -la cd foo && ls -la
# Run `leo build`. # Run `leo run`.
$LEO build || exit $LEO run || exit
# Assert that the 'build' folder exists. # Assert that the 'build' folder exists.
if [ "$(ls -A build)" ]; then if [ "$(ls -A build)" ]; then

32
.circleci/leo-example.sh Normal file
View File

@ -0,0 +1,32 @@
(
# Create a new Leo lottery example program.
$LEO example lottery || exit
ls -la
cd lottery && ls -la
# Run the play function.
$LEO run play || exit
)
(
# Create a new Leo tictactoe example program.
$LEO example tictactoe || exit
ls -la
cd tictactoe && ls -la
# Create a new game.
$LEO run new || exit
# Create a make a move.
$LEO run make_move || exit
)
(
#Create a new Leo token example program.
$LEO example token || exit
ls -la
cd token && ls -la
# Run the mint_public function.
$LEO run mint_public || exit
)

View File

@ -48,3 +48,35 @@ leo run <function_name>
```bash ```bash
leo execute <function_name> <input_1> <input_2> ... leo execute <function_name> <input_1> <input_2> ...
``` ```
## Playing the Game
### 1. Create a new game board
```bash
leo run new
```
| | | |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 0 | 0 |
| 0 | 0 | 0 |
### 2. Player 1 makes a move
```bash
leo run make_move 1u8 1u8 1u8 "{ r1: { c1: 0u8, c2: 0u8, c3: 0u8 }, r2: { c1: 0u8, c2: 0u8, c3: 0u8 }, r3: { c1: 0u8, c2: 0u8, c3: 0u8 } }"
```
| | | |
|---|---|---|
| 1 | 0 | 0 |
| 0 | 0 | 0 |
| 0 | 0 | 0 |
### 3. Player 2 makes a move
```bash
leo run make_move 2u8 2u8 2u8 "{ r1: { c1: 1u8, c2: 0u8, c3: 0u8 }, r2: { c1: 0u8, c2: 0u8, c3: 0u8 }, r3: { c1: 0u8, c2: 0u8, c3: 0u8 } }"
```
| | | |
|---|---|---|
| 1 | 0 | 0 |
| 0 | 2 | 0 |
| 0 | 0 | 0 |

View File

@ -11,8 +11,8 @@ player: u8 = 1u8;
row: u8 = 1u8; row: u8 = 1u8;
col: u8 = 1u8; col: u8 = 1u8;
board: Board = Board { board: Board = Board {
r1: Row { c1: 0u8, c2: 1u8, c3: 1u8 }, r1: Row { c1: 0u8, c2: 0u8, c3: 0u8 },
r2: Row { c1: 2u8, c2: 2u8, c3: 0u8 }, r2: Row { c1: 0u8, c2: 0u8, c3: 0u8 },
r3: Row { c1: 0u8, c2: 0u8, c3: 0u8 }, r3: Row { c1: 0u8, c2: 0u8, c3: 0u8 },
}; };

View File

@ -8,12 +8,5 @@ A transparent & shielded custom token in Leo.
To run this program, run: To run this program, run:
```bash ```bash
leo run main ./run.sh
``` ```
## Execute Guide
To execute this program, run:
```bash
leo execute main
```

View File

@ -49,7 +49,7 @@ impl Command for Example {
fs::write(main_file_path, self.main_file_string()).map_err(CliError::failed_to_write_file)?; fs::write(main_file_path, self.main_file_string()).map_err(CliError::failed_to_write_file)?;
// Write the input file. // Write the input file.
let input_file_path = package_dir.join("inputs").join("input.in"); let input_file_path = package_dir.join("inputs").join(format!("{}.in", self.name()));
fs::write(input_file_path, self.input_file_string()).map_err(CliError::failed_to_write_file)?; fs::write(input_file_path, self.input_file_string()).map_err(CliError::failed_to_write_file)?;
// Write the README file. // Write the README file.
@ -98,9 +98,7 @@ impl Example {
Self::TicTacToe => { Self::TicTacToe => {
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/examples/tictactoe/inputs/tictactoe.in")).to_string() include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/examples/tictactoe/inputs/tictactoe.in")).to_string()
} }
Self::Token => { Self::Token => include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/examples/token/run.sh")).to_string(),
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/examples/token/inputs/token.in")).to_string()
}
} }
} }