From 4e5f9bf9e1a23b5e7fc3707520a1c4fe26e0a49f Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 12 Mar 2024 08:40:44 +0000 Subject: [PATCH] Expect null if bond or authority is not found (#6) Part of https://www.notion.so/Create-laconic-registry-SDK-d3a636d4aba44f7cbba3bd99b7146811 Co-authored-by: neeraj Reviewed-on: https://git.vdb.to/deep-stack/registry-sdk/pulls/6 Co-authored-by: Prathamesh Musale Co-committed-by: Prathamesh Musale --- .env.example | 4 +++- README.md | 30 +++++++++++------------------- src/bond.test.ts | 4 +--- src/naming.test.ts | 5 +---- src/registry-client.ts | 2 +- src/sdk.test.ts | 3 +-- src/testing/helper.ts | 2 +- 7 files changed, 19 insertions(+), 31 deletions(-) diff --git a/.env.example b/.env.example index 9354a4b..f14a8fc 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,4 @@ -PRIVATE_KEY=75f719e613d05efab06a3f1dde5250b497723b13d4afa4f8ed80145764e40cf7 +PRIVATE_KEY= COSMOS_CHAIN_ID=laconic_9000-1 +LACONICD_GQL_ENDPOINT=http://localhost:9473/api +LACONICD_REST_ENDPOINT=http://127.0.0.1:26657 diff --git a/README.md b/README.md index 5054a8c..620f2de 100644 --- a/README.md +++ b/README.md @@ -14,14 +14,18 @@ Follow these steps to run the tests: - Copy [.env.example](./.env.example) file and create a `.env` file. -- Clone the [laconicd repo](https://github.com/cerc-io/laconicd) and change to repo directory. + ```bash + cp .env.example .env + ``` -- Run the chain using `./init.sh`. +- Clone the [laconic2d repo](https://git.vdb.to/deep-stack/laconic2d) and change to repo directory. + +- Run the chain using `./scripts/init.sh`. - Export the private key using: ```bash - laconicd keys export mykey --unarmored-hex --unsafe + laconic2d keys export alice --keyring-backend test --unarmored-hex --unsafe ``` - Copy the private key and assign it to variable `PRIVATE_KEY` in the `.env` file. @@ -34,22 +38,16 @@ Follow these steps to run the tests: - Run the tests with auctions enabled - - Remove laconicd data from previous run - - ```bash - rm -rf ~/.laconicd - ``` - - In laconicd repo run: ```bash - TEST_AUCTION_ENABLED=true ./init.sh + TEST_AUCTION_ENABLED=true ./scripts/init.sh clean ``` - Export the private key and change it in `.env` file again using: ```bash - laconicd keys export mykey --unarmored-hex --unsafe + laconic2d keys export alice --keyring-backend test --unarmored-hex --unsafe ``` - Run tests: @@ -60,22 +58,16 @@ Follow these steps to run the tests: - Run the tests for record and authority expiry - - Remove laconicd data from previous run - - ```bash - rm -rf ~/.laconicd - ``` - - In laconicd repo run: ```bash - TEST_REGISTRY_EXPIRY=true ./init.sh + TEST_REGISTRY_EXPIRY=true ./scripts/init.sh clean ``` - Export the private key and change it in `.env` file again using: ```bash - laconicd keys export mykey --unarmored-hex --unsafe + laconic2d keys export alice --keyring-backend test --unarmored-hex --unsafe ``` - Run tests: diff --git a/src/bond.test.ts b/src/bond.test.ts index 681c787..92124dc 100644 --- a/src/bond.test.ts +++ b/src/bond.test.ts @@ -88,9 +88,7 @@ const bondTests = () => { test('Cancel bond.', async () => { await registry.cancelBond({ id: bond1.id }, privateKey, fee); const [bond] = await registry.getBondsByIds([bond1.id]); - expect(bond.id).toBe(''); - expect(bond.owner).toBe(''); - expect(bond.balance).toHaveLength(0); + expect(bond).toBe(null); }); }); diff --git a/src/naming.test.ts b/src/naming.test.ts index 12320ef..71ce007 100644 --- a/src/naming.test.ts +++ b/src/naming.test.ts @@ -69,10 +69,7 @@ const namingTests = () => { test('Lookup non existing authority', async () => { const [record] = await registry.lookupAuthorities(['does-not-exist']); - - expect(record.ownerAddress).toBe(''); - expect(record.ownerPublicKey).toBe(''); - expect(Number(record.height)).toBe(0); + expect(record).toBe(null); }); test('Reserve already reserved authority', async () => { diff --git a/src/registry-client.ts b/src/registry-client.ts index 6b6852c..9372926 100644 --- a/src/registry-client.ts +++ b/src/registry-client.ts @@ -105,7 +105,7 @@ export class RegistryClient { */ static async getResult (query: any, key: string, modifier?: (rows: any[]) => {}) { const result = await query; - if (result && result[key] && result[key].length && result[key][0] !== null) { + if (result && result[key]) { if (modifier) { return modifier(result[key]); } diff --git a/src/sdk.test.ts b/src/sdk.test.ts index 885cb63..a69edaf 100644 --- a/src/sdk.test.ts +++ b/src/sdk.test.ts @@ -36,8 +36,7 @@ describe('Querying', () => { expect(registry.chainID).toBe(chainId); }); - // TODO: Check get status error - xtest('Get status.', async () => { + test('Get status.', async () => { const status = await registry.getStatus(); expect(status).toBeDefined(); expect(status.version).toBeDefined(); diff --git a/src/testing/helper.ts b/src/testing/helper.ts index 17c23d3..6a7579e 100644 --- a/src/testing/helper.ts +++ b/src/testing/helper.ts @@ -26,7 +26,7 @@ export const getConfig = () => { return { chainId: process.env.COSMOS_CHAIN_ID || DEFAULT_CHAIN_ID, privateKey: process.env.PRIVATE_KEY, - restEndpoint: process.env.LACONICD_REST_ENDPOINT || 'http://localhost:1317', + restEndpoint: process.env.LACONICD_REST_ENDPOINT || 'http://localhost:26657', gqlEndpoint: process.env.LACONICD_GQL_ENDPOINT || 'http://localhost:9473/api', fee: { amount: [{ denom: 'photon', amount: '40' }],