Add test for util getContentId

This commit is contained in:
nabarun 2022-04-14 10:04:52 +05:30 committed by Ashwin Phatak
parent 407d31cea7
commit c3066db987
6 changed files with 53 additions and 14 deletions

View File

@ -5,14 +5,14 @@ import * as bip39 from 'bip39';
import canonicalStringify from 'canonical-json'; import canonicalStringify from 'canonical-json';
import secp256k1 from 'secp256k1'; import secp256k1 from 'secp256k1';
import { utils } from 'ethers'; import { utils } from 'ethers';
import { sha256 } from 'js-sha256';
import { MessageTypes, signTypedData, SignTypedDataVersion } from '@metamask/eth-sig-util'; 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 { fromHex, toHex } from '@cosmjs/encoding';
import { ethToEthermint } from "@tharsis/address-converter" import { ethToEthermint } from "@tharsis/address-converter"
import { encodeSecp256k1Pubkey } from '@cosmjs/amino'; import { encodeSecp256k1Pubkey } from '@cosmjs/amino';
import { Payload, Signature } from './types'; import { Payload, Signature } from './types';
import { sha256 } from 'js-sha256';
const AMINO_PREFIX = 'EB5AE98721'; const AMINO_PREFIX = 'EB5AE98721';
const HDPATH = "m/44'/60'/0'/0"; const HDPATH = "m/44'/60'/0'/0";
@ -120,7 +120,6 @@ export class Account {
/** /**
* Get record signature. * Get record signature.
* @param {object} record
*/ */
async signRecord(record: any) { async signRecord(record: any) {
assert(record); assert(record);

View File

@ -73,7 +73,6 @@ const auctionTests = (numBidders = 3) => {
expect(auction.status).toEqual('reveal'); expect(auction.status).toEqual('reveal');
for (let i = 0; i < numBidders; i++) { 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); await registry.revealBid({ auctionId, reveal: accounts[i].bid.revealString }, accounts[i].privateKey, fee);
} }
}); });

View File

@ -320,10 +320,6 @@ export class Registry {
/** /**
* Set authority bond. * Set authority bond.
* @param {string} name
* @param {string} bondId
* @param {string} privateKey
* @param {object} fee
*/ */
async setAuthorityBond(params: MessageMsgSetAuthorityBond, privateKey: string, fee: Fee) { async setAuthorityBond(params: MessageMsgSetAuthorityBond, privateKey: string, fee: Fee) {
let result; let result;
@ -401,10 +397,6 @@ export class Registry {
/** /**
* Set name (WRN) to record ID (CID). * 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) { async setName(params: MessageMsgSetName, privateKey: string, fee: Fee) {
let result; let result;

View File

@ -3,7 +3,7 @@ import path from 'path';
import { Account } from './account'; import { Account } from './account';
import { Registry } from './index'; 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'); const WATCHER_YML_PATH = path.join(__dirname, './testing/data/watcher.yml');

49
src/util.test.ts Normal file
View File

@ -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);