Compare commits
14 Commits
murali/tes
...
main
Author | SHA1 | Date | |
---|---|---|---|
6814707752 | |||
e1da44bae7 | |||
51fd81a082 | |||
3cdd930b82 | |||
80d1b01713 | |||
f3c0ae8c34 | |||
f5625d0c87 | |||
fb381c07f3 | |||
145da8c453 | |||
6e0829d91f | |||
1fa32a3cc1 | |||
129019105d | |||
|
37b69da3bb | ||
707b3049ef |
36
.gitea/workflows/publish.yaml
Normal file
36
.gitea/workflows/publish.yaml
Normal file
@ -0,0 +1,36 @@
|
||||
name: Publish npm package to gitea
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
jobs:
|
||||
npm_publish:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [ 18.x ]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Download yarn
|
||||
run: |
|
||||
curl -fsSL -o /usr/local/bin/yarn https://github.com/yarnpkg/yarn/releases/download/v1.22.21/yarn-1.22.21.js
|
||||
chmod +x /usr/local/bin/yarn
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- run: yarn
|
||||
- name: Run yarn build
|
||||
run: |
|
||||
yarn build
|
||||
- name: Configure git.vdb.to npm registry
|
||||
run: |
|
||||
npm config set registry https://git.vdb.to/api/packages/cerc-io/npm/
|
||||
- name: Authenticate to git.vdb.to registry
|
||||
run: |
|
||||
npm config set -- '//git.vdb.to/api/packages/cerc-io/npm/:_authToken' "${{ secrets.CICD_PUBLISH_TOKEN }}"
|
||||
- name: npm publish
|
||||
run: |
|
||||
npm publish
|
45
.gitea/workflows/test.yml
Normal file
45
.gitea/workflows/test.yml
Normal file
@ -0,0 +1,45 @@
|
||||
name: Tests
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- '*'
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- release/**
|
||||
|
||||
env:
|
||||
DOCKER_HOST: unix:///var/run/dind.sock
|
||||
|
||||
jobs:
|
||||
sdk_tests:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Checkout laconicd
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
path: "./laconicd/"
|
||||
repository: cerc-io/laconicd
|
||||
fetch-depth: 0
|
||||
ref: main
|
||||
- name: Environment
|
||||
run: ls -tlh && env
|
||||
- name: Start dockerd
|
||||
run: |
|
||||
dockerd -H $DOCKER_HOST --userland-proxy=false &
|
||||
sleep 5
|
||||
- name: build 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.CICD_PUBLISH_TOKEN }}" .
|
||||
- name: build containers scripts
|
||||
working-directory: laconicd/tests/sdk_tests
|
||||
run: ./build-laconicd-container.sh
|
||||
- name: start laconicd container
|
||||
working-directory: laconicd/tests/sdk_tests
|
||||
run: docker compose up laconicd -d
|
||||
|
||||
- name: Run registry-cli demo commands in registry-cli container
|
||||
run : ls -tla
|
||||
- name: stop containers
|
||||
working-directory: laconicd/tests/sdk_tests
|
||||
run: docker compose down
|
8
.github/workflows/test.yml
vendored
8
.github/workflows/test.yml
vendored
@ -21,7 +21,7 @@ jobs:
|
||||
- name: Environment
|
||||
run: ls -tlh && env
|
||||
- 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
|
||||
working-directory: laconicd/tests/sdk_tests
|
||||
run: ./build-laconicd-container.sh
|
||||
@ -30,11 +30,7 @@ jobs:
|
||||
run: docker compose up laconicd -d
|
||||
|
||||
- name: Run registry-cli demo commands in registry-cli container
|
||||
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
|
||||
run : ls -tla
|
||||
- name: stop containers
|
||||
working-directory: laconicd/tests/sdk_tests
|
||||
run: docker compose down
|
||||
|
50
README.md
50
README.md
@ -514,53 +514,3 @@ Reassociate records (switch bond):
|
||||
```bash
|
||||
$ 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
|
||||
```
|
@ -1,30 +0,0 @@
|
||||
#!/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
|
@ -1,5 +0,0 @@
|
||||
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
};
|
@ -1,5 +0,0 @@
|
||||
{
|
||||
"version": "2.9.0",
|
||||
"useWorkspaces": true,
|
||||
"npmClient": "yarn"
|
||||
}
|
12
package.json
12
package.json
@ -1,25 +1,21 @@
|
||||
{
|
||||
"name": "@cerc-io/laconic-registry-cli",
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.7",
|
||||
"main": "index.js",
|
||||
"repository": "git@github.com:cerc-io/laconic-registry-cli.git",
|
||||
"author": "",
|
||||
"license": "UNLICENSED",
|
||||
"devDependencies": {
|
||||
"@types/fs-extra": "^9.0.13",
|
||||
"@types/jest": "^29.5.0",
|
||||
"@types/js-yaml": "^4.0.5",
|
||||
"@types/lodash": "^4.14.182",
|
||||
"@types/node": "^17.0.25",
|
||||
"@types/semver": "^7.3.13",
|
||||
"@types/yargs": "^17.0.10",
|
||||
"jest": "^29.5.0",
|
||||
"ts-jest": "^29.0.5",
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@cerc-io/laconic-sdk": "0.1.6",
|
||||
"fs-extra": "^10.1.0",
|
||||
"@cerc-io/laconic-sdk": "^0.1.13",
|
||||
"js-yaml": "^3.14.1",
|
||||
"lodash": "^4.17.21",
|
||||
"lodash-clean": "^2.2.3",
|
||||
@ -28,9 +24,7 @@
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"clean": "rm -rf ./dist",
|
||||
"build": "tsc",
|
||||
"test": "jest --runInBand --verbose",
|
||||
"test:auctions": "TEST_AUCTIONS_ENABLED=1 jest --runInBand --verbose test/auction.test.ts"
|
||||
"build": "tsc"
|
||||
},
|
||||
"bin": {
|
||||
"laconic": "bin/laconic"
|
||||
|
@ -2,7 +2,7 @@ import { Arguments } from 'yargs';
|
||||
import assert from 'assert';
|
||||
import { Registry } from '@cerc-io/laconic-sdk';
|
||||
|
||||
import { getConfig, getConnectionInfo,queryOutput } from '../../../util';
|
||||
import { getConfig, getConnectionInfo, queryOutput } from '../../../util';
|
||||
|
||||
export const command = 'resolve [name]';
|
||||
|
||||
@ -20,6 +20,8 @@ export const handler = async (argv: Arguments) => {
|
||||
|
||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||
|
||||
const result = await registry.resolveNames([name]);
|
||||
queryOutput(result,argv.output)
|
||||
let result = await registry.resolveNames([name]);
|
||||
result = result.filter((v: any) => v);
|
||||
|
||||
queryOutput(result, argv.output);
|
||||
}
|
||||
|
@ -12,6 +12,9 @@ export const builder = {
|
||||
'bond-id': {
|
||||
type: 'string'
|
||||
},
|
||||
owner: {
|
||||
type: 'string'
|
||||
},
|
||||
type: {
|
||||
type: 'string'
|
||||
},
|
||||
@ -27,7 +30,13 @@ export const builder = {
|
||||
export const handler = async (argv: Arguments) => {
|
||||
const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
|
||||
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
|
||||
const { type, name, bondId, all } = argv;
|
||||
const { type, name, bondId, owner, all } = argv;
|
||||
const filters: any = {};
|
||||
|
||||
const filterArgs = argv._.slice(3);
|
||||
for (let i = 0; i < filterArgs.length-1; i+=2) {
|
||||
filters[String(filterArgs[i]).replace(/^-+/,"")] = filterArgs[i+1];
|
||||
}
|
||||
|
||||
assert(restEndpoint, 'Invalid CNS REST endpoint.');
|
||||
assert(gqlEndpoint, 'Invalid CNS GQL endpoint.');
|
||||
@ -35,6 +44,16 @@ export const handler = async (argv: Arguments) => {
|
||||
|
||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||
|
||||
const result = await registry.queryRecords({ bondId, type, name }, all as boolean);
|
||||
queryOutput(result,argv.output)
|
||||
let result = await registry.queryRecords({...filters, type, name}, all as boolean);
|
||||
|
||||
// Apply ex post filters.
|
||||
if (bondId) {
|
||||
result = result.filter((v: any) => v.bondId === bondId);
|
||||
}
|
||||
|
||||
if (owner) {
|
||||
result = result.filter((v: any) => v.owners?.find((e: string) => e === owner));
|
||||
}
|
||||
|
||||
queryOutput(result, argv.output)
|
||||
}
|
||||
|
@ -30,12 +30,20 @@ export const handler = async (argv: Arguments) => {
|
||||
|
||||
let file = null;
|
||||
if (filename) {
|
||||
file = path.join(process.cwd(), filename as string);
|
||||
file = filename as string;
|
||||
} else {
|
||||
file = 0; // stdin
|
||||
}
|
||||
|
||||
const { record } = await yaml.load(fs.readFileSync(file, 'utf-8')) as any;
|
||||
|
||||
// Convert sub-objects (other than arrays) to a JSON automatically.
|
||||
for (const [k, v] of Object.entries(record)) {
|
||||
if (v && typeof v === "object" && !Array.isArray(v)) {
|
||||
record[k] = JSON.stringify(v);
|
||||
}
|
||||
}
|
||||
|
||||
const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||
const fee = getGasAndFees(argv, cnsConfig);
|
||||
const result = await registry.setRecord({ privateKey: userKey, record, bondId }, txKey as string, fee);
|
||||
|
@ -6,5 +6,6 @@ export const desc = 'Record operations.';
|
||||
|
||||
exports.builder = (yargs: yargs.Argv) => {
|
||||
return yargs.commandDir('record-cmds')
|
||||
.parserConfiguration({'unknown-options-as-args': true})
|
||||
.demandCommand()
|
||||
}
|
||||
|
@ -11,6 +11,12 @@ export const queryOutput = (result: any, output: unknown) => {
|
||||
if (output=="json"){
|
||||
console.log(JSON.parse(JSON.stringify(result)));
|
||||
} else {
|
||||
console.log(JSON.stringify(result,undefined,2));
|
||||
console.log(JSON.stringify(result, (key, value) => {
|
||||
try {
|
||||
return JSON.parse(value)
|
||||
} catch (e) {
|
||||
return value;
|
||||
}
|
||||
}, 2));
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +0,0 @@
|
||||
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)
|
||||
});
|
||||
});
|
@ -1,63 +0,0 @@
|
||||
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+"")
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -1,41 +0,0 @@
|
||||
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)
|
||||
});
|
||||
});
|
@ -1,169 +0,0 @@
|
||||
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,7 +0,0 @@
|
||||
record:
|
||||
type: WebsiteRegistrationRecord
|
||||
url: 'https://cerc.io'
|
||||
repo_registration_record_cid: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D
|
||||
build_artifact_cid: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9
|
||||
tls_cert_cid: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
|
||||
version: 1.0.35
|
@ -1,49 +0,0 @@
|
||||
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
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
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();
|
||||
});
|
||||
});
|
@ -1,39 +0,0 @@
|
||||
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,12 +0,0 @@
|
||||
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")
|
||||
});
|
||||
});
|
@ -1,36 +0,0 @@
|
||||
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)
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user