Skip to content

Commit

Permalink
test: basic e2e tests (#337)
Browse files Browse the repository at this point in the history
* test: basic e2e tests

* test: init namada per test

* docs: e2e README

* bug: correct genesis implicit addresses

* feat: make e2e work on macos

* chore: update e2e to 0.20.1
  • Loading branch information
mateuszjasiuk authored Aug 9, 2023
1 parent 17540d1 commit 501daef
Show file tree
Hide file tree
Showing 18 changed files with 1,889 additions and 34 deletions.
2 changes: 1 addition & 1 deletion apps/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
"@namada/utils": "0.1.0",
"@namada/ledger-namada": "0.0.1",
"@cosmjs/encoding": "^0.29.0",
"@dao-xyz/borsh": "^5.1.5",
"@ledgerhq/hw-transport": "^6.28.3",
"@ledgerhq/hw-transport-webhid": "^6.27.14",
"@ledgerhq/hw-transport-webusb": "^6.27.14",
"bignumber.js": "^9.1.1",
"@dao-xyz/borsh": "^5.1.5",
"buffer": "^6.0.3",
"dompurify": "^3.0.2",
"framer-motion": "6.2.4",
Expand Down
45 changes: 45 additions & 0 deletions e2e/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"env": {
"es2021": true
},
"extends": [
"plugin:@typescript-eslint/recommended",
"prettier",
"prettier/prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": ["@typescript-eslint", "import"],
"rules": {
"no-use-before-define": "off",
"import/extensions": [
"error",
"ignorePackages",
{
"ts": "never"
}
],
"no-shadow": "off",
"@typescript-eslint/no-shadow": ["off"],
"@typescript-eslint/explicit-function-return-type": [
"error",
{
"allowExpressions": true
}
],
"import/prefer-default-export": "off"
},
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [".ts"]
},
"import/resolver": {
"typescript": {
"paths": ["./src"]
}
}
}
}
1 change: 1 addition & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.namada
1 change: 1 addition & 0 deletions e2e/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
6 changes: 6 additions & 0 deletions e2e/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"singleQuote": false
}
36 changes: 36 additions & 0 deletions e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# @anoma/e2e
Package containing extension and web interface e2e tests.

## Development
- run `yarn setup` which builds extension and web interface with `--watch` flag
- wait for setup to finish
- run `yarn test` or `yarn test:watch`

## CI
- WIP :)

## Other stuff
- **So far only works for namada 0.19** - you can change version in `./setup-namada.sh`
- **So far downloads MASP params every time we load extension**
- **Namada binaries, wasm checksums and wasms are cached** - they will dl again only if namada version changes

### Helper scripts
`./setup-frontend.sh`
- builds extension and web interface with `--watch` flag
`./setup-namada.sh`
- if needed downloads namada binaries, wasm checksums.json file and wasm files from s3
- initializes the chain
- reads chain id of the initialized chain, copies wasm files and replaces chain id in built extension and web interface files[^1]
`./start-namada.sh`
- starts namada with the current chain id

### Writing tests
If you wrtie a test that needs namada running you have to consider few things:
- you need to setup namada **before** puppeteer loads the extension. Otherwise there would be a chain id mismatch and things like transfers will not work.
- you need to be sure that there is only one test using namada running at the same time. The reason is the same as above. This is something that can change in future. We need to figure out how many instances of namada we want to run at the same time.
- make sure that you stop namada process after test(s) are done

You can use predefined values in `utils/values` and addresses defined in `genesis.toml` for quicker test setup.


[^1]: We do this so we do not have to rebuild extension/web interface every time we reinitialize the chain. Unfortunately we can not force namada to initialize with the same chain id all the time.
232 changes: 232 additions & 0 deletions e2e/genesis.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
# Genesis configuration source for E2E tests with:
# - 1 genesis validator
# - User accounts same as the ones in "dev" build (Albert, Bertha, Christel)

genesis_time = "2021-09-30T10:00:00Z"
native_token = "NAM"
faucet_pow_difficulty = 1
faucet_withdrawal_limit = "1000"

[validator.validator-0]
# Validator's staked NAM at genesis.
tokens = 200000
# Amount of the validator's genesis token balance which is not staked.
non_staked_balance = 1000000000000
# VP for the validator account
validator_vp = "vp_validator"
# Commission rate for rewards
commission_rate = "0.05"
# Maximum change per epoch in the commission rate
max_commission_rate_change = "0.01"
# Public IP:port address.
# We set the port to be the default+1000, so that if a local node was running at
# the same time as the E2E tests, it wouldn't affect them.
net_address = "127.0.0.1:27656"

# Some tokens present at genesis.

[token.NAM]
address = "atest1v4ehgw36x3prswzxggunzv6pxqmnvdj9xvcyzvpsggeyvs3cg9qnywf589qnwvfsg5erg3fkl09rg5"
denom = 6
[token.NAM.balances]
Albert = "1000000"
"Albert.public_key" = "100"
Bertha = "1000000"
"Bertha.public_key" = "2000"
Christel = "1000000"
"Christel.public_key" = "100"
Daewon = "1000000"
Ester = "1000000"
TestA = "1000"
TestB = "1000"
faucet = "9223372036854"
"faucet.public_key" = "100"
"validator-0.public_key" = "100"

[token.BTC]
address = "atest1v4ehgw36xdzryve5gsc52veeg5cnsv2yx5eygvp38qcrvd29xy6rys6p8yc5xvp4xfpy2v694wgwcp"
denom = 8
[token.BTC.balances]
Albert = "1000000"
Bertha = "1000000"
Christel = "1000000"
Daewon = "1000000"
Ester = "1000000"
TestA = "1000000"
faucet = "9223372036854"

[token.ETH]
address = "atest1v4ehgw36xqmr2d3nx3ryvd2xxgmrq33j8qcns33sxezrgv6zxdzrydjrxveygd2yxumrsdpsf9jc2p"
denom = 18
[token.ETH.balances]
Albert = "1000000"
Bertha = "1000000"
Christel = "1000000"
Daewon = "1000000"
Ester = "1000000"
faucet = "9223372036854"

[token.DOT]
address = "atest1v4ehgw36gg6nvs2zgfpyxsfjgc65yv6pxy6nwwfsxgungdzrggeyzv35gveyxsjyxymyz335hur2jn"
denom = 10
[token.DOT.balances]
Albert = "1000000"
Bertha = "1000000"
Christel = "1000000"
Daewon = "1000000"
Ester = "1000000"
faucet = "9223372036854"

[token.Schnitzel]
address = "atest1v4ehgw36xue5xvf5xvuyzvpjx5un2v3k8qeyvd3cxdqns32p89rrxd6xx9zngvpegccnzs699rdnnt"
denom = 6
[token.Schnitzel.balances]
Albert = "1000000"
Bertha = "1000000"
Christel = "1000000"
Daewon = "1000000"
Ester = "1000000"
faucet = "9223372036854"

[token.Apfel]
address = "atest1v4ehgw36gfryydj9g3p5zv3kg9znyd358ycnzsfcggc5gvecgc6ygs2rxv6ry3zpg4zrwdfeumqcz9"
denom = 6
[token.Apfel.balances]
Albert = "1000000"
Bertha = "1000000"
Christel = "1000000"
Daewon = "1000000"
Ester = "1000000"
faucet = "9223372036854"

[token.Kartoffel]
address = "atest1v4ehgw36gep5ysecxq6nyv3jg3zygv3e89qn2vp48pryxsf4xpznvve5gvmy23fs89pryvf5a6ht90"
public_key = ""
denom = 6
[token.Kartoffel.balances]
Albert = "1000000"
Bertha = "1000000"
Christel = "1000000"
Daewon = "1000000"
Ester = "1000000"
faucet = "9223372036854"

# Some established accounts present at genesis.
[established.faucet]
vp = "vp_testnet_faucet"

[established.Albert]
vp = "vp_user"

[established.Bertha]
vp = "vp_user"

[established.Christel]
vp = "vp_user"

[established.masp]
address = "atest1v4ehgw36xaryysfsx5unvve4g5my2vjz89p52sjxxgenzd348yuyyv3hg3pnjs35g5unvde4ca36y5"
vp = "vp_masp"

[implicit.Daewon]

[implicit.Ester]

[implicit.TestA]
public_key = "0076a9df923fd0746a17682429ca1a5ff859f066c4be6c0bcdaaadb5f45524ad8a"

[implicit.TestB]
public_key = "0041cca22e607fca642fb42640927f1d459e33f5e12e676ca1aa292fc6d9affbfa"
# Wasm VP definitions

# Implicit VP
[wasm.vp_implicit]
filename = "vp_implicit.wasm"

# Default user VP in established accounts
[wasm.vp_user]
filename = "vp_user.wasm"

# Default validator VP
[wasm.vp_validator]
# filename (relative to wasm path used by the node)
filename = "vp_validator.wasm"

# Faucet VP
[wasm.vp_testnet_faucet]
filename = "vp_testnet_faucet.wasm"

# MASP VP
[wasm.vp_masp]
filename = "vp_masp.wasm"

# General protocol parameters.
[parameters]
# Minimum number of blocks in an epoch.
min_num_of_blocks = 4
# Maximum expected time per block (in seconds).
max_expected_time_per_block = 30
# Max payload size, in bytes, for a tx batch proposal.
max_proposal_bytes = 22020096
# vp whitelist
vp_whitelist = []
# tx whitelist
tx_whitelist = []
# Implicit VP WASM name
implicit_vp = "vp_implicit"
# Expected number of epochs per year (also sets the min duration of an epoch in seconds).
# Remember to set this to a more reasonable number for production networks. Also, expect most masp
# txs to fail due to epoch boundary errors.
epochs_per_year = 525_600
# The P gain factor in the Proof of Stake rewards controller
pos_gain_p = "0.1"
# The D gain factor in the Proof of Stake rewards controller
pos_gain_d = "0.1"

# Proof of stake parameters.
[pos_params]
# Maximum number of consensus validators.
max_validator_slots = 128
# Pipeline length (in epochs). Any change in the validator set made in
# epoch 'n' will become active in epoch 'n + pipeline_len'.
pipeline_len = 2
# Unbonding length (in epochs). Validators may have their stake slashed
# for a fault in epoch 'n' up through epoch 'n + unbonding_len'.
unbonding_len = 3
# Votes per fundamental staking token (namnam) - for testnets this should be 1. For e2e toml, a decimal is used for testing purposes.
tm_votes_per_token = "0.1"
# Reward for proposing a block.
block_proposer_reward = "0.125"
# Reward for voting on a block.
block_vote_reward = "0.1"
# Maximum inflation rate per annum (10%)
max_inflation_rate = "0.1"
# Targeted ratio of staked tokens to total tokens in the supply
target_staked_ratio = "0.6667"
# Portion of a validator's stake that should be slashed on a duplicate
# vote.
duplicate_vote_min_slash_rate = "0.001"
# Portion of a validator's stake that should be slashed on a light
# client attack.
light_client_attack_min_slash_rate = "0.001"
# Number of epochs above and below (separately) the current epoch to
# consider when doing cubic slashing
cubic_slashing_window_length = 1
# The minimum amount of bonded tokens that a validator needs to be in
# either the `consensus` or `below_capacity` validator sets
validator_stake_threshold = "1"

# Governance parameters.
[gov_params]
# minimum amount of nam token to lock
min_proposal_fund = 500
# proposal code size in bytes
max_proposal_code_size = 1000000
# min proposal period length in epochs
min_proposal_period = 3
# max proposal period length in epochs
max_proposal_period = 27
# maximum number of characters in the proposal content
max_proposal_content_size = 10000
# minimum epochs between end and grace epoch
min_proposal_grace_epochs = 6
14 changes: 14 additions & 0 deletions e2e/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Config } from "@jest/types";

const config: Config.InitialOptions = {
verbose: true,
preset: "ts-jest",
transform: {
"^.+\\.ts$": "ts-jest",
},
moduleDirectories: ["node_modules", "e2e/tests"],
testEnvironment: "node",
roots: ["src"],
};

export default config;
36 changes: 36 additions & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@anoma/e2e",
"version": "0.1.0",
"description": "e2e tests for apps",
"main": "src/index.ts",
"repository": "https://github.com/anoma/namada-interface",
"author": "Heliax Dev <[email protected]>",
"license": "MIT",
"private": true,
"scripts": {
"lint": "npx eslint src --ext .ts",
"lint:fix": "yarn lint -- --fix",
"lint:ci": "yarn lint --max-warnings 0",
"setup": "./setup-frontend.sh",
"test": "jest --runInBand",
"test:watch": "jest --watch --runInBand"
},
"dependencies": {
"typescript": "^5.1.3"
},
"devDependencies": {
"@types/jest": "^29.0.0",
"@types/node": "^20.4.2",
"@types/puppeteer": "^7.0.4",
"eslint": "^8.23.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^3.5.1",
"http-server": "^14.1.1",
"jest": "^29.0.2",
"jest-puppeteer": "^9.0.0",
"puppeteer": "^20.8.2",
"start-server-and-test": "^2.0.0",
"terminate": "^2.6.1"
}
}
Loading

0 comments on commit 501daef

Please sign in to comment.