Skip to content

Commit

Permalink
Commit leo example tests (#2524)
Browse files Browse the repository at this point in the history
* commit leo example tests

* improve leo example readme's and ci

* commit leo token example script
  • Loading branch information
collinc97 authored Aug 14, 2023
1 parent a601ccd commit 12570e4
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .circleci/leo-clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ $LEO new foo || exit
ls -la
cd foo && ls -la

# Run `leo build`.
$LEO build || exit
# Run `leo run`.
$LEO run || exit

# Assert that the 'build' folder exists.
if [ "$(ls -A build)" ]; then
Expand Down
32 changes: 32 additions & 0 deletions .circleci/leo-example.sh
Original file line number Diff line number Diff line change
@@ -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
)
32 changes: 32 additions & 0 deletions examples/tictactoe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,35 @@ leo run <function_name>
```bash
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 |
4 changes: 2 additions & 2 deletions examples/tictactoe/inputs/tictactoe.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ player: u8 = 1u8;
row: u8 = 1u8;
col: u8 = 1u8;
board: Board = Board {
r1: Row { c1: 0u8, c2: 1u8, c3: 1u8 },
r2: Row { c1: 2u8, c2: 2u8, c3: 0u8 },
r1: Row { c1: 0u8, c2: 0u8, c3: 0u8 },
r2: Row { c1: 0u8, c2: 0u8, c3: 0u8 },
r3: Row { c1: 0u8, c2: 0u8, c3: 0u8 },
};

11 changes: 2 additions & 9 deletions examples/token/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,5 @@ A transparent & shielded custom token in Leo.

To run this program, run:
```bash
leo run main
```

## Execute Guide

To execute this program, run:
```bash
leo execute main
```
./run.sh
```
6 changes: 2 additions & 4 deletions leo/cli/commands/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Command for Example {
fs::write(main_file_path, self.main_file_string()).map_err(CliError::failed_to_write_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)?;

// Write the README file.
Expand Down Expand Up @@ -98,9 +98,7 @@ impl Example {
Self::TicTacToe => {
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/examples/tictactoe/inputs/tictactoe.in")).to_string()
}
Self::Token => {
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/examples/token/inputs/token.in")).to_string()
}
Self::Token => include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/examples/token/run.sh")).to_string(),
}
}

Expand Down

0 comments on commit 12570e4

Please sign in to comment.