Skip to content

Commit

Permalink
mock for api v1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Jan 28, 2025
1 parent 3bfb56a commit 9d15fd9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions counterparty-core/counterpartycore/pytest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from counterpartycore.lib.utils.helpers import to_short_json
from counterpartycore.pytest.mocks.counterpartydbs import check_records

from .mocks.apiv1 import apiv1_app, apiv1_client
from .mocks.bitcoind import bitcoind_mock, blockchain_mock, monkeymodule
from .mocks.counterpartydbs import (
build_dbs,
Expand Down Expand Up @@ -43,6 +44,8 @@ def test_helpers():


__all__ = [
"apiv1_app",
"apiv1_client",
"bitcoind_mock",
"blockchain_mock",
"build_dbs",
Expand Down
34 changes: 34 additions & 0 deletions counterparty-core/counterpartycore/pytest/mocks/apiv1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest
from counterpartycore.lib.api import apiv1


@pytest.fixture()
def apiv1_app(ledger_db, state_db):

Check warning

Code scanning / pylint

Unused argument 'ledger_db'. Warning

Unused argument 'ledger_db'.

Check warning

Code scanning / pylint

Unused argument 'state_db'. Warning

Unused argument 'state_db'.
app = apiv1.create_app()
app.config.update(
{
"TESTING": True,
}
)
yield app


def rpc_call(client, method, params):
import json

Check warning

Code scanning / pylint

Import outside toplevel (json). Warning

Import outside toplevel (json).

headers = {"content-type": "application/json"}
payload = {
"method": method,
"params": params,
"jsonrpc": "2.0",
"id": 0,
}
return client.post("/", data=json.dumps(payload), headers=headers, auth=("rpc", "rpc"))


@pytest.fixture()
def apiv1_client(apiv1_app):

Check warning

Code scanning / pylint

Redefining name 'apiv1_app' from outer scope (line 6). Warning

Redefining name 'apiv1_app' from outer scope (line 6).
def call(method, params):
return rpc_call(apiv1_app.test_client(), method, params)

return call
15 changes: 15 additions & 0 deletions counterparty-core/counterpartycore/pytest/units/api/apiv1_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
from counterpartycore.lib.api import apiv1


def test_create_burn(apiv1_client, defaults):
result = apiv1_client(
"create_burn",
{
"source": defaults["addresses"][1],
"quantity": defaults["burn_quantity"],
"encoding": "multisig",
},
).json
assert (
result["result"]
== "0200000001c5c9b5c88b6c5e28fe4a4fd8b6792f2980c5cacc0cca959eff213818be01e0a80000000000ffffffff02800bb203000000001976a914a11b66a67b3ff69671c8f82254099faf374b800e88acbcbce837000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac00000000"
)


def test_get_rows(ledger_db, state_db, monkeypatch):

Check warning

Code scanning / pylint

Unused argument 'ledger_db'. Warning

Unused argument 'ledger_db'.

Check warning

Code scanning / pylint

Unused argument 'state_db'. Warning

Unused argument 'state_db'.

Check warning

Code scanning / pylint

Unused argument 'monkeypatch'. Warning

Unused argument 'monkeypatch'.
# print(json.dumps(apiv1.get_rows("balances", None, "AND", None, None, None, None, None, 1, 0, True), indent=4))

Expand Down

0 comments on commit 9d15fd9

Please sign in to comment.