Skip to content

Commit 674d759

Browse files
committed
update multiversx-sc and rewrite tests
1 parent 94bec21 commit 674d759

17 files changed

+1104
-1517
lines changed

Cargo.lock

Lines changed: 460 additions & 147 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "piggybank"
3-
version = "0.6.0"
3+
version = "0.7.0"
44
authors = ["Julian Ćwirko <[email protected]>"]
55
edition = "2021"
66
publish = false
@@ -9,7 +9,7 @@ publish = false
99
path = "src/lib.rs"
1010

1111
[dependencies.multiversx-sc]
12-
version = "0.48.0"
12+
version = "0.50.3"
1313

1414
[dev-dependencies.multiversx-sc-scenario]
15-
version = "0.48.0"
15+
version = "0.50.3"

README.md

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### PiggyBank - MultiversX Smart Contract for learning purposes
1+
## PiggyBank - MultiversX Smart Contract for learning purposes
22

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

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

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

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

19-
### The articles on how to prepare dev environment:
19+
## How to prepare dev environment:
20+
21+
The simples way is to use VS Code MultiversX IDE extension through which you can configure Rust and mxpy.
22+
23+
Here are more resources on that topic:
2024
- [Devcontainers](https://docs.multiversx.com/sdk-and-tools/devcontainers)
2125
- [MultiversX docs tutorial](https://docs.multiversx.com/developers/tutorials/staking-contract/#prerequisites)
2226
- [VSCode IDE extension walkthrough video](https://youtu.be/y0beoihLppA)
2327

24-
### Start with contract build**
28+
## Interaction with mxpy
29+
30+
Start with contract build
2531

2632
```
2733
mxpy contract build
@@ -31,8 +37,9 @@ mxpy contract build
3137

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

34-
### Example mxpy interaction commands
35-
##### These commands should be run one folder up from the cloned 'multiversx-simple-sc' folder or you would need to adjust your --project path
40+
### mxpy interaction commands
41+
42+
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>`).
3643

3744
**Deploy the contract:**
3845

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

46-
You can also use snippets. In the terminal run `. interactions/devnet.snippets.sh && deploy`.
47-
4853
**Create the Piggy:**
4954
(here, with the working SC address example, change it, if you deployed yours, you should have one)
5055

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

5560
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/).
5661

57-
You can also use snippets. In the terminal run `. interactions/devnet.snippets.sh && createPiggy`.
58-
5962
**Add amount:**
6063
(here, with the working SC address example, change it, if you deployed yours, you should have one)
6164

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

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

68-
You can also use snippets. In the terminal run `. interactions/devnet.snippets.sh && addAmount`.
69-
7071
**Payout:**
7172
(here, with the working SC address example, change it, if you deployed yours, you should have one)
7273

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

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

79-
You can also use snippets. In the terminal run `. interactions/devnet.snippets.sh && payOut`.
80-
8180
**Upgrade the contract:**
8281
(here, with the working SC address example, change it, if you deployed yours, you should have one)
8382

8483
```
8584
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
8685
```
8786

88-
You can also use snippets. In the terminal run `. interactions/devnet.snippets.sh && upgrade`.
89-
90-
### Snippets
91-
92-
You will find interaction snippets in `interactions/snippets.sh`. It is convenient to use when working with VSCode and MultiversX SDK plugin.
93-
94-
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`.
95-
96-
### Testing
87+
## Testing
9788

98-
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`.
89+
Tests are based on [blackbox testing](https://docs.multiversx.com/developers/testing/rust/sc-blackbox-calls) approach.
90+
You will find tests in `tests/piggybank_rust_test.rs`.
91+
To run a test, you can click on the `Run Test` button from under the test name in VS Code.
92+
You can also run it with `cargo test --test piggybank_rust_test`.
93+
Or you can use `sc-meta` tool: `sc-meta test`.
9994

100-
### Development
95+
## Development
10196
Besides cloning the repository, you can also use buildo-begins CLI:
10297
- `npx buildo-begins@latest init` - from the list, choose Piggy Bank smart contract. You can also initialize the dapp for interactions.

interactions/devnet.snippets.sh

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)