From c3066db9872e71761994e513b012c1b8691a34b8 Mon Sep 17 00:00:00 2001 From: nabarun Date: Thu, 14 Apr 2022 10:04:52 +0530 Subject: [PATCH] Add test for util getContentId --- src/account.ts | 5 ++--- src/auction.test.ts | 1 - src/index.ts | 8 -------- src/messages/util.ts | 2 +- src/naming.test.ts | 2 +- src/util.test.ts | 49 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 src/util.test.ts diff --git a/src/account.ts b/src/account.ts index 8b40cb5..eae01c9 100644 --- a/src/account.ts +++ b/src/account.ts @@ -5,14 +5,14 @@ import * as bip39 from 'bip39'; import canonicalStringify from 'canonical-json'; import secp256k1 from 'secp256k1'; import { utils } from 'ethers'; +import { sha256 } from 'js-sha256'; import { MessageTypes, signTypedData, SignTypedDataVersion } from '@metamask/eth-sig-util'; -import { Ripemd160, Secp256k1 } from "@cosmjs/crypto"; +import { Ripemd160 } from "@cosmjs/crypto"; import { fromHex, toHex } from '@cosmjs/encoding'; import { ethToEthermint } from "@tharsis/address-converter" import { encodeSecp256k1Pubkey } from '@cosmjs/amino'; import { Payload, Signature } from './types'; -import { sha256 } from 'js-sha256'; const AMINO_PREFIX = 'EB5AE98721'; const HDPATH = "m/44'/60'/0'/0"; @@ -120,7 +120,6 @@ export class Account { /** * Get record signature. - * @param {object} record */ async signRecord(record: any) { assert(record); diff --git a/src/auction.test.ts b/src/auction.test.ts index 5b1ed15..c911833 100644 --- a/src/auction.test.ts +++ b/src/auction.test.ts @@ -73,7 +73,6 @@ const auctionTests = (numBidders = 3) => { expect(auction.status).toEqual('reveal'); for (let i = 0; i < numBidders; i++) { - // eslint-disable-next-line no-await-in-loop await registry.revealBid({ auctionId, reveal: accounts[i].bid.revealString }, accounts[i].privateKey, fee); } }); diff --git a/src/index.ts b/src/index.ts index 064dfbc..3ac7e09 100644 --- a/src/index.ts +++ b/src/index.ts @@ -320,10 +320,6 @@ export class Registry { /** * Set authority bond. - * @param {string} name - * @param {string} bondId - * @param {string} privateKey - * @param {object} fee */ async setAuthorityBond(params: MessageMsgSetAuthorityBond, privateKey: string, fee: Fee) { let result; @@ -401,10 +397,6 @@ export class Registry { /** * Set name (WRN) to record ID (CID). - * @param {string} wrn - * @param {string} id - * @param {string} privateKey - * @param {object} fee */ async setName(params: MessageMsgSetName, privateKey: string, fee: Fee) { let result; diff --git a/src/messages/util.ts b/src/messages/util.ts index 355a3c6..038e74d 100644 --- a/src/messages/util.ts +++ b/src/messages/util.ts @@ -76,4 +76,4 @@ export const createTx = ( legacyAmino: tx.legacyAmino, eipToSign, } -} \ No newline at end of file +} diff --git a/src/naming.test.ts b/src/naming.test.ts index 260e939..49239c3 100644 --- a/src/naming.test.ts +++ b/src/naming.test.ts @@ -3,7 +3,7 @@ import path from 'path'; import { Account } from './account'; import { Registry } from './index'; -import { ensureUpdatedConfig, getBaseConfig, getConfig } from './testing/helper'; +import { ensureUpdatedConfig, getConfig } from './testing/helper'; const WATCHER_YML_PATH = path.join(__dirname, './testing/data/watcher.yml'); diff --git a/src/util.test.ts b/src/util.test.ts new file mode 100644 index 0000000..e686773 --- /dev/null +++ b/src/util.test.ts @@ -0,0 +1,49 @@ +import path from 'path'; + +import { Registry } from './index'; +import { getBaseConfig, getConfig } from './testing/helper'; +import { Util } from './util'; + +const WATCHER_YML_PATH = path.join(__dirname, './testing/data/watcher.yml'); + +jest.setTimeout(90 * 1000); + +const { chainId, restEndpoint, gqlEndpoint, privateKey, fee } = getConfig(); + +const utilTests = () => { + let registry: Registry; + + let bondId: string; + let watcher: any; + let watcherId: string; + + beforeAll(async () => { + registry = new Registry(restEndpoint, gqlEndpoint, chainId); + + // Create bond. + bondId = await registry.getNextBondId(privateKey); + await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee); + + // Create bot. + watcher = await getBaseConfig(WATCHER_YML_PATH); + await registry.setRecord( + { + privateKey, + bondId, + record: watcher.record + }, + privateKey, + fee + ) + + const [record] = await registry.queryRecords({ type: 'watcher', version: watcher.record.version }, true); + watcherId = record.id; + }); + + xtest('generate content id.', async () => { + const cid = await Util.getContentId(watcher.record); + expect(cid).toBe(watcherId) + }); +} + +describe('Util', utilTests);