From d123a68c3ae8903b4dde089f8a9cd5f9a00a78c0 Mon Sep 17 00:00:00 2001 From: garikbesson Date: Thu, 7 Mar 2024 15:44:15 +0100 Subject: [PATCH 1/3] Added rust version of coin-flip contract --- docs/3.tutorials/examples/coin-flip.md | 51 +++++++++++++------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/docs/3.tutorials/examples/coin-flip.md b/docs/3.tutorials/examples/coin-flip.md index f3d8155fc8b..a4337fb78ae 100644 --- a/docs/3.tutorials/examples/coin-flip.md +++ b/docs/3.tutorials/examples/coin-flip.md @@ -15,31 +15,16 @@ Coin Flip is a game where the player tries to guess the outcome of a coin flip. ## Starting the Game You have two options to start the example: 1. **Recommended:** use the app through Gitpod (a web-based interactive environment) -2. Clone the project locally . - - - - +2. Clone the project locally. | Gitpod | Clone locally | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------- | -| Open in Gitpod | 🌐 `https://github.com/near-examples/coin-flip-js.git` | +| Open in Gitpod | `https://github.com/near-examples/coin-flip-examples.git` | - - - If you choose Gitpod, a new browser window will open automatically with the code. Give it a minute, and the front-end will pop up (ensure the pop-up window is not blocked). -If you are running the app locally, enter the directory where you cloned it and use `yarn` to install dependencies, and `yarn start` to start it. - -```bash -cd coin-flip-js -yarn -yarn deploy -yarn start -``` -Your contract will then be **compiled** and **deployed** to an **account** in the `testnet` network. When done, a browser window should open. +If you are running the app locally, you should build and deploy a contract (JavaScript or Rust version) and a client manually. --- @@ -56,7 +41,12 @@ Go ahead and log in with your NEAR account. If you don't have one, you can creat Now that you understand what the dApp does, let us take a closer look to its structure: 1. The frontend code lives in the `/frontend` folder. -2. The smart contract code is in the `/contract` folder. +2. The smart contract code in Rust is in the `/contract-rs` folder. +3. The smart contract code in JavaScript is in the `/contract-ts` folder. + +:::note +Both Rust and JavaScript versions of contract implement the same functionality. +::: ### Contract The contract presents 2 methods: `flip_coin`, and `points_of`. @@ -64,9 +54,14 @@ The contract presents 2 methods: `flip_coin`, and `points_of`. + + + ### Frontend @@ -89,21 +84,25 @@ It indicates our app, when it starts, to check if the user is already logged in ## Testing When writing smart contracts, it is very important to test all methods exhaustively. In this -project, you have two types: unit and integration tests. Before digging into them, -go ahead and perform the tests present in the dApp through the command `yarn test`. +project, you have integration tests. Before digging into them, go ahead and perform the tests present in the dApp through the command `yarn test` for the JavaScript version of contract or `./test.sh` for the Rust version of contract. ### Integration test -Integration tests are generally written in JavaScript. They automatically deploy a new +Integration tests could be written in both Rust and JavaScript. They automatically deploy a new contract and execute methods on it. In this way, integration tests simulate interactions from users in a realistic scenario. You will find the integration tests for the `coin-flip` -in `tests/integration-tests`. +in `contract-ts/integration-tests` (for the contract in JavaScript) and `contract-rs/sandbox-rs` (for the contract in Rust). + url="https://github.com/near-examples/coin-flip-examples/blob/rust-version/contract-ts/integration-tests/src/main.ava.ts" + start="32" end="57" /> + + + From cd09e81867318aeef241d23ad66e48a225c992af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dami=C3=A1n=20Parrino?= Date: Thu, 7 Mar 2024 12:19:30 -0300 Subject: [PATCH 2/3] Apply suggestions from code review --- docs/3.tutorials/examples/coin-flip.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/3.tutorials/examples/coin-flip.md b/docs/3.tutorials/examples/coin-flip.md index a4337fb78ae..dd474ac21c1 100644 --- a/docs/3.tutorials/examples/coin-flip.md +++ b/docs/3.tutorials/examples/coin-flip.md @@ -45,7 +45,7 @@ Now that you understand what the dApp does, let us take a closer look to its str 3. The smart contract code in JavaScript is in the `/contract-ts` folder. :::note -Both Rust and JavaScript versions of contract implement the same functionality. +Both Rust and JavaScript versions of the contract implement the same functionality. ::: ### Contract @@ -84,14 +84,14 @@ It indicates our app, when it starts, to check if the user is already logged in ## Testing When writing smart contracts, it is very important to test all methods exhaustively. In this -project, you have integration tests. Before digging into them, go ahead and perform the tests present in the dApp through the command `yarn test` for the JavaScript version of contract or `./test.sh` for the Rust version of contract. +project you have integration tests. Before digging into them, go ahead and perform the tests present in the dApp through the command `yarn test` for the JavaScript version, or `./test.sh` for the Rust version. ### Integration test -Integration tests could be written in both Rust and JavaScript. They automatically deploy a new +Integration tests can be written in both Rust and JavaScript. They automatically deploy a new contract and execute methods on it. In this way, integration tests simulate interactions from users in a realistic scenario. You will find the integration tests for the `coin-flip` -in `contract-ts/integration-tests` (for the contract in JavaScript) and `contract-rs/sandbox-rs` (for the contract in Rust). +in `contract-ts/integration-tests` (for the JavaScript contract) and `contract-rs/sandbox-rs` (for the Rust contract). From e06397a27e087f0d06744d18307cb76f0267d774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dami=C3=A1n=20Parrino?= Date: Fri, 15 Mar 2024 10:09:24 -0300 Subject: [PATCH 3/3] Apply suggestions from code review --- docs/3.tutorials/examples/coin-flip.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/3.tutorials/examples/coin-flip.md b/docs/3.tutorials/examples/coin-flip.md index dd474ac21c1..11aea90d91a 100644 --- a/docs/3.tutorials/examples/coin-flip.md +++ b/docs/3.tutorials/examples/coin-flip.md @@ -54,12 +54,12 @@ The contract presents 2 methods: `flip_coin`, and `points_of`. @@ -96,12 +96,12 @@ in `contract-ts/integration-tests` (for the JavaScript contract) and `contract-r