Skip to content

Commit

Permalink
update multiversx-sc and rewrite tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juliancwirko committed May 28, 2024
1 parent 94bec21 commit 674d759
Show file tree
Hide file tree
Showing 17 changed files with 1,104 additions and 1,517 deletions.
607 changes: 460 additions & 147 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "piggybank"
version = "0.6.0"
version = "0.7.0"
authors = ["Julian Ćwirko <[email protected]>"]
edition = "2021"
publish = false
Expand All @@ -9,7 +9,7 @@ publish = false
path = "src/lib.rs"

[dependencies.multiversx-sc]
version = "0.48.0"
version = "0.50.3"

[dev-dependencies.multiversx-sc-scenario]
version = "0.48.0"
version = "0.50.3"
45 changes: 20 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### PiggyBank - MultiversX Smart Contract for learning purposes
## PiggyBank - MultiversX Smart Contract for learning purposes

The logic is quite simple:
1. You create a Piggy Bank where you define the lock time using Epoch Timestamp as the argument
Expand All @@ -7,7 +7,7 @@ The logic is quite simple:

To interact with the PiggyBank Smart Contract, you would need to have:
- [wallet](https://devnet-wallet.multiversx.com)
- [mxpy](https://docs.multiversx.com/sdk-and-tools/sdk-py/installing-mxpy/)
- [mxpy](https://docs.multiversx.com/sdk-and-tools/sdk-py/installing-mxpy/) (can be also shipped with VS Code MultiversX IDE extension)
- PEM file derived from the seed phrase

You can get all with [VSCode MultiversX IDE extension](https://marketplace.visualstudio.com/items?itemName=Elrond.vscode-elrond-ide)
Expand All @@ -16,12 +16,18 @@ To derive the wallet pem file, check the docs [Deriving the Wallet PEM file](htt

**For simplicity, you can also deploy and interact using the dApp:** https://piggy-bank-dapp.vercel.app/

### The articles on how to prepare dev environment:
## How to prepare dev environment:

The simples way is to use VS Code MultiversX IDE extension through which you can configure Rust and mxpy.

Here are more resources on that topic:
- [Devcontainers](https://docs.multiversx.com/sdk-and-tools/devcontainers)
- [MultiversX docs tutorial](https://docs.multiversx.com/developers/tutorials/staking-contract/#prerequisites)
- [VSCode IDE extension walkthrough video](https://youtu.be/y0beoihLppA)

### Start with contract build**
## Interaction with mxpy

Start with contract build

```
mxpy contract build
Expand All @@ -31,8 +37,9 @@ mxpy contract build

To use testnet switch to `--chain="T"` and --proxy="https://testnet-gateway.multiversx.com".

### Example mxpy interaction commands
##### These commands should be run one folder up from the cloned 'multiversx-simple-sc' folder or you would need to adjust your --project path
### mxpy interaction commands

We asume that the pem file is outside of the project directory. You can adjust the `--pem` path in each command. The smart contract address should be the one you'll get from deployment. Adjust the timestamp when creating a piggy bank (`--arguments <timestamp in future>`).

**Deploy the contract:**

Expand All @@ -43,8 +50,6 @@ mxpy --verbose contract deploy --chain="D" --bytecode="./output/piggybank.wasm"
Smart Contract deployment. You will need to do this once.
In the example, the project name is `multiversx-simple-sc`, and the PEM file is located in `../walletKey.pem`.

You can also use snippets. In the terminal run `. interactions/devnet.snippets.sh && deploy`.

**Create the Piggy:**
(here, with the working SC address example, change it, if you deployed yours, you should have one)

Expand All @@ -54,8 +59,6 @@ mxpy --verbose contract call erd1qqqqqqqqqqqqqpgqvqphdwsdtd6cnlt025kuu9hzjqhnexg

As an argument for the `createPiggy` function, we will pass the timestamp for the lock time (it should be in the future, of course, use https://www.epochconverter.com/).

You can also use snippets. In the terminal run `. interactions/devnet.snippets.sh && createPiggy`.

**Add amount:**
(here, with the working SC address example, change it, if you deployed yours, you should have one)

Expand All @@ -65,8 +68,6 @@ mxpy --verbose contract call erd1qqqqqqqqqqqqqpgqvqphdwsdtd6cnlt025kuu9hzjqhnexg

We are adding one xEGLD (denomination 18, this is why it is, in fact, 1000000000000000000).

You can also use snippets. In the terminal run `. interactions/devnet.snippets.sh && addAmount`.

**Payout:**
(here, with the working SC address example, change it, if you deployed yours, you should have one)

Expand All @@ -76,27 +77,21 @@ mxpy --verbose contract call erd1qqqqqqqqqqqqqpgqvqphdwsdtd6cnlt025kuu9hzjqhnexg

It will check if you can withdraw. It will compare lock time and the current block timestamp.

You can also use snippets. In the terminal run `. interactions/devnet.snippets.sh && payOut`.

**Upgrade the contract:**
(here, with the working SC address example, change it, if you deployed yours, you should have one)

```
mxpy --verbose contract upgrade erd1qqqqqqqqqqqqqpgqvqphdwsdtd6cnlt025kuu9hzjqhnexgu67es8lqc44 --chain="D" --bytecode="./output/piggybank.wasm" --pem="../walletKey.pem" --gas-limit=20000000 --proxy="https://devnet-gateway.multiversx.com" --recall-nonce --send
```

You can also use snippets. In the terminal run `. interactions/devnet.snippets.sh && upgrade`.

### Snippets

You will find interaction snippets in `interactions/snippets.sh`. It is convenient to use when working with VSCode and MultiversX SDK plugin.

After deploying the smart contract, you need to edit the `SC_ADDRESS`. Also, make sure that the relative path to your wallet PEM file is correct. You will need to set it in `USER_PEM`.

### Testing
## Testing

You will find tests in `tests/piggybank_rust_test.rs`. To run a test, you can use click on the `Run Test` button from under the test name in VS Code or you can run it with `cargo test --test piggybank_rust_test`.
Tests are based on [blackbox testing](https://docs.multiversx.com/developers/testing/rust/sc-blackbox-calls) approach.
You will find tests in `tests/piggybank_rust_test.rs`.
To run a test, you can click on the `Run Test` button from under the test name in VS Code.
You can also run it with `cargo test --test piggybank_rust_test`.
Or you can use `sc-meta` tool: `sc-meta test`.

### Development
## Development
Besides cloning the repository, you can also use buildo-begins CLI:
- `npx buildo-begins@latest init` - from the list, choose Piggy Bank smart contract. You can also initialize the dapp for interactions.
38 changes: 0 additions & 38 deletions interactions/devnet.snippets.sh

This file was deleted.

Loading

0 comments on commit 674d759

Please sign in to comment.