Skip to content

Commit d0eb1ad

Browse files
committed
add test publish
1 parent aaf33e1 commit d0eb1ad

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

docker/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ RUN echo "\nexport PATH=\$PATH:\$HOME/pyth-client/build" >> .profile
2020

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

23-
RUN /bin/bash -l -c "pytest-3 --pyargs pyth"
24-
2523
# Install Rust
2624
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none
2725

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

35+
RUN /bin/bash -l -c "pytest-3 --pyargs pyth"
36+
3737
ENTRYPOINT []
3838
CMD []
3939

pyth/tests/conftest.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@
33
import inspect
44
import os
55
import subprocess
6+
import time
7+
from shutil import rmtree
8+
from subprocess import DEVNULL, Popen, check_call, check_output
9+
from tempfile import mkdtemp
10+
11+
import pytest
612

713

814
__all__ = [
915
'BaseTest',
1016
]
1117

18+
__this_file = os.path.abspath(__file__)
19+
__this_dir = os.path.dirname(__this_file)
20+
1221

1322
class BaseTest:
1423

@@ -97,3 +106,66 @@ def run_test(self, input_path: str, output_path: str, *, inplace: bool):
97106
f.write(actual)
98107
else:
99108
assert actual == expected
109+
110+
111+
@pytest.fixture
112+
def solana_test_validator():
113+
114+
ledger_dir = mkdtemp(prefix='stv_')
115+
cmd = [
116+
'solana-test-validator',
117+
'--rpc-port', '8899',
118+
'--ledger', ledger_dir,
119+
]
120+
kwargs = {
121+
'stdin': DEVNULL,
122+
'stdout': DEVNULL,
123+
'stderr': DEVNULL,
124+
}
125+
with Popen(cmd, **kwargs) as p:
126+
time.sleep(3)
127+
yield
128+
p.terminate()
129+
rmtree(ledger_dir)
130+
131+
132+
@pytest.fixture
133+
def solana_keygen():
134+
135+
cmd = ['solana-keygen', 'new', '--no-passphrase']
136+
output = check_output(cmd)
137+
output = output.decode('ascii')
138+
output = output.splitlines()
139+
output = [line for line in output if 'pubkey' in line][0]
140+
output = output.split('pubkey: ')[1]
141+
return output
142+
143+
144+
@pytest.fixture
145+
def solana_airdrop(solana_test_validator, solana_keygen):
146+
147+
cmd = [
148+
'solana', 'airdrop', '100', solana_keygen,
149+
'--commitment', 'finalized',
150+
'--url', 'localhost',
151+
]
152+
check_call(cmd)
153+
154+
155+
@pytest.fixture
156+
def solana_program_deploy(solana_test_validator, solana_airdrop):
157+
158+
cmd = [
159+
'solana', 'program', 'deploy',
160+
os.path.abspath(
161+
os.path.join(__this_dir, '..', '..', 'target', 'oracle.so')
162+
),
163+
'--commitment', 'finalized',
164+
'--url', 'localhost',
165+
]
166+
output = check_output(cmd)
167+
output = output.decode('ascii')
168+
output = output.splitlines()
169+
output = [line for line in output if 'Program Id' in line][0]
170+
output = output.split('Program Id: ')[1]
171+
return output

pyth/tests/test_deploy.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def test_deploy(solana_program_deploy):
2+
3+
assert(True)

0 commit comments

Comments
 (0)