Compare commits

..

6 Commits

Author SHA1 Message Date
66a9b6a4b5 rm debugs 2023-10-20 01:47:11 -05:00
ebe80aba78 protobuf query update 2023-10-20 01:20:01 -05:00
0e57f2fc8f graphql schema update 2023-10-20 01:20:01 -05:00
5562d9f985 combine proto scripts 2023-09-25 19:43:44 +08:00
a6d7d230d9 remove hard-coded record types 2023-09-21 19:42:24 +08:00
c0ac805601 add missing proto files 2023-09-13 23:48:48 +08:00
38 changed files with 407 additions and 453 deletions

View File

@ -1,2 +0,0 @@
Dockerfile
node_modules

View File

@ -7,16 +7,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 18.x ]
node-version: [ 16.x ]
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Download yarn
run: |
curl -fsSL -o /usr/local/bin/yarn https://github.com/yarnpkg/yarn/releases/download/v1.22.21/yarn-1.22.21.js
chmod +x /usr/local/bin/yarn
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
@ -30,7 +26,7 @@ jobs:
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.CICD_PUBLISH_TOKEN }}"
npm config set -- '//git.vdb.to/api/packages/cerc-io/npm/:_authToken' "${{ secrets.GITEA_PUBLISH_TOKEN }}"
- name: npm publish
run: |
npm publish

View File

@ -25,39 +25,57 @@ jobs:
ref: main
- name: Environment
run: ls -tlh && env
- name: Start dockerd
run: |
dockerd -H $DOCKER_HOST --userland-proxy=false &
sleep 5
- name: Build laconicd container
- name: build containers scripts
working-directory: laconicd/tests/sdk_tests
run: ./build-laconicd-container.sh
- name: Build laconic-sdk container
run: ./scripts/build-sdk-test-container.sh
- name: Start containers
- 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 tests
- name: run basic tests
working-directory: laconicd/tests/sdk_tests
run: ./run-tests.sh
- name: Start containers (auctions enabled)
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
env:
TEST_AUCTION_ENABLED: true
run: docker compose up -d
- name: Run auction tests
run: docker compose down
- name: start auction containers
working-directory: laconicd/tests/sdk_tests
run: ./run-tests.sh test:auctions
- name: Start containers (expiry enabled)
run: docker compose -f docker-compose-auctions.yml up -d
- name: run auction tests
working-directory: laconicd/tests/sdk_tests
env:
TEST_REGISTRY_EXPIRY: true
run: docker compose up -d
- name: Run nameservice expiry 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: ./run-tests.sh test:nameservice-expiry
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

View File

@ -20,34 +20,53 @@ jobs:
ref: main
- name: Environment
run: ls -tlh && env
- name: Build laconicd container
- name: build containers scripts
working-directory: laconicd/tests/sdk_tests
run: ./build-laconicd-container.sh
- name: Build laconic-sdk container
run: ./scripts/build-sdk-test-container.sh
- name: Start containers
- 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 tests
- name: run basic tests
working-directory: laconicd/tests/sdk_tests
run: ./run-tests.sh
- name: Start containers (auctions enabled)
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
env:
TEST_AUCTION_ENABLED: true
run: docker compose up -d
- name: Run auction tests
run: docker compose down
- name: start auction containers
working-directory: laconicd/tests/sdk_tests
run: ./run-tests.sh test:auctions
- name: Start containers (expiry enabled)
run: docker compose -f docker-compose-auctions.yml up -d
- name: run auction tests
working-directory: laconicd/tests/sdk_tests
env:
TEST_REGISTRY_EXPIRY: true
run: docker compose up -d
- name: Run nameservice expiry 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: ./run-tests.sh test:nameservice-expiry
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

View File

@ -12,5 +12,13 @@ Run following scripts when [proto files](./proto/) are updated.
2. Generate typescript code for the proto files
```bash
./scripts/proto-gen.sh
./scripts/create-proto-files.sh
```
3. Remove GRPC code from generated code
```bash
./scripts/remove-grpc.sh
```
Reference: https://github.com/tharsis/evmosjs/tree/main/packages/proto#note

View File

@ -21,18 +21,34 @@ RUN \
&& 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" \
&& 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
WORKDIR /app/laconic-sdk
COPY package*.json .
# Temp hack, clone the laconic-sdk repo here
WORKDIR /app
RUN yarn install
COPY . .
WORKDIR /app/laconic-sdk

View File

@ -34,12 +34,6 @@ Follow these steps to run the tests:
- Run the tests with auctions enabled
- Remove laconicd data from previous run
```bash
rm -rf ~/.laconicd
```
- In laconicd repo run:
```bash
@ -60,12 +54,6 @@ Follow these steps to run the tests:
- Run the tests for record and authority expiry
- Remove laconicd data from previous run
```bash
rm -rf ~/.laconicd
```
- In laconicd repo run:
```bash

View File

@ -1,6 +1,6 @@
{
"name": "@cerc-io/laconic-sdk",
"version": "0.1.16",
"version": "0.1.6",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"repository": "git@github.com:cerc-io/laconic-sdk.git",
@ -14,7 +14,7 @@
"dotenv": "^16.0.0",
"google-protobuf": "^3.21.0",
"jest": "29.0.0",
"protoc-gen-ts": "^0.8.7",
"protoc-gen-ts": "^0.8.5",
"ts-jest": "^29.0.2",
"typescript": "^4.6.2"
},
@ -48,7 +48,7 @@
"tiny-secp256k1": "^1.1.6"
},
"scripts": {
"test": "jest --runInBand --verbose --testPathPattern=src",
"test": "jest --runInBand --verbose",
"test:auctions": "TEST_AUCTIONS_ENABLED=1 jest --runInBand --verbose src/auction.test.ts",
"test:nameservice-expiry": "TEST_NAMESERVICE_EXPIRY=1 jest --runInBand --verbose src/nameservice-expiry.test.ts",
"build": "tsc"

View File

@ -1,2 +0,0 @@
#!/usr/bin/env bash
docker build -t cerc/laconic-sdk-tester:local -f Dockerfile .

View File

@ -23,7 +23,6 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
fi
echo "Removing gRPC references..."
# https://github.com/tharsis/evmosjs/tree/main/packages/proto#note
for file in $(find $REPO_ROOT/src/proto -type f)
do

View File

@ -12,10 +12,20 @@ jest.setTimeout(90 * 1000);
const bondTests = () => {
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) => {
let watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
await registry.setRecord({ privateKey, record: watcher.record, bondId }, privateKey, fee);
return watcher;
return watcher.record.version;
};
beforeAll(async () => {
@ -23,119 +33,93 @@ const bondTests = () => {
});
test('Create bond.', async () => {
let bondId = await registry.getNextBondId(privateKey);
expect(bondId).toBeDefined();
bondId1 = await registry.getNextBondId(privateKey);
expect(bondId1).toBeDefined();
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;
});
describe('With bond created', () => {
let bond1: any
test('Query bonds.', async () => {
const bonds = await registry.queryBonds();
expect(bonds).toBeDefined();
const bond = bonds.filter((bond: any) => bond.id === bondId1);
expect(bond).toBeDefined();
});
beforeAll(async () => {
let bondId1 = await registry.getNextBondId(privateKey);
expect(bondId1).toBeDefined();
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
test('Query bonds by owner.', async () => {
const bonds = await registry.queryBonds({ owner: bondOwner });
expect(bonds).toBeDefined();
const bond = bonds.filter((bond: any) => bond.id === bondId1);
expect(bond).toBeDefined();
});
[bond1] = await registry.getBondsByIds([bondId1]);
expect(bond1).toBeDefined();
expect(bond1.id).toEqual(bondId1);
});
test('Refill bond.', async () => {
await registry.refillBond({ id: bondId1, denom: 'aphoton', amount: '500' }, privateKey, fee);
test('Get bond by ID.', async () => {
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' });
});
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: '1000000500' });
});
test('Query bonds.', async () => {
const bonds = await registry.queryBonds();
expect(bonds).toBeDefined();
const bond = bonds.filter((bond: any) => bond.id === bond1.id);
expect(bond).toBeDefined();
});
test('Withdraw bond.', async () => {
await registry.withdrawBond({ id: bondId1, denom: 'aphoton', amount: '500' }, privateKey, fee);
test('Query bonds by owner.', async () => {
const bonds = await registry.queryBonds({ owner: bond1.owner });
expect(bonds).toBeDefined();
const bond = bonds.filter((bond: any) => bond.id === bond1.id);
expect(bond).toBeDefined();
});
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' });
});
test('Refill bond.', async () => {
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);
});
test('Cancel bond.', async () => {
await registry.cancelBond({ id: bondId1 }, privateKey, fee);
const [bond] = await registry.getBondsByIds([bondId1]);
expect(bond.id).toBe("");
expect(bond.owner).toBe("");
expect(bond.balance).toHaveLength(0);
});
test('Associate/Dissociate bond.', async () => {
let bondId1: string;
bondId1 = await registry.getNextBondId(privateKey);
expect(bondId1).toBeDefined();
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
// Create a new record.
let watcher = await publishNewWatcherVersion(bondId1);
let query = { type: watcher.record.type, url: watcher.record.url, version: watcher.record.version };
let [record1] = await registry.queryRecords(query, true);
version1 = await publishNewWatcherVersion(bondId1);
let [record1] = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
expect(record1.bondId).toBe(bondId1);
// Dissociate record, query and confirm.
await registry.dissociateBond({ recordId: record1.id }, privateKey, fee);
[record1] = await registry.queryRecords(query, true);
[record1] = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
expect(record1.bondId).toBe('');
// Associate record with bond, query and confirm.
await registry.associateBond({ recordId: record1.id, bondId: bondId1 }, privateKey, fee);
[record1] = await registry.queryRecords(query, true);
[record1] = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
expect(record1.bondId).toBe(bondId1);
});
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.
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 };
version2 = await publishNewWatcherVersion(bondId1);
// Check version1, version2 as associated with bondId1.
let records;
records = await registry.queryRecords(queryv1, true);
records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
expect(records[0].bondId).toBe(bondId1);
records = await registry.queryRecords(queryv2, true);
records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version2 }, true);
expect(records[0].bondId).toBe(bondId1);
// Create another bond.
@ -147,16 +131,16 @@ const bondTests = () => {
// Reassociate records from bondId1 to bondId2, verify change.
await registry.reassociateRecords({ oldBondId: bondId1, newBondId: bondId2 }, privateKey, fee);
records = await registry.queryRecords(queryv1, true);
records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
expect(records[0].bondId).toBe(bondId2);
records = await registry.queryRecords(queryv2, true);
records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version2 }, true);
expect(records[0].bondId).toBe(bondId2);
// Dissociate all records from bond, verify change.
await registry.dissociateRecords({ bondId: bondId2 }, privateKey, fee);
records = await registry.queryRecords(queryv1, true);
records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version1 }, true);
expect(records[0].bondId).toBe('');
records = await registry.queryRecords(queryv2, true);
records = await registry.queryRecords({ type: watcher.record.type, name: watcher.record.name, version: version2 }, true);
expect(records[0].bondId).toBe('');
});
};

View File

@ -54,7 +54,7 @@ import {
export const DEFAULT_CHAIN_ID = 'laconic_9000-1';
const DEFAULT_WRITE_ERROR = 'Unable to write to laconicd';
const DEFAULT_WRITE_ERROR = 'Unable to write to laconicd.';
// Parse Tx response from cosmos-sdk.
export const parseTxResponse = (result: any, parseResponse?: (data: string) => any) => {
@ -117,8 +117,7 @@ export class Registry {
console.error(error)
}
const [lastErrorLine] = error.split("\n").slice(-1);
return `${errorMessage || DEFAULT_WRITE_ERROR}: ${lastErrorLine}`;
return errorMessage || DEFAULT_WRITE_ERROR;
}
constructor(gqlUrl: string, restUrl: string = "", chainId: string = DEFAULT_CHAIN_ID) {
@ -181,9 +180,9 @@ export class Registry {
}
/**
* Publish record.
* @param transactionPrivateKey - private key in HEX to sign transaction.
*/
* Publish record.
* @param transactionPrivateKey - private key in HEX to sign transaction.
*/
async setRecord(
params: { privateKey: string, record: any, bondId: string },
transactionPrivateKey: string,

View File

@ -81,10 +81,10 @@ export const parseMsgSetRecordResponse = (data: string) => {
}
export const NAMESERVICE_ERRORS = [
'Name already reserved',
'Authority bond not found',
'Name authority not found',
'Access denied',
'Name already reserved.',
'Authority bond not found.',
'Name authority not found.',
'Access denied.',
]
export interface MessageMsgReserveAuthority {

View File

@ -7,7 +7,7 @@ import { ensureUpdatedConfig, getConfig } from './testing/helper';
const WATCHER_YML_PATH = path.join(__dirname, './testing/data/watcher.yml');
jest.setTimeout(5 * 60 * 1000);
jest.setTimeout(120 * 1000);
const { chainId, restEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
@ -18,6 +18,12 @@ const namingTests = () => {
let watcher: any;
let watcherId: string;
let authorityName: string;
let otherAuthorityName: string;
let otherPrivateKey: string;
let crn: string;
beforeAll(async () => {
registry = new Registry(gqlEndpoint, restEndpoint, chainId);
@ -40,272 +46,221 @@ const namingTests = () => {
watcherId = result.data.id;
});
describe('Authority tests', () => {
test('Reserve authority.', async () => {
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('Reserve authority.', async () => {
authorityName = `laconic-${Date.now()}`;
await registry.reserveAuthority({ name: authorityName }, privateKey, fee);
});
describe('Naming tests', () => {
let authorityName: string;
let otherAuthorityName: string;
let otherPrivateKey: string;
let otherAccount: Account;
test('Lookup authority.', async () => {
const [record] = await registry.lookupAuthorities([authorityName]);
beforeAll(async () => {
authorityName = `laconic-${Date.now()}`;
expect(record).toBeDefined();
expect(record.ownerAddress).not.toBe('');
expect(record.ownerPublicKey).not.toBe('');
expect(Number(record.height)).toBeGreaterThan(0);
});
await registry.reserveAuthority({ name: authorityName }, privateKey, fee);
await registry.setAuthorityBond({ name: authorityName, bondId }, privateKey, fee);
test('Lookup non existing authority', async () => {
const [record] = await registry.lookupAuthorities(['does-not-exist']);
// Create another account.
const mnenonic = Account.generateMnemonic();
otherAccount = await Account.generateFromMnemonic(mnenonic);
await registry.sendCoins({ denom: 'aphoton', amount: '1000000000', destinationAddress: otherAccount.formattedCosmosAddress }, privateKey, fee);
expect(record.ownerAddress).toBe('');
expect(record.ownerPublicKey).toBe('');
expect(Number(record.height)).toBe(0);
});
otherAuthorityName = `other-${Date.now()}`;
otherPrivateKey = otherAccount.privateKey.toString('hex');
});
test('Reserve already reserved authority', async () => {
await expect(registry.reserveAuthority({ name: authorityName }, privateKey, fee)).rejects.toThrow('Name already reserved.');
});
test('Set name', async () => {
const crn = `crn://${authorityName}/app/test1`;
test('Reserve sub-authority.', async () => {
const subAuthority = `echo.${authorityName}`;
await registry.reserveAuthority({ name: subAuthority }, privateKey, fee);
await registry.setName({ crn, cid: watcherId }, 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);
});
// Query records should return it (some CRN points to it).
const [record] = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version });
expect(record).toBeDefined();
expect(record.names).toHaveLength(1);
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);
await registry.deleteName({ crn }, 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);
describe('With name set', () => {
let crn: string;
const subAuthority = `halo.${authorityName}`;
await registry.reserveAuthority({ name: subAuthority, owner: otherAccount1.formattedCosmosAddress }, privateKey, fee);
beforeAll(async () => {
crn = `crn://${authorityName}/app/test2`;
await registry.setName({ crn, cid: watcherId }, 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);
});
afterAll(async () => {
await registry.deleteName({ crn }, privateKey, fee);
});
test('Set name for unbonded authority', async () => {
crn = `crn://${authorityName}/app/test`;
assert(watcherId)
await expect(registry.setName({ crn, cid: watcherId }, privateKey, fee)).rejects.toThrow('Authority bond not found.');
});
test('Lookup name', async () => {
const records = await registry.lookupNames([crn]);
expect(records).toBeDefined();
expect(records).toHaveLength(1);
test('Set authority bond', async () => {
await registry.setAuthorityBond({ name: authorityName, bondId }, privateKey, fee);
});
const [{ latest, history }] = records;
expect(latest).toBeDefined();
expect(latest.id).toBeDefined();
expect(latest.id).toBe(watcherId);
expect(latest.height).toBeDefined();
expect(history).toBeUndefined();
});
test('Set name', async () => {
crn = `crn://${authorityName}/app/test`;
await registry.setName({ crn, cid: watcherId }, privateKey, fee);
test('Resolve name', async () => {
const records = await registry.resolveNames([crn]);
expect(records).toBeDefined();
expect(records).toHaveLength(1);
// Query records should return it (some CRN points to it).
const records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version });
expect(records).toBeDefined();
expect(records).toHaveLength(1);
});
const [{ attributes }] = records;
expect(attributes).toEqual(watcher.record);
});
test('Lookup name', async () => {
const records = await registry.lookupNames([crn]);
expect(records).toBeDefined();
expect(records).toHaveLength(1);
test('Lookup name with history', async () => {
const updatedWatcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
const result = await registry.setRecord(
{
privateKey,
bondId,
record: updatedWatcher.record
},
privateKey,
fee
)
const [{ latest, history }] = records;
expect(latest).toBeDefined();
expect(latest.id).toBeDefined();
expect(latest.id).toBe(watcherId);
expect(latest.height).toBeDefined();
expect(history).toBeUndefined();
});
const updatedWatcherId = result.data.id;
await registry.setName({ crn, cid: updatedWatcherId }, privateKey, fee);
test('Resolve name', async () => {
const records = await registry.resolveNames([crn]);
expect(records).toBeDefined();
expect(records).toHaveLength(1);
const records = await registry.lookupNames([crn], true);
expect(records).toHaveLength(1);
const [{ attributes }] = records;
expect(attributes).toEqual(watcher.record);
});
const [{ latest, history }] = records;
expect(latest).toBeDefined();
expect(latest.id).toBeDefined();
expect(latest.id).toBe(updatedWatcherId);
expect(latest.height).toBeDefined();
expect(history).toBeDefined();
expect(history).toHaveLength(1);
test('Lookup name with history', async () => {
const updatedWatcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
const result = await registry.setRecord(
{
privateKey,
bondId,
record: updatedWatcher.record
},
privateKey,
fee
)
const [oldRecord] = history;
expect(oldRecord).toBeDefined();
expect(oldRecord.id).toBeDefined();
expect(oldRecord.id).toBe(watcherId);
expect(oldRecord.height).toBeDefined();
});
const updatedWatcherId = result.data.id;
await registry.setName({ crn, cid: updatedWatcherId }, privateKey, fee);
test('Delete name', async () => {
await registry.deleteName({ crn }, privateKey, fee);
const records = await registry.lookupNames([crn], true);
expect(records).toHaveLength(1);
let records = await registry.lookupNames([crn], true);
expect(records).toBeDefined();
expect(records).toHaveLength(1);
const [{ latest, history }] = records;
expect(latest).toBeDefined();
expect(latest.id).toBeDefined();
expect(latest.id).toBe(updatedWatcherId);
expect(latest.height).toBeDefined();
expect(history).toBeDefined();
expect(history).toHaveLength(1);
const [{ latest }] = records;
expect(latest).toBeDefined();
expect(latest.id).toBeDefined();
expect(latest.id).toBe('');
expect(latest.height).toBeDefined();
const [oldRecord] = history;
expect(oldRecord).toBeDefined();
expect(oldRecord.id).toBeDefined();
expect(oldRecord.id).toBe(watcherId);
expect(oldRecord.height).toBeDefined();
});
// Query records should NOT return it (no CRN points to it).
records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version });
expect(records).toBeDefined();
expect(records).toHaveLength(0);
test('Set name without reserving authority', async () => {
await expect(registry.setName({ crn: 'crn://not-reserved/app/test', cid: watcherId }, privateKey, fee))
.rejects.toThrow('Name authority not found.');
});
// Query all records should return it (all: true).
records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }, true);
expect(records).toBeDefined();
expect(records).toHaveLength(1);
});
test('Set name for non-owned authority', async () => {
// Create another account.
const mnenonic = Account.generateMnemonic();
const otherAccount = await Account.generateFromMnemonic(mnenonic);
await registry.sendCoins({ denom: 'aphoton', amount: '1000000000', destinationAddress: otherAccount.formattedCosmosAddress }, privateKey, fee);
test('Delete already deleted name', async () => {
await registry.deleteName({ crn }, privateKey, fee);
await registry.deleteName({ crn }, privateKey, fee);
// Other account reserves an authority.
otherAuthorityName = `other-${Date.now()}`;
otherPrivateKey = otherAccount.privateKey.toString('hex');
await registry.reserveAuthority({ name: otherAuthorityName }, otherPrivateKey, fee);
const records = await registry.lookupNames([crn], true);
expect(records).toBeDefined();
expect(records).toHaveLength(1);
// Try setting name under other authority.
await expect(registry.setName({ crn: `crn://${otherAuthorityName}/app/test`, cid: watcherId }, privateKey, fee)).rejects.toThrow('Access denied.');
});
const [{ latest }] = records;
expect(latest).toBeDefined();
expect(latest.id).toBeDefined();
expect(latest.id).toBe('');
expect(latest.height).toBeDefined();
});
});
test('Lookup non existing name', async () => {
const records = await registry.lookupNames(['crn://not-reserved/app/test']);
expect(records).toBeDefined();
expect(records).toHaveLength(1);
const [record] = records;
expect(record).toBeNull();
});
test('Set name without reserving authority', async () => {
await expect(registry.setName({ crn: 'crn://not-reserved/app/test', cid: watcherId }, privateKey, fee))
.rejects.toThrow('Name authority not found.');
});
test('Resolve non existing name', async () => {
const records = await registry.resolveNames(['crn://not-reserved/app/test']);
expect(records).toBeDefined();
expect(records).toHaveLength(1);
const [record] = records;
expect(record).toBeNull();
});
test('Set name for non-owned authority', async () => {
await registry.sendCoins({ denom: 'aphoton', amount: '1000000000', destinationAddress: otherAccount.formattedCosmosAddress }, privateKey, fee);
test('Delete name', async () => {
await registry.deleteName({ crn }, privateKey, fee);
// Other account reserves an authority.
await registry.reserveAuthority({ name: otherAuthorityName }, otherPrivateKey, fee);
let records = await registry.lookupNames([crn], true);
expect(records).toBeDefined();
expect(records).toHaveLength(1);
// Try setting name under other authority.
await expect(registry.setName({ crn: `crn://${otherAuthorityName}/app/test`, cid: watcherId }, privateKey, fee)).rejects.toThrow('Access denied.');
});
const [{ latest }] = records;
expect(latest).toBeDefined();
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);
// Query records should NOT return it (no CRN points to it).
records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version });
expect(records).toBeDefined();
expect(records).toHaveLength(0);
// Try deleting name under other authority.
await expect(registry.deleteName({ crn: `crn://${otherAuthorityName}/app/test` }, privateKey, fee)).rejects.toThrow('Access denied.');
});
// Query all records should return it (all: true).
records = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version }, true);
expect(records).toBeDefined();
expect(records).toHaveLength(1);
});
test('Lookup non existing name', async () => {
const records = await registry.lookupNames(['crn://not-reserved/app/test']);
expect(records).toBeDefined();
expect(records).toHaveLength(1);
const [record] = records;
expect(record).toBeNull();
});
test('Delete already deleted name', async () => {
await registry.deleteName({ crn }, privateKey, fee);
test('Resolve non existing name', async () => {
const records = await registry.resolveNames(['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);
expect(records).toBeDefined();
expect(records).toHaveLength(1);
const [{ latest }] = records;
expect(latest).toBeDefined();
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.');
});
};

View File

@ -2,7 +2,7 @@
/* eslint-disable */
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1
* compiler version: 4.24.4
* source: cosmos/base/query/v1beta1/pagination.proto
* git: https://github.com/thesayyn/protoc-gen-ts */
import * as pb_1 from "google-protobuf";

View File

@ -2,7 +2,7 @@
/* eslint-disable */
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1
* compiler version: 4.24.4
* source: cosmos/base/v1beta1/coin.proto
* git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -2,7 +2,7 @@
/* eslint-disable */
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1
* compiler version: 4.24.4
* source: gogoproto/gogo.proto
* git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../google/protobuf/descriptor";

View File

@ -2,7 +2,7 @@
/* eslint-disable */
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1
* compiler version: 4.24.4
* source: google/api/annotations.proto
* git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./http";

View File

@ -2,7 +2,7 @@
/* eslint-disable */
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1
* compiler version: 4.24.4
* source: google/api/http.proto
* git: https://github.com/thesayyn/protoc-gen-ts */
import * as pb_1 from "google-protobuf";

View File

@ -2,7 +2,7 @@
/* eslint-disable */
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1
* compiler version: 4.24.4
* source: google/protobuf/descriptor.proto
* git: https://github.com/thesayyn/protoc-gen-ts */
import * as pb_1 from "google-protobuf";

View File

@ -2,7 +2,7 @@
/* eslint-disable */
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1
* compiler version: 4.24.4
* source: google/protobuf/duration.proto
* git: https://github.com/thesayyn/protoc-gen-ts */
import * as pb_1 from "google-protobuf";

View File

@ -2,7 +2,7 @@
/* eslint-disable */
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1
* compiler version: 4.24.4
* source: google/protobuf/timestamp.proto
* git: https://github.com/thesayyn/protoc-gen-ts */
import * as pb_1 from "google-protobuf";

View File

@ -2,7 +2,7 @@
/* eslint-disable */
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1
* compiler version: 4.24.4
* source: vulcanize/auction/v1beta1/genesis.proto
* git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -2,7 +2,7 @@
/* eslint-disable */
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1
* compiler version: 4.24.4
* source: vulcanize/auction/v1beta1/query.proto
* git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -2,7 +2,7 @@
/* eslint-disable */
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1
* compiler version: 4.24.4
* source: vulcanize/auction/v1beta1/tx.proto
* git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -2,7 +2,7 @@
/* eslint-disable */
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1
* compiler version: 4.24.4
* source: vulcanize/auction/v1beta1/types.proto
* git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -2,7 +2,7 @@
/* eslint-disable */
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1
* compiler version: 4.24.4
* source: vulcanize/bond/v1beta1/bond.proto
* git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -2,7 +2,7 @@
/* eslint-disable */
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1
* compiler version: 4.24.4
* source: vulcanize/bond/v1beta1/genesis.proto
* git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -2,7 +2,7 @@
/* eslint-disable */
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1
* compiler version: 4.24.4
* source: vulcanize/bond/v1beta1/query.proto
* git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -2,7 +2,7 @@
/* eslint-disable */
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1
* compiler version: 4.24.4
* source: vulcanize/bond/v1beta1/tx.proto
* git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -2,7 +2,7 @@
/* eslint-disable */
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1
* compiler version: 4.24.4
* source: vulcanize/registry/v1beta1/genesis.proto
* git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -2,7 +2,7 @@
/* eslint-disable */
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1
* compiler version: 4.24.4
* source: vulcanize/registry/v1beta1/query.proto
* git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./registry";

View File

@ -2,7 +2,7 @@
/* eslint-disable */
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1
* compiler version: 4.24.4
* source: vulcanize/registry/v1beta1/registry.proto
* git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../google/protobuf/duration";

View File

@ -2,7 +2,7 @@
/* eslint-disable */
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!
* compiler version: 4.25.1
* compiler version: 4.24.4
* source: vulcanize/registry/v1beta1/tx.proto
* git: https://github.com/thesayyn/protoc-gen-ts */
import * as dependency_1 from "./../../../gogoproto/gogo";

View File

@ -16,16 +16,7 @@ const attributeField = `
... on StringValue { string: value }
... on BytesValue { bytes: value }
... on LinkValue { link: value }
... on ArrayValue {
array: value {
... on BooleanValue { bool: value }
... on IntValue { int: value }
... on FloatValue { float: value }
... on StringValue { string: value }
... on BytesValue { bytes: value }
... on LinkValue { link: value }
}
}
... on ArrayValue { array: value { __typename } }
... on MapValue { map: value { key mapping: value { __typename } } }
}
}

View File

@ -55,7 +55,7 @@ describe('Querying', () => {
test('Query records by attributes.', async () => {
const { version, url } = watcher.record;
const records = await registry.queryRecords({ version, url, type: undefined }, true);
const records = await registry.queryRecords({ version, url }, true);
expect(records.length).toBe(1);
[ watcher ] = records;

View File

@ -35,11 +35,7 @@ export class Util {
static toGQLAttributes(obj: any) {
const vars: any[] = [];
Object.keys(obj).forEach(key => {
const value = this.toGQLValue(obj[key]);
if (value !== undefined) {
vars.push({ key, value });
}
vars.push({ key, value: this.toGQLValue(obj[key]) });
});
return vars;
}
@ -65,8 +61,6 @@ export class Util {
return { 'array': obj };
}
return { 'map': obj };
case 'undefined':
return undefined;
default:
throw new Error(`Unknown object type '${type}': ${obj}`);
}
@ -79,26 +73,17 @@ export class Util {
const res: {[key: string]: any} = {};
attributes.forEach(attr => {
res[attr.key] = (attr.value === null) ? null : this.fromGQLValue(attr.value);
res[attr.key] = this.fromGQLValue(attr.value);
});
return res;
}
static fromGQLValue(obj: any) {
// Get first non-null key
const present = Object.keys(obj).find(k => obj[k] !== null);
if (present === undefined) {
throw new Error('Object has no non-null values');
}
// Create an array if array type attribute
if (present === 'array') {
return obj[present].map((e: any) => {
return this.fromGQLValue(e);
});
}
return obj[present];
}

View File

@ -3093,10 +3093,10 @@ protobufjs@~6.11.2:
"@types/node" ">=13.7.0"
long "^4.0.0"
protoc-gen-ts@^0.8.7:
version "0.8.7"
resolved "https://registry.yarnpkg.com/protoc-gen-ts/-/protoc-gen-ts-0.8.7.tgz#63e4d9af2ad30b753acf6f739323d01fc9f80b52"
integrity sha512-jr4VJey2J9LVYCV7EVyVe53g1VMw28cCmYJhBe5e3YX5wiyiDwgxWxeDf9oTqAe4P1bN/YGAkW2jhlH8LohwiQ==
protoc-gen-ts@^0.8.5:
version "0.8.6"
resolved "https://registry.yarnpkg.com/protoc-gen-ts/-/protoc-gen-ts-0.8.6.tgz#e789a6fc3fbe09bdc119acecc349b9554ec5940e"
integrity sha512-66oeorGy4QBvYjQGd/gaeOYyFqKyRmRgTpofmnw8buMG0P7A0jQjoKSvKJz5h5tNUaVkIzvGBUTRVGakrhhwpA==
pure-rand@^6.0.0:
version "6.0.3"