Compare commits

...
Author SHA1 Message Date
prathamesh cbff9646c7 Upgrade SDK version (#55)
Part of cerc-io/laconicd#144

Reviewed-on: cerc-io/laconic-registry-cli#55
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
2024-02-08 06:27:12 +00:00
prathamesh c3f8d53f09 Setup linter and add it to CI (#54)
- Setup eslint with husky for precommit lint
- Fix existing lint errors
- Setup linter CI

Reviewed-on: cerc-io/laconic-registry-cli#54
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
2024-01-29 05:21:34 +00:00
prathamesh b01201ca50 Add CLI tests and setup CI (#53)
Part of cerc-io/laconic-registry-cli#52

- Add tests for the CLI following demo steps present in the README
- Setup CI to run the CLI tests

Reviewed-on: cerc-io/laconic-registry-cli#53
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
2024-01-29 04:46:32 +00:00
telackey 5a0298dda5 Fix yarn.lock (#51)
Reviewed-on: cerc-io/laconic-registry-cli#51
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2024-01-15 18:23:30 +00:00
telackey 97b74760d9 Bump version. (#50)
Reviewed-on: cerc-io/laconic-registry-cli#50
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2024-01-15 18:03:26 +00:00
telackey 6814707752 Update SDK version. (#48)
Reviewed-on: cerc-io/laconic-registry-cli#48
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-12-21 21:38:11 +00:00
telackey e1da44bae7 Bump version (#47)
Reviewed-on: cerc-io/laconic-registry-cli#47
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-12-13 21:13:39 +00:00
telackey 51fd81a082 Decode JSON strings automatically. 2023-12-13 15:10:09 -06:00
telackey 3cdd930b82 0.1.5 (#46)
Reviewed-on: cerc-io/laconic-registry-cli#46
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-12-08 04:55:27 +00:00
telackey 80d1b01713 SDK 0.1.11 (#45)
Reviewed-on: cerc-io/laconic-registry-cli#45
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-12-08 04:53:08 +00:00
telackey f3c0ae8c34 Use SDK 0.1.10 (#44)
Reviewed-on: cerc-io/laconic-registry-cli#44
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-12-07 22:15:04 +00:00
telackey f5625d0c87 Take the path as-is, not relative to the current dir. (#43)
Reviewed-on: cerc-io/laconic-registry-cli#43
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-12-05 03:53:15 +00:00
telackey fb381c07f3 Fix cns name resolve (#42)
The `cns name resolve` does not return the result.  Obviously it should.

Reviewed-on: cerc-io/laconic-registry-cli#42
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-11-30 05:01:25 +00:00
telackey 145da8c453 v0.1.2 (#41)
Reviewed-on: cerc-io/laconic-registry-cli#41
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-11-29 17:39:18 +00:00
telackey 6e0829d91f Filter by arbitrary attributes (#40)
```
laconic cns record list \
  --type GeneralRecord \
  --value anything-goes-here \
  --category filter-by-this \
  --bond-id d0094c75e267abb709d631abd7bfaa8d610413f5766ddfc07db735822905d641 \
  --owner AB0A17A1EBF47DDCF6AB267CA8E07B7EA836E1AF \
  --all
```

Reviewed-on: cerc-io/laconic-registry-cli#40
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-11-28 23:22:57 +00:00
telackey 1fa32a3cc1 Add .gitea workflows (#39)
Reviewed-on: cerc-io/laconic-registry-cli#39
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-11-22 04:19:39 +00:00
telackey 129019105d Convert sub-objects (other than arrays) in YAML to JSON strings automatically. (#38)
This allows us to support attributes in YAML like this:

```
  meta:
    foo: bar
    bar:
      baz: boz
```

Which will automatically become:

```
"meta": "{\"foo\":\"bar\",\"bar\":{\"baz\":\"boz\"}}"
```

> Note: cosmos-sdk's protobuf code does not support maps (https://github.com/cosmos/cosmos-sdk/issues/15254), or else we would just use a map.

Reviewed-on: https://git.vdb.to/cerc-io/laconic-registry-cli/pulls/38
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-11-20 22:01:39 +00:00
Zach 37b69da3bb Merge pull request #35 from cerc-io/dboreham/remove-lerna-file
Remove unnecessary lerna.json file
2023-04-04 09:14:47 -04:00
dboreham 707b3049ef Remove unnecessary lerna.json file 2023-04-04 07:09:48 -06:00
Zach a986e4cccb Merge pull request #33 from cerc-io/murali/output
fix cmd outputs
2023-03-28 08:30:56 -04:00
0xmuralik 61a2aaab0f fix send output 2023-03-27 19:37:16 +05:30
0xmuralik 0c0eb79fa3 eliminate dry code 2023-03-27 18:14:42 +05:30
0xmuralik 8ebb80beed json format 2023-03-27 17:35:47 +05:30
0xmuralik 9b9e8829ec name outputs 2023-03-27 16:58:14 +05:30
0xmuralik 1de17a40ef authority and auction output 2023-03-27 13:58:41 +05:30
0xmuralik d3020daf2e bond and records outputs 2023-03-27 13:14:02 +05:30
Zach 495bbfdb3c Merge pull request #21 from cerc-io/integrated_testing
Integrated testing
2023-03-17 14:21:49 -04:00
Zach 64a796c421 Merge pull request #30 from cerc-io/murali/bond
get bond id
2023-03-15 21:26:47 -04:00
0xmuralik 3258e4cfe3 get bond id 2023-03-07 16:27:53 +05:30
Zach cbcc31d6bd Merge pull request #23 from cerc-io/0xmuralik-patch-1
Update README.md
2023-03-06 21:10:10 -05:00
Zach a5e0a6dd22 Merge pull request #24 from cerc-io/0xmuralik-patch-2
Update README.md to fix null auction
2023-03-06 17:50:55 -05:00
Murali Krishna Komatireddy 5e0c6dd649 Update README.md 2023-03-01 14:51:15 +05:30
Murali Krishna Komatireddy 46c333985e Update README.md 2023-03-01 11:48:50 +05:30
dboreham 2ef028a671 Update to latest sdk (#22) 2023-02-20 12:37:20 -07:00
Michael e7121de87b Merge pull request #20 from cerc-io/integrated_testing
Create manual_npm_publish.yml
2023-02-15 15:54:07 -05:00
61 changed files with 4450 additions and 201 deletions
+5
View File
@@ -0,0 +1,5 @@
# Don't lint node_modules.
node_modules
# Don't lint build output.
dist
+21
View File
@@ -0,0 +1,21 @@
{
"env": {
"node": true
},
"extends": [
"semistandard",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"indent": ["error", 2, { "SwitchCase": 1 }],
"@typescript-eslint/no-explicit-any": "off"
}
}
+28
View File
@@ -0,0 +1,28 @@
name: Lint
on:
pull_request:
branches:
- '*'
push:
branches:
- main
jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v3
- 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:
node-version: ${{ matrix.node-version }}
- run: yarn
- name: Linter check
run: yarn lint
+36
View File
@@ -0,0 +1,36 @@
name: Publish npm package to gitea
on:
release:
types: [published]
jobs:
npm_publish:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 18.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:
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.CICD_PUBLISH_TOKEN }}"
- name: npm publish
run: |
npm publish
+58
View File
@@ -0,0 +1,58 @@
name: Tests
on:
pull_request:
branches:
- '*'
push:
branches:
- main
- release/**
env:
DOCKER_HOST: unix:///var/run/dind.sock
jobs:
cli_tests:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v3
- 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:
node-version: ${{ matrix.node-version }}
- name: Set registry
run: npm config set @cerc-io:registry https://git.vdb.to/api/packages/cerc-io/npm/
- name: Install dependencies and build
run: yarn && yarn build
- name: Install registry-cli
run: yarn global add file:$PWD
- name: Checkout laconicd
uses: actions/checkout@v3
with:
path: "./laconicd/"
repository: cerc-io/laconicd
fetch-depth: 0
ref: main
- name: Build laconicd container
working-directory: ./laconicd/tests/sdk_tests
run: ./build-laconicd-container.sh
- name: Start laconicd container
env:
TEST_AUCTION_ENABLED: true
run: docker compose up laconicd -d
- name: Run registry-cli tests
run: ./test/run-tests.sh
- name: Stop containers
run: docker compose down
+1
View File
@@ -0,0 +1 @@
yarn lint
+15 -15
View File
@@ -10,6 +10,14 @@ CLI utility written in TS, used to interact with laconicd. Depends on [laconic-s
## Account Setup
Run the chain:
- In laconicd repo run:
```bash
TEST_AUCTION_ENABLED=true ./init.sh
```
Registering records in CNS requires an account. To get account private key run:
```bash
@@ -128,26 +136,18 @@ Create record (generic):
```yaml
# watcher.yml
record:
name: ERC20 Watcher
type: watcher
version: 1.0.0
protocol:
/: QmbQiRpLX5djUsfc2yDswHvTkHTGd9uQEy6oUJfxkBYwRq
package:
linux:
x64:
/: QmVRmLrQeLZS8Xee7YVzYYAQANWmXqsNgNkaPMxM8MtPLA
arm:
/: QmX3DDmeFunX5aVmaTNnViwQUe15Wa4UbZYcC3AwFwoWcg
macos:
x64:
/: QmXogCVZZ867qZfS3CYjYdDEziPb4ARiDfgwqbd7urVKkr
type: WebsiteRegistrationRecord
url: 'https://cerc.io'
repo_registration_record_cid: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
build_artifact_cid: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
tls_cert_cid: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
version: 1.0.23
```
Publish record (see below for commands to create/query bonds):
```bash
$ laconic cns record publish --filename watcher.yml --bond-id 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785
$ laconic cns record publish --filename watcher.yml --bond-id 58508984500aa2ed18e059fa8203b40fbc9828e3bfa195361335c4e4524c4785 --gas 250000
{ id: 'bafyreic3auqajvgszh3vfjsouew2rsctswukc346dmlf273ln4g6iyyhba' }
```
+9 -12
View File
@@ -1,28 +1,25 @@
services:
laconicd:
restart: unless-stopped
image: cerc-io/laconicd:local-test
image: cerc/laconicd:local
command: ["sh", "/docker-entrypoint-scripts.d/create-fixturenet.sh"]
environment:
- TEST_AUCTION_ENABLED
- TEST_REGISTRY_EXPIRY
- LOGLEVEL
volumes:
- laconicd/init.sh:/docker-entrypoint-scripts.d/create-fixturenet.sh
- ./laconicd/init.sh:/docker-entrypoint-scripts.d/create-fixturenet.sh
healthcheck:
test: ["CMD", "curl", "-v", "http://127.0.0.1:6060"]
interval: 1s
timeout: 5s
retries: 30
ports:
- "6060"
- "26657"
- "26656"
- "9473"
- "8545"
- "8546"
- "9090"
- "9091"
- "1317"
- "9473:9473"
- "1317:1317"
cli-test-runner:
image: cerc/laconic-registry-cli:local-test
image: cerc/laconic-registry-cli:local
depends_on:
laconicd:
condition: service_healthy
+6
View File
@@ -0,0 +1,6 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
setupFiles: ['dotenv/config']
};
-5
View File
@@ -1,5 +0,0 @@
{
"version": "2.9.0",
"useWorkspaces": true,
"npmClient": "yarn"
}
+20 -4
View File
@@ -1,32 +1,48 @@
{
"name": "@cerc-io/laconic-registry-cli",
"version": "0.1.0",
"version": "0.1.10",
"main": "index.js",
"repository": "git@github.com:cerc-io/laconic-registry-cli.git",
"author": "",
"license": "UNLICENSED",
"devDependencies": {
"@types/fs-extra": "^9.0.13",
"@types/jest": "^27.4.1",
"@types/js-yaml": "^4.0.5",
"@types/lodash": "^4.14.182",
"@types/node": "^17.0.25",
"@types/yargs": "^17.0.10",
"@typescript-eslint/eslint-plugin": "^5.47.1",
"@typescript-eslint/parser": "^5.47.1",
"dotenv": "^16.3.2",
"eslint": "^8.35.0",
"eslint-config-semistandard": "^15.0.1",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-standard": "^5.0.0",
"husky": "^9.0.2",
"jest": "29.0.0",
"ts-jest": "^29.0.2",
"typescript": "^4.6.3"
},
"dependencies": {
"@cerc-io/laconic-sdk": "^0.1.15",
"fs-extra": "^10.1.0",
"@cerc-io/laconic-sdk": "0.1.6",
"js-yaml": "^3.14.1",
"lodash": "^4.17.21",
"lodash-clean": "^2.2.3",
"yargs": "^17.4.1"
},
"scripts": {
"test": "jest --runInBand --verbose test/cli.test.ts",
"lint": "eslint .",
"clean": "rm -rf ./dist",
"build": "tsc"
"build": "tsc",
"prepare": "husky"
},
"bin": {
"laconic": "bin/laconic"
}
}
}
+4 -4
View File
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Account, Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util';
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'get';
@@ -11,7 +11,7 @@ export const desc = 'Get account.';
export const handler = async (argv: Arguments) => {
let address = argv.address as string;
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -24,5 +24,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.getAccounts([address]);
console.log(JSON.stringify(result, undefined, 2));
}
queryOutput(result, argv.output);
};
+1 -1
View File
@@ -7,4 +7,4 @@ export const desc = 'Account operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('account-cmds')
.demandCommand();
}
};
@@ -5,7 +5,7 @@ import { Account, createBid, Registry } from '@cerc-io/laconic-sdk';
import { ensureDir } from 'fs-extra';
import fs from 'fs';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../../util';
const OUT_DIR = 'out';
@@ -21,7 +21,7 @@ export const handler = async (argv: Arguments) => {
assert(quantity, 'Invalid token quantity.');
assert(denom, 'Invalid token type.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -43,7 +43,7 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.commitBid({ auctionId, commitHash }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
const revealFile = `{"reveal_file":"${revealFilePath}"}`;
console.log(`\nReveal file: ${revealFilePath}`);
}
txOutput(result, revealFile, argv.output, argv.verbose);
};
@@ -4,7 +4,7 @@ import path from 'path';
import { Registry } from '@cerc-io/laconic-sdk';
import fs from 'fs';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../../util';
export const command = 'reveal [auction-id] [file-path]';
@@ -16,7 +16,7 @@ export const handler = async (argv: Arguments) => {
assert(auctionId, 'Invalid auction ID.');
assert(filePath, 'Invalid reveal file path.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -28,5 +28,7 @@ export const handler = async (argv: Arguments) => {
const reveal = fs.readFileSync(path.resolve(filePath));
const result = await registry.revealBid({ auctionId, reveal: reveal.toString('hex') }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};
+6 -6
View File
@@ -6,10 +6,10 @@ export const desc = 'Auction bid operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.options({
'auction-id': { type: 'string' },
'type': { type: 'string' },
'quantity': { type: 'string' },
'file-path': { type: 'string' }
}).commandDir('bid-cmds')
'auction-id': { type: 'string' },
type: { type: 'string' },
quantity: { type: 'string' },
'file-path': { type: 'string' }
}).commandDir('bid-cmds')
.demandCommand();
}
};
+4 -4
View File
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util';
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'get [id]';
@@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const { id, config } = argv;
assert(id, 'Invalid auction ID.');
const { services: { cns: cnsConfig } } = getConfig(config as string)
const { services: { cns: cnsConfig } } = getConfig(config as string);
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -21,5 +21,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.getAuctionsByIds([id as string]);
console.log(JSON.stringify(result, undefined, 2));
}
queryOutput(result, argv.output);
};
+1 -1
View File
@@ -7,4 +7,4 @@ export const desc = 'Auction operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('auction-cmds')
.demandCommand();
}
};
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../../util';
export const command = 'set [name] [bond-id]';
@@ -14,7 +14,7 @@ export const handler = async (argv: Arguments) => {
assert(name, 'Invalid authority name.');
assert(bondId, 'Invalid Bond ID.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -24,5 +24,7 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.setAuthorityBond({ name, bondId }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};
+1 -1
View File
@@ -7,4 +7,4 @@ export const desc = 'Authority bond operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('bond-cmds')
.demandCommand();
}
};
+6 -5
View File
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
export const command = 'reserve [name]';
@@ -13,14 +13,14 @@ export const builder = {
type: 'string',
default: ''
}
}
};
export const handler = async (argv: Arguments) => {
const name = argv.name as string;
const owner = argv.owner as string;
assert(name, 'Invalid authority name.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -31,5 +31,6 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.reserveAuthority({ name, owner }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};
+4 -4
View File
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util';
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'whois [name]';
@@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const name = argv.name as string;
assert(name, 'Invalid authority name.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -21,5 +21,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.lookupAuthorities([name], true);
console.log(JSON.stringify(result, undefined, 2));
}
queryOutput(result, argv.output);
};
+1 -1
View File
@@ -7,4 +7,4 @@ export const desc = 'Name authority operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('authority-cmds')
.demandCommand();
}
};
+6 -5
View File
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
export const command = 'associate';
@@ -12,7 +12,7 @@ export const builder = {
'bond-id': {
type: 'string'
}
}
};
export const handler = async (argv: Arguments) => {
const id = argv.id as string;
@@ -20,7 +20,7 @@ export const handler = async (argv: Arguments) => {
assert(id, 'Invalid Record ID.');
assert(bondId, 'Invalid Bond ID.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -30,5 +30,6 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.associateBond({ recordId: id, bondId }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};
+6 -5
View File
@@ -2,17 +2,17 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
export const command = 'cancel';
export const desc = 'Cancel bond.';
export const handler = async (argv: Arguments) => {
const id = argv.id as string
const id = argv.id as string;
assert(id, 'Invalid Bond ID.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -22,5 +22,6 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.cancelBond({ id }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};
+9 -6
View File
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
export const command = 'create';
@@ -15,17 +15,17 @@ export const builder = {
quantity: {
type: 'string'
}
}
};
export const handler = async (argv: Arguments) => {
const { config, verbose } = argv;
const { config } = argv;
const denom = argv.type as string;
const amount = argv.quantity as string;
assert(denom, 'Invalid Type.');
assert(amount, 'Invalid Quantity.');
const { services: { cns: cnsConfig } } = getConfig(config as string)
const { services: { cns: cnsConfig } } = getConfig(config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -34,6 +34,9 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const bondId = await registry.getNextBondId(privateKey);
const result = await registry.createBond({ denom, amount }, privateKey, fee);
console.log(verbose ? JSON.stringify(result, undefined, 2) : result.data);
}
const jsonString = `{"bondId":"${bondId}"}`;
txOutput(result, jsonString, argv.output, argv.verbose);
};
+5 -4
View File
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
export const command = 'dissociate';
@@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const id = argv.id as string;
assert(id, 'Invalid Record ID.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -22,5 +22,6 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.dissociateBond({ recordId: id }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};
+5 -4
View File
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util';
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'get';
@@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const { id, config } = argv;
console.assert(id, 'Bond Id is required.');
const { services: { cns: cnsConfig } } = getConfig(config as string)
const { services: { cns: cnsConfig } } = getConfig(config as string);
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -21,5 +21,6 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.getBondsByIds([id as string]);
console.log(JSON.stringify(result, undefined, 2));
}
queryOutput(result, argv.output);
};
+6 -5
View File
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util';
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'list';
@@ -12,10 +12,10 @@ export const builder = {
owner: {
type: 'string'
}
}
};
export const handler = async (argv: Arguments) => {
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -25,5 +25,6 @@ export const handler = async (argv: Arguments) => {
const { owner } = argv;
const result = await registry.queryBonds({ owner });
console.log(JSON.stringify(result, undefined, 2));
}
queryOutput(result, argv.output);
};
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../../util';
export const command = 'dissociate';
@@ -12,13 +12,13 @@ export const builder = {
'bond-id': {
type: 'string'
}
}
};
export const handler = async (argv: Arguments) => {
const bondId = argv.bondId as string;
assert(bondId, 'Invalid Bond ID.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -28,5 +28,6 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.dissociateRecords({ bondId }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../../util';
export const command = 'reassociate';
@@ -15,7 +15,7 @@ export const builder = {
'new-bond-id': {
type: 'string'
}
}
};
export const handler = async (argv: Arguments) => {
const oldBondId = argv.oldBondId as string;
@@ -23,7 +23,7 @@ export const handler = async (argv: Arguments) => {
assert(oldBondId, 'Invalid Old Bond ID.');
assert(newBondId, 'Invalid New Bond ID.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -33,5 +33,6 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.reassociateRecords({ oldBondId, newBondId }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};
+1 -1
View File
@@ -7,4 +7,4 @@ export const desc = 'Bond records operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('records-cmds')
.demandCommand();
}
};
+7 -6
View File
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
export const command = 'refill';
@@ -15,18 +15,18 @@ export const builder = {
quantity: {
type: 'string'
}
}
};
export const handler = async (argv: Arguments) => {
const denom = argv.type as string;
const amount = argv.quantity as string;
const id = argv.id as string
const id = argv.id as string;
assert(id, 'Invalid Bond ID.');
assert(denom, 'Invalid Type.');
assert(amount, 'Invalid Quantity.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -36,5 +36,6 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.refillBond({ id, denom, amount }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};
+7 -6
View File
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
export const command = 'withdraw';
@@ -15,18 +15,18 @@ export const builder = {
quantity: {
type: 'string'
}
}
};
export const handler = async (argv: Arguments) => {
const denom = argv.type as string;
const amount = argv.quantity as string;
const id = argv.id as string
const id = argv.id as string;
assert(id, 'Invalid Bond ID.');
assert(denom, 'Invalid Type.');
assert(amount, 'Invalid Quantity.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -36,5 +36,6 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.withdrawBond({ id, denom, amount }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};
+1 -1
View File
@@ -7,4 +7,4 @@ export const desc = 'Bonds operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('bond-cmds')
.demandCommand();
}
};
+5 -4
View File
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
export const command = 'delete [name]';
@@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const name = argv.name as string;
assert(name, 'Invalid Name.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -23,5 +23,6 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.deleteName({ crn: name }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};
+5 -5
View File
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util';
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'lookup [name]';
@@ -12,13 +12,13 @@ export const builder = {
history: {
type: 'boolean'
}
}
};
export const handler = async (argv: Arguments) => {
const name = argv.name as string;
assert(name, 'Invalid Name.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -27,5 +27,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.lookupNames([name], argv.history as boolean);
console.log(JSON.stringify(result, undefined, 2));
}
queryOutput(result, argv.output);
};
+7 -5
View File
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util';
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'resolve [name]';
@@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const name = argv.name as string;
assert(name, 'Invalid Name.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -20,6 +20,8 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.resolveNames([name]);
console.log(JSON.stringify(result, undefined, 4));
}
let result = await registry.resolveNames([name]);
result = result.filter((v: any) => v);
queryOutput(result, argv.output);
};
+5 -4
View File
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
export const command = 'set [name] [id]';
@@ -14,7 +14,7 @@ export const handler = async (argv: Arguments) => {
assert(name, 'Invalid Name.');
assert(id, 'Invalid Record ID.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -25,5 +25,6 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.setName({ crn: name, cid: id }, privateKey, fee);
console.log(JSON.stringify(result, undefined, 2));
}
const success = `{"success":${result.code === 0}}`;
txOutput(result, success, argv.output, argv.verbose);
};
+2 -2
View File
@@ -6,5 +6,5 @@ export const desc = 'Name operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('name-cmds')
.demandCommand()
}
.demandCommand();
};
+4 -4
View File
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util';
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'get';
@@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
const { id, config } = argv;
assert(id, 'Invalid Record ID.');
const { services: { cns: cnsConfig } } = getConfig(config as string)
const { services: { cns: cnsConfig } } = getConfig(config as string);
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -21,5 +21,5 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.getRecordsByIds([id as string]);
console.log(JSON.stringify(result, undefined, 2));
}
queryOutput(result, argv.output);
};
+26 -7
View File
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo } from '../../../util';
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
export const command = 'list';
@@ -12,6 +12,9 @@ export const builder = {
'bond-id': {
type: 'string'
},
owner: {
type: 'string'
},
type: {
type: 'string'
},
@@ -22,12 +25,18 @@ export const builder = {
type: 'boolean',
default: false
}
}
};
export const handler = async (argv: Arguments) => {
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
const { type, name, bondId, all } = argv;
const { type, name, bondId, owner, all } = argv;
const filters: any = {};
const filterArgs = argv._.slice(3);
for (let i = 0; i < filterArgs.length - 1; i += 2) {
filters[String(filterArgs[i]).replace(/^-+/, '')] = filterArgs[i + 1];
}
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -35,6 +44,16 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const result = await registry.queryRecords({ bondId, type, name }, all as boolean);
console.log(JSON.stringify(result, undefined, 2));
}
let result = await registry.queryRecords({ ...filters, type, name }, all as boolean);
// Apply ex post filters.
if (bondId) {
result = result.filter((v: any) => v.bondId === bondId);
}
if (owner) {
result = result.filter((v: any) => v.owners?.find((e: string) => e === owner));
}
queryOutput(result, argv.output);
};
+16 -9
View File
@@ -1,11 +1,10 @@
import { Arguments } from 'yargs';
import assert from 'assert';
import path from 'path';
import yaml from 'js-yaml';
import fs from 'fs';
import { Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getGasAndFees, getConnectionInfo } from '../../../util';
import { getConfig, getGasAndFees, getConnectionInfo, txOutput } from '../../../util';
export const command = 'publish';
@@ -14,12 +13,12 @@ export const desc = 'Register record.';
export const builder = {
'bond-id': {
type: 'string'
},
}
}
};
export const handler = async (argv: Arguments) => {
const { txKey, filename, verbose, config } = argv;
const { services: { cns: cnsConfig } } = getConfig(config as string)
const { txKey, filename, config } = argv;
const { services: { cns: cnsConfig } } = getConfig(config as string);
const { restEndpoint, gqlEndpoint, userKey, bondId, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
@@ -30,15 +29,23 @@ export const handler = async (argv: Arguments) => {
let file = null;
if (filename) {
file = path.join(process.cwd(), filename as string);
file = filename as string;
} else {
file = 0; // stdin
}
const { record } = await yaml.load(fs.readFileSync(file, 'utf-8')) as any;
// Convert sub-objects (other than arrays) to a JSON automatically.
for (const [k, v] of Object.entries(record)) {
if (v && typeof v === 'object' && !Array.isArray(v)) {
record[k] = JSON.stringify(v);
}
}
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
const fee = getGasAndFees(argv, cnsConfig);
const result = await registry.setRecord({ privateKey: userKey, record, bondId }, txKey as string, fee);
console.log(verbose ? JSON.stringify(result, undefined, 2) : result.data);
}
txOutput(result, JSON.stringify(result.data, undefined, 2), argv.output, argv.verbose);
};
+3 -2
View File
@@ -6,5 +6,6 @@ export const desc = 'Record operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('record-cmds')
.demandCommand()
}
.parserConfiguration({ 'unknown-options-as-args': true })
.demandCommand();
};
+2 -2
View File
@@ -9,7 +9,7 @@ export const command = 'status';
export const desc = 'Get CNS status.';
export const handler = async (argv: Arguments) => {
const { services: { cns } } = getConfig(argv.config as string)
const { services: { cns } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cns);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -19,4 +19,4 @@ export const handler = async (argv: Arguments) => {
const result = await registry.getStatus();
console.log(JSON.stringify(result, undefined, 2));
}
};
+5 -5
View File
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
import assert from 'assert';
import { Account, Registry } from '@cerc-io/laconic-sdk';
import { getConfig, getConnectionInfo, getGasAndFees } from '../../../util';
import { getConfig, getConnectionInfo, getGasAndFees, queryOutput } from '../../../util';
export const command = 'send';
@@ -15,7 +15,7 @@ export const builder = {
quantity: {
type: 'string'
}
}
};
export const handler = async (argv: Arguments) => {
const destinationAddress = argv.address as string;
@@ -26,7 +26,7 @@ export const handler = async (argv: Arguments) => {
assert(denom, 'Invalid Type.');
assert(amount, 'Invalid Quantity.');
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { services: { cns: cnsConfig } } = getConfig(argv.config as string);
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
assert(restEndpoint, 'Invalid CNS REST endpoint.');
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
@@ -40,5 +40,5 @@ export const handler = async (argv: Arguments) => {
const fee = getGasAndFees(argv, cnsConfig);
await registry.sendCoins({ denom, amount, destinationAddress }, privateKey, fee);
const result = await registry.getAccounts([fromAddress, destinationAddress]);
console.log(JSON.stringify(result, undefined, 2));
}
queryOutput(result, argv.output);
};
+1 -1
View File
@@ -7,4 +7,4 @@ export const desc = 'Tokens operations.';
exports.builder = (yargs: yargs.Argv) => {
return yargs.commandDir('tokens-cmds')
.demandCommand();
}
};
+7 -7
View File
@@ -11,13 +11,13 @@ exports.builder = (yargs: yargs.Argv) => {
'tx-key': { type: 'string' },
'bond-id': { type: 'string' },
'chain-id': { type: 'string' },
'filename': { alias: 'f' },
'id': { type: 'string' },
'address': { type: 'string' },
'gas': { type: 'string' },
'fees': { type: 'string' }
filename: { alias: 'f' },
id: { type: 'string' },
address: { type: 'string' },
gas: { type: 'string' },
fees: { type: 'string' }
})
.commandDir('cns-cmds')
.demandCommand()
.help()
}
.help();
};
+6
View File
@@ -1,6 +1,7 @@
import yargs from 'yargs/yargs';
import { hideBin } from 'yargs/helpers';
// eslint-disable-next-line no-unused-expressions
yargs(hideBin(process.argv))
.options({
verbose: {
@@ -15,6 +16,11 @@ yargs(hideBin(process.argv))
default: 'config.yml',
describe: 'Config file path.',
type: 'string'
},
output: {
alias: 'o',
describe: 'Gives output in json format when specified.',
type: 'string'
}
})
.commandDir('cmds')
+1 -1
View File
@@ -1,4 +1,4 @@
import { Arguments } from "yargs";
import { Arguments } from 'yargs';
import clean from 'lodash-clean';
export const getConnectionInfo = (argv: Arguments, config: any) => {
+4 -4
View File
@@ -1,9 +1,9 @@
import yaml from 'js-yaml'
import fs from 'fs'
import path from 'path'
import yaml from 'js-yaml';
import fs from 'fs';
import path from 'path';
export const getConfig = (configFilePath: string): any => {
const resolvedFilePath = path.resolve(process.cwd(), configFilePath);
const configFile = fs.readFileSync(resolvedFilePath, 'utf-8')
const configFile = fs.readFileSync(resolvedFilePath, 'utf-8');
return yaml.load(configFile);
};
+1
View File
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import assert from 'assert';
import { Arguments } from 'yargs';
+1
View File
@@ -1,3 +1,4 @@
export * from './fees';
export * from './config';
export * from './common';
export * from './output';
+22
View File
@@ -0,0 +1,22 @@
export const txOutput = (result:any, msg:string, output:unknown, verbose:unknown) => {
if (output === 'json') {
console.log(verbose ? JSON.parse(JSON.stringify(result)) : JSON.parse(msg));
} else {
console.log(verbose ? JSON.stringify(result, undefined, 2) : msg);
}
};
export const queryOutput = (result: any, output: unknown) => {
if (output === 'json') {
console.log(JSON.parse(JSON.stringify(result)));
} else {
console.log(JSON.stringify(result, (key, value) => {
try {
return JSON.parse(value);
} catch (e) {
return value;
}
}, 2));
}
};
+528
View File
@@ -0,0 +1,528 @@
import fs from 'fs';
import assert from 'assert';
import { spawnSync } from 'child_process';
import {
CHAIN_ID,
TOKEN_TYPE,
AUCTION_COMMIT_DURATION,
AUCTION_REVEAL_DURATION,
delay,
checkResultAndRetrieveOutput,
createBond,
getBondObj,
getAccountObj,
getRecordObj,
getAuthorityObj,
getAuctionObj,
getBidObj
} from './helpers';
describe('Test laconic CLI commands', () => {
test('laconic', async () => {
const result = spawnSync('laconic');
expect(result.status).toBe(1);
const output = result.stdout.toString().trim();
const errorOutput = result.stderr.toString().trim();
// Expect error with usage string
expect(output).toBe('');
expect(errorOutput).toContain('laconic <command>');
});
test('laconic cns', async () => {
const result = spawnSync('laconic', ['cns']);
expect(result.status).toBe(1);
const output = result.stdout.toString().trim();
const errorOutput = result.stderr.toString().trim();
// Expect error with usage string
expect(output).toBe('');
expect(errorOutput).toContain('laconic cns');
expect(errorOutput).toContain('CNS tools');
expect(errorOutput).toContain('Commands:');
});
// TODO: Break up tests into separate files
// TODO: Add tests for CNS commands with all available flags
describe('laconic CNS commands', () => {
const testAccount = process.env.TEST_ACCOUNT;
assert(testAccount, 'TEST_ACCOUNT not set in env');
const testAccount2 = 'ethm1vc62ysqu504at932jjq8pwrqgjt67rx6ggn5yu';
const initialAccountBalance = Number('100000000000000000000000000');
const testAuthorityName = 'laconic';
const testRecordFilePath = 'test/data/watcher-record.yml';
let testAuctionId: string, testRecordId: string, testRecordBondId: string;
test('laconic cns status', async () => {
const result = spawnSync('laconic', ['cns', 'status']);
const outputObj = checkResultAndRetrieveOutput(result);
// Expect output object to have CNS status props
expect(outputObj).toHaveProperty('version');
expect(outputObj).toHaveProperty('node');
expect(outputObj).toHaveProperty('node.network', CHAIN_ID);
expect(outputObj).toHaveProperty('sync');
expect(Number(outputObj.sync.latest_block_height)).toBeGreaterThan(0);
expect(outputObj).toHaveProperty('validator');
expect(outputObj).toHaveProperty('validators');
expect(outputObj).toHaveProperty('num_peers');
expect(outputObj).toHaveProperty('peers');
expect(outputObj).toHaveProperty('disk_usage');
});
describe('Bond operations', () => {
const bondOwner = testAccount;
let bondBalance = 1000000000;
let bondId: string;
test('laconic cns bond create --type <type> --quantity <quantity> --gas <gas> --fees <fees>', async () => {
const result = spawnSync('laconic', ['cns', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondBalance.toString(), '--gas', '200000', '--fees', `200000${TOKEN_TYPE}`]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expect output object to have resultant bond id
expect(outputObj.bondId).toBeDefined();
bondId = outputObj.bondId;
});
test('laconic cns bond list', async () => {
const result = spawnSync('laconic', ['cns', 'bond', 'list']);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected bond
const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance });
expect(outputObj.length).toEqual(1);
expect(outputObj[0]).toEqual(expectedBond);
});
test('laconic cns bond list --owner <owner_address>', async () => {
const result = spawnSync('laconic', ['cns', 'bond', 'list', '--owner', bondOwner]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected bond
const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance });
expect(outputObj.length).toEqual(1);
expect(outputObj[0]).toEqual(expectedBond);
});
test('laconic cns bond get --id <bond_id>', async () => {
const result = spawnSync('laconic', ['cns', 'bond', 'get', '--id', bondId]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected bond
const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance });
expect(outputObj.length).toEqual(1);
expect(outputObj[0]).toEqual(expectedBond);
});
test('laconic cns bond refill --id <bond_id> --type <type> --quantity <quantity>', async () => {
const bondRefillAmount = 1000;
bondBalance += bondRefillAmount;
const result = spawnSync('laconic', ['cns', 'bond', 'refill', '--id', bondId, '--type', TOKEN_TYPE, '--quantity', bondRefillAmount.toString()]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected output
expect(outputObj).toEqual({ success: true });
// Check updated bond
const bondResult = spawnSync('laconic', ['cns', 'bond', 'get', '--id', bondId]);
const bondOutputObj = checkResultAndRetrieveOutput(bondResult);
// Expected bond
const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance });
expect(bondOutputObj.length).toEqual(1);
expect(bondOutputObj[0]).toEqual(expectedBond);
});
test('laconic cns bond withdraw --id <bond_id> --type <type> --quantity <quantity>', async () => {
const bondWithdrawAmount = 500;
bondBalance -= bondWithdrawAmount;
const result = spawnSync('laconic', ['cns', 'bond', 'withdraw', '--id', bondId, '--type', TOKEN_TYPE, '--quantity', bondWithdrawAmount.toString()]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected output
expect(outputObj).toEqual({ success: true });
// Check updated bond
const bondResult = spawnSync('laconic', ['cns', 'bond', 'get', '--id', bondId]);
const bondOutputObj = checkResultAndRetrieveOutput(bondResult);
// Expected bond
const expectedBond = getBondObj({ id: bondId, owner: bondOwner, balance: bondBalance });
// Expect balance to be deducted
expect(bondOutputObj.length).toEqual(1);
expect(bondOutputObj[0]).toEqual(expectedBond);
});
test('laconic cns bond cancel --id <bond_id>', async () => {
const result = spawnSync('laconic', ['cns', 'bond', 'cancel', '--id', bondId]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected output
expect(outputObj).toEqual({ success: true });
// Check updated bond
const bondResult = spawnSync('laconic', ['cns', 'bond', 'get', '--id', bondId]);
const bondOutputObj = checkResultAndRetrieveOutput(bondResult);
// Expect empty object
expect(bondOutputObj.length).toEqual(1);
expect(bondOutputObj[0]).toEqual({ id: '', owner: '', balance: [] });
});
});
describe('Account and tokens operations', () => {
let balanceBeforeSend: number;
test('laconic cns account get --address <account_address>', async () => {
const result = spawnSync('laconic', ['cns', 'account', 'get', '--address', testAccount]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected account
const expectedAccount = getAccountObj({ address: testAccount });
expect(outputObj.length).toEqual(1);
expect(outputObj[0]).toMatchObject(expectedAccount);
expect(outputObj[0].number).toBeDefined();
expect(outputObj[0].sequence).toBeDefined();
balanceBeforeSend = Number(outputObj[0].balance[0].quantity);
expect(balanceBeforeSend).toBeGreaterThan(0);
expect(balanceBeforeSend).toBeLessThan(initialAccountBalance);
});
test('laconic cns tokens send --address <account_address> --type <token_type> --quantity <quantity>', async () => {
const sendAmount = 1000000000;
const balanceAfterSend = balanceBeforeSend - sendAmount;
const result = spawnSync('laconic', ['cns', 'tokens', 'send', '--address', testAccount2, '--type', TOKEN_TYPE, '--quantity', sendAmount.toString()]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected acconts
const expectedAccounts = [
getAccountObj({ address: testAccount, balance: balanceAfterSend }),
getAccountObj({ address: testAccount2, balance: sendAmount })
];
expect(outputObj.length).toEqual(2);
expect(outputObj).toMatchObject(expectedAccounts);
});
});
describe('Record operations', () => {
const gas = 250000;
const bondBalance = 1000000000;
test('laconic cns record publish --filename <record_file> --bond-id <bond_id> --gas <gas>', async () => {
// Create a new bond to be associated with the record
({ bondId: testRecordBondId } = createBond(bondBalance));
const result = spawnSync('laconic', ['cns', 'record', 'publish', '--filename', testRecordFilePath, '--bond-id', testRecordBondId, '--gas', gas.toString()]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expect output object to resultant bond id
expect(outputObj.id).toBeDefined();
testRecordId = outputObj.id;
});
test('laconic cns record list', async () => {
const result = spawnSync('laconic', ['cns', 'record', 'list']);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected record
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId, recordId: testRecordId, names: null });
expect(outputObj.length).toEqual(1);
expect(outputObj[0]).toMatchObject(expectedRecord);
expect(outputObj[0].createTime).toBeDefined();
expect(outputObj[0].expiryTime).toBeDefined();
expect(outputObj[0].owners).toBeDefined();
expect(outputObj[0].owners.length).toEqual(1);
});
test('laconic cns record get --id <record_id>', async () => {
const result = spawnSync('laconic', ['cns', 'record', 'get', '--id', testRecordId]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected record
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId, recordId: testRecordId, names: null });
expect(outputObj.length).toEqual(1);
expect(outputObj[0]).toMatchObject(expectedRecord);
});
describe('Bond records operations', () => {
let testRecordBondId2: string;
test('laconic cns bond dissociate --id <record_id>', async () => {
const result = spawnSync('laconic', ['cns', 'bond', 'dissociate', '--id', testRecordId]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected output
expect(outputObj).toEqual({ success: true });
const recordResult = spawnSync('laconic', ['cns', 'record', 'get', '--id', testRecordId]);
const recordOutputObj = checkResultAndRetrieveOutput(recordResult);
// Expected record
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: '', recordId: testRecordId, names: null });
expect(recordOutputObj.length).toEqual(1);
expect(recordOutputObj[0]).toMatchObject(expectedRecord);
});
test('laconic cns bond associate --id <record_id> --bond-id <bond_id>', async () => {
// Create a new bond to be associated with the record
({ bondId: testRecordBondId2 } = createBond(bondBalance));
const result = spawnSync('laconic', ['cns', 'bond', 'associate', '--id', testRecordId, '--bond-id', testRecordBondId2]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected output
expect(outputObj).toEqual({ success: true });
const recordResult = spawnSync('laconic', ['cns', 'record', 'get', '--id', testRecordId]);
const recordOutputObj = checkResultAndRetrieveOutput(recordResult);
// Expected record
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId2, recordId: testRecordId, names: null });
expect(recordOutputObj.length).toEqual(1);
expect(recordOutputObj[0]).toMatchObject(expectedRecord);
});
test('laconic cns bond records reassociate --old-bond-id <old_bond_id> --new-bond-id <new_bond_id>', async () => {
const result = spawnSync('laconic', ['cns', 'bond', 'records', 'reassociate', '--old-bond-id', testRecordBondId2, '--new-bond-id', testRecordBondId]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected output
expect(outputObj).toEqual({ success: true });
const recordResult = spawnSync('laconic', ['cns', 'record', 'get', '--id', testRecordId]);
const recordOutputObj = checkResultAndRetrieveOutput(recordResult);
// Expected record
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId, recordId: testRecordId, names: null });
expect(recordOutputObj.length).toEqual(1);
expect(recordOutputObj[0]).toMatchObject(expectedRecord);
});
});
});
describe('Name authority operations (pre auction)', () => {
test('laconic cns authority reserve <authority_name>', async () => {
const result = spawnSync('laconic', ['cns', 'authority', 'reserve', testAuthorityName]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expect result
expect(outputObj).toEqual({ success: true });
});
test('laconic cns authority whois <authority_name>', async () => {
const result = spawnSync('laconic', ['cns', 'authority', 'whois', testAuthorityName]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected authority (still in auction)
const expectedAuthority = getAuthorityObj({ owner: '', status: 'auction', auction: getAuctionObj({ owner: testAccount }) });
expect(outputObj.length).toEqual(1);
expect(outputObj[0]).toMatchObject(expectedAuthority);
expect(outputObj[0].expiryTime).toBeDefined();
expect(outputObj[0].height).toBeGreaterThan(0);
testAuctionId = outputObj[0].auction.id;
});
});
describe('Auction operations', () => {
const bidAmount = 25000000;
let bidRevealFilePath: string;
test('laconic cns auction get <auction_id>', async () => {
const result = spawnSync('laconic', ['cns', 'auction', 'get', testAuctionId]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected auction (still in commit stage)
const expectedAuction = getAuctionObj({ owner: testAccount, status: 'commit' });
expect(outputObj.length).toEqual(1);
expect(outputObj[0]).toMatchObject(expectedAuction);
});
test('laconic cns auction bid commit <auction_id> <quantity> <type>', async () => {
const result = spawnSync('laconic', ['cns', 'auction', 'bid', 'commit', testAuctionId, bidAmount.toString(), TOKEN_TYPE]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected output
expect(outputObj.reveal_file).toBeDefined();
bidRevealFilePath = outputObj.reveal_file;
});
test('laconic cns auction bid reveal <auction_id> <file_path>', async () => {
// Wait for auction commits duration (60s)
await delay(AUCTION_COMMIT_DURATION * 1000);
const auctionResult = spawnSync('laconic', ['cns', 'auction', 'get', testAuctionId]);
const auctionOutputObj = checkResultAndRetrieveOutput(auctionResult);
const expectedAuction = getAuctionObj({ owner: testAccount, status: 'reveal' });
const expectedBid = getBidObj({ bidder: testAccount });
expect(auctionOutputObj[0]).toMatchObject(expectedAuction);
expect(auctionOutputObj[0].bids[0]).toMatchObject(expectedBid);
// Reveal bid
const result = spawnSync('laconic', ['cns', 'auction', 'bid', 'reveal', testAuctionId, bidRevealFilePath]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected output
expect(outputObj).toEqual({ success: true });
const revealObject = JSON.parse(fs.readFileSync(bidRevealFilePath, 'utf8'));
expect(revealObject).toMatchObject({
chainId: CHAIN_ID,
auctionId: testAuctionId,
bidderAddress: testAccount,
bidAmount: `${bidAmount}aphoton`
});
}, (AUCTION_COMMIT_DURATION + 5) * 1000);
});
describe('Name authority operations (post auction)', () => {
const testSubAuthorityName = 'echo.laconic';
const testSubAuthorityName2 = 'kube.laconic';
test('laconic cns authority whois <authority_name>', async () => {
// Wait for auction reveals duration (60s)
await delay(AUCTION_REVEAL_DURATION * 1000);
const result = spawnSync('laconic', ['cns', 'authority', 'whois', testAuthorityName]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected authority (active)
const expectedAuthority = getAuthorityObj({ owner: testAccount, status: 'active', auction: null });
expect(outputObj.length).toEqual(1);
expect(outputObj[0]).toMatchObject(expectedAuthority);
}, (AUCTION_REVEAL_DURATION + 5) * 1000);
test('laconic cns authority bond set laconic <bond_id>', async () => {
// Create a new bond to be set on the authority
const bondBalance = 1000000000;
const { bondId } = createBond(bondBalance);
const result = spawnSync('laconic', ['cns', 'authority', 'bond', 'set', testAuthorityName, bondId]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected output
expect(outputObj).toEqual({ success: true });
// Check updated authority
const authorityResult = spawnSync('laconic', ['cns', 'authority', 'whois', testAuthorityName]);
const authorityOutputObj = checkResultAndRetrieveOutput(authorityResult);
// Expected authority (active with bond)
const expectedAuthority = getAuthorityObj({ owner: testAccount, status: 'active', auction: null, bondId: bondId });
expect(authorityOutputObj.length).toEqual(1);
expect(authorityOutputObj[0]).toMatchObject(expectedAuthority);
});
test('laconic cns authority reserve <sub_authority> (same owner)', async () => {
const result = spawnSync('laconic', ['cns', 'authority', 'reserve', testSubAuthorityName]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected output
expect(outputObj).toEqual({ success: true });
// Check updated authority
const authorityResult = spawnSync('laconic', ['cns', 'authority', 'whois', testSubAuthorityName]);
const authorityOutputObj = checkResultAndRetrieveOutput(authorityResult);
// Expected authority (active with bond)
const expectedAuthority = getAuthorityObj({ owner: testAccount, status: 'active', auction: null });
expect(authorityOutputObj.length).toEqual(1);
expect(authorityOutputObj[0]).toMatchObject(expectedAuthority);
});
test('laconic cns authority reserve <sub_authority> --owner <owner_address> (different owner)', async () => {
const result = spawnSync('laconic', ['cns', 'authority', 'reserve', testSubAuthorityName2, '--owner', testAccount2]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected output
expect(outputObj).toEqual({ success: true });
// Check updated authority
const authorityResult = spawnSync('laconic', ['cns', 'authority', 'whois', testSubAuthorityName2]);
const authorityOutputObj = checkResultAndRetrieveOutput(authorityResult);
// Expected authority (active with bond)
const expectedAuthority = getAuthorityObj({ owner: testAccount2, status: 'active', auction: null });
expect(authorityOutputObj.length).toEqual(1);
expect(authorityOutputObj[0]).toMatchObject(expectedAuthority);
});
});
describe('Name operations', () => {
const testName = 'crn://laconic/watcher/erc20';
test('laconic cns name set <name> <record_id>', async () => {
const result = spawnSync('laconic', ['cns', 'name', 'set', testName, testRecordId]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected output
expect(outputObj).toEqual({ success: true });
});
test('laconic cns name lookup <name>', async () => {
const result = spawnSync('laconic', ['cns', 'name', 'lookup', testName]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected output
expect(outputObj.length).toEqual(1);
expect(outputObj[0]).toMatchObject({ latest: { id: testRecordId } });
});
test('laconic cns name resolve <name>', async () => {
const result = spawnSync('laconic', ['cns', 'name', 'resolve', testName]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected resolved record
const expectedRecord = getRecordObj(testRecordFilePath, { bondId: testRecordBondId, recordId: testRecordId, names: [testName] });
expect(outputObj.length).toEqual(1);
expect(outputObj[0]).toMatchObject(expectedRecord);
});
test('laconic cns name delete <name>', async () => {
const result = spawnSync('laconic', ['cns', 'name', 'delete', testName]);
const outputObj = checkResultAndRetrieveOutput(result);
// Expected output
expect(outputObj).toEqual({ success: true });
// Check that name doesn't resolve
const resolveResult = spawnSync('laconic', ['cns', 'name', 'resolve', testName]);
const resolveOutputObj = checkResultAndRetrieveOutput(resolveResult);
expect(resolveOutputObj.length).toEqual(0);
});
});
});
});
+7
View File
@@ -0,0 +1,7 @@
record:
type: WebsiteRegistrationRecord
url: 'https://cerc.io'
repo_registration_record_cid: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
build_artifact_cid: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
tls_cert_cid: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
version: 1.0.23
+121
View File
@@ -0,0 +1,121 @@
import fs from 'fs';
import yaml from 'js-yaml';
import { SpawnSyncReturns, spawnSync } from 'child_process';
export const CHAIN_ID = 'laconic_9000-1';
export const TOKEN_TYPE = 'aphoton';
export const AUCTION_FEES = {
commit: 1000000,
reveal: 1000000,
minimumBid: 5000000
};
export const AUCTION_COMMIT_DURATION = 60; // 60s
export const AUCTION_REVEAL_DURATION = 60; // 60s
export function checkResultAndRetrieveOutput (result: SpawnSyncReturns<Buffer>): any {
expect(result.status).toBe(0);
const errorOutput = result.stderr.toString().trim();
expect(errorOutput).toBe('');
const output = result.stdout.toString().trim();
expect(output.length).toBeGreaterThan(0);
return JSON.parse(output);
}
export function createBond (quantity: number): { bondId: string } {
const result = spawnSync('laconic', ['cns', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', quantity.toString(), '--gas', '200000', '--fees', `200000${TOKEN_TYPE}`]);
const output = result.stdout.toString().trim();
return JSON.parse(output);
}
export function getBondObj (params: { id: string, owner: string, balance: number}): any {
return {
id: params.id,
owner: params.owner,
balance: [
{
type: TOKEN_TYPE,
quantity: params.balance
}
]
};
}
export function getAccountObj (params: { address: string, balance?: number }): any {
const balanceObj: any = { type: TOKEN_TYPE };
if (params.balance) {
balanceObj.quantity = params.balance;
}
return {
address: params.address,
balance: [balanceObj]
};
}
export function getRecordObj (recordFilePath: string, params: { bondId: string, recordId: string, names: any }): any {
const recordContent = yaml.load(fs.readFileSync(recordFilePath, 'utf8')) as any;
return {
id: params.recordId,
names: params.names,
bondId: params.bondId,
attributes: recordContent.record
};
}
export function getAuthorityObj (params: { owner: string, status: string, auction: any, bondId?: string }): any {
return {
ownerAddress: params.owner,
status: params.status,
bondId: params.bondId || '',
auction: params.auction
};
}
export function getAuctionObj (params: { owner: string, status?: string }): any {
return {
status: params.status || 'commit',
ownerAddress: params.owner,
commitFee: {
type: TOKEN_TYPE,
quantity: AUCTION_FEES.commit
},
revealFee: {
type: TOKEN_TYPE,
quantity: AUCTION_FEES.reveal
},
minimumBid: {
type: TOKEN_TYPE,
quantity: AUCTION_FEES.minimumBid
},
winnerAddress: ''
};
}
export function getBidObj (params: { bidder: string, status?: string }): any {
return {
bidderAddress: params.bidder,
status: params.status || 'commit',
commitFee: {
type: TOKEN_TYPE,
quantity: AUCTION_FEES.commit
},
revealFee: {
type: TOKEN_TYPE,
quantity: AUCTION_FEES.reveal
},
bidAmount: {
type: '',
quantity: 0
}
};
}
export async function delay (ms: number): Promise<any> {
return new Promise((resolve) => setTimeout(resolve, ms));
}
+34
View File
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
# Get the key from laconicd
laconicd_key=$(yes | docker compose exec laconicd laconicd keys export mykey --unarmored-hex --unsafe)
# Get the fixturenet account address
laconicd_account_address=$(docker compose exec laconicd laconicd keys list | awk '/- address:/ {print $3}')
# Set parameters for the test suite
cosmos_chain_id=laconic_9000-1
laconicd_rest_endpoint=http://127.0.0.1:1317
laconicd_gql_endpoint=http://127.0.0.1:9473/api
# Create the required config
config_file="config.yml"
config=$(cat <<EOL
services:
cns:
restEndpoint: $laconicd_rest_endpoint
gqlEndpoint: $laconicd_gql_endpoint
userKey: $laconicd_key
bondId:
chainId: $cosmos_chain_id
gas: 200000
fees: 200000aphoton
EOL
)
echo "$config" > "$config_file"
# Wait for the laconid endpoint to come up
docker compose exec laconicd sh -c "curl --retry 10 --retry-delay 3 --retry-connrefused http://127.0.0.1:9473/api"
# Run tests
TEST_ACCOUNT=$laconicd_account_address yarn test
+3 -1
View File
@@ -97,5 +97,7 @@
/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
},
"include": ["src"],
"exclude": ["test"]
}
+7
View File
@@ -0,0 +1,7 @@
record:
type: WebsiteRegistrationRecord
url: 'https://cerc.io'
repo_registration_record_cid: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
build_artifact_cid: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
tls_cert_cid: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
version: 1.0.35
+3318 -9
View File
File diff suppressed because it is too large Load Diff