dimkk / terra_integration_example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Workshop: How to do integration tests

event Terra Spacecamp 2021
time Aug 24 2021 7:00 pm EST
livestream https://www.youtube.com/watch?v=hU5HWCL7WWc

Speaker

website larry.engineer
github @larry0x
twitter @larry0x
telegram @larry_0x

Requirements

Notes:

  • Windows users: Sorry, but Windows is an inferior OS for software developement. I suggest upgrading to a Mac or install Linux on your PC (I used arch btw)
  • M1 Mac users: Sorry, LocalTerra doesn't run on ARM processors. There is currently no solution to this

Procedures

Spin up LocalTerra

git clone https://github.com/terra-money/LocalTerra.git
cd LocalTerra
git checkout v0.5.0  # important

Edit LocalTerra/config/config.toml as follows. This speeds up LocalTerra's blocktime which improves our productivity.

##### consensus configuration options #####
[consensus]

wal_file = "data/cs.wal/wal"
- timeout_propose = "3s"
- timeout_propose_delta = "500ms"
- timeout_prevote = "1s"
- timeout_prevote_delta = "500ms"
- timeout_precommit_delta = "500ms"
- timeout_commit = "5s"
+ timeout_propose = "200ms"
+ timeout_propose_delta = "200ms"
+ timeout_prevote = "200ms"
+ timeout_prevote_delta = "200ms"
+ timeout_precommit_delta = "200ms"
+ timeout_commit = "200ms"

Edit LocalTerra/config/genesis.json as follows. This fixes the stability fee ("tax") on Terra stablecoin transfers to a constant value (0.1%) so that our test transactions give reproducible results.

"app_state": {
  "treasury": {
    "params": {
      "tax_policy": {
-       "rate_min": "0.000500000000000000",
-       "rate_max": "0.010000000000000000",
+       "rate_min": "0.001000000000000000",
+       "rate_max": "0.001000000000000000",
      },
-     "change_rate_max": "0.000250000000000000"
+     "change_rate_max": "0.000000000000000000"
    }
  }
}

Once done, start LocalTerra by

docker compose up  # Ctrl + C to quit

From time to time, you may need to revert LocalTerra to its initial state. Do this by

docker compose rm

How to know if LocalTerra is working properly:

  1. Go to https://localhost:1317/swagger/. You should see a page with some APIs which can be used to send transactions or query blockchain state. However, we will be using terra.js library to do this instead of from the swagger page
  2. Go to this Terra Finder page. Don't forget to select "LocalTerra" from the network selector on top right of the page. You should see an account with huge amounts of Luna and stablecoins. This is one of the accounts we will be using for the tests

Compile contracts

# .zshrc or .bashrc

# set this to whichever latest version of the optimizer is
OPTIMIZER_VERSION="0.11.4"

alias rust-optimizer='docker run --rm -v "$(pwd)":/code \
  --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
  --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
  cosmwasm/rust-optimizer:${OPTIMIZER_VERSION}'

alias workspace-optimizer='docker run --rm -v "$(pwd)":/code \
  --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
  --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
  cosmwasm/workspace-optimizer:${OPTIMIZER_VERSION}'
# in your project folder
rust-optimizer       # if your project contains only 1 contract
workspace-optimizer  # otherwise

Run tests

git clone https://github.com/larry0x/spacecamp-2021-workshop.git
cd terra-spacecamp-2021-workshop/scripts
npm install
ts-node main.ts

Acknowledgement

  • Terraform Labs, Delphi Digital, Secret Network, and Confio for hosting this hackathon
  • TerraSwap for the contract code

License

The contents of this repository are open source under MIT license

About

License:MIT License


Languages

Language:TypeScript 100.0%