Skip to content
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

run evm tests separately #248

Merged
merged 14 commits into from
Dec 15, 2023
33 changes: 22 additions & 11 deletions .github/workflows/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@
DOCKER_PASSWORD = os.environ.get("DHUBP")
IMAGE_NAME = os.environ.get("IMAGE_NAME")
RUN_LINK_REPO = os.environ.get("RUN_LINK_REPO")
DOCKERHUB_ORG_NAME = os.environ.get("DOCKERHUB_ORG_NAME")
SOLANA_NODE_VERSION = 'v1.16.23'
SOLANA_BPF_VERSION = 'v1.16.23'

VERSION_BRANCH_TEMPLATE = r"[vt]{1}\d{1,2}\.\d{1,2}\.x.*"
docker_client = docker.APIClient()
NEON_TEST_IMAGE_NAME = f"{DOCKERHUB_ORG_NAME.lower()}/neon_tests"

PROXY_ENDPOINT = os.environ.get("PROXY_ENDPOINT")
NEON_TESTS_ENDPOINT = os.environ.get("NEON_TESTS_ENDPOINT")

@click.group()
def cli():
Expand Down Expand Up @@ -100,17 +104,27 @@ def run_subprocess(command):

@cli.command(name="run_tests")
@click.option('--github_sha')
def run_tests(github_sha):
image_name = f"{IMAGE_NAME}:{github_sha}"
os.environ["EVM_LOADER_IMAGE"] = image_name
@click.option('--neon_test_branch')
def run_tests(github_sha, neon_test_branch):
os.environ["EVM_LOADER_IMAGE"] = f"{IMAGE_NAME}:{github_sha}"

if neon_test_branch in GithubClient.get_branches_list(NEON_TESTS_ENDPOINT) \
and neon_test_branch not in ('master', 'develop'):
neon_test_image_tag = neon_test_branch
else:
neon_test_image_tag = 'latest'
os.environ["NEON_TESTS_IMAGE"] = f"{NEON_TEST_IMAGE_NAME}:{neon_test_image_tag}"

project_name = f"neon-evm-{github_sha}"
stop_containers(project_name)

run_subprocess(f"docker-compose -p {project_name} -f ./ci/docker-compose-ci.yml pull")
run_subprocess(f"docker-compose -p {project_name} -f ./ci/docker-compose-ci.yml up -d")
container_name = get_solana_container_name(project_name)
test_container_name = get_container_name(project_name, "tests")

click.echo("Start tests")
exec_id = docker_client.exec_create(
container=container_name, cmd="/opt/deploy-test.sh")
container=test_container_name, cmd="python3 clickfile.py run evm --numprocesses 6")
logs = docker_client.exec_start(exec_id['Id'], stream=True)

tests_are_failed = False
Expand All @@ -122,9 +136,6 @@ def run_tests(github_sha):
if 'ERROR ' in current_line or 'FAILED ' in current_line:
tests_are_failed = True
print("Tests are failed")
if "[100%]" not in all_logs:
tests_are_failed = True
print("Part of tests are skipped")

exec_status = docker_client.exec_inspect(exec_id['Id'])["ExitCode"]

Expand All @@ -136,12 +147,12 @@ def run_tests(github_sha):
sys.exit(1)


def get_solana_container_name(project_name):
def get_container_name(project_name, service_name):
data = subprocess.run(
f"docker-compose -p {project_name} -f ./ci/docker-compose-ci.yml ps",
shell=True, capture_output=True, text=True).stdout
click.echo(data)
pattern = rf'{project_name}_solana_[1-9]+'
pattern = rf'{project_name}_{service_name}_[1-9]+'

match = re.search(pattern, data)
return match.group(0)
Expand Down Expand Up @@ -178,7 +189,7 @@ def trigger_proxy_action(head_ref_branch, base_ref_branch, github_ref, github_sh

github = GithubClient(token)

if head_ref_branch in github.get_proxy_branches():
if head_ref_branch in github.get_branches_list(PROXY_ENDPOINT):
proxy_branch = head_ref_branch
elif re.match(VERSION_BRANCH_TEMPLATE, base_ref_branch):
proxy_branch = base_ref_branch
Expand Down
15 changes: 8 additions & 7 deletions .github/workflows/github_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@


class GithubClient():
PROXY_ENDPOINT = os.environ.get("PROXY_ENDPOINT")

def __init__(self, token):
self.proxy_endpoint = os.environ.get("PROXY_ENDPOINT")
self.headers = {"Authorization": f"Bearer {token}",
"Accept": "application/vnd.github+json"}

def get_proxy_runs_list(self, proxy_branch):
response = requests.get(
f"{self.PROXY_ENDPOINT}/actions/workflows/pipeline.yml/runs?branch={proxy_branch}", headers=self.headers)
f"{self.proxy_endpoint}/actions/workflows/pipeline.yml/runs?branch={proxy_branch}", headers=self.headers)
if response.status_code != 200:
raise RuntimeError(f"Can't get proxy runs list. Error: {response.json()}")
runs = [item['id'] for item in response.json()['workflow_runs']]
return runs

def get_proxy_runs_count(self, proxy_branch):
response = requests.get(
f"{self.PROXY_ENDPOINT}/actions/workflows/pipeline.yml/runs?branch={proxy_branch}", headers=self.headers)
f"{self.proxy_endpoint}/actions/workflows/pipeline.yml/runs?branch={proxy_branch}", headers=self.headers)
return int(response.json()["total_count"])

def run_proxy_dispatches(self, proxy_branch, github_ref, github_sha, test_set, initial_pr):
Expand All @@ -31,18 +31,19 @@ def run_proxy_dispatches(self, proxy_branch, github_ref, github_sha, test_set, i
"initial_pr": initial_pr}
}
response = requests.post(
f"{self.PROXY_ENDPOINT}/actions/workflows/pipeline.yml/dispatches", json=data, headers=self.headers)
f"{self.proxy_endpoint}/actions/workflows/pipeline.yml/dispatches", json=data, headers=self.headers)
click.echo(f"Sent data: {data}")
click.echo(f"Status code: {response.status_code}")
if response.status_code != 204:
raise RuntimeError("proxy-model.py action is not triggered")

def get_proxy_branches(self):
@staticmethod
def get_branches_list(endpoint):
proxy_branches_obj = requests.get(
f"{self.PROXY_ENDPOINT}/branches?per_page=100").json()
f"{endpoint}/branches?per_page=100").json()
return [item["name"] for item in proxy_branches_obj]

def get_proxy_run_info(self, id):
response = requests.get(
f"{self.PROXY_ENDPOINT}/actions/runs/{id}", headers=self.headers)
f"{self.proxy_endpoint}/actions/runs/{id}", headers=self.headers)
return response.json()
28 changes: 27 additions & 1 deletion .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ env:
DHUBP: ${{secrets.DHUBP}}
IMAGE_NAME: ${{vars.IMAGE_NAME}}
PROXY_ENDPOINT: ${{vars.PROXY_ENDPOINT}}
NEON_TESTS_ENDPOINT: ${{vars.NEON_TESTS_ENDPOINT}}
DOCKERHUB_ORG_NAME: ${{vars.DOCKERHUB_ORG_NAME}}
RUN_LINK_REPO: ${{vars.RUN_LINK_REPO}}
BUILD_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"

Expand Down Expand Up @@ -46,10 +48,34 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Define base branch if the action is tag creation
id: tag_creation
if: startsWith(github.ref , 'refs/tags/')
run: |
base_branch=`echo ${{ github.ref_name }} | sed 's/\.[0-9]*$/\.x/'`
echo "base_branch=$base_branch" >> $GITHUB_OUTPUT
echo "base_branch=$base_branch"
- name: Define neon test branch
id: neon_test_branch
run: |
if [[ "${{ github.ref }}" =~ "refs/heads/"[vt][0-9]+\.[0-9]+\.x ]]; then # version branch
tag=${GITHUB_REF/refs\/heads\//}

elif [[ "${{ steps.tag_creation.outputs.base_branch }}" != "" ]]; then # tag creation
tag=${{ steps.tag_creation.outputs.base_branch }}

elif [[ "${{ github.head_ref }}" != "" ]]; then # pr to feature or version branch
tag=${{ github.head_ref }}
else
tag='develop'
fi
echo "value=${tag}"
echo "value=${tag}" >> $GITHUB_OUTPUT
- name: Run tests
run: |
python3 ./.github/workflows/deploy.py run_tests \
--github_sha=${GITHUB_SHA}
--github_sha=${GITHUB_SHA} \
--neon_test_branch=${{ steps.neon_test_branch.outputs.value }}
trigger-proxy-tests:
runs-on: trigger-runner
needs:
Expand Down
18 changes: 1 addition & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,52 +27,36 @@ RUN cargo fmt --check && \
cargo build-bpf --features mainnet,emergency && cp target/deploy/evm_loader.so target/deploy/evm_loader-mainnet-emergency.so && \
cargo build-bpf --features ci --dump

# Build Solidity contracts
FROM ethereum/solc:stable-alpine AS contracts
COPY tests/contracts/*.sol /opt/
COPY solidity/*.sol /opt/
WORKDIR /opt/
RUN /usr/local/bin/solc --optimize --optimize-runs 200 --output-dir . --bin *.sol && \
for file in $(ls *.bin); do xxd -r -p $file >${file}ary; done && \
ls -l

# Add neon_test_invoke_program to the genesis
FROM neonlabsorg/neon_test_invoke_program:develop AS neon_test_invoke_program

# Define solana-image that contains utility
FROM builder AS base
RUN apt-get update
RUN apt-get -y install curl python3 python3-pip

COPY tests/requirements.txt /tmp/
RUN pip3 install -r /tmp/requirements.txt

RUN solana program dump metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s /opt/metaplex.so --url mainnet-beta

COPY --from=evm-loader-builder /opt/neon-evm/evm_loader/target/deploy/evm_loader*.so /opt/
COPY --from=evm-loader-builder /opt/neon-evm/evm_loader/target/deploy/evm_loader-dump.txt /opt/
COPY --from=evm-loader-builder /opt/neon-evm/evm_loader/target/release/neon-cli /opt/
COPY --from=evm-loader-builder /opt/neon-evm/evm_loader/target/release/neon-api /opt/
COPY --from=contracts /opt/ /opt/solidity/
COPY --from=neon_test_invoke_program /opt/neon_test_invoke_program.so /opt/
COPY --from=neon_test_invoke_program /opt/neon_test_invoke_program-keypair.json /opt/

COPY ci/wait-for-solana.sh \
ci/wait-for-neon.sh \
ci/solana-run-neon.sh \
ci/deploy-evm.sh \
ci/deploy-test.sh \
ci/create-test-accounts.sh \
ci/evm_loader-keypair.json \
/opt/

COPY solidity/ /opt/solidity
COPY ci/operator-keypairs/ /opt/operator-keypairs
COPY tests /opt/tests
COPY ci/operator-keypairs/id.json /root/.config/solana/id.json
COPY ci/operator-keypairs/id2.json /root/.config/solana/id2.json
COPY ci/keys/ /opt/keys

#ENV CONTRACTS_DIR=/opt/solidity/
ENV PATH=${PATH}:/opt

ENTRYPOINT [ "/opt/solana-run-neon.sh" ]
25 changes: 0 additions & 25 deletions ci/deploy-test.sh

This file was deleted.

14 changes: 13 additions & 1 deletion ci/docker-compose-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
networks:
- net

dk-neon-api:
neon-core-api:
restart: unless-stopped
hostname: neon_api
entrypoint:
Expand All @@ -40,6 +40,18 @@ services:
image: ${EVM_LOADER_IMAGE}
ports:
- "8085"
expose:
- "8085"
networks:
- net

tests:
image: ${NEON_TESTS_IMAGE}
environment:
- SOLANA_URL=http://solana:8899
- NEON_CORE_API_URL=http://neon_api:8085/api
hostname: tests
command: sleep infinity
networks:
- net

Expand Down
49 changes: 37 additions & 12 deletions ci/docker-compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,43 @@ services:
- "8003/udp"
entrypoint:
/opt/solana-run-neon.sh
networks:
- net

# proxy:
# container_name: proxy
# image: proxy.py:latest
# hostname: proxy
# environment:
# - SOLANA_URL=http://solana:8899
# ports:
# - 9090:9090
# expose:
# - "9090"
neon-core-api:
container_name: neon-core-api
restart: unless-stopped
hostname: neon_api
entrypoint:
/opt/neon-api -H 0.0.0.0:8085
environment:
RUST_BACKTRACE: 1
RUST_LOG: debug
NEON_API_LISTENER_ADDR: 0.0.0.0:8085
SOLANA_URL: http://solana:8899
EVM_LOADER: 53DfF883gyixYNXnM7s5xhdeyV8mVk9T4i2hGV9vG9io
NEON_TOKEN_MINT: HPsV9Deocecw3GeZv1FkAPNCBRfuVyfw9MMwjwRe1xaU
NEON_CHAIN_ID: 111
COMMITMENT: confirmed
NEON_DB_CLICKHOUSE_URLS: "http://45.250.253.36:8123;http://45.250.253.38:8123"
KEYPAIR: /opt/operator-keypairs/id.json
FEEPAIR: /opt/operator-keypairs/id.json
image: ${EVM_LOADER_IMAGE}
ports:
- "8085:8085"
expose:
- "8085"
networks:
- net
tests:
image: ${NEON_TESTS_IMAGE}
environment:
- SOLANA_URL=http://solana:8899
- NEON_CORE_API_URL=http://neon_api:8085/api
hostname: tests
command: sleep infinity
networks:
- net

networks:
default:
name: evm_loader-deploy_test-net
net:
3 changes: 0 additions & 3 deletions tests/.gitignore

This file was deleted.

Loading