-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MiniWallet MVP: 1. Implemented all APIs defined in spec https://github.com/diem/client-sdks/blob/master/specs/mini_wallet.md 2. Created cli for start a miniwallet service 3. Created initial testsuite for testing a MiniWallet API. 4. MiniWallet API openapi spec 5. Refund is not handled yet, will be follow up PRs.
- Loading branch information
Xiao Li
authored
Mar 2, 2021
1 parent
89c667b
commit 5c5bcb7
Showing
40 changed files
with
2,467 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright (c) The Diem Core Contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from diem import chain_ids, testnet | ||
import pytest, os | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def setup_testnet() -> None: | ||
if os.getenv("dt"): | ||
os.system("make docker") | ||
print("swap testnet default values to local testnet launched by docker-compose") | ||
testnet.JSON_RPC_URL = "http://localhost:8080/v1" | ||
testnet.FAUCET_URL = "http://localhost:8000/mint" | ||
testnet.CHAIN_ID = chain_ids.TESTING |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
## Try MiniWallet | ||
|
||
Install Diem python sdk with MiniWallet and MiniWallet Test Suite: | ||
``` | ||
pip install diem[all] | ||
``` | ||
|
||
`dmw` cli will be installed. You can check it out by: | ||
``` | ||
dmw --help | ||
``` | ||
|
||
Start a MiniWallet server, connects to Diem testnet by default | ||
``` | ||
dmw start-server | ||
``` | ||
|
||
Open http://localhost:8888 to check MiniWallet API specification document (Defined by OpenAPI Specification 3.0.3). | ||
The document includes simple examples to try out the API. | ||
|
||
`start-server` options: | ||
|
||
``` | ||
dmw start-server --help | ||
Usage: dmw start-server [OPTIONS] | ||
Options: | ||
-n, --name TEXT Application name. [default: mini-wallet] | ||
-h, --host TEXT Start server host. [default: localhost] | ||
-p, --port INTEGER Start server port. [default: 8888] | ||
-j, --jsonrpc TEXT Diem fullnode JSON-RPC URL. [default: | ||
http://testnet.diem.com/v1] | ||
-f, --faucet TEXT Testnet faucet URL. [default: | ||
http://testnet.diem.com/mint] | ||
-l, --logfile TEXT Log to a file instead of printing into | ||
console. | ||
-o, --enable-debug-api BOOLEAN Enable debug API. [default: True] | ||
--help Show this message and exit. | ||
``` | ||
|
||
|
||
## MiniWallet Test Suite | ||
|
||
Try out MiniWallet Test Suite by hitting the target server we started by `dmw start-server` | ||
``` | ||
dmw test --target http://localhost:8888 | ||
``` | ||
You should see something like this: | ||
|
||
``` | ||
> dmw test | ||
Diem JSON-RPC URL: http://testnet.diem.com/v1 | ||
Diem Testnet Faucet URL: http://testnet.diem.com/mint | ||
======================================== test session starts =============================================== | ||
…... | ||
collected 61 items | ||
src/diem/testing/suites/test_miniwallet_api.py ......................ss. [ 40%] | ||
src/diem/testing/suites/test_payment.py .................................... [100%] | ||
============================== 59 passed, 2 skipped, 198 deselected in 18.26s =============================== | ||
``` | ||
|
||
Follow MiniWallet API specification to create a proxy server for your wallet application. | ||
Assume you run your application at port 9999, run MiniWallet Test Suite: | ||
``` | ||
dmw test --target http://localhost:9999 | ||
``` | ||
|
||
`test` options: | ||
``` | ||
dmw test --help | ||
Usage: dmw test [OPTIONS] | ||
Options: | ||
-t, --target TEXT Target mini-wallet application URL. [default: | ||
http://localhost:8888] | ||
-j, --jsonrpc TEXT Diem fullnode JSON-RPC URL. [default: | ||
http://testnet.diem.com/v1] | ||
-f, --faucet TEXT Testnet faucet URL. [default: | ||
http://testnet.diem.com/mint] | ||
--pytest-args TEXT Additional pytest arguments, split by empty | ||
space, e.g. `--pytest-args '-v -s'`. | ||
-d, --test-debug-api BOOLEAN Run tests for debug APIs. [default: False] | ||
-v, --verbose BOOLEAN Enable verbose log output. [default: False] | ||
--help Show this message and exit. | ||
``` | ||
|
||
### How it works | ||
|
||
1. Test suite is located at diem.testing.suites package, including a pytest conftest.py. | ||
2. `dmw test` will launch a pytest runner to run tests. | ||
3. The conftest.py will start a stub MiniWallet as counterparty service for testing payment with the target server specified by the `--target` option. | ||
|
||
|
||
### Work with local testnet | ||
|
||
1. [Download](https://docs.docker.com/get-docker/) and install Docker and Docker Compose (comes with Docker for Mac and Windows). | ||
2. Download Diem testnet docker compose config: https://github.com/diem/diem/blob/master/docker/compose/validator-testnet/docker-compose.yaml | ||
3. Run `docker-compose -f <validator-testnet/docker-compose.yaml file path> up --detach` | ||
* Faucet will be available at http://127.0.0.1:8000 | ||
* JSON-RPC will be available at http://127.0.0.1:8080 | ||
4. Test your application with local testnet: `dmw test --jsonrpc http://127.0.0.1:8080 --faucet http://127.0.0.1:8000 --target http://localhost:9999` | ||
|
||
### Test Off-chain API | ||
|
||
As the test counterparty wallet application server is started at local, you need make sure your wallet application's off-chain API can access the stub server by it's base_url: `http://localhost:<port>`. | ||
If your wallet application is not running local, you will need to make sure setup tunnel for your wallet application to access the stub server. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,18 +22,23 @@ | |
long_description_content_type='text/markdown', | ||
license="Apache-2.0", | ||
url="https://github.com/diem/client-sdk-python", | ||
# author="Diem Open Source", | ||
author="The Diem Core Contributors", | ||
author_email="[email protected]", | ||
py_modules=["diem.testing.cli.click"], | ||
entry_points=''' | ||
[console_scripts] | ||
dmw=diem.testing.cli.click:main | ||
''', | ||
python_requires=">=3.7", # requires dataclasses | ||
packages=["diem"], | ||
# package_data={"": ["src/diem/jsonrpc/*.pyi"]}, | ||
package_dir={"": "src"}, | ||
include_package_data=True, # see MANIFEST.in | ||
zip_safe=True, | ||
install_requires=["requests>=2.20.0", "cryptography>=2.8", "numpy>=1.18", "protobuf>=3.12.4"], | ||
setup_requires=[ | ||
# Setuptools 18.0 properly handles Cython extensions. | ||
"setuptools>=18.0", | ||
], | ||
extras_require={ | ||
"all": ["falcon>=2.0.0", "waitress>=1.4.4", "pytest>=6.2.1", "click>=7.1"] | ||
}, | ||
classifiers=[ | ||
'Programming Language :: Python :: 3.7', | ||
'Programming Language :: Python :: 3.8', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Copyright (c) The Diem Core Contributors | ||
# SPDX-License-Identifier: Apache-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Copyright (c) The Diem Core Contributors | ||
# SPDX-License-Identifier: Apache-2.0 |
Oops, something went wrong.