Skip to content

add test publish #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ RUN echo "\nexport PATH=\$PATH:\$HOME/pyth-client/build" >> .profile

RUN echo "\nexport PYTHONPATH=\${PYTHONPATH:+\${PYTHONPATH}:}\$HOME/pyth-client" >> .profile

RUN /bin/bash -l -c "pytest-3 --pyargs pyth"

# Install Rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none

Expand All @@ -34,6 +32,8 @@ RUN PATH=$PATH:$HOME/.cargo/bin && cd pyth-client/program && make V=1
# Print hash of the program
RUN sha256sum -b pyth-client/target/oracle.so

RUN /bin/bash -l -c "pytest-3 --pyargs pyth"

ENTRYPOINT []
CMD []

72 changes: 72 additions & 0 deletions pyth/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
import inspect
import os
import subprocess
import time
from shutil import rmtree
from subprocess import DEVNULL, Popen, check_call, check_output
from tempfile import mkdtemp

import pytest


__all__ = [
'BaseTest',
]

__this_file = os.path.abspath(__file__)
__this_dir = os.path.dirname(__this_file)


class BaseTest:

Expand Down Expand Up @@ -97,3 +106,66 @@ def run_test(self, input_path: str, output_path: str, *, inplace: bool):
f.write(actual)
else:
assert actual == expected


@pytest.fixture
def solana_test_validator():

ledger_dir = mkdtemp(prefix='stv_')
cmd = [
'solana-test-validator',
'--rpc-port', '8899',
'--ledger', ledger_dir,
]
kwargs = {
'stdin': DEVNULL,
'stdout': DEVNULL,
'stderr': DEVNULL,
}
with Popen(cmd, **kwargs) as p:
time.sleep(3)
yield
p.terminate()
rmtree(ledger_dir)


@pytest.fixture
def solana_keygen():

cmd = ['solana-keygen', 'new', '--no-passphrase']
output = check_output(cmd)
output = output.decode('ascii')
output = output.splitlines()
output = [line for line in output if 'pubkey' in line][0]
output = output.split('pubkey: ')[1]
return output


@pytest.fixture
def solana_airdrop(solana_test_validator, solana_keygen):

cmd = [
'solana', 'airdrop', '100', solana_keygen,
'--commitment', 'finalized',
'--url', 'localhost',
]
check_call(cmd)


@pytest.fixture
def solana_program_deploy(solana_test_validator, solana_airdrop):

cmd = [
'solana', 'program', 'deploy',
os.path.abspath(
os.path.join(__this_dir, '..', '..', 'target', 'oracle.so')
),
'--commitment', 'finalized',
'--url', 'localhost',
]
output = check_output(cmd)
output = output.decode('ascii')
output = output.splitlines()
output = [line for line in output if 'Program Id' in line][0]
output = output.split('Program Id: ')[1]
return output
3 changes: 3 additions & 0 deletions pyth/tests/test_deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def test_deploy(solana_program_deploy):

assert(True)