Skip to content

Commit

Permalink
test: Added integration test for mnemonics from ethers.js
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu committed Mar 20, 2020
1 parent 67478b1 commit 780a7cf
Show file tree
Hide file tree
Showing 10 changed files with 1,224 additions and 1 deletion.
61 changes: 61 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,46 @@ common: &common
- ./eggs
key: cache-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }}

integration: &integration
working_directory: ~/repo
steps:
- checkout
- run:
name: merge pull request base
command: ./.circleci/merge_pr.sh
- run:
name: merge pull request base (2nd try)
command: ./.circleci/merge_pr.sh
when: on_fail
- run:
name: merge pull request base (3nd try)
command: ./.circleci/merge_pr.sh
when: on_fail
- restore_cache:
keys:
- cache-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }}
- run:
name: install dependencies (python)
command: pip install --user tox
- run:
name: install dependencies (node)
command: sudo -E bash tests/integration/ethers-cli/setup_node_v12.sh && sudo apt-get install -y nodejs
- run:
name: Build ethers-cli
command: cd tests/integration/ethers-cli && sudo npm install -g . && cd ../../../
- run:
name: run tox
command: ~/.local/bin/tox -r
- save_cache:
paths:
- .hypothesis
- .tox
- ~/.cache/pip
- ~/.local
- ./eggs
- tests/integration/ethers-cli/node_modules
key: cache-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }}

jobs:
doctest:
<<: *common
Expand Down Expand Up @@ -66,6 +106,24 @@ jobs:
- image: circleci/python:3.8
environment:
TOXENV: py38-core
py36-integration:
<<: *integration
docker:
- image: circleci/python:3.6
environment:
TOXENV: py36-integration
py37-integration:
<<: *integration
docker:
- image: circleci/python:3.7
environment:
TOXENV: py37-integration
py38-integration:
<<: *integration
docker:
- image: circleci/python:3.8
environment:
TOXENV: py38-integration
workflows:
version: 2
test:
Expand All @@ -75,3 +133,6 @@ workflows:
- py36-core
- py37-core
- py38-core
- py36-integration
- py37-integration
- py38-integration
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ virtualenv -p python3 venv
pip install -e .[dev]
```

To run the integration test cases, you need to install node and the custom cli tool as follows:

```sh
apt-get install -y nodejs # As sudo
./tests/integration/ethers-cli/setup_node_v12.sh # As sudo
cd tests/integration/ethers-cli
npm install -g . # As sudo
```

### Testing Setup

During development, you might like to have tests run on every file save.
Expand Down
4 changes: 3 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[pytest]
addopts= -v --showlocals --doctest-modules --durations 10
addopts= -v --showlocals --doctest-modules --durations 10 --ignore tests/integration/ethers-cli
python_paths= .
xfail_strict=true
markers =
compatibility: mark a test to be run during compatibility fuzz testing

[pytest-watch]
runner= pytest --failed-first --maxfail=1
1 change: 1 addition & 0 deletions tests/integration/ethers-cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
61 changes: 61 additions & 0 deletions tests/integration/ethers-cli/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env node

const ethers = require('ethers');
const yargs = require('yargs');

const options = yargs
.usage("Usage: -m <mnemonic>")
.option("m", {
alias: "mnemonic",
describe: "BIP39 Mnemonic seed phrase",
type: "array",
demandOption: true,
})
.option("l", {
alias: "language",
describe: "Wordlist language used for mnemonic",
type: "String",
})
.argv;

var wordlist;

switch(options.language) {
case "english":
wordlist = ethers.wordlists.en;
break;
case "spanish":
wordlist = ethers.wordlists.es;
break;
case "french":
wordlist = ethers.wordlists.fr;
break;
case "italian":
wordlist = ethers.wordlists.it;
break;
case "czech":
wordlist = ethers.wordlists.cz;
break;
case "japanese":
wordlist = ethers.wordlists.ja;
break;
case "korean":
wordlist = ethers.wordlists.ko;
break;
case "chinese_simplified":
wordlist = ethers.wordlists.zh_cn;
break;
case "chinese_traditional":
wordlist = ethers.wordlists.zh_tw;
break;
default:
wordlist = ethers.wordlists.en;
}

const account = ethers.Wallet.fromMnemonic(
options.mnemonic.join(" "),
"m/44'/60'/0'/0/0", // path (default)
wordlist,
);

console.log(account.address);
Loading

0 comments on commit 780a7cf

Please sign in to comment.