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/README.md b/README.md index 592a976..fb95d33 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ Follow these steps to run the tests: - In laconicd repo run: ```bash - TEST_NAMESERVICE_EXPIRY=true ./init.sh + TEST_REGISTRY_EXPIRY=true ./init.sh ``` - Export the private key and change it in `.env` file again using: 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/package.json b/package.json index b6ae848..7eb4ea1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cerc-io/laconic-sdk", - "version": "0.1.5", + "version": "0.1.6", "main": "dist/index.js", "types": "dist/index.d.ts", "repository": "git@github.com:cerc-io/laconic-sdk.git", diff --git a/src/nameservice-expiry.test.ts b/src/nameservice-expiry.test.ts index 1e2f68d..4fd4536 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 717aaf1..4223cc2 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 new file mode 100644 index 0000000..c1900b5 --- /dev/null +++ b/src/testing/data/watcher.yml @@ -0,0 +1,7 @@ +record: + type: WebsiteRegistrationRecord + url: 'https://cerc.io' + repo_registration_record_cid: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D + build_artifact_cid: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9 + tls_cert_cid: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR + version: 1.0.23