Skip to content

Commit

Permalink
Allow tests to pass without XBR dependencies (#1580)
Browse files Browse the repository at this point in the history
* Allow tests to pass without XBR dependencies - fixes #1579
* Address review comments
* Fix test skipping notes
  • Loading branch information
Chih-Hsuan Yen committed Jun 17, 2022
1 parent b00c4d1 commit 3fe75d9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
11 changes: 6 additions & 5 deletions autobahn/xbr/test/test_xbr_frealm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
from twisted.internet.defer import inlineCallbacks

from autobahn.xbr import HAS_XBR
if HAS_XBR:
from autobahn.xbr._frealm import Seeder, FederatedRealm
from autobahn.wamp.cryptosign import HAS_CRYPTOSIGN

from autobahn.xbr._secmod import SecurityModuleMemory, EthereumKey
from autobahn.wamp.cryptosign import CryptosignKey
if HAS_XBR and HAS_CRYPTOSIGN:
from autobahn.xbr._frealm import Seeder, FederatedRealm
from autobahn.xbr._secmod import SecurityModuleMemory, EthereumKey
from autobahn.wamp.cryptosign import CryptosignKey

# https://web3py.readthedocs.io/en/stable/providers.html#infura-mainnet
HAS_INFURA = 'WEB3_INFURA_PROJECT_ID' in os.environ and len(os.environ['WEB3_INFURA_PROJECT_ID']) > 0
Expand All @@ -22,7 +23,7 @@

@skipIf(not os.environ.get('USE_TWISTED', False), 'only for Twisted')
@skipIf(not HAS_INFURA, 'env var WEB3_INFURA_PROJECT_ID not defined')
@skipIf(not HAS_XBR, 'package autobahn[xbr] not installed')
@skipIf(not (HAS_XBR and HAS_CRYPTOSIGN), 'package autobahn[encryption,xbr] not installed')
class TestFederatedRealm(TestCase):

gw_config = {
Expand Down
7 changes: 6 additions & 1 deletion autobahn/xbr/test/test_xbr_schema_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pkg_resources
from random import randint, random
import txaio
from unittest import skipIf

if 'USE_TWISTED' in os.environ and os.environ['USE_TWISTED']:
from twisted.trial import unittest
Expand All @@ -13,10 +14,14 @@

txaio.use_asyncio()

from autobahn.xbr import FbsRepository
from autobahn.xbr import HAS_XBR
from autobahn.wamp.exception import InvalidPayload

if HAS_XBR:
from autobahn.xbr import FbsRepository


@skipIf(not HAS_XBR, 'package autobahn[xbr] not installed')
class TestFbsBase(unittest.TestCase):
"""
FlatBuffers tests base class, loads test schemas.
Expand Down
12 changes: 9 additions & 3 deletions autobahn/xbr/test/test_xbr_schema_wamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pkg_resources
from binascii import a2b_hex
import txaio
from unittest import skipIf

if 'USE_TWISTED' in os.environ and os.environ['USE_TWISTED']:
from twisted.trial import unittest
Expand All @@ -12,12 +13,16 @@

txaio.use_asyncio()

from autobahn.xbr._util import pack_ethadr, unpack_ethadr
from autobahn.xbr import FbsType, FbsObject, FbsService, FbsRPCCall, FbsRepository, FbsSchema, FbsField, FbsEnum, \
FbsEnumValue
from autobahn.xbr import HAS_XBR
from autobahn.wamp.exception import InvalidPayload

if HAS_XBR:
from autobahn.xbr._util import pack_ethadr, unpack_ethadr
from autobahn.xbr import FbsType, FbsObject, FbsService, FbsRPCCall, FbsRepository, FbsSchema, FbsField, FbsEnum, \
FbsEnumValue


@skipIf(not HAS_XBR, 'package autobahn[xbr] not installed')
class TestPackEthAdr(unittest.TestCase):
"""
Test :func:`pack_ethadr` and :func:`unpack_ethadr` helpers.
Expand Down Expand Up @@ -63,6 +68,7 @@ def test_roundtrip(self):
self.assertEqual(cnt, 8)


@skipIf(not HAS_XBR, 'package autobahn[xbr] not installed')
class TestFbsBase(unittest.TestCase):
"""
FlatBuffers tests base class, loads test schemas.
Expand Down
7 changes: 6 additions & 1 deletion autobahn/xbr/test/test_xbr_schema_wamp_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import copy
import pkg_resources
import txaio
from unittest import skipIf

if 'USE_TWISTED' in os.environ and os.environ['USE_TWISTED']:
from twisted.trial import unittest
Expand All @@ -12,10 +13,14 @@

txaio.use_asyncio()

from autobahn.xbr import FbsRepository
from autobahn.xbr import HAS_XBR
from autobahn.wamp.exception import InvalidPayload

if HAS_XBR:
from autobahn.xbr import FbsRepository


@skipIf(not HAS_XBR, 'package autobahn[xbr] not installed')
class TestFbsBase(unittest.TestCase):
"""
FlatBuffers tests base class, loads test schemas.
Expand Down
10 changes: 5 additions & 5 deletions autobahn/xbr/test/test_xbr_secmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
from twisted.internet.defer import inlineCallbacks
from twisted.trial.unittest import TestCase

from py_eth_sig_utils.eip712 import encode_typed_data
from py_eth_sig_utils.utils import ecsign, ecrecover_to_pub, checksum_encode, sha3
from py_eth_sig_utils.signing import v_r_s_to_signature, signature_to_v_r_s
from py_eth_sig_utils.signing import sign_typed_data, recover_typed_data

from autobahn.wamp.cryptosign import HAS_CRYPTOSIGN
from autobahn.xbr import HAS_XBR

if HAS_XBR and HAS_CRYPTOSIGN:
from py_eth_sig_utils.eip712 import encode_typed_data
from py_eth_sig_utils.utils import ecsign, ecrecover_to_pub, checksum_encode, sha3
from py_eth_sig_utils.signing import v_r_s_to_signature, signature_to_v_r_s
from py_eth_sig_utils.signing import sign_typed_data, recover_typed_data

from autobahn.xbr import make_w3, EthereumKey, mnemonic_to_private_key
from autobahn.xbr._eip712_member_register import _create_eip712_member_register
from autobahn.xbr._eip712_market_create import _create_eip712_market_create
Expand Down

0 comments on commit 3fe75d9

Please sign in to comment.