forked from cerc-io/laconic-sdk
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
3dabf399f7 | |||
73bef00dd3 | |||
809c4d8f5b | |||
fedf35d702 |
2
.dockerignore
Normal file
2
.dockerignore
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Dockerfile
|
||||||
|
node_modules
|
@ -25,57 +25,39 @@ jobs:
|
|||||||
ref: main
|
ref: main
|
||||||
- name: Environment
|
- name: Environment
|
||||||
run: ls -tlh && env
|
run: ls -tlh && env
|
||||||
|
|
||||||
- name: Start dockerd
|
- name: Start dockerd
|
||||||
run: |
|
run: |
|
||||||
dockerd -H $DOCKER_HOST --userland-proxy=false &
|
dockerd -H $DOCKER_HOST --userland-proxy=false &
|
||||||
sleep 5
|
sleep 5
|
||||||
- name: build containers scripts
|
|
||||||
|
- name: Build laconicd container
|
||||||
working-directory: laconicd/tests/sdk_tests
|
working-directory: laconicd/tests/sdk_tests
|
||||||
run: ./build-laconicd-container.sh
|
run: ./build-laconicd-container.sh
|
||||||
- name: build test-container
|
- name: Build laconic-sdk container
|
||||||
run: docker build -t cerc-io/laconic-sdk-tester:local-test -f laconicd/tests/sdk_tests/Dockerfile-sdk .
|
run: ./scripts/build-sdk-test-container.sh
|
||||||
- name: start containers
|
|
||||||
|
- name: Start containers
|
||||||
working-directory: laconicd/tests/sdk_tests
|
working-directory: laconicd/tests/sdk_tests
|
||||||
run: docker compose up -d
|
run: docker compose up -d
|
||||||
- name: run basic tests
|
- name: Run tests
|
||||||
working-directory: laconicd/tests/sdk_tests
|
working-directory: laconicd/tests/sdk_tests
|
||||||
run: |
|
run: ./run-tests.sh
|
||||||
laconicd_key=$( docker compose exec laconicd echo y | docker compose exec laconicd laconicd keys export mykey --unarmored-hex --unsafe )
|
|
||||||
cosmos_chain_id=laconic_9000-1
|
- name: Start containers (auctions enabled)
|
||||||
laconicd_rest_endpoint=http://laconicd:1317
|
|
||||||
laconicd_gql_endpoint=http://laconicd:9473/api
|
|
||||||
sleep 30s
|
|
||||||
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test"
|
|
||||||
- name: stop containers
|
|
||||||
working-directory: laconicd/tests/sdk_tests
|
working-directory: laconicd/tests/sdk_tests
|
||||||
run: docker compose down
|
env:
|
||||||
- name: start auction containers
|
TEST_AUCTION_ENABLED: true
|
||||||
|
run: docker compose up -d
|
||||||
|
- name: Run auction tests
|
||||||
working-directory: laconicd/tests/sdk_tests
|
working-directory: laconicd/tests/sdk_tests
|
||||||
run: docker compose -f docker-compose-auctions.yml up -d
|
run: ./run-tests.sh test:auctions
|
||||||
- name: run auction tests
|
|
||||||
|
- name: Start containers (expiry enabled)
|
||||||
working-directory: laconicd/tests/sdk_tests
|
working-directory: laconicd/tests/sdk_tests
|
||||||
run: |
|
env:
|
||||||
laconicd_key=$( docker compose exec laconicd echo y | docker compose exec laconicd laconicd keys export mykey --unarmored-hex --unsafe )
|
TEST_REGISTRY_EXPIRY: true
|
||||||
cosmos_chain_id=laconic_9000-1
|
run: docker compose up -d
|
||||||
laconicd_rest_endpoint=http://laconicd:1317
|
- name: Run nameservice expiry tests
|
||||||
laconicd_gql_endpoint=http://laconicd:9473/api
|
|
||||||
sleep 30s
|
|
||||||
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test:auctions"
|
|
||||||
- name: start containers
|
|
||||||
working-directory: laconicd/tests/sdk_tests
|
working-directory: laconicd/tests/sdk_tests
|
||||||
run: docker compose down
|
run: ./run-tests.sh test:nameservice-expiry
|
||||||
- name: start containers
|
|
||||||
working-directory: laconicd/tests/sdk_tests
|
|
||||||
run: docker compose -f docker-compose-nameservice.yml up -d
|
|
||||||
- name: run nameservice expiry tests
|
|
||||||
working-directory: laconicd/tests/sdk_tests
|
|
||||||
run: |
|
|
||||||
laconicd_key=$( docker compose exec laconicd echo y | docker compose exec laconicd laconicd keys export mykey --unarmored-hex --unsafe )
|
|
||||||
cosmos_chain_id=laconic_9000-1
|
|
||||||
laconicd_rest_endpoint=http://laconicd:1317
|
|
||||||
laconicd_gql_endpoint=http://laconicd:9473/api
|
|
||||||
sleep 30s
|
|
||||||
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test:nameservice-expiry"
|
|
||||||
- name: stop nameservice containers
|
|
||||||
working-directory: laconicd/tests/sdk_tests
|
|
||||||
run: docker compose down
|
|
||||||
|
63
.github/workflows/test.yml
vendored
63
.github/workflows/test.yml
vendored
@ -20,53 +20,34 @@ jobs:
|
|||||||
ref: main
|
ref: main
|
||||||
- name: Environment
|
- name: Environment
|
||||||
run: ls -tlh && env
|
run: ls -tlh && env
|
||||||
- name: build containers scripts
|
|
||||||
|
- name: Build laconicd container
|
||||||
working-directory: laconicd/tests/sdk_tests
|
working-directory: laconicd/tests/sdk_tests
|
||||||
run: ./build-laconicd-container.sh
|
run: ./build-laconicd-container.sh
|
||||||
- name: build test-container
|
- name: Build laconic-sdk container
|
||||||
run: docker build -t cerc-io/laconic-sdk-tester:local-test -f laconicd/tests/sdk_tests/Dockerfile-sdk .
|
run: ./scripts/build-sdk-test-container.sh
|
||||||
- name: start containers
|
|
||||||
|
- name: Start containers
|
||||||
working-directory: laconicd/tests/sdk_tests
|
working-directory: laconicd/tests/sdk_tests
|
||||||
run: docker compose up -d
|
run: docker compose up -d
|
||||||
- name: run basic tests
|
- name: Run tests
|
||||||
working-directory: laconicd/tests/sdk_tests
|
working-directory: laconicd/tests/sdk_tests
|
||||||
run: |
|
run: ./run-tests.sh
|
||||||
laconicd_key=$( docker compose exec laconicd echo y | docker compose exec laconicd laconicd keys export mykey --unarmored-hex --unsafe )
|
|
||||||
cosmos_chain_id=laconic_9000-1
|
- name: Start containers (auctions enabled)
|
||||||
laconicd_rest_endpoint=http://laconicd:1317
|
|
||||||
laconicd_gql_endpoint=http://laconicd:9473/api
|
|
||||||
sleep 30s
|
|
||||||
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test"
|
|
||||||
- name: stop containers
|
|
||||||
working-directory: laconicd/tests/sdk_tests
|
working-directory: laconicd/tests/sdk_tests
|
||||||
run: docker compose down
|
env:
|
||||||
- name: start auction containers
|
TEST_AUCTION_ENABLED: true
|
||||||
|
run: docker compose up -d
|
||||||
|
- name: Run auction tests
|
||||||
working-directory: laconicd/tests/sdk_tests
|
working-directory: laconicd/tests/sdk_tests
|
||||||
run: docker compose -f docker-compose-auctions.yml up -d
|
run: ./run-tests.sh test:auctions
|
||||||
- name: run auction tests
|
|
||||||
|
- name: Start containers (expiry enabled)
|
||||||
working-directory: laconicd/tests/sdk_tests
|
working-directory: laconicd/tests/sdk_tests
|
||||||
run: |
|
env:
|
||||||
laconicd_key=$( docker compose exec laconicd echo y | docker compose exec laconicd laconicd keys export mykey --unarmored-hex --unsafe )
|
TEST_REGISTRY_EXPIRY: true
|
||||||
cosmos_chain_id=laconic_9000-1
|
run: docker compose up -d
|
||||||
laconicd_rest_endpoint=http://laconicd:1317
|
- name: Run nameservice expiry tests
|
||||||
laconicd_gql_endpoint=http://laconicd:9473/api
|
|
||||||
sleep 30s
|
|
||||||
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test:auctions"
|
|
||||||
- name: start containers
|
|
||||||
working-directory: laconicd/tests/sdk_tests
|
working-directory: laconicd/tests/sdk_tests
|
||||||
run: docker compose down
|
run: ./run-tests.sh test:nameservice-expiry
|
||||||
- name: start containers
|
|
||||||
working-directory: laconicd/tests/sdk_tests
|
|
||||||
run: docker compose -f docker-compose-nameservice.yml up -d
|
|
||||||
- name: run nameservice expiry tests
|
|
||||||
working-directory: laconicd/tests/sdk_tests
|
|
||||||
run: |
|
|
||||||
laconicd_key=$( docker compose exec laconicd echo y | docker compose exec laconicd laconicd keys export mykey --unarmored-hex --unsafe )
|
|
||||||
cosmos_chain_id=laconic_9000-1
|
|
||||||
laconicd_rest_endpoint=http://laconicd:1317
|
|
||||||
laconicd_gql_endpoint=http://laconicd:9473/api
|
|
||||||
sleep 30s
|
|
||||||
docker compose exec sdk-test-runner sh -c "COSMOS_CHAIN_ID=${cosmos_chain_id} LACONICD_REST_ENDPOINT=${laconicd_rest_endpoint} LACONICD_GQL_ENDPOINT=${laconicd_gql_endpoint} PRIVATE_KEY=${laconicd_key} yarn test:nameservice-expiry"
|
|
||||||
- name: stop nameservice containers
|
|
||||||
working-directory: laconicd/tests/sdk_tests
|
|
||||||
run: docker compose down
|
|
||||||
|
@ -21,34 +21,18 @@ RUN \
|
|||||||
&& npm config -g set prefix ${NPM_GLOBAL} \
|
&& npm config -g set prefix ${NPM_GLOBAL} \
|
||||||
&& su ${USERNAME} -c "npm config -g set prefix ${NPM_GLOBAL}" \
|
&& su ${USERNAME} -c "npm config -g set prefix ${NPM_GLOBAL}" \
|
||||||
# Install eslint
|
# Install eslint
|
||||||
&& su ${USERNAME} -c "umask 0002 && npm install -g eslint lerna jest" \
|
&& su ${USERNAME} -c "umask 0002 && npm install -g eslint" \
|
||||||
&& npm cache clean --force > /dev/null 2>&1
|
&& npm cache clean --force > /dev/null 2>&1
|
||||||
|
|
||||||
# [Optional] Uncomment this section to install additional OS packages.
|
|
||||||
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
|
||||||
# && apt-get -y install --no-install-recommends <your-package-list-here>
|
|
||||||
|
|
||||||
# [Optional] Uncomment if you want to install an additional version of node using nvm
|
|
||||||
# ARG EXTRA_NODE_VERSION=10
|
|
||||||
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
|
|
||||||
|
|
||||||
# [Optional] Uncomment if you want to install more global node modules
|
|
||||||
# RUN su node -c "npm install -g <your-package-list-here>"
|
|
||||||
|
|
||||||
WORKDIR /
|
WORKDIR /
|
||||||
RUN mkdir node_modules && mkdir proto && mkdir scripts && mkdir src
|
|
||||||
COPY node_modules ./node_modules/
|
|
||||||
COPY proto . ./proto/
|
|
||||||
COPY scripts ./scripts/
|
|
||||||
COPY src ./src/
|
|
||||||
COPY entrypoint.sh .
|
COPY entrypoint.sh .
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
# Placeholder CMD : generally this will be overridden at run time like :
|
|
||||||
# docker run -it -v /home/builder/cerc/laconic-sdk:/workspace cerc/builder-js sh -c 'cd /workspace && yarn && yarn build'
|
|
||||||
CMD node --version
|
CMD node --version
|
||||||
|
|
||||||
# Temp hack, clone the laconic-sdk repo here
|
WORKDIR /app/laconic-sdk
|
||||||
WORKDIR /app
|
|
||||||
|
COPY package*.json .
|
||||||
RUN yarn install
|
RUN yarn install
|
||||||
|
COPY . .
|
||||||
|
|
||||||
WORKDIR /app/laconic-sdk
|
WORKDIR /app/laconic-sdk
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@cerc-io/laconic-sdk",
|
"name": "@cerc-io/laconic-sdk",
|
||||||
"version": "0.1.14",
|
"version": "0.1.16",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"repository": "git@github.com:cerc-io/laconic-sdk.git",
|
"repository": "git@github.com:cerc-io/laconic-sdk.git",
|
||||||
@ -48,7 +48,7 @@
|
|||||||
"tiny-secp256k1": "^1.1.6"
|
"tiny-secp256k1": "^1.1.6"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest --runInBand --verbose",
|
"test": "jest --runInBand --verbose --testPathPattern=src",
|
||||||
"test:auctions": "TEST_AUCTIONS_ENABLED=1 jest --runInBand --verbose src/auction.test.ts",
|
"test:auctions": "TEST_AUCTIONS_ENABLED=1 jest --runInBand --verbose src/auction.test.ts",
|
||||||
"test:nameservice-expiry": "TEST_NAMESERVICE_EXPIRY=1 jest --runInBand --verbose src/nameservice-expiry.test.ts",
|
"test:nameservice-expiry": "TEST_NAMESERVICE_EXPIRY=1 jest --runInBand --verbose src/nameservice-expiry.test.ts",
|
||||||
"build": "tsc"
|
"build": "tsc"
|
||||||
|
2
scripts/build-sdk-test-container.sh
Executable file
2
scripts/build-sdk-test-container.sh
Executable file
@ -0,0 +1,2 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
docker build -t cerc/laconic-sdk-tester:local -f Dockerfile .
|
@ -12,20 +12,10 @@ jest.setTimeout(90 * 1000);
|
|||||||
const bondTests = () => {
|
const bondTests = () => {
|
||||||
let registry: Registry;
|
let registry: Registry;
|
||||||
|
|
||||||
let watcher: any;
|
|
||||||
|
|
||||||
let version1: string;
|
|
||||||
let version2: string;
|
|
||||||
|
|
||||||
let bondId1: string;
|
|
||||||
let bondId2: string;
|
|
||||||
|
|
||||||
let bondOwner: string;
|
|
||||||
|
|
||||||
const publishNewWatcherVersion = async (bondId: string) => {
|
const publishNewWatcherVersion = async (bondId: string) => {
|
||||||
watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
|
let watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
|
||||||
await registry.setRecord({ privateKey, record: watcher.record, bondId }, privateKey, fee);
|
await registry.setRecord({ privateKey, record: watcher.record, bondId }, privateKey, fee);
|
||||||
return watcher.record.version;
|
return watcher;
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
@ -33,93 +23,119 @@ const bondTests = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Create bond.', async () => {
|
test('Create bond.', async () => {
|
||||||
bondId1 = await registry.getNextBondId(privateKey);
|
let bondId = await registry.getNextBondId(privateKey);
|
||||||
|
expect(bondId).toBeDefined();
|
||||||
|
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('With bond created', () => {
|
||||||
|
let bond1: any
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
let bondId1 = await registry.getNextBondId(privateKey);
|
||||||
expect(bondId1).toBeDefined();
|
expect(bondId1).toBeDefined();
|
||||||
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
|
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
|
||||||
})
|
|
||||||
|
[bond1] = await registry.getBondsByIds([bondId1]);
|
||||||
|
expect(bond1).toBeDefined();
|
||||||
|
expect(bond1.id).toEqual(bondId1);
|
||||||
|
});
|
||||||
|
|
||||||
test('Get bond by ID.', async () => {
|
test('Get bond by ID.', async () => {
|
||||||
const [bond] = await registry.getBondsByIds([bondId1]);
|
const [bond] = await registry.getBondsByIds([bond1.id]);
|
||||||
expect(bond).toBeDefined();
|
expect(bond).toBeDefined();
|
||||||
expect(bond.id).toBe(bondId1);
|
expect(bond.id).toBe(bond1.id);
|
||||||
expect(bond.balance).toHaveLength(1);
|
expect(bond.balance).toHaveLength(1);
|
||||||
expect(bond.balance[0]).toEqual({ type: 'aphoton', quantity: '1000000000' });
|
expect(bond.balance[0]).toEqual({ type: 'aphoton', quantity: '1000000000' });
|
||||||
bondOwner = bond.owner;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Query bonds.', async () => {
|
test('Query bonds.', async () => {
|
||||||
const bonds = await registry.queryBonds();
|
const bonds = await registry.queryBonds();
|
||||||
expect(bonds).toBeDefined();
|
expect(bonds).toBeDefined();
|
||||||
const bond = bonds.filter((bond: any) => bond.id === bondId1);
|
const bond = bonds.filter((bond: any) => bond.id === bond1.id);
|
||||||
expect(bond).toBeDefined();
|
expect(bond).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Query bonds by owner.', async () => {
|
test('Query bonds by owner.', async () => {
|
||||||
const bonds = await registry.queryBonds({ owner: bondOwner });
|
const bonds = await registry.queryBonds({ owner: bond1.owner });
|
||||||
expect(bonds).toBeDefined();
|
expect(bonds).toBeDefined();
|
||||||
const bond = bonds.filter((bond: any) => bond.id === bondId1);
|
const bond = bonds.filter((bond: any) => bond.id === bond1.id);
|
||||||
expect(bond).toBeDefined();
|
expect(bond).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Refill bond.', async () => {
|
test('Refill bond.', async () => {
|
||||||
await registry.refillBond({ id: bondId1, denom: 'aphoton', amount: '500' }, privateKey, fee);
|
await registry.refillBond({ id: bond1.id, denom: 'aphoton', amount: '500' }, privateKey, fee);
|
||||||
|
|
||||||
const [bond] = await registry.getBondsByIds([bondId1]);
|
const [bond] = await registry.getBondsByIds([bond1.id]);
|
||||||
expect(bond).toBeDefined();
|
expect(bond).toBeDefined();
|
||||||
expect(bond.id).toBe(bondId1);
|
expect(bond.id).toBe(bond1.id);
|
||||||
expect(bond.balance).toHaveLength(1);
|
expect(bond.balance).toHaveLength(1);
|
||||||
expect(bond.balance[0]).toEqual({ type: 'aphoton', quantity: '1000000500' });
|
expect(bond.balance[0]).toEqual({ type: 'aphoton', quantity: '1000000500' });
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Withdraw bond.', async () => {
|
test('Withdraw bond.', async () => {
|
||||||
await registry.withdrawBond({ id: bondId1, denom: 'aphoton', amount: '500' }, privateKey, fee);
|
await registry.withdrawBond({ id: bond1.id, denom: 'aphoton', amount: '500' }, privateKey, fee);
|
||||||
|
|
||||||
const [bond] = await registry.getBondsByIds([bondId1]);
|
const [bond] = await registry.getBondsByIds([bond1.id]);
|
||||||
expect(bond).toBeDefined();
|
expect(bond).toBeDefined();
|
||||||
expect(bond.id).toBe(bondId1);
|
expect(bond.id).toBe(bond1.id);
|
||||||
expect(bond.balance).toHaveLength(1);
|
expect(bond.balance).toHaveLength(1);
|
||||||
expect(bond.balance[0]).toEqual({ type: 'aphoton', quantity: '1000000000' });
|
expect(bond.balance[0]).toEqual({ type: 'aphoton', quantity: '1000000000' });
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Cancel bond.', async () => {
|
test('Cancel bond.', async () => {
|
||||||
await registry.cancelBond({ id: bondId1 }, privateKey, fee);
|
await registry.cancelBond({ id: bond1.id }, privateKey, fee);
|
||||||
|
|
||||||
const [bond] = await registry.getBondsByIds([bondId1]);
|
const [bond] = await registry.getBondsByIds([bond1.id]);
|
||||||
expect(bond.id).toBe("");
|
expect(bond.id).toBe("");
|
||||||
expect(bond.owner).toBe("");
|
expect(bond.owner).toBe("");
|
||||||
expect(bond.balance).toHaveLength(0);
|
expect(bond.balance).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
test('Associate/Dissociate bond.', async () => {
|
test('Associate/Dissociate bond.', async () => {
|
||||||
|
let bondId1: string;
|
||||||
|
|
||||||
bondId1 = await registry.getNextBondId(privateKey);
|
bondId1 = await registry.getNextBondId(privateKey);
|
||||||
expect(bondId1).toBeDefined();
|
expect(bondId1).toBeDefined();
|
||||||
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
|
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
|
||||||
|
|
||||||
// Create a new record.
|
// Create a new record.
|
||||||
version1 = await publishNewWatcherVersion(bondId1);
|
let watcher = await publishNewWatcherVersion(bondId1);
|
||||||
let [record1] = await registry.queryRecords({ type: watcher.record.type, version: version1 }, true);
|
let query = { type: watcher.record.type, url: watcher.record.url, version: watcher.record.version };
|
||||||
|
let [record1] = await registry.queryRecords(query, true);
|
||||||
expect(record1.bondId).toBe(bondId1);
|
expect(record1.bondId).toBe(bondId1);
|
||||||
|
|
||||||
// Dissociate record, query and confirm.
|
// Dissociate record, query and confirm.
|
||||||
await registry.dissociateBond({ recordId: record1.id }, privateKey, fee);
|
await registry.dissociateBond({ recordId: record1.id }, privateKey, fee);
|
||||||
[record1] = await registry.queryRecords({ type: watcher.record.type, version: version1 }, true);
|
[record1] = await registry.queryRecords(query, true);
|
||||||
expect(record1.bondId).toBe('');
|
expect(record1.bondId).toBe('');
|
||||||
|
|
||||||
// Associate record with bond, query and confirm.
|
// Associate record with bond, query and confirm.
|
||||||
await registry.associateBond({ recordId: record1.id, bondId: bondId1 }, privateKey, fee);
|
await registry.associateBond({ recordId: record1.id, bondId: bondId1 }, privateKey, fee);
|
||||||
[record1] = await registry.queryRecords({ type: watcher.record.type, version: version1 }, true);
|
[record1] = await registry.queryRecords(query, true);
|
||||||
expect(record1.bondId).toBe(bondId1);
|
expect(record1.bondId).toBe(bondId1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Reassociate/Dissociate records.', async () => {
|
test('Reassociate/Dissociate records.', async () => {
|
||||||
|
let bondId1: string;
|
||||||
|
let bondId2: string;
|
||||||
|
|
||||||
|
bondId1 = await registry.getNextBondId(privateKey);
|
||||||
|
expect(bondId1).toBeDefined();
|
||||||
|
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
|
||||||
|
|
||||||
// Create a new record version.
|
// Create a new record version.
|
||||||
version2 = await publishNewWatcherVersion(bondId1);
|
let watcher = await publishNewWatcherVersion(bondId1);
|
||||||
|
let queryv1 = { type: watcher.record.type, url: watcher.record.url, version: watcher.record.version };
|
||||||
|
let queryv2 = { type: watcher.record.type, url: watcher.record.url, version: watcher.record.version };
|
||||||
|
|
||||||
// Check version1, version2 as associated with bondId1.
|
// Check version1, version2 as associated with bondId1.
|
||||||
let records;
|
let records;
|
||||||
records = await registry.queryRecords({ type: watcher.record.type, version: version1 }, true);
|
records = await registry.queryRecords(queryv1, true);
|
||||||
expect(records[0].bondId).toBe(bondId1);
|
expect(records[0].bondId).toBe(bondId1);
|
||||||
records = await registry.queryRecords({ type: watcher.record.type, version: version2 }, true);
|
records = await registry.queryRecords(queryv2, true);
|
||||||
expect(records[0].bondId).toBe(bondId1);
|
expect(records[0].bondId).toBe(bondId1);
|
||||||
|
|
||||||
// Create another bond.
|
// Create another bond.
|
||||||
@ -131,16 +147,16 @@ const bondTests = () => {
|
|||||||
|
|
||||||
// Reassociate records from bondId1 to bondId2, verify change.
|
// Reassociate records from bondId1 to bondId2, verify change.
|
||||||
await registry.reassociateRecords({ oldBondId: bondId1, newBondId: bondId2 }, privateKey, fee);
|
await registry.reassociateRecords({ oldBondId: bondId1, newBondId: bondId2 }, privateKey, fee);
|
||||||
records = await registry.queryRecords({ type: watcher.record.type, version: version1 }, true);
|
records = await registry.queryRecords(queryv1, true);
|
||||||
expect(records[0].bondId).toBe(bondId2);
|
expect(records[0].bondId).toBe(bondId2);
|
||||||
records = await registry.queryRecords({ type: watcher.record.type, version: version2 }, true);
|
records = await registry.queryRecords(queryv2, true);
|
||||||
expect(records[0].bondId).toBe(bondId2);
|
expect(records[0].bondId).toBe(bondId2);
|
||||||
|
|
||||||
// Dissociate all records from bond, verify change.
|
// Dissociate all records from bond, verify change.
|
||||||
await registry.dissociateRecords({ bondId: bondId2 }, privateKey, fee);
|
await registry.dissociateRecords({ bondId: bondId2 }, privateKey, fee);
|
||||||
records = await registry.queryRecords({ type: watcher.record.type, version: version1 }, true);
|
records = await registry.queryRecords(queryv1, true);
|
||||||
expect(records[0].bondId).toBe('');
|
expect(records[0].bondId).toBe('');
|
||||||
records = await registry.queryRecords({ type: watcher.record.type, version: version2 }, true);
|
records = await registry.queryRecords(queryv2, true);
|
||||||
expect(records[0].bondId).toBe('');
|
expect(records[0].bondId).toBe('');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -54,7 +54,7 @@ import {
|
|||||||
|
|
||||||
export const DEFAULT_CHAIN_ID = 'laconic_9000-1';
|
export const DEFAULT_CHAIN_ID = 'laconic_9000-1';
|
||||||
|
|
||||||
const DEFAULT_WRITE_ERROR = 'Unable to write to laconicd.';
|
const DEFAULT_WRITE_ERROR = 'Unable to write to laconicd';
|
||||||
|
|
||||||
// Parse Tx response from cosmos-sdk.
|
// Parse Tx response from cosmos-sdk.
|
||||||
export const parseTxResponse = (result: any, parseResponse?: (data: string) => any) => {
|
export const parseTxResponse = (result: any, parseResponse?: (data: string) => any) => {
|
||||||
@ -117,7 +117,8 @@ export class Registry {
|
|||||||
console.error(error)
|
console.error(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
return errorMessage || DEFAULT_WRITE_ERROR;
|
const [lastErrorLine] = error.split("\n").slice(-1);
|
||||||
|
return `${errorMessage || DEFAULT_WRITE_ERROR}: ${lastErrorLine}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(gqlUrl: string, restUrl: string = "", chainId: string = DEFAULT_CHAIN_ID) {
|
constructor(gqlUrl: string, restUrl: string = "", chainId: string = DEFAULT_CHAIN_ID) {
|
||||||
|
@ -81,10 +81,10 @@ export const parseMsgSetRecordResponse = (data: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const NAMESERVICE_ERRORS = [
|
export const NAMESERVICE_ERRORS = [
|
||||||
'Name already reserved.',
|
'Name already reserved',
|
||||||
'Authority bond not found.',
|
'Authority bond not found',
|
||||||
'Name authority not found.',
|
'Name authority not found',
|
||||||
'Access denied.',
|
'Access denied',
|
||||||
]
|
]
|
||||||
|
|
||||||
export interface MessageMsgReserveAuthority {
|
export interface MessageMsgReserveAuthority {
|
||||||
|
@ -7,7 +7,7 @@ import { ensureUpdatedConfig, getConfig } from './testing/helper';
|
|||||||
|
|
||||||
const WATCHER_YML_PATH = path.join(__dirname, './testing/data/watcher.yml');
|
const WATCHER_YML_PATH = path.join(__dirname, './testing/data/watcher.yml');
|
||||||
|
|
||||||
jest.setTimeout(120 * 1000);
|
jest.setTimeout(5 * 60 * 1000);
|
||||||
|
|
||||||
const { chainId, restEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
|
const { chainId, restEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
|
||||||
|
|
||||||
@ -18,12 +18,6 @@ const namingTests = () => {
|
|||||||
let watcher: any;
|
let watcher: any;
|
||||||
let watcherId: string;
|
let watcherId: string;
|
||||||
|
|
||||||
let authorityName: string;
|
|
||||||
let otherAuthorityName: string;
|
|
||||||
let otherPrivateKey: string;
|
|
||||||
|
|
||||||
let crn: string;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||||
|
|
||||||
@ -46,11 +40,25 @@ const namingTests = () => {
|
|||||||
watcherId = result.data.id;
|
watcherId = result.data.id;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Authority tests', () => {
|
||||||
test('Reserve authority.', async () => {
|
test('Reserve authority.', async () => {
|
||||||
authorityName = `laconic-${Date.now()}`;
|
const authorityName = `laconic-${Date.now()}`;
|
||||||
|
|
||||||
await registry.reserveAuthority({ name: authorityName }, privateKey, fee);
|
await registry.reserveAuthority({ name: authorityName }, privateKey, fee);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('With authority reserved', () => {
|
||||||
|
let authorityName: string;
|
||||||
|
let crn: string;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
|
||||||
|
authorityName = `laconic-${Date.now()}`;
|
||||||
|
crn = `crn://${authorityName}/app/test`;
|
||||||
|
|
||||||
|
await registry.reserveAuthority({ name: authorityName }, privateKey, fee);
|
||||||
|
})
|
||||||
|
|
||||||
test('Lookup authority.', async () => {
|
test('Lookup authority.', async () => {
|
||||||
const [record] = await registry.lookupAuthorities([authorityName]);
|
const [record] = await registry.lookupAuthorities([authorityName]);
|
||||||
|
|
||||||
@ -69,7 +77,8 @@ const namingTests = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Reserve already reserved authority', async () => {
|
test('Reserve already reserved authority', async () => {
|
||||||
await expect(registry.reserveAuthority({ name: authorityName }, privateKey, fee)).rejects.toThrow('Name already reserved.');
|
await expect(registry.reserveAuthority({ name: authorityName }, privateKey, fee)).
|
||||||
|
rejects.toThrow('Name already reserved.');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Reserve sub-authority.', async () => {
|
test('Reserve sub-authority.', async () => {
|
||||||
@ -105,23 +114,61 @@ const namingTests = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Set name for unbonded authority', async () => {
|
test('Set name for unbonded authority', async () => {
|
||||||
crn = `crn://${authorityName}/app/test`;
|
|
||||||
assert(watcherId)
|
assert(watcherId)
|
||||||
await expect(registry.setName({ crn, cid: watcherId }, privateKey, fee)).rejects.toThrow('Authority bond not found.');
|
await expect(registry.setName({ crn, cid: watcherId }, privateKey, fee)).
|
||||||
|
rejects.toThrow('Authority bond not found.');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Set authority bond', async () => {
|
test('Set authority bond', async () => {
|
||||||
await registry.setAuthorityBond({ name: authorityName, bondId }, privateKey, fee);
|
await registry.setAuthorityBond({ name: authorityName, bondId }, privateKey, fee);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Naming tests', () => {
|
||||||
|
let authorityName: string;
|
||||||
|
let otherAuthorityName: string;
|
||||||
|
let otherPrivateKey: string;
|
||||||
|
let otherAccount: Account;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
authorityName = `laconic-${Date.now()}`;
|
||||||
|
|
||||||
|
await registry.reserveAuthority({ name: authorityName }, privateKey, fee);
|
||||||
|
await registry.setAuthorityBond({ name: authorityName, bondId }, privateKey, fee);
|
||||||
|
|
||||||
|
// Create another account.
|
||||||
|
const mnenonic = Account.generateMnemonic();
|
||||||
|
otherAccount = await Account.generateFromMnemonic(mnenonic);
|
||||||
|
await registry.sendCoins({ denom: 'aphoton', amount: '1000000000', destinationAddress: otherAccount.formattedCosmosAddress }, privateKey, fee);
|
||||||
|
|
||||||
|
otherAuthorityName = `other-${Date.now()}`;
|
||||||
|
otherPrivateKey = otherAccount.privateKey.toString('hex');
|
||||||
|
});
|
||||||
|
|
||||||
test('Set name', async () => {
|
test('Set name', async () => {
|
||||||
crn = `crn://${authorityName}/app/test`;
|
const crn = `crn://${authorityName}/app/test1`;
|
||||||
|
|
||||||
await registry.setName({ crn, cid: watcherId }, privateKey, fee);
|
await registry.setName({ crn, cid: watcherId }, privateKey, fee);
|
||||||
|
|
||||||
// Query records should return it (some CRN points to it).
|
// Query records should return it (some CRN points to it).
|
||||||
const [record] = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version });
|
const [record] = await registry.queryRecords({ type: 'WebsiteRegistrationRecord', version: watcher.record.version });
|
||||||
expect(record).toBeDefined();
|
expect(record).toBeDefined();
|
||||||
expect(record.names).toHaveLength(1);
|
expect(record.names).toHaveLength(1);
|
||||||
|
|
||||||
|
await registry.deleteName({ crn }, privateKey, fee);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('With name set', () => {
|
||||||
|
let crn: string;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
crn = `crn://${authorityName}/app/test2`;
|
||||||
|
await registry.setName({ crn, cid: watcherId }, privateKey, fee);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await registry.deleteName({ crn }, privateKey, fee);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Lookup name', async () => {
|
test('Lookup name', async () => {
|
||||||
@ -179,42 +226,6 @@ const namingTests = () => {
|
|||||||
expect(oldRecord.height).toBeDefined();
|
expect(oldRecord.height).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Set name without reserving authority', async () => {
|
|
||||||
await expect(registry.setName({ crn: 'crn://not-reserved/app/test', cid: watcherId }, privateKey, fee))
|
|
||||||
.rejects.toThrow('Name authority not found.');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Set name for non-owned authority', async () => {
|
|
||||||
// Create another account.
|
|
||||||
const mnenonic = Account.generateMnemonic();
|
|
||||||
const otherAccount = await Account.generateFromMnemonic(mnenonic);
|
|
||||||
await registry.sendCoins({ denom: 'aphoton', amount: '1000000000', destinationAddress: otherAccount.formattedCosmosAddress }, privateKey, fee);
|
|
||||||
|
|
||||||
// Other account reserves an authority.
|
|
||||||
otherAuthorityName = `other-${Date.now()}`;
|
|
||||||
otherPrivateKey = otherAccount.privateKey.toString('hex');
|
|
||||||
await registry.reserveAuthority({ name: otherAuthorityName }, otherPrivateKey, fee);
|
|
||||||
|
|
||||||
// Try setting name under other authority.
|
|
||||||
await expect(registry.setName({ crn: `crn://${otherAuthorityName}/app/test`, cid: watcherId }, privateKey, fee)).rejects.toThrow('Access denied.');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Lookup non existing name', async () => {
|
|
||||||
const records = await registry.lookupNames(['crn://not-reserved/app/test']);
|
|
||||||
expect(records).toBeDefined();
|
|
||||||
expect(records).toHaveLength(1);
|
|
||||||
const [record] = records;
|
|
||||||
expect(record).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Resolve non existing name', async () => {
|
|
||||||
const records = await registry.resolveNames(['crn://not-reserved/app/test']);
|
|
||||||
expect(records).toBeDefined();
|
|
||||||
expect(records).toHaveLength(1);
|
|
||||||
const [record] = records;
|
|
||||||
expect(record).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Delete name', async () => {
|
test('Delete name', async () => {
|
||||||
await registry.deleteName({ crn }, privateKey, fee);
|
await registry.deleteName({ crn }, privateKey, fee);
|
||||||
|
|
||||||
@ -241,6 +252,7 @@ const namingTests = () => {
|
|||||||
|
|
||||||
test('Delete already deleted name', async () => {
|
test('Delete already deleted name', async () => {
|
||||||
await registry.deleteName({ crn }, privateKey, fee);
|
await registry.deleteName({ crn }, privateKey, fee);
|
||||||
|
await registry.deleteName({ crn }, privateKey, fee);
|
||||||
|
|
||||||
const records = await registry.lookupNames([crn], true);
|
const records = await registry.lookupNames([crn], true);
|
||||||
expect(records).toBeDefined();
|
expect(records).toBeDefined();
|
||||||
@ -252,6 +264,22 @@ const namingTests = () => {
|
|||||||
expect(latest.id).toBe('');
|
expect(latest.id).toBe('');
|
||||||
expect(latest.height).toBeDefined();
|
expect(latest.height).toBeDefined();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Set name without reserving authority', async () => {
|
||||||
|
await expect(registry.setName({ crn: 'crn://not-reserved/app/test', cid: watcherId }, privateKey, fee))
|
||||||
|
.rejects.toThrow('Name authority not found.');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Set name for non-owned authority', async () => {
|
||||||
|
await registry.sendCoins({ denom: 'aphoton', amount: '1000000000', destinationAddress: otherAccount.formattedCosmosAddress }, privateKey, fee);
|
||||||
|
|
||||||
|
// Other account reserves an authority.
|
||||||
|
await registry.reserveAuthority({ name: otherAuthorityName }, otherPrivateKey, fee);
|
||||||
|
|
||||||
|
// Try setting name under other authority.
|
||||||
|
await expect(registry.setName({ crn: `crn://${otherAuthorityName}/app/test`, cid: watcherId }, privateKey, fee)).rejects.toThrow('Access denied.');
|
||||||
|
});
|
||||||
|
|
||||||
test('Delete name for non-owned authority.', async () => {
|
test('Delete name for non-owned authority.', async () => {
|
||||||
const otherBondId = await registry.getNextBondId(otherPrivateKey);
|
const otherBondId = await registry.getNextBondId(otherPrivateKey);
|
||||||
@ -262,6 +290,23 @@ const namingTests = () => {
|
|||||||
// Try deleting name under other authority.
|
// Try deleting name under other authority.
|
||||||
await expect(registry.deleteName({ crn: `crn://${otherAuthorityName}/app/test` }, privateKey, fee)).rejects.toThrow('Access denied.');
|
await expect(registry.deleteName({ crn: `crn://${otherAuthorityName}/app/test` }, privateKey, fee)).rejects.toThrow('Access denied.');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Lookup non existing name', async () => {
|
||||||
|
const records = await registry.lookupNames(['crn://not-reserved/app/test']);
|
||||||
|
expect(records).toBeDefined();
|
||||||
|
expect(records).toHaveLength(1);
|
||||||
|
const [record] = records;
|
||||||
|
expect(record).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Resolve non existing name', async () => {
|
||||||
|
const records = await registry.resolveNames(['crn://not-reserved/app/test']);
|
||||||
|
expect(records).toBeDefined();
|
||||||
|
expect(records).toHaveLength(1);
|
||||||
|
const [record] = records;
|
||||||
|
expect(record).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (process.env.TEST_AUCTIONS_ENABLED) {
|
if (process.env.TEST_AUCTIONS_ENABLED) {
|
||||||
|
@ -79,7 +79,7 @@ export class Util {
|
|||||||
const res: {[key: string]: any} = {};
|
const res: {[key: string]: any} = {};
|
||||||
|
|
||||||
attributes.forEach(attr => {
|
attributes.forEach(attr => {
|
||||||
res[attr.key] = this.fromGQLValue(attr.value);
|
res[attr.key] = (attr.value === null) ? null : this.fromGQLValue(attr.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
Loading…
Reference in New Issue
Block a user