Merge branch 'main' of github.com:cerc-io/laconic-sdk into murali/record-types
This commit is contained in:
commit
578ed5956e
72
.github/workflows/test.yml
vendored
Normal file
72
.github/workflows/test.yml
vendored
Normal file
@ -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
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
node_modules
|
||||
dist
|
||||
.env
|
||||
.idea*
|
54
Dockerfile-sdk
Normal file
54
Dockerfile-sdk
Normal file
@ -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 <your-package-list-here>
|
||||
|
||||
# [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 <your-package-list-here>"
|
||||
|
||||
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
|
@ -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:
|
||||
|
3
entrypoint.sh
Executable file
3
entrypoint.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
exec "$@"
|
||||
|
@ -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",
|
||||
|
@ -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:
|
||||
|
@ -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);
|
||||
|
7
src/testing/data/watcher.yml
Normal file
7
src/testing/data/watcher.yml
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user