Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd5b23a1b1 | ||
|
|
2bc89bcb5d | ||
|
|
e061b3da69 | ||
|
|
82d8626d0f | ||
|
|
6b53c43c51 | ||
|
|
7dd8dca408 | ||
|
|
2493e2c706 | ||
|
|
81f45e95a8 | ||
|
|
db3f9707d2 | ||
|
|
2870a7543a | ||
|
|
77af2e5e22 | ||
|
|
663ebbf8e0 |
@@ -0,0 +1,2 @@
|
|||||||
|
Dockerfile
|
||||||
|
node_modules
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
name: Publish npm package to gitea
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [published]
|
||||||
|
jobs:
|
||||||
|
npm_publish:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
node-version: [ 16.x ]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Use Node.js ${{ matrix.node-version }}
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node-version }}
|
||||||
|
- run: yarn
|
||||||
|
- name: Run yarn build
|
||||||
|
run: |
|
||||||
|
yarn build
|
||||||
|
- name: Configure git.vdb.to npm registry
|
||||||
|
run: |
|
||||||
|
npm config set registry https://git.vdb.to/api/packages/cerc-io/npm/
|
||||||
|
- name: Authenticate to git.vdb.to registry
|
||||||
|
run: |
|
||||||
|
npm config set -- '//git.vdb.to/api/packages/cerc-io/npm/:_authToken' "${{ secrets.GITEA_PUBLISH_TOKEN }}"
|
||||||
|
- name: npm publish
|
||||||
|
run: |
|
||||||
|
npm publish
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
name: Tests
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- '*'
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- release/**
|
||||||
|
|
||||||
|
env:
|
||||||
|
DOCKER_HOST: unix:///var/run/dind.sock
|
||||||
|
|
||||||
|
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: Start dockerd
|
||||||
|
run: |
|
||||||
|
dockerd -H $DOCKER_HOST --userland-proxy=false &
|
||||||
|
sleep 5
|
||||||
|
- 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
|
||||||
@@ -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,3 +1,4 @@
|
|||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
.env
|
.env
|
||||||
|
.idea*
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
# 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" \
|
||||||
|
&& npm cache clean --force > /dev/null 2>&1
|
||||||
|
|
||||||
|
WORKDIR /
|
||||||
|
COPY entrypoint.sh .
|
||||||
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
|
CMD node --version
|
||||||
|
|
||||||
|
WORKDIR /app/laconic-sdk
|
||||||
|
|
||||||
|
COPY package*.json .
|
||||||
|
RUN yarn install
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
WORKDIR /app/laconic-sdk
|
||||||
Executable
+3
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
exec "$@"
|
||||||
|
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@cerc-io/laconic-sdk",
|
"name": "@cerc-io/laconic-sdk",
|
||||||
"version": "0.1.5",
|
"version": "0.1.6",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"repository": "git@github.com:cerc-io/laconic-sdk.git",
|
"repository": "git@github.com:cerc-io/laconic-sdk.git",
|
||||||
|
|||||||
+84
-68
@@ -12,20 +12,10 @@ jest.setTimeout(90 * 1000);
|
|||||||
const bondTests = () => {
|
const bondTests = () => {
|
||||||
let registry: Registry;
|
let registry: Registry;
|
||||||
|
|
||||||
let watcher: any;
|
|
||||||
|
|
||||||
let version1: string;
|
|
||||||
let version2: string;
|
|
||||||
|
|
||||||
let bondId1: string;
|
|
||||||
let bondId2: string;
|
|
||||||
|
|
||||||
let bondOwner: string;
|
|
||||||
|
|
||||||
const publishNewWatcherVersion = async (bondId: string) => {
|
const publishNewWatcherVersion = async (bondId: string) => {
|
||||||
watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
|
let watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
|
||||||
await registry.setRecord({ privateKey, record: watcher.record, bondId }, privateKey, fee);
|
await registry.setRecord({ privateKey, record: watcher.record, bondId }, privateKey, fee);
|
||||||
return watcher.record.version;
|
return watcher;
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
@@ -33,93 +23,119 @@ const bondTests = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Create bond.', async () => {
|
test('Create bond.', async () => {
|
||||||
bondId1 = await registry.getNextBondId(privateKey);
|
let bondId = await registry.getNextBondId(privateKey);
|
||||||
expect(bondId1).toBeDefined();
|
expect(bondId).toBeDefined();
|
||||||
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
|
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
|
||||||
})
|
|
||||||
|
|
||||||
test('Get bond by ID.', async () => {
|
|
||||||
const [bond] = await registry.getBondsByIds([bondId1]);
|
|
||||||
expect(bond).toBeDefined();
|
|
||||||
expect(bond.id).toBe(bondId1);
|
|
||||||
expect(bond.balance).toHaveLength(1);
|
|
||||||
expect(bond.balance[0]).toEqual({ type: 'aphoton', quantity: '1000000000' });
|
|
||||||
bondOwner = bond.owner;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Query bonds.', async () => {
|
describe('With bond created', () => {
|
||||||
const bonds = await registry.queryBonds();
|
let bond1: any
|
||||||
expect(bonds).toBeDefined();
|
|
||||||
const bond = bonds.filter((bond: any) => bond.id === bondId1);
|
|
||||||
expect(bond).toBeDefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Query bonds by owner.', async () => {
|
beforeAll(async () => {
|
||||||
const bonds = await registry.queryBonds({ owner: bondOwner });
|
let bondId1 = await registry.getNextBondId(privateKey);
|
||||||
expect(bonds).toBeDefined();
|
expect(bondId1).toBeDefined();
|
||||||
const bond = bonds.filter((bond: any) => bond.id === bondId1);
|
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
|
||||||
expect(bond).toBeDefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Refill bond.', async () => {
|
[bond1] = await registry.getBondsByIds([bondId1]);
|
||||||
await registry.refillBond({ id: bondId1, denom: 'aphoton', amount: '500' }, privateKey, fee);
|
expect(bond1).toBeDefined();
|
||||||
|
expect(bond1.id).toEqual(bondId1);
|
||||||
|
});
|
||||||
|
|
||||||
const [bond] = await registry.getBondsByIds([bondId1]);
|
test('Get bond by ID.', async () => {
|
||||||
expect(bond).toBeDefined();
|
const [bond] = await registry.getBondsByIds([bond1.id]);
|
||||||
expect(bond.id).toBe(bondId1);
|
expect(bond).toBeDefined();
|
||||||
expect(bond.balance).toHaveLength(1);
|
expect(bond.id).toBe(bond1.id);
|
||||||
expect(bond.balance[0]).toEqual({ type: 'aphoton', quantity: '1000000500' });
|
expect(bond.balance).toHaveLength(1);
|
||||||
});
|
expect(bond.balance[0]).toEqual({ type: 'aphoton', quantity: '1000000000' });
|
||||||
|
});
|
||||||
|
|
||||||
test('Withdraw bond.', async () => {
|
test('Query bonds.', async () => {
|
||||||
await registry.withdrawBond({ id: bondId1, denom: 'aphoton', amount: '500' }, privateKey, fee);
|
const bonds = await registry.queryBonds();
|
||||||
|
expect(bonds).toBeDefined();
|
||||||
|
const bond = bonds.filter((bond: any) => bond.id === bond1.id);
|
||||||
|
expect(bond).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
const [bond] = await registry.getBondsByIds([bondId1]);
|
test('Query bonds by owner.', async () => {
|
||||||
expect(bond).toBeDefined();
|
const bonds = await registry.queryBonds({ owner: bond1.owner });
|
||||||
expect(bond.id).toBe(bondId1);
|
expect(bonds).toBeDefined();
|
||||||
expect(bond.balance).toHaveLength(1);
|
const bond = bonds.filter((bond: any) => bond.id === bond1.id);
|
||||||
expect(bond.balance[0]).toEqual({ type: 'aphoton', quantity: '1000000000' });
|
expect(bond).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Cancel bond.', async () => {
|
test('Refill bond.', async () => {
|
||||||
await registry.cancelBond({ id: bondId1 }, privateKey, fee);
|
await registry.refillBond({ id: bond1.id, denom: 'aphoton', amount: '500' }, privateKey, fee);
|
||||||
|
|
||||||
|
const [bond] = await registry.getBondsByIds([bond1.id]);
|
||||||
|
expect(bond).toBeDefined();
|
||||||
|
expect(bond.id).toBe(bond1.id);
|
||||||
|
expect(bond.balance).toHaveLength(1);
|
||||||
|
expect(bond.balance[0]).toEqual({ type: 'aphoton', quantity: '1000000500' });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Withdraw bond.', async () => {
|
||||||
|
await registry.withdrawBond({ id: bond1.id, denom: 'aphoton', amount: '500' }, privateKey, fee);
|
||||||
|
|
||||||
|
const [bond] = await registry.getBondsByIds([bond1.id]);
|
||||||
|
expect(bond).toBeDefined();
|
||||||
|
expect(bond.id).toBe(bond1.id);
|
||||||
|
expect(bond.balance).toHaveLength(1);
|
||||||
|
expect(bond.balance[0]).toEqual({ type: 'aphoton', quantity: '1000000000' });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Cancel bond.', async () => {
|
||||||
|
await registry.cancelBond({ id: bond1.id }, privateKey, fee);
|
||||||
|
|
||||||
|
const [bond] = await registry.getBondsByIds([bond1.id]);
|
||||||
|
expect(bond.id).toBe("");
|
||||||
|
expect(bond.owner).toBe("");
|
||||||
|
expect(bond.balance).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
const [bond] = await registry.getBondsByIds([bondId1]);
|
|
||||||
expect(bond.id).toBe("");
|
|
||||||
expect(bond.owner).toBe("");
|
|
||||||
expect(bond.balance).toHaveLength(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Associate/Dissociate bond.', async () => {
|
test('Associate/Dissociate bond.', async () => {
|
||||||
|
let bondId1: string;
|
||||||
|
|
||||||
bondId1 = await registry.getNextBondId(privateKey);
|
bondId1 = await registry.getNextBondId(privateKey);
|
||||||
expect(bondId1).toBeDefined();
|
expect(bondId1).toBeDefined();
|
||||||
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
|
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
|
||||||
|
|
||||||
// Create a new record.
|
// Create a new record.
|
||||||
version1 = await publishNewWatcherVersion(bondId1);
|
let watcher = await publishNewWatcherVersion(bondId1);
|
||||||
let [record1] = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
|
let query = { type: watcher.record.type, url: watcher.record.url, version: watcher.record.version };
|
||||||
|
let [record1] = await registry.queryRecords(query, true);
|
||||||
expect(record1.bondId).toBe(bondId1);
|
expect(record1.bondId).toBe(bondId1);
|
||||||
|
|
||||||
// Dissociate record, query and confirm.
|
// Dissociate record, query and confirm.
|
||||||
await registry.dissociateBond({ recordId: record1.id }, privateKey, fee);
|
await registry.dissociateBond({ recordId: record1.id }, privateKey, fee);
|
||||||
[record1] = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
|
[record1] = await registry.queryRecords(query, true);
|
||||||
expect(record1.bondId).toBe('');
|
expect(record1.bondId).toBe('');
|
||||||
|
|
||||||
// Associate record with bond, query and confirm.
|
// Associate record with bond, query and confirm.
|
||||||
await registry.associateBond({ recordId: record1.id, bondId: bondId1 }, privateKey, fee);
|
await registry.associateBond({ recordId: record1.id, bondId: bondId1 }, privateKey, fee);
|
||||||
[record1] = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
|
[record1] = await registry.queryRecords(query, true);
|
||||||
expect(record1.bondId).toBe(bondId1);
|
expect(record1.bondId).toBe(bondId1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Reassociate/Dissociate records.', async () => {
|
test('Reassociate/Dissociate records.', async () => {
|
||||||
|
let bondId1: string;
|
||||||
|
let bondId2: string;
|
||||||
|
|
||||||
|
bondId1 = await registry.getNextBondId(privateKey);
|
||||||
|
expect(bondId1).toBeDefined();
|
||||||
|
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
|
||||||
|
|
||||||
// Create a new record version.
|
// Create a new record version.
|
||||||
version2 = await publishNewWatcherVersion(bondId1);
|
let watcher = await publishNewWatcherVersion(bondId1);
|
||||||
|
let queryv1 = { type: watcher.record.type, url: watcher.record.url, version: watcher.record.version };
|
||||||
|
let queryv2 = { type: watcher.record.type, url: watcher.record.url, version: watcher.record.version };
|
||||||
|
|
||||||
// Check version1, version2 as associated with bondId1.
|
// Check version1, version2 as associated with bondId1.
|
||||||
let records;
|
let records;
|
||||||
records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
|
records = await registry.queryRecords(queryv1, true);
|
||||||
expect(records[0].bondId).toBe(bondId1);
|
expect(records[0].bondId).toBe(bondId1);
|
||||||
records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version2 }, true);
|
records = await registry.queryRecords(queryv2, true);
|
||||||
expect(records[0].bondId).toBe(bondId1);
|
expect(records[0].bondId).toBe(bondId1);
|
||||||
|
|
||||||
// Create another bond.
|
// Create another bond.
|
||||||
@@ -131,16 +147,16 @@ const bondTests = () => {
|
|||||||
|
|
||||||
// Reassociate records from bondId1 to bondId2, verify change.
|
// Reassociate records from bondId1 to bondId2, verify change.
|
||||||
await registry.reassociateRecords({ oldBondId: bondId1, newBondId: bondId2 }, privateKey, fee);
|
await registry.reassociateRecords({ oldBondId: bondId1, newBondId: bondId2 }, privateKey, fee);
|
||||||
records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
|
records = await registry.queryRecords(queryv1, true);
|
||||||
expect(records[0].bondId).toBe(bondId2);
|
expect(records[0].bondId).toBe(bondId2);
|
||||||
records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version2 }, true);
|
records = await registry.queryRecords(queryv2, true);
|
||||||
expect(records[0].bondId).toBe(bondId2);
|
expect(records[0].bondId).toBe(bondId2);
|
||||||
|
|
||||||
// Dissociate all records from bond, verify change.
|
// Dissociate all records from bond, verify change.
|
||||||
await registry.dissociateRecords({ bondId: bondId2 }, privateKey, fee);
|
await registry.dissociateRecords({ bondId: bondId2 }, privateKey, fee);
|
||||||
records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
|
records = await registry.queryRecords(queryv1, true);
|
||||||
expect(records[0].bondId).toBe('');
|
expect(records[0].bondId).toBe('');
|
||||||
records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version2 }, true);
|
records = await registry.queryRecords(queryv2, true);
|
||||||
expect(records[0].bondId).toBe('');
|
expect(records[0].bondId).toBe('');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
+3
-3
@@ -180,9 +180,9 @@ export class Registry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Publish record.
|
* Publish record.
|
||||||
* @param transactionPrivateKey - private key in HEX to sign transaction.
|
* @param transactionPrivateKey - private key in HEX to sign transaction.
|
||||||
*/
|
*/
|
||||||
async setRecord(
|
async setRecord(
|
||||||
params: { privateKey: string, record: any, bondId: string },
|
params: { privateKey: string, record: any, bondId: string },
|
||||||
transactionPrivateKey: string,
|
transactionPrivateKey: string,
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ const nameserviceExpiryTests = () => {
|
|||||||
test('Set record and check bond balance', async () => {
|
test('Set record and check bond balance', async () => {
|
||||||
// Create watcher.
|
// Create watcher.
|
||||||
watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
|
watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
|
||||||
await registry.setRecord(
|
const result = await registry.setRecord(
|
||||||
{
|
{
|
||||||
privateKey,
|
privateKey,
|
||||||
bondId,
|
bondId,
|
||||||
@@ -39,8 +39,8 @@ const nameserviceExpiryTests = () => {
|
|||||||
privateKey,
|
privateKey,
|
||||||
fee
|
fee
|
||||||
)
|
)
|
||||||
|
console.log("SetRecordResult: " + result.data.id)
|
||||||
const [record] = await registry.queryRecords({ type: 'watcher', version: watcher.record.version }, true);
|
const [record] = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }, true);
|
||||||
recordExpiryTime = new Date(record.expiryTime);
|
recordExpiryTime = new Date(record.expiryTime);
|
||||||
|
|
||||||
const [bond] = await registry.getBondsByIds([bondId]);
|
const [bond] = await registry.getBondsByIds([bondId]);
|
||||||
@@ -63,21 +63,22 @@ const nameserviceExpiryTests = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Check record expiry time', async() => {
|
test('Check record expiry time', async() => {
|
||||||
const [record] = await registry.queryRecords({ type: 'watcher', version: watcher.record.version }, true);
|
const [record] = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }, true);
|
||||||
const updatedExpiryTime = new Date(record.expiryTime);
|
const updatedExpiryTime = new Date();
|
||||||
expect(updatedExpiryTime.getTime()).toBeGreaterThan(recordExpiryTime.getTime());
|
expect(updatedExpiryTime.getTime()).toBeGreaterThan(recordExpiryTime.getTime());
|
||||||
recordExpiryTime = updatedExpiryTime;
|
recordExpiryTime = updatedExpiryTime;
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Check authority expiry time', async() => {
|
test('Check authority expiry time', async() => {
|
||||||
const [authority] = await registry.lookupAuthorities([authorityName]);
|
const [authority] = await registry.lookupAuthorities([authorityName]);
|
||||||
const updatedExpiryTime = new Date(authority.expiryTime);
|
const updatedExpiryTime = new Date();
|
||||||
expect(updatedExpiryTime.getTime()).toBeGreaterThan(authorityExpiryTime.getTime());
|
expect(updatedExpiryTime.getTime()).toBeGreaterThan(authorityExpiryTime.getTime());
|
||||||
authorityExpiryTime = updatedExpiryTime;
|
authorityExpiryTime = updatedExpiryTime;
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Check bond balance', async () => {
|
test('Check bond balance', async () => {
|
||||||
const [bond] = await registry.getBondsByIds([bondId]);
|
const [bond] = await registry.getBondsByIds([bondId]);
|
||||||
|
console.log(bond)
|
||||||
expect(bond).toBeDefined();
|
expect(bond).toBeDefined();
|
||||||
expect(bond.balance).toHaveLength(0);
|
expect(bond.balance).toHaveLength(0);
|
||||||
})
|
})
|
||||||
@@ -87,7 +88,7 @@ const nameserviceExpiryTests = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Check record deleted without bond balance', async() => {
|
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);
|
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:
|
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:
|
Run tests:
|
||||||
|
|||||||
+228
-184
@@ -18,18 +18,12 @@ const namingTests = () => {
|
|||||||
let watcher: any;
|
let watcher: any;
|
||||||
let watcherId: string;
|
let watcherId: string;
|
||||||
|
|
||||||
let authorityName: string;
|
|
||||||
let otherAuthorityName: string;
|
|
||||||
let otherPrivateKey: string;
|
|
||||||
|
|
||||||
let crn: string;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||||
|
|
||||||
// Create bond.
|
// Create bond.
|
||||||
bondId = await registry.getNextBondId(privateKey);
|
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.
|
// Create watcher.
|
||||||
watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
|
watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
|
||||||
@@ -46,221 +40,271 @@ const namingTests = () => {
|
|||||||
watcherId = result.data.id;
|
watcherId = result.data.id;
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Reserve authority.', async () => {
|
describe('Authority tests', () => {
|
||||||
authorityName = `laconic-${Date.now()}`;
|
test('Reserve authority.', async () => {
|
||||||
await registry.reserveAuthority({ name: authorityName }, privateKey, fee);
|
const authorityName = `laconic-${Date.now()}`;
|
||||||
|
|
||||||
|
await registry.reserveAuthority({ name: authorityName }, privateKey, fee);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('With authority reserved', () => {
|
||||||
|
let authorityName: string;
|
||||||
|
let crn: string;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
authorityName = `laconic-${Date.now()}`;
|
||||||
|
crn = `crn://${authorityName}/app/test`;
|
||||||
|
|
||||||
|
await registry.reserveAuthority({ name: authorityName }, privateKey, fee);
|
||||||
|
})
|
||||||
|
|
||||||
|
test('Lookup authority.', async () => {
|
||||||
|
const [record] = await registry.lookupAuthorities([authorityName]);
|
||||||
|
|
||||||
|
expect(record).toBeDefined();
|
||||||
|
expect(record.ownerAddress).not.toBe('');
|
||||||
|
expect(record.ownerPublicKey).not.toBe('');
|
||||||
|
expect(Number(record.height)).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Lookup non existing authority', async () => {
|
||||||
|
const [record] = await registry.lookupAuthorities(['does-not-exist']);
|
||||||
|
|
||||||
|
expect(record.ownerAddress).toBe('');
|
||||||
|
expect(record.ownerPublicKey).toBe('');
|
||||||
|
expect(Number(record.height)).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Reserve already reserved authority', async () => {
|
||||||
|
await expect(registry.reserveAuthority({ name: authorityName }, privateKey, fee)).
|
||||||
|
rejects.toThrow('Name already reserved.');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Reserve sub-authority.', async () => {
|
||||||
|
const subAuthority = `echo.${authorityName}`;
|
||||||
|
await registry.reserveAuthority({ name: subAuthority }, privateKey, fee);
|
||||||
|
|
||||||
|
const [record] = await registry.lookupAuthorities([subAuthority]);
|
||||||
|
expect(record).toBeDefined();
|
||||||
|
expect(record.ownerAddress).not.toBe('');
|
||||||
|
expect(record.ownerPublicKey).not.toBe('');
|
||||||
|
expect(Number(record.height)).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Reserve sub-authority with different owner.', async () => {
|
||||||
|
// Create another account, send tx to set public key on the account.
|
||||||
|
const mnenonic1 = Account.generateMnemonic();
|
||||||
|
const otherAccount1 = await Account.generateFromMnemonic(mnenonic1);
|
||||||
|
await registry.sendCoins({ denom: 'aphoton', amount: '1000000000', destinationAddress: otherAccount1.formattedCosmosAddress }, privateKey, fee);
|
||||||
|
|
||||||
|
const mnenonic2 = Account.generateMnemonic();
|
||||||
|
const otherAccount2 = await Account.generateFromMnemonic(mnenonic2);
|
||||||
|
await registry.sendCoins({ denom: 'aphoton', amount: '10', destinationAddress: otherAccount2.formattedCosmosAddress }, otherAccount1.getPrivateKey(), fee);
|
||||||
|
|
||||||
|
const subAuthority = `halo.${authorityName}`;
|
||||||
|
await registry.reserveAuthority({ name: subAuthority, owner: otherAccount1.formattedCosmosAddress }, privateKey, fee);
|
||||||
|
|
||||||
|
const [record] = await registry.lookupAuthorities([subAuthority]);
|
||||||
|
expect(record).toBeDefined();
|
||||||
|
expect(record.ownerAddress).toBeDefined();
|
||||||
|
expect(record.ownerAddress).toBe(otherAccount1.getCosmosAddress());
|
||||||
|
expect(record.ownerPublicKey).toBeDefined();
|
||||||
|
expect(Number(record.height)).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Set name for unbonded authority', async () => {
|
||||||
|
assert(watcherId)
|
||||||
|
await expect(registry.setName({ crn, cid: watcherId }, privateKey, fee)).
|
||||||
|
rejects.toThrow('Authority bond not found.');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Set authority bond', async () => {
|
||||||
|
await registry.setAuthorityBond({ name: authorityName, bondId }, privateKey, fee);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Lookup authority.', async () => {
|
describe('Naming tests', () => {
|
||||||
const [record] = await registry.lookupAuthorities([authorityName]);
|
let authorityName: string;
|
||||||
|
let otherAuthorityName: string;
|
||||||
|
let otherPrivateKey: string;
|
||||||
|
let otherAccount: Account;
|
||||||
|
|
||||||
expect(record).toBeDefined();
|
beforeAll(async () => {
|
||||||
expect(record.ownerAddress).not.toBe('');
|
authorityName = `laconic-${Date.now()}`;
|
||||||
expect(record.ownerPublicKey).not.toBe('');
|
|
||||||
expect(Number(record.height)).toBeGreaterThan(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Lookup non existing authority', async () => {
|
await registry.reserveAuthority({ name: authorityName }, privateKey, fee);
|
||||||
const [record] = await registry.lookupAuthorities(['does-not-exist']);
|
await registry.setAuthorityBond({ name: authorityName, bondId }, privateKey, fee);
|
||||||
|
|
||||||
expect(record.ownerAddress).toBe('');
|
// Create another account.
|
||||||
expect(record.ownerPublicKey).toBe('');
|
const mnenonic = Account.generateMnemonic();
|
||||||
expect(Number(record.height)).toBe(0);
|
otherAccount = await Account.generateFromMnemonic(mnenonic);
|
||||||
});
|
await registry.sendCoins({ denom: 'aphoton', amount: '1000000000', destinationAddress: otherAccount.formattedCosmosAddress }, privateKey, fee);
|
||||||
|
|
||||||
test('Reserve already reserved authority', async () => {
|
otherAuthorityName = `other-${Date.now()}`;
|
||||||
await expect(registry.reserveAuthority({ name: authorityName }, privateKey, fee)).rejects.toThrow('Name already reserved.');
|
otherPrivateKey = otherAccount.privateKey.toString('hex');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Reserve sub-authority.', async () => {
|
test('Set name', async () => {
|
||||||
const subAuthority = `echo.${authorityName}`;
|
const crn = `crn://${authorityName}/app/test1`;
|
||||||
await registry.reserveAuthority({ name: subAuthority }, privateKey, fee);
|
|
||||||
|
|
||||||
const [record] = await registry.lookupAuthorities([subAuthority]);
|
await registry.setName({ crn, cid: watcherId }, privateKey, fee);
|
||||||
expect(record).toBeDefined();
|
|
||||||
expect(record.ownerAddress).not.toBe('');
|
|
||||||
expect(record.ownerPublicKey).not.toBe('');
|
|
||||||
expect(Number(record.height)).toBeGreaterThan(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Reserve sub-authority with different owner.', async () => {
|
// Query records should return it (some CRN points to it).
|
||||||
// Create another account, send tx to set public key on the account.
|
const records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version });
|
||||||
const mnenonic1 = Account.generateMnemonic();
|
expect(records).toBeDefined();
|
||||||
const otherAccount1 = await Account.generateFromMnemonic(mnenonic1);
|
expect(records).toHaveLength(1);
|
||||||
await registry.sendCoins({ denom: 'aphoton', amount: '1000000000', destinationAddress: otherAccount1.formattedCosmosAddress }, privateKey, fee);
|
|
||||||
|
|
||||||
const mnenonic2 = Account.generateMnemonic();
|
await registry.deleteName({ crn }, privateKey, fee);
|
||||||
const otherAccount2 = await Account.generateFromMnemonic(mnenonic2);
|
});
|
||||||
await registry.sendCoins({ denom: 'aphoton', amount: '10', destinationAddress: otherAccount2.formattedCosmosAddress }, otherAccount1.getPrivateKey(), fee);
|
|
||||||
|
|
||||||
const subAuthority = `halo.${authorityName}`;
|
describe('With name set', () => {
|
||||||
await registry.reserveAuthority({ name: subAuthority, owner: otherAccount1.formattedCosmosAddress }, privateKey, fee);
|
let crn: string;
|
||||||
|
|
||||||
const [record] = await registry.lookupAuthorities([subAuthority]);
|
beforeAll(async () => {
|
||||||
expect(record).toBeDefined();
|
crn = `crn://${authorityName}/app/test2`;
|
||||||
expect(record.ownerAddress).toBeDefined();
|
await registry.setName({ crn, cid: watcherId }, privateKey, fee);
|
||||||
expect(record.ownerAddress).toBe(otherAccount1.getCosmosAddress());
|
});
|
||||||
expect(record.ownerPublicKey).toBeDefined();
|
|
||||||
expect(Number(record.height)).toBeGreaterThan(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Set name for unbonded authority', async () => {
|
afterAll(async () => {
|
||||||
crn = `crn://${authorityName}/app/test`;
|
await registry.deleteName({ crn }, privateKey, fee);
|
||||||
assert(watcherId)
|
});
|
||||||
await expect(registry.setName({ crn, cid: watcherId }, privateKey, fee)).rejects.toThrow('Authority bond not found.');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Set authority bond', async () => {
|
test('Lookup name', async () => {
|
||||||
await registry.setAuthorityBond({ name: authorityName, bondId }, privateKey, fee);
|
const records = await registry.lookupNames([crn]);
|
||||||
});
|
expect(records).toBeDefined();
|
||||||
|
expect(records).toHaveLength(1);
|
||||||
|
|
||||||
test('Set name', async () => {
|
const [{ latest, history }] = records;
|
||||||
crn = `crn://${authorityName}/app/test`;
|
expect(latest).toBeDefined();
|
||||||
await registry.setName({ crn, cid: watcherId }, privateKey, fee);
|
expect(latest.id).toBeDefined();
|
||||||
|
expect(latest.id).toBe(watcherId);
|
||||||
|
expect(latest.height).toBeDefined();
|
||||||
|
expect(history).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
// Query records should return it (some CRN points to it).
|
test('Resolve name', async () => {
|
||||||
const records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version });
|
const records = await registry.resolveNames([crn]);
|
||||||
expect(records).toBeDefined();
|
expect(records).toBeDefined();
|
||||||
expect(records).toHaveLength(1);
|
expect(records).toHaveLength(1);
|
||||||
});
|
|
||||||
|
|
||||||
test('Lookup name', async () => {
|
const [{ attributes }] = records;
|
||||||
const records = await registry.lookupNames([crn]);
|
expect(attributes).toEqual(watcher.record);
|
||||||
expect(records).toBeDefined();
|
});
|
||||||
expect(records).toHaveLength(1);
|
|
||||||
|
|
||||||
const [{ latest, history }] = records;
|
test('Lookup name with history', async () => {
|
||||||
expect(latest).toBeDefined();
|
const updatedWatcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
|
||||||
expect(latest.id).toBeDefined();
|
const result = await registry.setRecord(
|
||||||
expect(latest.id).toBe(watcherId);
|
{
|
||||||
expect(latest.height).toBeDefined();
|
privateKey,
|
||||||
expect(history).toBeUndefined();
|
bondId,
|
||||||
});
|
record: updatedWatcher.record
|
||||||
|
},
|
||||||
|
privateKey,
|
||||||
|
fee
|
||||||
|
)
|
||||||
|
|
||||||
test('Resolve name', async () => {
|
const updatedWatcherId = result.data.id;
|
||||||
const records = await registry.resolveNames([crn]);
|
await registry.setName({ crn, cid: updatedWatcherId }, privateKey, fee);
|
||||||
expect(records).toBeDefined();
|
|
||||||
expect(records).toHaveLength(1);
|
|
||||||
|
|
||||||
const [{ attributes }] = records;
|
const records = await registry.lookupNames([crn], true);
|
||||||
expect(attributes).toEqual(watcher.record);
|
expect(records).toHaveLength(1);
|
||||||
});
|
|
||||||
|
|
||||||
test('Lookup name with history', async () => {
|
const [{ latest, history }] = records;
|
||||||
const updatedWatcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
|
expect(latest).toBeDefined();
|
||||||
const result = await registry.setRecord(
|
expect(latest.id).toBeDefined();
|
||||||
{
|
expect(latest.id).toBe(updatedWatcherId);
|
||||||
privateKey,
|
expect(latest.height).toBeDefined();
|
||||||
bondId,
|
expect(history).toBeDefined();
|
||||||
record: updatedWatcher.record
|
expect(history).toHaveLength(1);
|
||||||
},
|
|
||||||
privateKey,
|
|
||||||
fee
|
|
||||||
)
|
|
||||||
|
|
||||||
const updatedWatcherId = result.data.id;
|
const [oldRecord] = history;
|
||||||
await registry.setName({ crn, cid: updatedWatcherId }, privateKey, fee);
|
expect(oldRecord).toBeDefined();
|
||||||
|
expect(oldRecord.id).toBeDefined();
|
||||||
|
expect(oldRecord.id).toBe(watcherId);
|
||||||
|
expect(oldRecord.height).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
const records = await registry.lookupNames([crn], true);
|
test('Delete name', async () => {
|
||||||
expect(records).toHaveLength(1);
|
await registry.deleteName({ crn }, privateKey, fee);
|
||||||
|
|
||||||
const [{ latest, history }] = records;
|
let records = await registry.lookupNames([crn], true);
|
||||||
expect(latest).toBeDefined();
|
expect(records).toBeDefined();
|
||||||
expect(latest.id).toBeDefined();
|
expect(records).toHaveLength(1);
|
||||||
expect(latest.id).toBe(updatedWatcherId);
|
|
||||||
expect(latest.height).toBeDefined();
|
|
||||||
expect(history).toBeDefined();
|
|
||||||
expect(history).toHaveLength(1);
|
|
||||||
|
|
||||||
const [oldRecord] = history;
|
const [{ latest }] = records;
|
||||||
expect(oldRecord).toBeDefined();
|
expect(latest).toBeDefined();
|
||||||
expect(oldRecord.id).toBeDefined();
|
expect(latest.id).toBeDefined();
|
||||||
expect(oldRecord.id).toBe(watcherId);
|
expect(latest.id).toBe('');
|
||||||
expect(oldRecord.height).toBeDefined();
|
expect(latest.height).toBeDefined();
|
||||||
});
|
|
||||||
|
|
||||||
test('Set name without reserving authority', async () => {
|
// Query records should NOT return it (no CRN points to it).
|
||||||
await expect(registry.setName({ crn: 'crn://not-reserved/app/test', cid: watcherId }, privateKey, fee))
|
records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version });
|
||||||
.rejects.toThrow('Name authority not found.');
|
expect(records).toBeDefined();
|
||||||
});
|
expect(records).toHaveLength(0);
|
||||||
|
|
||||||
test('Set name for non-owned authority', async () => {
|
// Query all records should return it (all: true).
|
||||||
// Create another account.
|
records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }, true);
|
||||||
const mnenonic = Account.generateMnemonic();
|
expect(records).toBeDefined();
|
||||||
const otherAccount = await Account.generateFromMnemonic(mnenonic);
|
expect(records).toHaveLength(1);
|
||||||
await registry.sendCoins({ denom: 'aphoton', amount: '1000000000', destinationAddress: otherAccount.formattedCosmosAddress }, privateKey, fee);
|
});
|
||||||
|
|
||||||
// Other account reserves an authority.
|
test('Delete already deleted name', async () => {
|
||||||
otherAuthorityName = `other-${Date.now()}`;
|
await registry.deleteName({ crn }, privateKey, fee);
|
||||||
otherPrivateKey = otherAccount.privateKey.toString('hex');
|
await registry.deleteName({ crn }, privateKey, fee);
|
||||||
await registry.reserveAuthority({ name: otherAuthorityName }, otherPrivateKey, fee);
|
|
||||||
|
|
||||||
// Try setting name under other authority.
|
const records = await registry.lookupNames([crn], true);
|
||||||
await expect(registry.setName({ crn: `crn://${otherAuthorityName}/app/test`, cid: watcherId }, privateKey, fee)).rejects.toThrow('Access denied.');
|
expect(records).toBeDefined();
|
||||||
});
|
expect(records).toHaveLength(1);
|
||||||
|
|
||||||
test('Lookup non existing name', async () => {
|
const [{ latest }] = records;
|
||||||
const records = await registry.lookupNames(['crn://not-reserved/app/test']);
|
expect(latest).toBeDefined();
|
||||||
expect(records).toBeDefined();
|
expect(latest.id).toBeDefined();
|
||||||
expect(records).toHaveLength(1);
|
expect(latest.id).toBe('');
|
||||||
const [record] = records;
|
expect(latest.height).toBeDefined();
|
||||||
expect(record).toBeNull();
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Resolve non existing name', async () => {
|
test('Set name without reserving authority', async () => {
|
||||||
const records = await registry.resolveNames(['crn://not-reserved/app/test']);
|
await expect(registry.setName({ crn: 'crn://not-reserved/app/test', cid: watcherId }, privateKey, fee))
|
||||||
expect(records).toBeDefined();
|
.rejects.toThrow('Name authority not found.');
|
||||||
expect(records).toHaveLength(1);
|
});
|
||||||
const [record] = records;
|
|
||||||
expect(record).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Delete name', async () => {
|
test('Set name for non-owned authority', async () => {
|
||||||
await registry.deleteName({ crn }, privateKey, fee);
|
await registry.sendCoins({ denom: 'aphoton', amount: '1000000000', destinationAddress: otherAccount.formattedCosmosAddress }, privateKey, fee);
|
||||||
|
|
||||||
let records = await registry.lookupNames([crn], true);
|
// Other account reserves an authority.
|
||||||
expect(records).toBeDefined();
|
await registry.reserveAuthority({ name: otherAuthorityName }, otherPrivateKey, fee);
|
||||||
expect(records).toHaveLength(1);
|
|
||||||
|
|
||||||
const [{ latest }] = records;
|
// Try setting name under other authority.
|
||||||
expect(latest).toBeDefined();
|
await expect(registry.setName({ crn: `crn://${otherAuthorityName}/app/test`, cid: watcherId }, privateKey, fee)).rejects.toThrow('Access denied.');
|
||||||
expect(latest.id).toBeDefined();
|
});
|
||||||
expect(latest.id).toBe('');
|
|
||||||
expect(latest.height).toBeDefined();
|
|
||||||
|
|
||||||
// Query records should NOT return it (no CRN points to it).
|
test('Delete name for non-owned authority.', async () => {
|
||||||
records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version });
|
const otherBondId = await registry.getNextBondId(otherPrivateKey);
|
||||||
expect(records).toBeDefined();
|
await registry.createBond({ denom: 'aphoton', amount: '10000' }, otherPrivateKey, fee);
|
||||||
expect(records).toHaveLength(0);
|
await registry.setAuthorityBond({ name: otherAuthorityName, bondId: otherBondId }, otherPrivateKey, fee);
|
||||||
|
await registry.setName({ crn: `crn://${otherAuthorityName}/app/test`, cid: watcherId }, otherPrivateKey, fee);
|
||||||
|
|
||||||
// Query all records should return it (all: true).
|
// Try deleting name under other authority.
|
||||||
records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }, true);
|
await expect(registry.deleteName({ crn: `crn://${otherAuthorityName}/app/test` }, privateKey, fee)).rejects.toThrow('Access denied.');
|
||||||
expect(records).toBeDefined();
|
});
|
||||||
expect(records).toHaveLength(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Delete already deleted name', async () => {
|
test('Lookup non existing name', async () => {
|
||||||
await registry.deleteName({ crn }, privateKey, fee);
|
const records = await registry.lookupNames(['crn://not-reserved/app/test']);
|
||||||
|
expect(records).toBeDefined();
|
||||||
|
expect(records).toHaveLength(1);
|
||||||
|
const [record] = records;
|
||||||
|
expect(record).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
const records = await registry.lookupNames([crn], true);
|
test('Resolve non existing name', async () => {
|
||||||
expect(records).toBeDefined();
|
const records = await registry.resolveNames(['crn://not-reserved/app/test']);
|
||||||
expect(records).toHaveLength(1);
|
expect(records).toBeDefined();
|
||||||
|
expect(records).toHaveLength(1);
|
||||||
const [{ latest }] = records;
|
const [record] = records;
|
||||||
expect(latest).toBeDefined();
|
expect(record).toBeNull();
|
||||||
expect(latest.id).toBeDefined();
|
});
|
||||||
expect(latest.id).toBe('');
|
|
||||||
expect(latest.height).toBeDefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Delete name for non-owned authority.', async () => {
|
|
||||||
const otherBondId = await registry.getNextBondId(otherPrivateKey);
|
|
||||||
await registry.createBond({ denom: 'aphoton', amount: '10000' }, otherPrivateKey, fee);
|
|
||||||
await registry.setAuthorityBond({ name: otherAuthorityName, bondId: otherBondId }, otherPrivateKey, fee);
|
|
||||||
await registry.setName({ crn: `crn://${otherAuthorityName}/app/test`, cid: watcherId }, otherPrivateKey, fee);
|
|
||||||
|
|
||||||
// Try deleting name under other authority.
|
|
||||||
await expect(registry.deleteName({ crn: `crn://${otherAuthorityName}/app/test` }, privateKey, fee)).rejects.toThrow('Access denied.');
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,4 +4,4 @@ record:
|
|||||||
repo_registration_record_cid: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
|
repo_registration_record_cid: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
|
||||||
build_artifact_cid: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
|
build_artifact_cid: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
|
||||||
tls_cert_cid: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
|
tls_cert_cid: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
|
||||||
version: 1.0.17
|
version: 1.0.23
|
||||||
|
|||||||
+12
-7
@@ -24,13 +24,18 @@ export const getBaseConfig = async (path: string) => {
|
|||||||
* Provision a bond for record registration.
|
* Provision a bond for record registration.
|
||||||
*/
|
*/
|
||||||
export const provisionBondId = async (registry: Registry, privateKey: string, fee: Fee) => {
|
export const provisionBondId = async (registry: Registry, privateKey: string, fee: Fee) => {
|
||||||
let bonds = await registry.queryBonds();
|
// let bonds = await registry.queryBonds();
|
||||||
if (!bonds.length) {
|
// console.log("found bonds: " + bonds.length)
|
||||||
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
|
// if (!bonds.length) {
|
||||||
bonds = await registry.queryBonds();
|
// await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
|
||||||
}
|
// bonds = await registry.queryBonds();
|
||||||
|
// console.log("created bond and got back: " + bonds.length)
|
||||||
return bonds[0].id;
|
// }
|
||||||
|
let bondId: string;
|
||||||
|
bondId = await registry.getNextBondId(privateKey);
|
||||||
|
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
|
||||||
|
return bondId
|
||||||
|
//return bonds[0].id;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getConfig = () => {
|
export const getConfig = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user