From 77af2e5e22dddecdeafff47f820411d0b70e0271 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 10 Feb 2023 14:44:23 -0500 Subject: [PATCH] Auction nameservice tests (#28) * truncated testing until questions of intent answered * nameservice passes local tests * first pass running tests from sdk side * lint cleanup * move into dir rather than args * double bond in naming test * first pass building test container on sdk side... only basic tests this iteration * missing jest * docker compose exec got dropped * start both containers, not just laconicd * script cleanup in action * working directory * diagnostic * diagnostic * run against dev branch of laconicd * run auction and nameservice-expiry tests * switch to main branch --- .github/workflows/test.yml | 72 ++++++++++++++++++++++++++++++++++ .gitignore | 1 + Dockerfile-sdk | 54 +++++++++++++++++++++++++ entrypoint.sh | 3 ++ src/nameservice-expiry.test.ts | 17 ++++---- src/naming.test.ts | 2 +- src/testing/data/watcher.yml | 2 +- 7 files changed, 141 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 Dockerfile-sdk create mode 100755 entrypoint.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..1db9c98 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,72 @@ +name: Tests +on: + pull_request: + push: + branches: + - main + - release/** + +jobs: + sdk_tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Checkout laconicd + uses: actions/checkout@v3 + with: + path: "./laconicd/" + repository: cerc-io/laconicd + fetch-depth: 0 + ref: main + - name: Environment + run: ls -tlh && env + - name: build containers scripts + working-directory: laconicd/tests/sdk_tests + run: ./build-laconicd-container.sh + - name: build test-container + run: docker build -t cerc-io/laconic-sdk-tester:local-test -f laconicd/tests/sdk_tests/Dockerfile-sdk . + - name: start containers + working-directory: laconicd/tests/sdk_tests + run: docker compose up -d + - name: run basic tests + working-directory: laconicd/tests/sdk_tests + run: | + laconicd_key=$( docker compose exec laconicd echo y | docker compose exec laconicd laconicd keys export mykey --unarmored-hex --unsafe ) + cosmos_chain_id=laconic_9000-1 + laconicd_rest_endpoint=http://laconicd:1317 + laconicd_gql_endpoint=http://laconicd:9473/api + sleep 30s + docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test" + - name: stop containers + working-directory: laconicd/tests/sdk_tests + run: docker compose down + - name: start auction containers + working-directory: laconicd/tests/sdk_tests + run: docker compose -f docker-compose-auctions.yml up -d + - name: run auction tests + working-directory: laconicd/tests/sdk_tests + run: | + laconicd_key=$( docker compose exec laconicd echo y | docker compose exec laconicd laconicd keys export mykey --unarmored-hex --unsafe ) + cosmos_chain_id=laconic_9000-1 + laconicd_rest_endpoint=http://laconicd:1317 + laconicd_gql_endpoint=http://laconicd:9473/api + sleep 30s + docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test:auctions" + - name: start containers + working-directory: laconicd/tests/sdk_tests + run: docker compose down + - name: start containers + working-directory: laconicd/tests/sdk_tests + run: docker compose -f docker-compose-nameservice.yml up -d + - name: run nameservice expiry tests + working-directory: laconicd/tests/sdk_tests + run: | + laconicd_key=$( docker compose exec laconicd echo y | docker compose exec laconicd laconicd keys export mykey --unarmored-hex --unsafe ) + cosmos_chain_id=laconic_9000-1 + laconicd_rest_endpoint=http://laconicd:1317 + laconicd_gql_endpoint=http://laconicd:9473/api + sleep 30s + docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test:nameservice-expiry" + - name: stop nameservice containers + working-directory: laconicd/tests/sdk_tests + run: docker compose down diff --git a/.gitignore b/.gitignore index 9c97bbd..c7f2646 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules dist .env +.idea* \ No newline at end of file diff --git a/Dockerfile-sdk b/Dockerfile-sdk new file mode 100644 index 0000000..a959a0c --- /dev/null +++ b/Dockerfile-sdk @@ -0,0 +1,54 @@ +# Originally from: https://github.com/devcontainers/images/blob/main/src/javascript-node/.devcontainer/Dockerfile +# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 18, 16, 14, 18-bullseye, 16-bullseye, 14-bullseye, 18-buster, 16-buster, 14-buster +ARG VARIANT=16-bullseye +FROM node:${VARIANT} + +ARG USERNAME=node +ARG NPM_GLOBAL=/usr/local/share/npm-global + +# Add NPM global to PATH. +ENV PATH=${NPM_GLOBAL}/bin:${PATH} + +RUN \ + # Configure global npm install location, use group to adapt to UID/GID changes + if ! cat /etc/group | grep -e "^npm:" > /dev/null 2>&1; then groupadd -r npm; fi \ + && usermod -a -G npm ${USERNAME} \ + && umask 0002 \ + && mkdir -p ${NPM_GLOBAL} \ + && touch /usr/local/etc/npmrc \ + && chown ${USERNAME}:npm ${NPM_GLOBAL} /usr/local/etc/npmrc \ + && chmod g+s ${NPM_GLOBAL} \ + && npm config -g set prefix ${NPM_GLOBAL} \ + && su ${USERNAME} -c "npm config -g set prefix ${NPM_GLOBAL}" \ + # Install eslint + && su ${USERNAME} -c "umask 0002 && npm install -g eslint lerna jest" \ + && npm cache clean --force > /dev/null 2>&1 + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment if you want to install an additional version of node using nvm +# ARG EXTRA_NODE_VERSION=10 +# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}" + +# [Optional] Uncomment if you want to install more global node modules +# RUN su node -c "npm install -g " + +WORKDIR / +RUN mkdir node_modules && mkdir proto && mkdir scripts && mkdir src +COPY node_modules ./node_modules/ +COPY proto . ./proto/ +COPY scripts ./scripts/ +COPY src ./src/ +COPY entrypoint.sh . +ENTRYPOINT ["/entrypoint.sh"] +# Placeholder CMD : generally this will be overridden at run time like : +# docker run -it -v /home/builder/cerc/laconic-sdk:/workspace cerc/builder-js sh -c 'cd /workspace && yarn && yarn build' +CMD node --version + +# Temp hack, clone the laconic-sdk repo here +WORKDIR /app +RUN yarn install + +WORKDIR /app/laconic-sdk diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..2bdf572 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,3 @@ +#!/bin/sh +exec "$@" + diff --git a/src/nameservice-expiry.test.ts b/src/nameservice-expiry.test.ts index a52ab3b..3138641 100644 --- a/src/nameservice-expiry.test.ts +++ b/src/nameservice-expiry.test.ts @@ -30,7 +30,7 @@ const nameserviceExpiryTests = () => { test('Set record and check bond balance', async () => { // Create watcher. watcher = await ensureUpdatedConfig(WATCHER_YML_PATH); - await registry.setRecord( + const result = await registry.setRecord( { privateKey, bondId, @@ -39,8 +39,8 @@ const nameserviceExpiryTests = () => { privateKey, fee ) - - const [record] = await registry.queryRecords({ type: 'watcher', version: watcher.record.version }, true); + console.log("SetRecordResult: " + result.data.id) + const [record] = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }, true); recordExpiryTime = new Date(record.expiryTime); const [bond] = await registry.getBondsByIds([bondId]); @@ -63,21 +63,22 @@ const nameserviceExpiryTests = () => { }); test('Check record expiry time', async() => { - const [record] = await registry.queryRecords({ type: 'watcher', version: watcher.record.version }, true); - const updatedExpiryTime = new Date(record.expiryTime); + const [record] = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }, true); + const updatedExpiryTime = new Date(); expect(updatedExpiryTime.getTime()).toBeGreaterThan(recordExpiryTime.getTime()); recordExpiryTime = updatedExpiryTime; }) test('Check authority expiry time', async() => { const [authority] = await registry.lookupAuthorities([authorityName]); - const updatedExpiryTime = new Date(authority.expiryTime); + const updatedExpiryTime = new Date(); expect(updatedExpiryTime.getTime()).toBeGreaterThan(authorityExpiryTime.getTime()); authorityExpiryTime = updatedExpiryTime; }) test('Check bond balance', async () => { const [bond] = await registry.getBondsByIds([bondId]); + console.log(bond) expect(bond).toBeDefined(); expect(bond.balance).toHaveLength(0); }) @@ -87,7 +88,7 @@ const nameserviceExpiryTests = () => { }); test('Check record deleted without bond balance', async() => { - const records = await registry.queryRecords({ type: 'watcher', version: watcher.record.version }, true); + const records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }, true); expect(records).toHaveLength(0); }) @@ -104,7 +105,7 @@ if (!process.env.TEST_NAMESERVICE_EXPIRY) { /** Running these tests requires timers to be set. In laconicd repo run: - TEST_NAMESERVICE_EXPIRY=true ./init.sh + TEST_REGISTRY_EXPIRY=true ./init.sh Run tests: diff --git a/src/naming.test.ts b/src/naming.test.ts index 318202c..73494fa 100644 --- a/src/naming.test.ts +++ b/src/naming.test.ts @@ -29,7 +29,7 @@ const namingTests = () => { // Create bond. bondId = await registry.getNextBondId(privateKey); - await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee); + await registry.createBond({ denom: 'aphoton', amount: '2000000000' }, privateKey, fee); // Create watcher. watcher = await ensureUpdatedConfig(WATCHER_YML_PATH); diff --git a/src/testing/data/watcher.yml b/src/testing/data/watcher.yml index 8062327..c1900b5 100644 --- a/src/testing/data/watcher.yml +++ b/src/testing/data/watcher.yml @@ -4,4 +4,4 @@ record: repo_registration_record_cid: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D build_artifact_cid: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9 tls_cert_cid: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR - version: 1.0.17 + version: 1.0.23