Escrow Pallet

November 2, 2022 ยท View on GitHub

License rustdoc Escrow Unit Test

Escrow Pallet Setup and Testing Guide (Ubuntu)

Prerequisite Setup

Install Dependencies

sudo apt install build-essential
sudo apt install -y git clang curl libssl-dev llvm libudev-dev

Install Rust

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

source ~/.cargo/env

rustup default stable

rustup update stable

rustup update nightly

rustup install nightly-2022-09-19 

rustup override set nightly-2022-09-19

rustup target add wasm32-unknown-unknown

rustup target add wasm32-unknown-unknown --toolchain nightly

Deploy a Local Ventur Node

Fetch the code

The following command pulls the ventur-node code from our github repo:

git clone https://github.com/Popular-Coding/ventur.git

cd ventur

Run the node

The following command builds the node. (This may take some time):

cargo run --release -- --dev

Run Unit Tests

Unit tests can be run locally using the following command:

cargo test

Manual Test Guide

1. Start the node

cargo run --release -- --dev
Running your local node
Running the Node

2. Access the Node through the polkadot.js.org interface

Once you have a ventur node running locally, follow this link: https://polkadot.js.org/apps/?rpc=ws://127.0.0.1:9944#/explorer

Accessing your Development Node Endpoint in polkadot.js.org
Accessing the Node

Confirm that you can see the recent blocks listed. If you are not able to access the block explorer on polkadot.js.org, you should:

  1. Confirm that your Ventur node is running

  2. Check if your Ventur node is running the JSON-RPC WS server on an address and port other than 127.0.0.1:9944 a. If your node is running on a different address and port, update the custom endpoint in polkadot.js.org to the address and port number your node is serving

    Setting your Development Node Endpoint in polkadot.js.org
    Setting your Custom Endpoint

3. Test Creating an Escrow

Create an Escrow
Creating an Escrow

4. Test Funding an Escrow

First check your account to see the Transferable Balance listed for Alice

Check Balance
Check Balance
Next, call the fundEscrow extrinsic with a balance of:
1000000000000000000
Fund Escrow
:--:
Fund Escrow
And back in accounts, confirm that the funded amount is now locked for Alice
Confirm Locked Funds
:--:
Confirm Locked Funds
4.a. Test Open Contributions on an Escrow
4.a.i. Admin Contribution

Now that Alice has created an Escrow, we can confirm that by default the escrow only allows admin contributions. Have AliceStash attempt to fund Alice's escrow. This should bring up an Unauthorized error message.

Attempt to Fund Alice's Escrow from AliceStash
Attempt to Fund Escrow
Confirm in accounts that Alice and AliceStash's balances have not changed.
Confirm Account Balances After Funding
:--:
Attempt to Fund Escrow
Next add AliceStash as an admin to Alice's Escrow.
Add AliceStash as Admin
:--:
Add Admin
And now attempt to fund escrow from AliceStash again, this time it should result in a success.
Fund Alice's Escrow from AliceStash
:--:
Fund Escrow
Confirm the expected balance change for Alice and AliceStash.
Confirm Balance of Alice and AliceStash
:--:
Confirm Balances
4.a.ii. Open Contribution

Next confirm the starting balance of Bob's account.

Confirm Balance of Bob
Confirm Bob
Next attempt to call fund escrow on Alice from Bob, this should fail as Bob is not an admin.
Attempt to Fund with Bob
:--:
Bob Funding Attempt
Next have Alice call the enableOpenContribution extrinsic
Alice Enable Open Contribution
:--:
Alice Enable Open Contribution
And now have Bob attempt to fund Alice again
Fund with Bob
:--:
Bob Funding
And confirm the balance changes for Bob and Alice
Confirm Balance of Alice and AliceStash
:--:
Confirm Balances

5. Test Distributing from an Escrow

Take note of Charlie's balance.

Take note of Charlie's balance
Note Charlie's balance
Have Alice distribute to Charlie.
Alice calls the payoutEscrow extrinsic to Charlie
:--:
Confirm Balances
Confirm Charlie and Alice's balance after distribution.
Confirm Balance of Charlie
:--:
Confirm Balances

6. Test Freezing an Escrow

Using Alice call the freezeEscrow extrinsic.

Freeze Alice
Freeze Alice
Attempt to fund Alice with 10000000000000000 (less than the previous amounts, as Alice currently has less than the previously used 1MUNIT). This should fail with an escrow Frozen error.
Attempt to Fund Alice
:--:
Alice Funding Attempt
Next thaw Alice
Thaw Alice
:--:
Thaw
Attempt to fund Alice with 10000000000000000 again.
Attempt to Fund Alice again
:--:
Alice Funding Attempt

7. Test Closing an Escrow

Using Alice call the closeEscrow extrinsic.

Close Alice
Close Alice