Compare commits
23
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
58c6d0ff06 | ||
|
|
ddbd0826bd | ||
|
|
dfbef9fe65 | ||
|
|
cf978e4490 | ||
|
|
59c709debd | ||
|
|
679313d960 | ||
|
|
9a45237b2d | ||
|
|
85411f3b06 | ||
|
|
2cc5ae6245 | ||
|
|
b76f52013b | ||
|
|
c3fa657687 | ||
|
|
2ceb7d8483 | ||
|
|
b7a8e7c234 | ||
|
|
a2237f3559 | ||
|
|
30861621cf | ||
|
|
85f350dea9 | ||
|
|
277744e52b | ||
|
|
772eca8c85 | ||
|
|
d1e1a00cf4 | ||
|
|
5f92f288c2 | ||
|
|
65c4c12891 | ||
|
|
6c35fc1980 | ||
|
|
84df789ccd |
@@ -1,5 +0,0 @@
|
|||||||
# Don't lint node_modules.
|
|
||||||
node_modules
|
|
||||||
|
|
||||||
# Don't lint build output.
|
|
||||||
dist
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
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
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
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
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
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
|
|
||||||
@@ -21,7 +21,7 @@ jobs:
|
|||||||
- name: Environment
|
- name: Environment
|
||||||
run: ls -tlh && env
|
run: ls -tlh && env
|
||||||
- name: build registry-cli container
|
- name: build registry-cli container
|
||||||
run: docker build -t cerc/laconic-registry-cli:local-test --build-arg CERC_NPM_URL=https://git.vdb.to/api/packages/cerc-io/npm/ --build-arg CERC_NPM_AUTH_TOKEN="${{ secrets.GITEA_PUBLISH_TOKEN }}" .
|
run: docker build -t cerc/laconic-registry-cli:local-test --build-arg CERC_NPM_URL=https://git.vdb.to/api/packages/cerc-io/npm/ --build-arg CERC_NPM_AUTH_TOKEN=${{ secrets.GITEA_PUBLISH_TOKEN }} .
|
||||||
- name: build containers scripts
|
- name: build containers scripts
|
||||||
working-directory: laconicd/tests/sdk_tests
|
working-directory: laconicd/tests/sdk_tests
|
||||||
run: ./build-laconicd-container.sh
|
run: ./build-laconicd-container.sh
|
||||||
@@ -30,7 +30,11 @@ jobs:
|
|||||||
run: docker compose up laconicd -d
|
run: docker compose up laconicd -d
|
||||||
|
|
||||||
- name: Run registry-cli demo commands in registry-cli container
|
- name: Run registry-cli demo commands in registry-cli container
|
||||||
run : ls -tla
|
run : |
|
||||||
|
laconicd_key=$( docker compose exec laconicd echo y | docker compose exec laconicd laconicd keys export mykey --unarmored-hex --unsafe )
|
||||||
|
./create-config.sh $laconicd_key
|
||||||
|
echo ./config.yml
|
||||||
|
ls -tla
|
||||||
- name: stop containers
|
- name: stop containers
|
||||||
working-directory: laconicd/tests/sdk_tests
|
working-directory: laconicd/tests/sdk_tests
|
||||||
run: docker compose down
|
run: docker compose down
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
yarn lint
|
|
||||||
@@ -515,3 +515,52 @@ Reassociate records (switch bond):
|
|||||||
$ laconic cns bond records reassociate --old-bond-id 5c40abd336ae1561f2a1b55be73b12f5a083080bf879b4c9288d182d238badb0 --new-bond-id 3e11c61f179897e4b12e9b63de35d36f88ac146755e7a28ce0bcdd07cf3a03ae
|
$ laconic cns bond records reassociate --old-bond-id 5c40abd336ae1561f2a1b55be73b12f5a083080bf879b4c9288d182d238badb0 --new-bond-id 3e11c61f179897e4b12e9b63de35d36f88ac146755e7a28ce0bcdd07cf3a03ae
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Run tests
|
||||||
|
|
||||||
|
Follow these steps to run the tests:
|
||||||
|
|
||||||
|
- After cloning this repo run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
yarn
|
||||||
|
```
|
||||||
|
|
||||||
|
- Copy [config.example.yml](./config.example.yml) file and create a `config.yml` file.
|
||||||
|
|
||||||
|
- Clone the [laconicd repo](https://github.com/cerc-io/laconicd) and change to repo directory.
|
||||||
|
|
||||||
|
- Run the chain using `./init.sh`.
|
||||||
|
|
||||||
|
- Export the private key using:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconicd keys export mykey --unarmored-hex --unsafe
|
||||||
|
```
|
||||||
|
|
||||||
|
- Copy the private key and assign it to variable `PRIVATE_KEY` in the `config.yml` file.
|
||||||
|
|
||||||
|
- Run the tests in laconic-sdk repo:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
yarn test
|
||||||
|
```
|
||||||
|
|
||||||
|
- Run the tests with auctions enabled
|
||||||
|
|
||||||
|
- In laconicd repo run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
TEST_AUCTION_ENABLED=true ./init.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
- Export the private key and change it in `config.yml` file again using:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
laconicd keys export mykey --unarmored-hex --unsafe
|
||||||
|
```
|
||||||
|
|
||||||
|
- Run tests:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
yarn test:auctions
|
||||||
|
```
|
||||||
Executable
+30
@@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
if [[ $# -ne 1 ]]; then
|
||||||
|
echo "Usage: $0 <new-key>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Assign the arguments to variables
|
||||||
|
new_key=$1
|
||||||
|
file_path=./config.yml
|
||||||
|
|
||||||
|
# Check if the file exists
|
||||||
|
if [[ ! -f "$file_path" ]]; then
|
||||||
|
echo "Creating file: $file_path"
|
||||||
|
# Create the YAML file
|
||||||
|
cat > $file_path <<EOF
|
||||||
|
services:
|
||||||
|
cns:
|
||||||
|
restEndpoint: 'http://localhost:1317'
|
||||||
|
gqlEndpoint: 'http://localhost:9473/api'
|
||||||
|
userKey: $new_key
|
||||||
|
bondId:
|
||||||
|
chainId: laconic_9000-1
|
||||||
|
gas: 300000
|
||||||
|
fees: 300000aphoton
|
||||||
|
EOF
|
||||||
|
else
|
||||||
|
# Use yq to update the value in the file
|
||||||
|
yq eval ".services.cns.userKey = \"$new_key\"" "$file_path" --inplace
|
||||||
|
fi
|
||||||
+12
-9
@@ -1,25 +1,28 @@
|
|||||||
services:
|
services:
|
||||||
laconicd:
|
laconicd:
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
image: cerc/laconicd:local
|
image: cerc-io/laconicd:local-test
|
||||||
command: ["sh", "/docker-entrypoint-scripts.d/create-fixturenet.sh"]
|
command: ["sh", "/docker-entrypoint-scripts.d/create-fixturenet.sh"]
|
||||||
environment:
|
|
||||||
- TEST_AUCTION_ENABLED
|
|
||||||
- TEST_REGISTRY_EXPIRY
|
|
||||||
- LOGLEVEL
|
|
||||||
volumes:
|
volumes:
|
||||||
- ./laconicd/init.sh:/docker-entrypoint-scripts.d/create-fixturenet.sh
|
- laconicd/init.sh:/docker-entrypoint-scripts.d/create-fixturenet.sh
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "curl", "-v", "http://127.0.0.1:6060"]
|
test: ["CMD", "curl", "-v", "http://127.0.0.1:6060"]
|
||||||
interval: 1s
|
interval: 1s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 30
|
retries: 30
|
||||||
ports:
|
ports:
|
||||||
- "9473:9473"
|
- "6060"
|
||||||
- "1317:1317"
|
- "26657"
|
||||||
|
- "26656"
|
||||||
|
- "9473"
|
||||||
|
- "8545"
|
||||||
|
- "8546"
|
||||||
|
- "9090"
|
||||||
|
- "9091"
|
||||||
|
- "1317"
|
||||||
|
|
||||||
cli-test-runner:
|
cli-test-runner:
|
||||||
image: cerc/laconic-registry-cli:local
|
image: cerc/laconic-registry-cli:local-test
|
||||||
depends_on:
|
depends_on:
|
||||||
laconicd:
|
laconicd:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
|||||||
+2
-3
@@ -1,6 +1,5 @@
|
|||||||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
preset: 'ts-jest',
|
preset: 'ts-jest',
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
setupFiles: ['dotenv/config']
|
};
|
||||||
};
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "2.9.0",
|
||||||
|
"useWorkspaces": true,
|
||||||
|
"npmClient": "yarn"
|
||||||
|
}
|
||||||
+9
-19
@@ -1,34 +1,24 @@
|
|||||||
{
|
{
|
||||||
"name": "@cerc-io/laconic-registry-cli",
|
"name": "@cerc-io/laconic-registry-cli",
|
||||||
"version": "0.1.13",
|
"version": "0.1.0",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"repository": "git@github.com:cerc-io/laconic-registry-cli.git",
|
"repository": "git@github.com:cerc-io/laconic-registry-cli.git",
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/fs-extra": "^9.0.13",
|
"@types/fs-extra": "^9.0.13",
|
||||||
"@types/jest": "^27.4.1",
|
"@types/jest": "^29.5.0",
|
||||||
"@types/js-yaml": "^4.0.5",
|
"@types/js-yaml": "^4.0.5",
|
||||||
"@types/lodash": "^4.14.182",
|
"@types/lodash": "^4.14.182",
|
||||||
"@types/node": "^17.0.25",
|
"@types/node": "^17.0.25",
|
||||||
|
"@types/semver": "^7.3.13",
|
||||||
"@types/yargs": "^17.0.10",
|
"@types/yargs": "^17.0.10",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.47.1",
|
"jest": "^29.5.0",
|
||||||
"@typescript-eslint/parser": "^5.47.1",
|
"ts-jest": "^29.0.5",
|
||||||
"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"
|
"typescript": "^4.6.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@cerc-io/laconic-sdk": "^0.1.16",
|
"@cerc-io/laconic-sdk": "0.1.6",
|
||||||
"fs-extra": "^10.1.0",
|
"fs-extra": "^10.1.0",
|
||||||
"js-yaml": "^3.14.1",
|
"js-yaml": "^3.14.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
@@ -36,13 +26,13 @@
|
|||||||
"yargs": "^17.4.1"
|
"yargs": "^17.4.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest --runInBand --verbose test/cli.test.ts",
|
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"clean": "rm -rf ./dist",
|
"clean": "rm -rf ./dist",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"prepare": "husky"
|
"test": "jest --runInBand --verbose",
|
||||||
|
"test:auctions": "TEST_AUCTIONS_ENABLED=1 jest --runInBand --verbose test/auction.test.ts"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"laconic": "bin/laconic"
|
"laconic": "bin/laconic"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export const desc = 'Get account.';
|
|||||||
export const handler = async (argv: Arguments) => {
|
export const handler = async (argv: Arguments) => {
|
||||||
let address = argv.address as string;
|
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);
|
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL 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 registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||||
const result = await registry.getAccounts([address]);
|
const result = await registry.getAccounts([address]);
|
||||||
|
|
||||||
queryOutput(result, argv.output);
|
queryOutput(result,argv.output);
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -7,4 +7,4 @@ export const desc = 'Account operations.';
|
|||||||
exports.builder = (yargs: yargs.Argv) => {
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
return yargs.commandDir('account-cmds')
|
return yargs.commandDir('account-cmds')
|
||||||
.demandCommand();
|
.demandCommand();
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
assert(quantity, 'Invalid token quantity.');
|
assert(quantity, 'Invalid token quantity.');
|
||||||
assert(denom, 'Invalid token type.');
|
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);
|
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||||
@@ -43,7 +43,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const fee = getGasAndFees(argv, cnsConfig);
|
const fee = getGasAndFees(argv, cnsConfig);
|
||||||
|
|
||||||
const result = await registry.commitBid({ auctionId, commitHash }, privateKey, fee);
|
const result = await registry.commitBid({ auctionId, commitHash }, privateKey, fee);
|
||||||
const revealFile = `{"reveal_file":"${revealFilePath}"}`;
|
const revealFile = `{"reveal_file":"${revealFilePath}"}`
|
||||||
|
|
||||||
txOutput(result, revealFile, argv.output, argv.verbose);
|
txOutput(result,revealFile,argv.output,argv.verbose)
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
assert(auctionId, 'Invalid auction ID.');
|
assert(auctionId, 'Invalid auction ID.');
|
||||||
assert(filePath, 'Invalid reveal file path.');
|
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);
|
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||||
@@ -28,7 +28,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
|
|
||||||
const reveal = fs.readFileSync(path.resolve(filePath));
|
const reveal = fs.readFileSync(path.resolve(filePath));
|
||||||
const result = await registry.revealBid({ auctionId, reveal: reveal.toString('hex') }, privateKey, fee);
|
const result = await registry.revealBid({ auctionId, reveal: reveal.toString('hex') }, privateKey, fee);
|
||||||
const success = `{"success":${result.code === 0}}`;
|
const success = `{"success":${result.code==0}}`
|
||||||
|
|
||||||
txOutput(result, success, argv.output, argv.verbose);
|
txOutput(result,success,argv.output,argv.verbose)
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ export const desc = 'Auction bid operations.';
|
|||||||
|
|
||||||
exports.builder = (yargs: yargs.Argv) => {
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
return yargs.options({
|
return yargs.options({
|
||||||
'auction-id': { type: 'string' },
|
'auction-id': { type: 'string' },
|
||||||
type: { type: 'string' },
|
'type': { type: 'string' },
|
||||||
quantity: { type: 'string' },
|
'quantity': { type: 'string' },
|
||||||
'file-path': { type: 'string' }
|
'file-path': { type: 'string' }
|
||||||
}).commandDir('bid-cmds')
|
}).commandDir('bid-cmds')
|
||||||
.demandCommand();
|
.demandCommand();
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const { id, config } = argv;
|
const { id, config } = argv;
|
||||||
assert(id, 'Invalid auction ID.');
|
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);
|
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL 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 registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||||
const result = await registry.getAuctionsByIds([id as string]);
|
const result = await registry.getAuctionsByIds([id as string]);
|
||||||
|
|
||||||
queryOutput(result, argv.output);
|
queryOutput(result,argv.output)
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -7,4 +7,4 @@ export const desc = 'Auction operations.';
|
|||||||
exports.builder = (yargs: yargs.Argv) => {
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
return yargs.commandDir('auction-cmds')
|
return yargs.commandDir('auction-cmds')
|
||||||
.demandCommand();
|
.demandCommand();
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
assert(name, 'Invalid authority name.');
|
assert(name, 'Invalid authority name.');
|
||||||
assert(bondId, 'Invalid Bond 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);
|
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||||
@@ -24,7 +24,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
const fee = getGasAndFees(argv, cnsConfig);
|
||||||
const result = await registry.setAuthorityBond({ name, bondId }, privateKey, fee);
|
const result = await registry.setAuthorityBond({ name, bondId }, privateKey, fee);
|
||||||
const success = `{"success":${result.code === 0}}`;
|
const success = `{"success":${result.code==0}}`
|
||||||
|
|
||||||
txOutput(result, success, argv.output, argv.verbose);
|
txOutput(result,success,argv.output,argv.verbose)
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -7,4 +7,4 @@ export const desc = 'Authority bond operations.';
|
|||||||
exports.builder = (yargs: yargs.Argv) => {
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
return yargs.commandDir('bond-cmds')
|
return yargs.commandDir('bond-cmds')
|
||||||
.demandCommand();
|
.demandCommand();
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -13,14 +13,14 @@ export const builder = {
|
|||||||
type: 'string',
|
type: 'string',
|
||||||
default: ''
|
default: ''
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
export const handler = async (argv: Arguments) => {
|
||||||
const name = argv.name as string;
|
const name = argv.name as string;
|
||||||
const owner = argv.owner as string;
|
const owner = argv.owner as string;
|
||||||
assert(name, 'Invalid authority name.');
|
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);
|
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||||
@@ -31,6 +31,6 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const fee = getGasAndFees(argv, cnsConfig);
|
const fee = getGasAndFees(argv, cnsConfig);
|
||||||
const result = await registry.reserveAuthority({ name, owner }, privateKey, fee);
|
const result = await registry.reserveAuthority({ name, owner }, privateKey, fee);
|
||||||
|
|
||||||
const success = `{"success":${result.code === 0}}`;
|
const success = `{"success":${result.code==0}}`
|
||||||
txOutput(result, success, argv.output, argv.verbose);
|
txOutput(result,success,argv.output,argv.verbose)
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const name = argv.name as string;
|
const name = argv.name as string;
|
||||||
assert(name, 'Invalid authority name.');
|
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);
|
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL 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 registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||||
const result = await registry.lookupAuthorities([name], true);
|
const result = await registry.lookupAuthorities([name], true);
|
||||||
|
|
||||||
queryOutput(result, argv.output);
|
queryOutput(result,argv.output)
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -7,4 +7,4 @@ export const desc = 'Name authority operations.';
|
|||||||
exports.builder = (yargs: yargs.Argv) => {
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
return yargs.commandDir('authority-cmds')
|
return yargs.commandDir('authority-cmds')
|
||||||
.demandCommand();
|
.demandCommand();
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
import { Registry } from '@cerc-io/laconic-sdk';
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
|
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
|
||||||
|
|
||||||
export const command = 'associate';
|
export const command = 'associate';
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ export const builder = {
|
|||||||
'bond-id': {
|
'bond-id': {
|
||||||
type: 'string'
|
type: 'string'
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
export const handler = async (argv: Arguments) => {
|
||||||
const id = argv.id as string;
|
const id = argv.id as string;
|
||||||
@@ -20,7 +20,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
assert(id, 'Invalid Record ID.');
|
assert(id, 'Invalid Record ID.');
|
||||||
assert(bondId, 'Invalid Bond 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);
|
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||||
@@ -30,6 +30,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
const fee = getGasAndFees(argv, cnsConfig);
|
||||||
const result = await registry.associateBond({ recordId: id, bondId }, privateKey, fee);
|
const result = await registry.associateBond({ recordId: id, bondId }, privateKey, fee);
|
||||||
const success = `{"success":${result.code === 0}}`;
|
const success = `{"success":${result.code==0}}`
|
||||||
txOutput(result, success, argv.output, argv.verbose);
|
txOutput(result,success,argv.output,argv.verbose)
|
||||||
};
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,17 +2,17 @@ import { Arguments } from 'yargs';
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
import { Registry } from '@cerc-io/laconic-sdk';
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
|
import { getConfig, getConnectionInfo, getGasAndFees,txOutput } from '../../../util';
|
||||||
|
|
||||||
export const command = 'cancel';
|
export const command = 'cancel';
|
||||||
|
|
||||||
export const desc = 'Cancel bond.';
|
export const desc = 'Cancel bond.';
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
export const handler = async (argv: Arguments) => {
|
||||||
const id = argv.id as string;
|
const id = argv.id as string
|
||||||
assert(id, 'Invalid Bond ID.');
|
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);
|
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||||
@@ -22,6 +22,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
const fee = getGasAndFees(argv, cnsConfig);
|
||||||
const result = await registry.cancelBond({ id }, privateKey, fee);
|
const result = await registry.cancelBond({ id }, privateKey, fee);
|
||||||
const success = `{"success":${result.code === 0}}`;
|
const success = `{"success":${result.code==0}}`
|
||||||
txOutput(result, success, argv.output, argv.verbose);
|
txOutput(result,success,argv.output,argv.verbose)
|
||||||
};
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
import { Registry } from '@cerc-io/laconic-sdk';
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
|
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
|
||||||
|
|
||||||
export const command = 'create';
|
export const command = 'create';
|
||||||
|
|
||||||
@@ -15,17 +15,17 @@ export const builder = {
|
|||||||
quantity: {
|
quantity: {
|
||||||
type: 'string'
|
type: 'string'
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
export const handler = async (argv: Arguments) => {
|
||||||
const { config } = argv;
|
const { config, verbose } = argv;
|
||||||
const denom = argv.type as string;
|
const denom = argv.type as string;
|
||||||
const amount = argv.quantity as string;
|
const amount = argv.quantity as string;
|
||||||
|
|
||||||
assert(denom, 'Invalid Type.');
|
assert(denom, 'Invalid Type.');
|
||||||
assert(amount, 'Invalid Quantity.');
|
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);
|
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||||
@@ -36,7 +36,8 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const fee = getGasAndFees(argv, cnsConfig);
|
const fee = getGasAndFees(argv, cnsConfig);
|
||||||
const bondId = await registry.getNextBondId(privateKey);
|
const bondId = await registry.getNextBondId(privateKey);
|
||||||
const result = await registry.createBond({ denom, amount }, privateKey, fee);
|
const result = await registry.createBond({ denom, amount }, privateKey, fee);
|
||||||
const jsonString = `{"bondId":"${bondId}"}`;
|
const jsonString=`{"bondId":"${bondId}"}`
|
||||||
|
|
||||||
txOutput(result, jsonString, argv.output, argv.verbose);
|
txOutput(result,jsonString,argv.output,argv.verbose)
|
||||||
};
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
import { Registry } from '@cerc-io/laconic-sdk';
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
|
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
|
||||||
|
|
||||||
export const command = 'dissociate';
|
export const command = 'dissociate';
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const id = argv.id as string;
|
const id = argv.id as string;
|
||||||
assert(id, 'Invalid Record ID.');
|
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);
|
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||||
@@ -22,6 +22,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
const fee = getGasAndFees(argv, cnsConfig);
|
||||||
const result = await registry.dissociateBond({ recordId: id }, privateKey, fee);
|
const result = await registry.dissociateBond({ recordId: id }, privateKey, fee);
|
||||||
const success = `{"success":${result.code === 0}}`;
|
const success = `{"success":${result.code==0}}`
|
||||||
txOutput(result, success, argv.output, argv.verbose);
|
txOutput(result,success,argv.output,argv.verbose)
|
||||||
};
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
import { Registry } from '@cerc-io/laconic-sdk';
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
|
||||||
|
|
||||||
export const command = 'get';
|
export const command = 'get';
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const { id, config } = argv;
|
const { id, config } = argv;
|
||||||
console.assert(id, 'Bond Id is required.');
|
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);
|
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||||
@@ -22,5 +22,5 @@ export const handler = async (argv: Arguments) => {
|
|||||||
|
|
||||||
const result = await registry.getBondsByIds([id as string]);
|
const result = await registry.getBondsByIds([id as string]);
|
||||||
|
|
||||||
queryOutput(result, argv.output);
|
queryOutput(result,argv.output)
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
import { Registry } from '@cerc-io/laconic-sdk';
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
|
||||||
|
|
||||||
export const command = 'list';
|
export const command = 'list';
|
||||||
|
|
||||||
@@ -12,10 +12,10 @@ export const builder = {
|
|||||||
owner: {
|
owner: {
|
||||||
type: 'string'
|
type: 'string'
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
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 { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||||
@@ -26,5 +26,5 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const { owner } = argv;
|
const { owner } = argv;
|
||||||
const result = await registry.queryBonds({ owner });
|
const result = await registry.queryBonds({ owner });
|
||||||
|
|
||||||
queryOutput(result, argv.output);
|
queryOutput(result,argv.output)
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
import { Registry } from '@cerc-io/laconic-sdk';
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../../util';
|
import { getConfig, getConnectionInfo, getGasAndFees,txOutput } from '../../../../util';
|
||||||
|
|
||||||
export const command = 'dissociate';
|
export const command = 'dissociate';
|
||||||
|
|
||||||
@@ -12,13 +12,13 @@ export const builder = {
|
|||||||
'bond-id': {
|
'bond-id': {
|
||||||
type: 'string'
|
type: 'string'
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
export const handler = async (argv: Arguments) => {
|
||||||
const bondId = argv.bondId as string;
|
const bondId = argv.bondId as string;
|
||||||
assert(bondId, 'Invalid Bond 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);
|
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||||
@@ -28,6 +28,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
const fee = getGasAndFees(argv, cnsConfig);
|
||||||
const result = await registry.dissociateRecords({ bondId }, privateKey, fee);
|
const result = await registry.dissociateRecords({ bondId }, privateKey, fee);
|
||||||
const success = `{"success":${result.code === 0}}`;
|
const success = `{"success":${result.code==0}}`
|
||||||
txOutput(result, success, argv.output, argv.verbose);
|
txOutput(result,success,argv.output,argv.verbose)
|
||||||
};
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
import { Registry } from '@cerc-io/laconic-sdk';
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../../util';
|
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../../util';
|
||||||
|
|
||||||
export const command = 'reassociate';
|
export const command = 'reassociate';
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ export const builder = {
|
|||||||
'new-bond-id': {
|
'new-bond-id': {
|
||||||
type: 'string'
|
type: 'string'
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
export const handler = async (argv: Arguments) => {
|
||||||
const oldBondId = argv.oldBondId as string;
|
const oldBondId = argv.oldBondId as string;
|
||||||
@@ -23,7 +23,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
assert(oldBondId, 'Invalid Old Bond ID.');
|
assert(oldBondId, 'Invalid Old Bond ID.');
|
||||||
assert(newBondId, 'Invalid New 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);
|
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||||
@@ -33,6 +33,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
const fee = getGasAndFees(argv, cnsConfig);
|
||||||
const result = await registry.reassociateRecords({ oldBondId, newBondId }, privateKey, fee);
|
const result = await registry.reassociateRecords({ oldBondId, newBondId }, privateKey, fee);
|
||||||
const success = `{"success":${result.code === 0}}`;
|
const success = `{"success":${result.code==0}}`
|
||||||
txOutput(result, success, argv.output, argv.verbose);
|
txOutput(result,success,argv.output,argv.verbose)
|
||||||
};
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,4 +7,4 @@ export const desc = 'Bond records operations.';
|
|||||||
exports.builder = (yargs: yargs.Argv) => {
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
return yargs.commandDir('records-cmds')
|
return yargs.commandDir('records-cmds')
|
||||||
.demandCommand();
|
.demandCommand();
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import { Arguments } from 'yargs';
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
import { Registry } from '@cerc-io/laconic-sdk';
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
|
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
|
||||||
|
import { isNil } from 'lodash';
|
||||||
|
|
||||||
export const command = 'refill';
|
export const command = 'refill';
|
||||||
|
|
||||||
@@ -15,18 +16,18 @@ export const builder = {
|
|||||||
quantity: {
|
quantity: {
|
||||||
type: 'string'
|
type: 'string'
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
export const handler = async (argv: Arguments) => {
|
||||||
const denom = argv.type as string;
|
const denom = argv.type as string;
|
||||||
const amount = argv.quantity 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(id, 'Invalid Bond ID.');
|
||||||
assert(denom, 'Invalid Type.');
|
assert(denom, 'Invalid Type.');
|
||||||
assert(amount, 'Invalid Quantity.');
|
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);
|
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||||
@@ -36,6 +37,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
const fee = getGasAndFees(argv, cnsConfig);
|
||||||
const result = await registry.refillBond({ id, denom, amount }, privateKey, fee);
|
const result = await registry.refillBond({ id, denom, amount }, privateKey, fee);
|
||||||
const success = `{"success":${result.code === 0}}`;
|
const success = `{"success":${result.code==0}}`
|
||||||
txOutput(result, success, argv.output, argv.verbose);
|
txOutput(result,success,argv.output,argv.verbose)
|
||||||
};
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
import { Registry } from '@cerc-io/laconic-sdk';
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
|
import { getConfig, getConnectionInfo, getGasAndFees,txOutput } from '../../../util';
|
||||||
|
|
||||||
export const command = 'withdraw';
|
export const command = 'withdraw';
|
||||||
|
|
||||||
@@ -15,18 +15,18 @@ export const builder = {
|
|||||||
quantity: {
|
quantity: {
|
||||||
type: 'string'
|
type: 'string'
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
export const handler = async (argv: Arguments) => {
|
||||||
const denom = argv.type as string;
|
const denom = argv.type as string;
|
||||||
const amount = argv.quantity 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(id, 'Invalid Bond ID.');
|
||||||
assert(denom, 'Invalid Type.');
|
assert(denom, 'Invalid Type.');
|
||||||
assert(amount, 'Invalid Quantity.');
|
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);
|
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||||
@@ -36,6 +36,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
const fee = getGasAndFees(argv, cnsConfig);
|
||||||
const result = await registry.withdrawBond({ id, denom, amount }, privateKey, fee);
|
const result = await registry.withdrawBond({ id, denom, amount }, privateKey, fee);
|
||||||
const success = `{"success":${result.code === 0}}`;
|
const success = `{"success":${result.code==0}}`
|
||||||
txOutput(result, success, argv.output, argv.verbose);
|
txOutput(result,success,argv.output,argv.verbose)
|
||||||
};
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,4 +7,4 @@ export const desc = 'Bonds operations.';
|
|||||||
exports.builder = (yargs: yargs.Argv) => {
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
return yargs.commandDir('bond-cmds')
|
return yargs.commandDir('bond-cmds')
|
||||||
.demandCommand();
|
.demandCommand();
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
import { Registry } from '@cerc-io/laconic-sdk';
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
|
import { getConfig, getConnectionInfo, getGasAndFees ,txOutput} from '../../../util';
|
||||||
|
|
||||||
export const command = 'delete [name]';
|
export const command = 'delete [name]';
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const name = argv.name as string;
|
const name = argv.name as string;
|
||||||
assert(name, 'Invalid Name.');
|
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);
|
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||||
@@ -23,6 +23,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const fee = getGasAndFees(argv, cnsConfig);
|
const fee = getGasAndFees(argv, cnsConfig);
|
||||||
const result = await registry.deleteName({ crn: name }, privateKey, fee);
|
const result = await registry.deleteName({ crn: name }, privateKey, fee);
|
||||||
|
|
||||||
const success = `{"success":${result.code === 0}}`;
|
const success = `{"success":${result.code==0}}`
|
||||||
txOutput(result, success, argv.output, argv.verbose);
|
txOutput(result,success,argv.output,argv.verbose)
|
||||||
};
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
import { Registry } from '@cerc-io/laconic-sdk';
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
|
||||||
|
|
||||||
export const command = 'lookup [name]';
|
export const command = 'lookup [name]';
|
||||||
|
|
||||||
@@ -12,13 +12,13 @@ export const builder = {
|
|||||||
history: {
|
history: {
|
||||||
type: 'boolean'
|
type: 'boolean'
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
export const handler = async (argv: Arguments) => {
|
||||||
const name = argv.name as string;
|
const name = argv.name as string;
|
||||||
assert(name, 'Invalid Name.');
|
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);
|
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL 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 registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||||
const result = await registry.lookupNames([name], argv.history as boolean);
|
const result = await registry.lookupNames([name], argv.history as boolean);
|
||||||
|
|
||||||
queryOutput(result, argv.output);
|
queryOutput(result,argv.output)
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
import { Registry } from '@cerc-io/laconic-sdk';
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
import { getConfig, getConnectionInfo,queryOutput } from '../../../util';
|
||||||
|
|
||||||
export const command = 'resolve [name]';
|
export const command = 'resolve [name]';
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const name = argv.name as string;
|
const name = argv.name as string;
|
||||||
assert(name, 'Invalid Name.');
|
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);
|
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||||
@@ -20,8 +20,6 @@ export const handler = async (argv: Arguments) => {
|
|||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||||
|
|
||||||
let result = await registry.resolveNames([name]);
|
const result = await registry.resolveNames([name]);
|
||||||
result = result.filter((v: any) => v);
|
queryOutput(result,argv.output)
|
||||||
|
}
|
||||||
queryOutput(result, argv.output);
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
import { Registry } from '@cerc-io/laconic-sdk';
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, getGasAndFees, txOutput } from '../../../util';
|
import { getConfig, getConnectionInfo, getGasAndFees,txOutput } from '../../../util';
|
||||||
|
|
||||||
export const command = 'set [name] [id]';
|
export const command = 'set [name] [id]';
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
assert(name, 'Invalid Name.');
|
assert(name, 'Invalid Name.');
|
||||||
assert(id, 'Invalid Record ID.');
|
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);
|
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||||
@@ -25,6 +25,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const fee = getGasAndFees(argv, cnsConfig);
|
const fee = getGasAndFees(argv, cnsConfig);
|
||||||
const result = await registry.setName({ crn: name, cid: id }, privateKey, fee);
|
const result = await registry.setName({ crn: name, cid: id }, privateKey, fee);
|
||||||
|
|
||||||
const success = `{"success":${result.code === 0}}`;
|
const success = `{"success":${result.code==0}}`
|
||||||
txOutput(result, success, argv.output, argv.verbose);
|
txOutput(result,success,argv.output,argv.verbose)
|
||||||
};
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,5 +6,5 @@ export const desc = 'Name operations.';
|
|||||||
|
|
||||||
exports.builder = (yargs: yargs.Argv) => {
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
return yargs.commandDir('name-cmds')
|
return yargs.commandDir('name-cmds')
|
||||||
.demandCommand();
|
.demandCommand()
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
import { Registry } from '@cerc-io/laconic-sdk';
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
|
||||||
|
|
||||||
export const command = 'get';
|
export const command = 'get';
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const { id, config } = argv;
|
const { id, config } = argv;
|
||||||
assert(id, 'Invalid Record ID.');
|
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);
|
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL 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 registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||||
const result = await registry.getRecordsByIds([id as string]);
|
const result = await registry.getRecordsByIds([id as string]);
|
||||||
|
|
||||||
queryOutput(result, argv.output);
|
queryOutput(result,argv.output)
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
import { Registry } from '@cerc-io/laconic-sdk';
|
||||||
|
|
||||||
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
import { getConfig, getConnectionInfo ,queryOutput} from '../../../util';
|
||||||
|
|
||||||
export const command = 'list';
|
export const command = 'list';
|
||||||
|
|
||||||
@@ -12,9 +12,6 @@ export const builder = {
|
|||||||
'bond-id': {
|
'bond-id': {
|
||||||
type: 'string'
|
type: 'string'
|
||||||
},
|
},
|
||||||
owner: {
|
|
||||||
type: 'string'
|
|
||||||
},
|
|
||||||
type: {
|
type: {
|
||||||
type: 'string'
|
type: 'string'
|
||||||
},
|
},
|
||||||
@@ -25,18 +22,12 @@ export const builder = {
|
|||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: false
|
default: false
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
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 { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
const { type, name, bondId, owner, all } = argv;
|
const { type, name, bondId, 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(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||||
@@ -44,16 +35,6 @@ export const handler = async (argv: Arguments) => {
|
|||||||
|
|
||||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||||
|
|
||||||
let result = await registry.queryRecords({ ...filters, type, name }, all as boolean);
|
const result = await registry.queryRecords({ bondId, type, name }, all as boolean);
|
||||||
|
queryOutput(result,argv.output)
|
||||||
// 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);
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Arguments } from 'yargs';
|
import { Arguments } from 'yargs';
|
||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
|
import path from 'path';
|
||||||
import yaml from 'js-yaml';
|
import yaml from 'js-yaml';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { Registry } from '@cerc-io/laconic-sdk';
|
import { Registry } from '@cerc-io/laconic-sdk';
|
||||||
@@ -13,12 +14,12 @@ export const desc = 'Register record.';
|
|||||||
export const builder = {
|
export const builder = {
|
||||||
'bond-id': {
|
'bond-id': {
|
||||||
type: 'string'
|
type: 'string'
|
||||||
}
|
},
|
||||||
};
|
}
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
export const handler = async (argv: Arguments) => {
|
||||||
const { txKey, filename, config } = argv;
|
const { txKey, filename, verbose, config } = argv;
|
||||||
const { services: { cns: cnsConfig } } = getConfig(config as string);
|
const { services: { cns: cnsConfig } } = getConfig(config as string)
|
||||||
const { restEndpoint, gqlEndpoint, userKey, bondId, chainId } = getConnectionInfo(argv, cnsConfig);
|
const { restEndpoint, gqlEndpoint, userKey, bondId, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
|
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
@@ -29,23 +30,15 @@ export const handler = async (argv: Arguments) => {
|
|||||||
|
|
||||||
let file = null;
|
let file = null;
|
||||||
if (filename) {
|
if (filename) {
|
||||||
file = filename as string;
|
file = path.join(process.cwd(), filename as string);
|
||||||
} else {
|
} else {
|
||||||
file = 0; // stdin
|
file = 0; // stdin
|
||||||
}
|
}
|
||||||
|
|
||||||
const { record } = await yaml.load(fs.readFileSync(file, 'utf-8')) as any;
|
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 registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||||
const fee = getGasAndFees(argv, cnsConfig);
|
const fee = getGasAndFees(argv, cnsConfig);
|
||||||
const result = await registry.setRecord({ privateKey: userKey, record, bondId }, txKey as string, fee);
|
const result = await registry.setRecord({ privateKey: userKey, record, bondId }, txKey as string, fee);
|
||||||
|
|
||||||
txOutput(result, JSON.stringify(result.data, undefined, 2), argv.output, argv.verbose);
|
txOutput(result,JSON.stringify(result.data,undefined,2),argv.output,argv.verbose)
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -6,6 +6,5 @@ export const desc = 'Record operations.';
|
|||||||
|
|
||||||
exports.builder = (yargs: yargs.Argv) => {
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
return yargs.commandDir('record-cmds')
|
return yargs.commandDir('record-cmds')
|
||||||
.parserConfiguration({ 'unknown-options-as-args': true })
|
.demandCommand()
|
||||||
.demandCommand();
|
}
|
||||||
};
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export const command = 'status';
|
|||||||
export const desc = 'Get CNS status.';
|
export const desc = 'Get CNS status.';
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
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);
|
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cns);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||||
@@ -19,4 +19,4 @@ export const handler = async (argv: Arguments) => {
|
|||||||
|
|
||||||
const result = await registry.getStatus();
|
const result = await registry.getStatus();
|
||||||
console.log(JSON.stringify(result, undefined, 2));
|
console.log(JSON.stringify(result, undefined, 2));
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export const builder = {
|
|||||||
quantity: {
|
quantity: {
|
||||||
type: 'string'
|
type: 'string'
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const handler = async (argv: Arguments) => {
|
export const handler = async (argv: Arguments) => {
|
||||||
const destinationAddress = argv.address as string;
|
const destinationAddress = argv.address as string;
|
||||||
@@ -26,7 +26,7 @@ export const handler = async (argv: Arguments) => {
|
|||||||
assert(denom, 'Invalid Type.');
|
assert(denom, 'Invalid Type.');
|
||||||
assert(amount, 'Invalid Quantity.');
|
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);
|
const { restEndpoint, gqlEndpoint, privateKey, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||||
@@ -40,5 +40,5 @@ export const handler = async (argv: Arguments) => {
|
|||||||
const fee = getGasAndFees(argv, cnsConfig);
|
const fee = getGasAndFees(argv, cnsConfig);
|
||||||
await registry.sendCoins({ denom, amount, destinationAddress }, privateKey, fee);
|
await registry.sendCoins({ denom, amount, destinationAddress }, privateKey, fee);
|
||||||
const result = await registry.getAccounts([fromAddress, destinationAddress]);
|
const result = await registry.getAccounts([fromAddress, destinationAddress]);
|
||||||
queryOutput(result, argv.output);
|
queryOutput(result,argv.output)
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -7,4 +7,4 @@ export const desc = 'Tokens operations.';
|
|||||||
exports.builder = (yargs: yargs.Argv) => {
|
exports.builder = (yargs: yargs.Argv) => {
|
||||||
return yargs.commandDir('tokens-cmds')
|
return yargs.commandDir('tokens-cmds')
|
||||||
.demandCommand();
|
.demandCommand();
|
||||||
};
|
}
|
||||||
|
|||||||
+7
-7
@@ -11,13 +11,13 @@ exports.builder = (yargs: yargs.Argv) => {
|
|||||||
'tx-key': { type: 'string' },
|
'tx-key': { type: 'string' },
|
||||||
'bond-id': { type: 'string' },
|
'bond-id': { type: 'string' },
|
||||||
'chain-id': { type: 'string' },
|
'chain-id': { type: 'string' },
|
||||||
filename: { alias: 'f' },
|
'filename': { alias: 'f' },
|
||||||
id: { type: 'string' },
|
'id': { type: 'string' },
|
||||||
address: { type: 'string' },
|
'address': { type: 'string' },
|
||||||
gas: { type: 'string' },
|
'gas': { type: 'string' },
|
||||||
fees: { type: 'string' }
|
'fees': { type: 'string' }
|
||||||
})
|
})
|
||||||
.commandDir('cns-cmds')
|
.commandDir('cns-cmds')
|
||||||
.demandCommand()
|
.demandCommand()
|
||||||
.help();
|
.help()
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import yargs from 'yargs/yargs';
|
import yargs from 'yargs/yargs';
|
||||||
import { hideBin } from 'yargs/helpers';
|
import { hideBin } from 'yargs/helpers';
|
||||||
|
|
||||||
// eslint-disable-next-line no-unused-expressions
|
|
||||||
yargs(hideBin(process.argv))
|
yargs(hideBin(process.argv))
|
||||||
.options({
|
.options({
|
||||||
verbose: {
|
verbose: {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
import { Arguments } from 'yargs';
|
import { Arguments } from "yargs";
|
||||||
import clean from 'lodash-clean';
|
import clean from 'lodash-clean';
|
||||||
|
|
||||||
export const getConnectionInfo = (argv: Arguments, config: any) => {
|
export const getConnectionInfo = (argv: Arguments, config: any) => {
|
||||||
|
|||||||
+4
-4
@@ -1,9 +1,9 @@
|
|||||||
import yaml from 'js-yaml';
|
import yaml from 'js-yaml'
|
||||||
import fs from 'fs';
|
import fs from 'fs'
|
||||||
import path from 'path';
|
import path from 'path'
|
||||||
|
|
||||||
export const getConfig = (configFilePath: string): any => {
|
export const getConfig = (configFilePath: string): any => {
|
||||||
const resolvedFilePath = path.resolve(process.cwd(), configFilePath);
|
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);
|
return yaml.load(configFile);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import { Arguments } from 'yargs';
|
import { Arguments } from 'yargs';
|
||||||
|
|
||||||
|
|||||||
+12
-18
@@ -1,22 +1,16 @@
|
|||||||
|
|
||||||
export const txOutput = (result:any, msg:string, output:unknown, verbose:unknown) => {
|
export const txOutput = (result:any,msg:string,output:unknown,verbose:unknown) => {
|
||||||
if (output === 'json') {
|
if (output=="json"){
|
||||||
console.log(verbose ? JSON.parse(JSON.stringify(result)) : JSON.parse(msg));
|
console.log(verbose ? JSON.parse(JSON.stringify(result)) : JSON.parse(msg));
|
||||||
} else {
|
} else {
|
||||||
console.log(verbose ? JSON.stringify(result, undefined, 2) : msg);
|
console.log(verbose ? JSON.stringify(result,undefined,2) : msg);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const queryOutput = (result: any, output: unknown) => {
|
export const queryOutput = (result: any, output: unknown) => {
|
||||||
if (output === 'json') {
|
if (output=="json"){
|
||||||
console.log(JSON.parse(JSON.stringify(result)));
|
console.log(JSON.parse(JSON.stringify(result)));
|
||||||
} else {
|
} else {
|
||||||
console.log(JSON.stringify(result, (key, value) => {
|
console.log(JSON.stringify(result,undefined,2));
|
||||||
try {
|
}
|
||||||
return JSON.parse(value);
|
}
|
||||||
} catch (e) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}, 2));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import {cliTest} from './helper';
|
||||||
|
|
||||||
|
const args= "account "
|
||||||
|
const type= "aphoton"
|
||||||
|
const quantity="10"
|
||||||
|
const address="ethm1vc62ysqu504at932jjq8pwrqgjt67rx6ggn5yu"
|
||||||
|
|
||||||
|
describe("test account",() => {
|
||||||
|
it("get account should return account details",async ()=>{
|
||||||
|
// send tokens to account to avoid account not found error
|
||||||
|
const sendResp=cliTest("tokens send --address "+address+" --type "+type+" --quantity "+quantity)
|
||||||
|
expect(sendResp).toBeDefined();
|
||||||
|
|
||||||
|
const resp=cliTest(args+"get --address "+address);
|
||||||
|
expect(resp).toBeDefined();
|
||||||
|
expect(resp[0].address).toEqual(address)
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import {cliTest,createAuthority, getAuctionId} from './helper';
|
||||||
|
|
||||||
|
jest.setTimeout(3 * 60 * 1000);
|
||||||
|
|
||||||
|
const args= "auction ";
|
||||||
|
const quantity=25000000
|
||||||
|
const type="aphoton"
|
||||||
|
const name=`laconic-auction-${Date.now()}`
|
||||||
|
|
||||||
|
|
||||||
|
var auctionId: string;
|
||||||
|
var filepath: string;
|
||||||
|
|
||||||
|
if (!process.env.TEST_AUCTIONS_ENABLED) {
|
||||||
|
// Required as jest complains if file has no tests.
|
||||||
|
test('skipping auction tests', () => {});
|
||||||
|
} else {
|
||||||
|
describe("test auction",() => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
// reserve authority
|
||||||
|
createAuthority(name)
|
||||||
|
auctionId = getAuctionId(name)
|
||||||
|
});
|
||||||
|
|
||||||
|
it("get auction",async ()=>{
|
||||||
|
const resp=cliTest(args+"get "+auctionId);
|
||||||
|
expect(resp).toBeDefined();
|
||||||
|
expect(resp.length).toEqual(1);
|
||||||
|
expect(resp[0].id).toEqual(auctionId)
|
||||||
|
});
|
||||||
|
|
||||||
|
it("bid commit",async ()=>{
|
||||||
|
const resp=cliTest(args+"bid commit "+auctionId+" "+quantity+" "+type);
|
||||||
|
expect(resp).toBeDefined();
|
||||||
|
expect(resp.reveal_file).toBeDefined();
|
||||||
|
|
||||||
|
filepath = resp.reveal_file
|
||||||
|
|
||||||
|
const auction=cliTest(args+"get "+auctionId);
|
||||||
|
expect(auction).toBeDefined;
|
||||||
|
expect(auction.length).toEqual(1);
|
||||||
|
expect(auction[0].bids.length).toEqual(1);
|
||||||
|
expect(auction[0].bids[0].bidAmount.quantity).toEqual("0")
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Wait for reveal phase.", (done) => {
|
||||||
|
setTimeout(done, 60 * 1000);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("bid reveal", async ()=>{
|
||||||
|
const resp=cliTest(args+"bid reveal "+auctionId+" "+filepath);
|
||||||
|
expect(resp).toBeDefined();
|
||||||
|
expect(resp.success).toBeTruthy();
|
||||||
|
|
||||||
|
const auction=cliTest(args+"get "+auctionId);
|
||||||
|
expect(auction).toBeDefined;
|
||||||
|
expect(auction.length).toEqual(1);
|
||||||
|
expect(auction[0].bids.length).toEqual(1);
|
||||||
|
expect(auction[0].bids[0].bidAmount.quantity).toEqual(quantity+"")
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import {cliTest,createBond} from './helper';
|
||||||
|
|
||||||
|
const args= "authority "
|
||||||
|
const name=`laconic-${Date.now()}`
|
||||||
|
|
||||||
|
var bondId: string;
|
||||||
|
|
||||||
|
describe("test authority",() => {
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
// get bond id
|
||||||
|
bondId=createBond("aphoton","1000000000")
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it("reserve authority",async ()=>{
|
||||||
|
const resp=cliTest(args+"reserve "+name);
|
||||||
|
expect(resp).toBeDefined();
|
||||||
|
expect(resp.success).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("lookup authority information.",async ()=>{
|
||||||
|
const resp=cliTest(args+"whois "+ name);
|
||||||
|
expect(resp).toBeDefined();
|
||||||
|
expect(resp.length).toEqual(1);
|
||||||
|
expect(resp[0].status).toEqual("active")
|
||||||
|
expect(resp[0].bondId).toEqual("")
|
||||||
|
});
|
||||||
|
|
||||||
|
it("set authority bond",async ()=>{
|
||||||
|
const bondSet=cliTest(args+"bond set "+name+" "+bondId);
|
||||||
|
expect(bondSet).toBeDefined();
|
||||||
|
expect(bondSet.success).toBeTruthy();
|
||||||
|
|
||||||
|
const resp=cliTest(args+"whois "+ name);
|
||||||
|
expect(resp).toBeDefined();
|
||||||
|
expect(resp.length).toEqual(1);
|
||||||
|
expect(resp[0].status).toEqual("active")
|
||||||
|
expect(resp[0].bondId).toEqual(bondId)
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,169 @@
|
|||||||
|
import {cliTest,createBond,createRecord} from './helper';
|
||||||
|
|
||||||
|
const args= "bond "
|
||||||
|
const quantity=1000000000
|
||||||
|
const refillQuantity=100
|
||||||
|
const withdrawQuantity=100
|
||||||
|
const type="aphoton"
|
||||||
|
|
||||||
|
var bondId: string;
|
||||||
|
var address: string;
|
||||||
|
var recordId: string;
|
||||||
|
|
||||||
|
describe("test bond",() => {
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
const resp=cliTest("account get");
|
||||||
|
expect(resp).toBeDefined();
|
||||||
|
address=resp[0].address
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it("create bond",async ()=>{
|
||||||
|
const resp=cliTest(args+"create --type "+type+" --quantity "+quantity);
|
||||||
|
expect(resp.bondId).toBeDefined();
|
||||||
|
bondId=resp.bondId
|
||||||
|
});
|
||||||
|
|
||||||
|
it("list bond",async ()=>{
|
||||||
|
const resp=cliTest(args+"list");
|
||||||
|
expect(resp.length).toBeGreaterThan(0);
|
||||||
|
const lenghtBefore=resp.length
|
||||||
|
|
||||||
|
createBond(type,quantity+"")
|
||||||
|
|
||||||
|
const respAfter=cliTest(args+"list");
|
||||||
|
expect(respAfter.length-lenghtBefore).toEqual(1)
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it("get bond",async ()=>{
|
||||||
|
const resp=cliTest(args+"get --id "+bondId);
|
||||||
|
expect(resp.length).toEqual(1);
|
||||||
|
expect(resp[0].id).toEqual(bondId);
|
||||||
|
expect(Number(resp[0].balance[0].quantity)).toEqual(quantity);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("list bonds by owner",async ()=>{
|
||||||
|
const resp=cliTest(args+"list --owner "+address);
|
||||||
|
expect(resp).toBeDefined();
|
||||||
|
expect(resp.length).toBeGreaterThan(0);
|
||||||
|
expect(resp[0].owner).toEqual(address);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("refill bond",async ()=>{
|
||||||
|
const resp=cliTest(args+"refill --id "+bondId+" --type "+type+" --quantity "+refillQuantity);
|
||||||
|
expect(resp).toBeDefined();
|
||||||
|
expect(resp.success).toBeTruthy();
|
||||||
|
|
||||||
|
const getResp=cliTest(args+"get --id "+bondId);
|
||||||
|
expect(getResp.length).toEqual(1);
|
||||||
|
expect(getResp[0].id).toEqual(bondId);
|
||||||
|
expect(Number(getResp[0].balance[0].quantity)).toEqual(quantity+refillQuantity);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("withdraw funds from bond, insufficient",async ()=>{
|
||||||
|
const resp=cliTest(args+"withdraw --id "+bondId+" --type "+type+" --quantity "+withdrawQuantity+quantity*2);
|
||||||
|
expect(resp.stderr).toBeDefined();
|
||||||
|
expect(resp.stderr.toString()).toContain("Insufficient bond balance.: insufficient funds")
|
||||||
|
});
|
||||||
|
|
||||||
|
it("withdraw funds from bond",async ()=>{
|
||||||
|
const resp=cliTest(args+"withdraw --id "+bondId+" --type "+type+" --quantity "+withdrawQuantity);
|
||||||
|
expect(resp).toBeDefined();
|
||||||
|
expect(resp.success).toBeTruthy();
|
||||||
|
|
||||||
|
const getResp=cliTest(args+"get --id "+bondId);
|
||||||
|
expect(getResp.length).toEqual(1);
|
||||||
|
expect(getResp[0].id).toEqual(bondId);
|
||||||
|
expect(Number(getResp[0].balance[0].quantity)).toEqual(quantity+refillQuantity-withdrawQuantity);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("cancel bond",async ()=>{
|
||||||
|
const resp=cliTest(args+"cancel --id "+bondId);
|
||||||
|
expect(resp).toBeDefined;
|
||||||
|
expect(resp.success).toBeTruthy();
|
||||||
|
|
||||||
|
const getResp=cliTest(args+"get --id "+bondId);
|
||||||
|
expect(getResp.length).toEqual(1);
|
||||||
|
expect(getResp[0].id).toEqual("");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("associate bond with record",async ()=>{
|
||||||
|
// get new bond Id
|
||||||
|
bondId=createBond(type,quantity+"")
|
||||||
|
// get record Id
|
||||||
|
recordId=createRecord("./test/examples/watcher.yml",bondId)
|
||||||
|
|
||||||
|
// dissociate bond from record
|
||||||
|
const dissociate=cliTest(args+"dissociate --id "+recordId);
|
||||||
|
expect(dissociate).toBeDefined;
|
||||||
|
expect(dissociate.success).toBeTruthy();
|
||||||
|
|
||||||
|
// get new bond Id
|
||||||
|
const newbondId=createBond(type,quantity+"")
|
||||||
|
|
||||||
|
const resp=cliTest(args+"associate --id "+recordId+" --bond-id "+newbondId);
|
||||||
|
expect(resp).toBeDefined();
|
||||||
|
expect(resp.success).toBeTruthy();
|
||||||
|
|
||||||
|
// check for bond id in record
|
||||||
|
const getRecord=cliTest(" record get --id "+recordId)
|
||||||
|
expect(getRecord).toBeDefined();
|
||||||
|
expect(getRecord.length).toEqual(1);
|
||||||
|
expect(getRecord[0].id).toEqual(recordId);
|
||||||
|
expect(getRecord[0].bondId).toEqual(newbondId);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("dissociate bond from record",async ()=>{
|
||||||
|
const resp=cliTest(args+"dissociate --id "+recordId);
|
||||||
|
expect(resp).toBeDefined;
|
||||||
|
expect(resp.success).toBeTruthy();
|
||||||
|
|
||||||
|
// check for bond id in record
|
||||||
|
const getRecord=cliTest(" record get --id "+recordId)
|
||||||
|
expect(getRecord).toBeDefined();
|
||||||
|
expect(getRecord.length).toEqual(1);
|
||||||
|
expect(getRecord[0].id).toEqual(recordId);
|
||||||
|
expect(getRecord[0].bondId).toEqual("");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("dissociate all records from bond",async ()=>{
|
||||||
|
// associate bond to record
|
||||||
|
const associate=cliTest(args+"associate --id "+recordId+" --bond-id "+bondId);
|
||||||
|
expect(associate).toBeDefined;
|
||||||
|
expect(associate.success).toBeTruthy();
|
||||||
|
|
||||||
|
const resp=cliTest(args+"records dissociate --bond-id "+bondId);
|
||||||
|
expect(resp).toBeDefined;
|
||||||
|
expect(resp.success).toBeTruthy();
|
||||||
|
|
||||||
|
// check for bond id in record
|
||||||
|
const getRecord=cliTest(" record get --id "+recordId)
|
||||||
|
expect(getRecord).toBeDefined();
|
||||||
|
expect(getRecord.length).toEqual(1);
|
||||||
|
expect(getRecord[0].id).toEqual(recordId);
|
||||||
|
expect(getRecord[0].bondId).toEqual("");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reassociate all records from bond",async ()=>{
|
||||||
|
// get new bondid
|
||||||
|
const newBondId =createBond(type,quantity+"")
|
||||||
|
|
||||||
|
// associate bond to record
|
||||||
|
const associate=cliTest(args+"associate --id "+recordId+" --bond-id "+bondId);
|
||||||
|
expect(associate).toBeDefined;
|
||||||
|
expect(associate.success).toBeTruthy();
|
||||||
|
|
||||||
|
const resp=cliTest(args+"records reassociate --old-bond-id "+bondId+" --new-bond-id "+newBondId);
|
||||||
|
expect(resp).toBeDefined;
|
||||||
|
expect(resp.success).toBeTruthy();
|
||||||
|
|
||||||
|
// check for bond id in record
|
||||||
|
const getRecord=cliTest(" record get --id "+recordId)
|
||||||
|
expect(getRecord).toBeDefined();
|
||||||
|
expect(getRecord.length).toEqual(1);
|
||||||
|
expect(getRecord[0].id).toEqual(recordId);
|
||||||
|
expect(getRecord[0].bondId).toEqual(newBondId);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,528 +0,0 @@
|
|||||||
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);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -4,4 +4,4 @@ record:
|
|||||||
repo_registration_record_cid: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
|
repo_registration_record_cid: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
|
||||||
build_artifact_cid: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
|
build_artifact_cid: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
|
||||||
tls_cert_cid: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
|
tls_cert_cid: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
|
||||||
version: 1.0.23
|
version: 1.0.35
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import yaml from 'js-yaml'
|
||||||
|
import fs from 'fs'
|
||||||
|
import path from 'path'
|
||||||
|
import semver from 'semver';
|
||||||
|
|
||||||
|
const { execSync } = require("child_process");
|
||||||
|
|
||||||
|
export const updateRecord = (filePath: string) => {
|
||||||
|
const resolvedFilePath = path.resolve(process.cwd(), filePath);
|
||||||
|
const file = fs.readFileSync(resolvedFilePath, 'utf-8')
|
||||||
|
const data = yaml.load(file) as any;
|
||||||
|
|
||||||
|
data.record.version=semver.inc(data.record.version, 'patch');
|
||||||
|
|
||||||
|
fs.writeFileSync(resolvedFilePath, yaml.dump(data));
|
||||||
|
};
|
||||||
|
|
||||||
|
export const cliTest = (args: any) => {
|
||||||
|
try{
|
||||||
|
return JSON.parse(execSync(`./bin/laconic cns ${args}`));
|
||||||
|
}catch(err){
|
||||||
|
return(err)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export function createBond(type: string, quantity: string):string{
|
||||||
|
const resp=cliTest("bond create --type aphoton --quantity 1000000000");
|
||||||
|
expect(resp.bondId).toBeDefined();
|
||||||
|
return resp.bondId
|
||||||
|
};
|
||||||
|
|
||||||
|
export function createRecord(filepath: string, bondId: string):string{
|
||||||
|
const resp=cliTest("record publish --filename "+filepath+" --bond-id "+bondId);
|
||||||
|
expect(resp.id).toBeDefined();
|
||||||
|
return resp.id
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createAuthority(name:string):any{
|
||||||
|
const resp=cliTest("authority reserve "+name);
|
||||||
|
expect(resp).toBeDefined;
|
||||||
|
expect(resp.success).toBeTruthy();
|
||||||
|
return resp
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAuctionId(name:string):string{
|
||||||
|
const jsonResp = cliTest("authority whois "+name)
|
||||||
|
expect(jsonResp).toBeDefined;
|
||||||
|
return jsonResp[0].auction.id
|
||||||
|
}
|
||||||
-121
@@ -1,121 +0,0 @@
|
|||||||
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));
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import {cliTest,createAuthority,createBond,createRecord} from './helper';
|
||||||
|
|
||||||
|
const args= "name ";
|
||||||
|
const name=`laconic-${Date.now()}`;
|
||||||
|
const crn=`crn://${name}/app/test`;
|
||||||
|
|
||||||
|
var recordId: string;
|
||||||
|
var bondId: string;
|
||||||
|
|
||||||
|
describe("test names",() => {
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
// get bond id
|
||||||
|
bondId = createBond("aphoton","10000000")
|
||||||
|
|
||||||
|
// get record id
|
||||||
|
recordId=createRecord("./test/examples/watcher.yml",bondId)
|
||||||
|
|
||||||
|
// reserve authority
|
||||||
|
createAuthority(name)
|
||||||
|
|
||||||
|
// set authority bond
|
||||||
|
const resp=cliTest("authority bond set "+name+" "+bondId);
|
||||||
|
expect(resp).toBeDefined();
|
||||||
|
expect(resp.success).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it("set name",async ()=>{
|
||||||
|
const resp=cliTest(args+"set "+crn+" "+recordId);
|
||||||
|
expect(resp).toBeDefined();
|
||||||
|
expect(resp.success).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("lookup name",async ()=>{
|
||||||
|
const resp=cliTest(args+"lookup "+ crn);
|
||||||
|
expect(resp).toBeDefined();
|
||||||
|
expect(resp[0].latest.id).toEqual(recordId)
|
||||||
|
});
|
||||||
|
|
||||||
|
it("resolve name",async ()=>{
|
||||||
|
const resp=cliTest(args+"resolve "+crn);
|
||||||
|
expect(resp).toBeDefined();
|
||||||
|
expect(resp[0].id).toEqual(recordId)
|
||||||
|
});
|
||||||
|
|
||||||
|
it("delete name",async ()=>{
|
||||||
|
const resp=cliTest(args+"delete "+crn);
|
||||||
|
expect(resp).toBeDefined();
|
||||||
|
expect(resp.success).toBeTruthy();
|
||||||
|
|
||||||
|
const resolve=cliTest(args+"resolve "+crn);
|
||||||
|
expect(resolve).toBeDefined();
|
||||||
|
expect(resolve[0]).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import {cliTest,createBond, updateRecord} from './helper';
|
||||||
|
|
||||||
|
const args= "record "
|
||||||
|
const filename = "./test/examples/watcher.yml"
|
||||||
|
|
||||||
|
var recordId: string;
|
||||||
|
var bondId: string;
|
||||||
|
|
||||||
|
describe("test record",() => {
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
// get bondId
|
||||||
|
bondId=createBond("aphoton","1000000000")
|
||||||
|
updateRecord(filename)
|
||||||
|
});
|
||||||
|
|
||||||
|
it("publish record",async ()=>{
|
||||||
|
const resp=cliTest(args+"publish --filename "+filename+" --bond-id "+bondId);
|
||||||
|
expect(resp).toBeDefined();
|
||||||
|
console.log(resp.toString())
|
||||||
|
expect(resp.id).toBeDefined();
|
||||||
|
|
||||||
|
recordId=resp.id
|
||||||
|
});
|
||||||
|
|
||||||
|
it("get record",async ()=>{
|
||||||
|
const resp=cliTest(args+"get --id "+recordId);
|
||||||
|
expect(resp).toBeDefined();
|
||||||
|
expect(resp.length).toEqual(1);
|
||||||
|
expect(resp[0].id).toEqual(recordId)
|
||||||
|
expect(resp[0].bondId).toEqual(bondId)
|
||||||
|
});
|
||||||
|
|
||||||
|
it("list records",async ()=>{
|
||||||
|
const resp=cliTest(args+"list");
|
||||||
|
expect(resp).toBeDefined();
|
||||||
|
expect(resp.length).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Wait for the laconid endpoint to come up
|
|
||||||
docker compose exec laconicd sh -c "curl --retry 20 --retry-delay 3 --retry-connrefused http://127.0.0.1:9473/api"
|
|
||||||
|
|
||||||
# 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"
|
|
||||||
|
|
||||||
# Run tests
|
|
||||||
TEST_ACCOUNT=$laconicd_account_address yarn test
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import {cliTest} from './helper';
|
||||||
|
|
||||||
|
const args= "status "
|
||||||
|
|
||||||
|
describe("test status",() => {
|
||||||
|
|
||||||
|
it("get status",async ()=>{
|
||||||
|
const resp=cliTest(args);
|
||||||
|
expect(resp).toBeDefined();
|
||||||
|
expect(resp.node.network).toContain("laconic")
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import {cliTest} from './helper';
|
||||||
|
|
||||||
|
const args= "tokens "
|
||||||
|
const type= "aphoton"
|
||||||
|
const quantity=10
|
||||||
|
const address="ethm1vc62ysqu504at932jjq8pwrqgjt67rx6ggn5yu"
|
||||||
|
|
||||||
|
describe("test account",() => {
|
||||||
|
it("get account should return account details",async ()=>{
|
||||||
|
// balance before
|
||||||
|
var balanceBefore;
|
||||||
|
const beforeResp=cliTest("account get --address "+address);
|
||||||
|
if (beforeResp.stderr){
|
||||||
|
expect(beforeResp.stderr.toString()).toContain("account "+address+ " not found")
|
||||||
|
balanceBefore=0
|
||||||
|
} else{
|
||||||
|
balanceBefore=beforeResp[0].balance[0].quantity
|
||||||
|
}
|
||||||
|
|
||||||
|
// send tokens to account
|
||||||
|
const sendResp=cliTest(args+"send --address "+address+" --type "+type+" --quantity "+quantity)
|
||||||
|
expect(sendResp).toBeDefined();
|
||||||
|
|
||||||
|
// balance after
|
||||||
|
var balanceAfter;
|
||||||
|
const afterResp=cliTest("account get --address "+address);
|
||||||
|
if (afterResp.stderr){
|
||||||
|
expect(afterResp.stderr.toString()).toContain("account "+address+ " not found")
|
||||||
|
balanceAfter=0
|
||||||
|
} else{
|
||||||
|
balanceAfter=afterResp[0].balance[0].quantity
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(balanceAfter-balanceBefore).toEqual(quantity)
|
||||||
|
});
|
||||||
|
});
|
||||||
+1
-3
@@ -97,7 +97,5 @@
|
|||||||
/* Completeness */
|
/* Completeness */
|
||||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||||
},
|
}
|
||||||
"include": ["src"],
|
|
||||||
"exclude": ["test"]
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user