-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alexey Poryadin
committed
Aug 18, 2024
1 parent
e4b39cb
commit 6465976
Showing
9 changed files
with
106 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,16 @@ | ||
## `KVStore` sample ABCI application | ||
|
||
To run the KVStore example, do the following: | ||
|
||
* If you are running it for the first time, you need to initialize the home directory of | ||
the single CometBFT node: `cometbft init --home ./.cometbft` | ||
* Run a single CometBFT node with the following parameters: `cometbft start --home ./.cometbft` | ||
* From this directory, launch the application: `python -m abci.server kvstore:app` | ||
* From this directory, launch the application: `python -m abci.server kvstore:app` | ||
* The `pyABCI` package must be installed. | ||
|
||
Check it: | ||
|
||
```shell | ||
curl -s 'localhost:26657/broadcast_tx_commit?tx="name=satoshi"' | ||
curl -s 'localhost:26657/abci_query?data="name"' | ||
``` |
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 |
---|---|---|
@@ -1 +1 @@ | ||
pure-protobuf @ git+https://github.com/Alesh/pure-protobuf.git@master | ||
pure-protobuf>=3.1.2 |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pytest | ||
pytest-asyncio | ||
httpx |
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,82 @@ | ||
import asyncio | ||
import logging | ||
import subprocess | ||
import os.path | ||
import tempfile | ||
from base64 import b64decode | ||
|
||
import httpx | ||
import pytest | ||
import pytest_asyncio | ||
|
||
import abci.server | ||
import abci.utils | ||
|
||
|
||
@pytest.fixture() | ||
def cometbft(): | ||
args = ['docker', 'run', '--net=host', '-d', 'cometbft/cometbft:v0.38.x', | ||
'start', '--proxy_app', 'tcp://127.0.0.1:26658'] | ||
proc = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
if proc.returncode != 0: | ||
logging.error(proc.stderr.decode('utf8')) | ||
assert proc.returncode == 0 | ||
container_id = proc.stdout.decode('utf8').strip() | ||
yield container_id[:12] | ||
subprocess.run(['docker', 'rm', '-f', container_id], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
|
||
|
||
@pytest_asyncio.fixture() | ||
async def kvstore(): | ||
curr_path = os.path.abspath(os.path.curdir) | ||
filename = os.path.join(os.path.dirname(__file__), '..', 'demo', 'kvstore.py') | ||
app = abci.utils.resolve_app(f'{filename}:app') | ||
assert app | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
os.chdir(tmpdir) | ||
srv = abci.server.Server(app) | ||
await srv.start() | ||
count_down = 10 | ||
while count_down: | ||
await asyncio.sleep(1) | ||
if len(srv.connections): | ||
break | ||
count_down -= 1 | ||
yield srv | ||
srv.stop() | ||
await srv | ||
os.chdir(curr_path) | ||
|
||
@pytest.mark.asyncio | ||
async def test_kvstore(cometbft, kvstore): | ||
assert cometbft | ||
assert kvstore | ||
async with httpx.AsyncClient(base_url='http://localhost:26657') as client: | ||
resp = await client.get('/status') | ||
assert resp.status_code == 200 | ||
result = resp.json() | ||
assert result['result']['node_info']['protocol_version']['app'] == '100' | ||
|
||
resp = await client.get('/broadcast_tx_commit?tx="name=satoshi"') | ||
assert resp.status_code == 200 | ||
result = resp.json() | ||
assert result['result']['tx_result']['code'] == 0 | ||
|
||
resp = await client.get('/abci_query?data="name"') | ||
assert resp.status_code == 200 | ||
result = resp.json() | ||
assert result['result']['response']['code'] == 0 | ||
assert b64decode(result['result']['response']['value']).decode() == 'satoshi' | ||
|
||
|
||
resp = await client.get('/broadcast_tx_commit?tx="my=Alesh"') | ||
assert resp.status_code == 200 | ||
result = resp.json() | ||
assert result['result']['tx_result']['code'] == 0 | ||
|
||
resp = await client.get('/abci_query?data="my"') | ||
assert resp.status_code == 200 | ||
result = resp.json() | ||
assert result['result']['response']['code'] == 0 | ||
assert b64decode(result['result']['response']['value']).decode() == 'Alesh' | ||
|
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