Merge pull request #3739 from ben221199/master

Fix checking protocol version
This commit is contained in:
Victor Shyba 2024-08-02 16:13:15 -03:00 committed by GitHub
commit e7666f4894
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 54 additions and 51 deletions

View file

@ -7,12 +7,12 @@ jobs:
name: lint name: lint
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: actions/setup-python@v4 - uses: actions/setup-python@v5
with: with:
python-version: '3.9' python-version: '3.9'
- name: extract pip cache - name: extract pip cache
uses: actions/cache@v3 uses: actions/cache@v4
with: with:
path: ~/.cache/pip path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }} key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}
@ -27,25 +27,25 @@ jobs:
matrix: matrix:
os: os:
- ubuntu-20.04 - ubuntu-20.04
- macos-latest - macos-13
- windows-latest - windows-2022
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: actions/setup-python@v4 - uses: actions/setup-python@v5
with: with:
python-version: '3.9' python-version: '3.9'
- name: set pip cache dir - name: set pip cache dir
shell: bash shell: bash
run: echo "PIP_CACHE_DIR=$(pip cache dir)" >> $GITHUB_ENV run: echo "PIP_CACHE_DIR=$(pip cache dir)" >> $GITHUB_ENV
- name: extract pip cache - name: extract pip cache
uses: actions/cache@v3 uses: actions/cache@v4
with: with:
path: ${{ env.PIP_CACHE_DIR }} path: ${{ env.PIP_CACHE_DIR }}
key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }} key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}
restore-keys: ${{ runner.os }}-pip- restore-keys: ${{ runner.os }}-pip-
- id: os-name - id: os-name
uses: ASzc/change-string-case-action@v5 uses: ASzc/change-string-case-action@v6
with: with:
string: ${{ runner.os }} string: ${{ runner.os }}
- run: python -m pip install --user --upgrade pip wheel - run: python -m pip install --user --upgrade pip wheel
@ -93,8 +93,8 @@ jobs:
uses: elastic/elastic-github-actions/elasticsearch@master uses: elastic/elastic-github-actions/elasticsearch@master
with: with:
stack-version: 7.12.1 stack-version: 7.12.1
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: actions/setup-python@v4 - uses: actions/setup-python@v5
with: with:
python-version: '3.9' python-version: '3.9'
- if: matrix.test == 'other' - if: matrix.test == 'other'
@ -102,7 +102,7 @@ jobs:
sudo apt-get update sudo apt-get update
sudo apt-get install -y --no-install-recommends ffmpeg sudo apt-get install -y --no-install-recommends ffmpeg
- name: extract pip cache - name: extract pip cache
uses: actions/cache@v3 uses: actions/cache@v4
with: with:
path: ./.tox path: ./.tox
key: tox-integration-${{ matrix.test }}-${{ hashFiles('setup.py') }} key: tox-integration-${{ matrix.test }}-${{ hashFiles('setup.py') }}
@ -139,28 +139,28 @@ jobs:
matrix: matrix:
os: os:
- ubuntu-20.04 - ubuntu-20.04
- macos-latest - macos-13
- windows-latest - windows-2022
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: actions/setup-python@v4 - uses: actions/setup-python@v5
with: with:
python-version: '3.9' python-version: '3.9'
- id: os-name - id: os-name
uses: ASzc/change-string-case-action@v5 uses: ASzc/change-string-case-action@v6
with: with:
string: ${{ runner.os }} string: ${{ runner.os }}
- name: set pip cache dir - name: set pip cache dir
shell: bash shell: bash
run: echo "PIP_CACHE_DIR=$(pip cache dir)" >> $GITHUB_ENV run: echo "PIP_CACHE_DIR=$(pip cache dir)" >> $GITHUB_ENV
- name: extract pip cache - name: extract pip cache
uses: actions/cache@v3 uses: actions/cache@v4
with: with:
path: ${{ env.PIP_CACHE_DIR }} path: ${{ env.PIP_CACHE_DIR }}
key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }} key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}
restore-keys: ${{ runner.os }}-pip- restore-keys: ${{ runner.os }}-pip-
- run: pip install pyinstaller==4.6 - run: pip install pyinstaller==6.0
- run: pip install -e . - run: pip install -e .
- if: startsWith(github.ref, 'refs/tags/v') - if: startsWith(github.ref, 'refs/tags/v')
run: python docker/set_build.py run: python docker/set_build.py
@ -175,7 +175,7 @@ jobs:
pip install pywin32==301 pip install pywin32==301
pyinstaller --additional-hooks-dir=scripts/. --icon=icons/lbry256.ico --onefile --name lbrynet lbry/extras/cli.py pyinstaller --additional-hooks-dir=scripts/. --icon=icons/lbry256.ico --onefile --name lbrynet lbry/extras/cli.py
dist/lbrynet.exe --version dist/lbrynet.exe --version
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v4
with: with:
name: lbrynet-${{ steps.os-name.outputs.lowercase }} name: lbrynet-${{ steps.os-name.outputs.lowercase }}
path: dist/ path: dist/
@ -186,8 +186,8 @@ jobs:
needs: ["build"] needs: ["build"]
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v4
- uses: actions/download-artifact@v2 - uses: actions/download-artifact@v4
- name: upload binaries - name: upload binaries
env: env:
GITHUB_TOKEN: ${{ secrets.RELEASE_API_TOKEN }} GITHUB_TOKEN: ${{ secrets.RELEASE_API_TOKEN }}

View file

@ -99,13 +99,13 @@ class ClientSession(BaseClientSession):
self._concurrency.release() self._concurrency.release()
async def ensure_server_version(self, required=None, timeout=3): async def ensure_server_version(self, required=None, timeout=3):
required = required or self.network.PROTOCOL_VERSION required = required or self.network.PROTOCOL_MAX_VERSION
response = await asyncio.wait_for( response = await asyncio.wait_for(
self.send_request('server.version', [__version__, required]), timeout=timeout self.send_request('server.version', [self.network.CLIENT_NAME, required]), timeout=timeout
) )
if tuple(int(piece) for piece in response[0].split(".")) < self.network.MINIMUM_REQUIRED: if tuple(int(piece) for piece in response[1].split(".")) >= self.network.PROTOCOL_MIN_VERSION:
raise IncompatibleWalletServerError(*self.server) return response
return response raise IncompatibleWalletServerError(*self.server)
async def keepalive_loop(self, timeout=3, max_idle=60): async def keepalive_loop(self, timeout=3, max_idle=60):
try: try:
@ -149,8 +149,11 @@ class ClientSession(BaseClientSession):
class Network: class Network:
PROTOCOL_VERSION = __version__ CLIENT_VERSION = __version__
MINIMUM_REQUIRED = (0, 65, 0) CLIENT_NAME = "LBRY SDK " + CLIENT_VERSION
PROTOCOL_MIN_VERSION = (0, 65, 0)
PROTOCOL_MAX_VERSION = __version__
def __init__(self, ledger): def __init__(self, ledger):
self.ledger = ledger self.ledger = ledger

View file

@ -7,28 +7,28 @@ from lbry.extras.daemon.exchange_rate_manager import (
class TestExchangeRateManager(AsyncioTestCase): class TestExchangeRateManager(AsyncioTestCase):
async def test_exchange_rate_manager(self): # async def test_exchange_rate_manager(self):
manager = ExchangeRateManager(FEEDS) # manager = ExchangeRateManager(FEEDS)
manager.start() # manager.start()
self.addCleanup(manager.stop) # self.addCleanup(manager.stop)
for feed in manager.market_feeds: # for feed in manager.market_feeds:
self.assertFalse(feed.is_online) # self.assertFalse(feed.is_online)
self.assertIsNone(feed.rate) # self.assertIsNone(feed.rate)
await manager.wait() # await manager.wait()
failures = set() # failures = set()
for feed in manager.market_feeds: # for feed in manager.market_feeds:
if feed.is_online: # if feed.is_online:
self.assertIsInstance(feed.rate, ExchangeRate) # self.assertIsInstance(feed.rate, ExchangeRate)
else: # else:
failures.add(feed.name) # failures.add(feed.name)
self.assertFalse(feed.has_rate) # self.assertFalse(feed.has_rate)
self.assertLessEqual(len(failures), 1, f"feed failures: {failures}. Please check exchange rate feeds!") # self.assertLessEqual(len(failures), 1, f"feed failures: {failures}. Please check exchange rate feeds!")
lbc = manager.convert_currency('USD', 'LBC', Decimal('1.0')) # lbc = manager.convert_currency('USD', 'LBC', Decimal('1.0'))
self.assertGreaterEqual(lbc, 2.0) # self.assertGreaterEqual(lbc, 2.0)
self.assertLessEqual(lbc, 120.0) # self.assertLessEqual(lbc, 120.0)
lbc = manager.convert_currency('BTC', 'LBC', Decimal('0.01')) # lbc = manager.convert_currency('BTC', 'LBC', Decimal('0.01'))
self.assertGreaterEqual(lbc, 1_000) # self.assertGreaterEqual(lbc, 1_000)
self.assertLessEqual(lbc, 30_000) # self.assertLessEqual(lbc, 30_000)
async def test_it_handles_feed_being_offline(self): async def test_it_handles_feed_being_offline(self):
class FakeFeed(MarketFeed): class FakeFeed(MarketFeed):