Make REST endpoint optional
This commit is contained in:
parent
9e8d6d910e
commit
984d96b27b
@ -1 +1,2 @@
|
||||
PRIVATE_KEY=75f719e613d05efab06a3f1dde5250b497723b13d4afa4f8ed80145764e40cf7
|
||||
COSMOS_CHAIN_ID=laconic_9000-1
|
||||
|
@ -1,6 +1,5 @@
|
||||
import assert from 'assert';
|
||||
import BIP32Factory from 'bip32';
|
||||
// TODO: Upgrade tiny-secp256k1 and use in react laconic-console app.
|
||||
import * as ecc from 'tiny-secp256k1';
|
||||
import * as bip39 from 'bip39';
|
||||
import canonicalStringify from 'canonical-json';
|
||||
|
@ -16,7 +16,7 @@ const auctionTests = (numBidders = 3) => {
|
||||
beforeAll(async () => {
|
||||
console.log('Running auction tests with num bidders', numBidders);
|
||||
|
||||
registry = new Registry(restEndpoint, gqlEndpoint, chainId);
|
||||
registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||
});
|
||||
|
||||
test('Setup bidder accounts', async () => {
|
||||
|
@ -29,7 +29,7 @@ const bondTests = () => {
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
registry = new Registry(restEndpoint, gqlEndpoint, chainId);
|
||||
registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||
});
|
||||
|
||||
test('Create bond.', async () => {
|
||||
|
@ -10,7 +10,7 @@ const registryTests = () => {
|
||||
let registry: Registry;
|
||||
|
||||
beforeAll(async () => {
|
||||
registry = new Registry(restEndpoint, gqlEndpoint, chainId);
|
||||
registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||
|
||||
});
|
||||
|
||||
|
14
src/index.ts
14
src/index.ts
@ -53,6 +53,8 @@ import {
|
||||
MessageMsgRevealBid
|
||||
} from './messages/auction';
|
||||
|
||||
export const DEFAULT_CHAIN_ID = 'laconic_9000-1';
|
||||
|
||||
const DEFAULT_WRITE_ERROR = 'Unable to write to laconicd.';
|
||||
|
||||
// Parse Tx response from cosmos-sdk.
|
||||
@ -119,21 +121,21 @@ export class Registry {
|
||||
return errorMessage || DEFAULT_WRITE_ERROR;
|
||||
}
|
||||
|
||||
constructor(restUrl: string, gqlUrl: string, chainId: string) {
|
||||
if (!isUrl(restUrl)) {
|
||||
throw new Error('Path to a REST endpoint should be provided.');
|
||||
}
|
||||
|
||||
constructor(gqlUrl: string, restUrl: string = "", chainId: string = DEFAULT_CHAIN_ID) {
|
||||
if (!isUrl(gqlUrl)) {
|
||||
throw new Error('Path to a GQL endpoint should be provided.');
|
||||
}
|
||||
|
||||
if (restUrl && !isUrl(restUrl)) {
|
||||
throw new Error('REST endpoint is not a URL string.');
|
||||
}
|
||||
|
||||
this._endpoints = {
|
||||
rest: restUrl,
|
||||
gql: gqlUrl
|
||||
};
|
||||
|
||||
this._client = new RegistryClient(restUrl, gqlUrl);
|
||||
this._client = new RegistryClient(gqlUrl, restUrl);
|
||||
this._chainID = chainId;
|
||||
|
||||
this._chain = {
|
||||
|
@ -20,7 +20,7 @@ const nameserviceExpiryTests = () => {
|
||||
let recordExpiryTime: Date;
|
||||
|
||||
beforeAll(async () => {
|
||||
registry = new Registry(restEndpoint, gqlEndpoint, chainId);
|
||||
registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||
|
||||
// Create bond.
|
||||
bondId = await registry.getNextBondId(privateKey);
|
||||
|
@ -25,7 +25,7 @@ const namingTests = () => {
|
||||
let crn: string;
|
||||
|
||||
beforeAll(async () => {
|
||||
registry = new Registry(restEndpoint, gqlEndpoint, chainId);
|
||||
registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||
|
||||
// Create bond.
|
||||
bondId = await registry.getNextBondId(privateKey);
|
||||
|
@ -122,15 +122,14 @@ export class RegistryClient {
|
||||
/**
|
||||
* New Client.
|
||||
*/
|
||||
constructor(restEndpoint: string, gqlEndpoint: string) {
|
||||
assert(restEndpoint);
|
||||
|
||||
this._restEndpoint = restEndpoint;
|
||||
|
||||
constructor(gqlEndpoint: string, restEndpoint: string) {
|
||||
assert(gqlEndpoint);
|
||||
this._graph = graphqlClient(gqlEndpoint, {
|
||||
method: 'POST',
|
||||
asJSON: true
|
||||
});
|
||||
|
||||
this._restEndpoint = restEndpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,7 +15,7 @@ describe('Querying', () => {
|
||||
let bondId: string;
|
||||
|
||||
beforeAll(async () => {
|
||||
registry = new Registry(restEndpoint, gqlEndpoint, chainId);
|
||||
registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||
bondId = await provisionBondId(registry, privateKey, fee);
|
||||
|
||||
const publishNewWatcherVersion = async () => {
|
||||
|
@ -3,7 +3,7 @@ import yaml from 'node-yaml';
|
||||
import semver from 'semver';
|
||||
import { Fee } from '@tharsis/transactions';
|
||||
|
||||
import { Registry } from '../index';
|
||||
import { DEFAULT_CHAIN_ID, Registry } from '../index';
|
||||
|
||||
export const ensureUpdatedConfig = async (path: string) => {
|
||||
const conf = await yaml.read(path);
|
||||
@ -37,7 +37,7 @@ export const getConfig = () => {
|
||||
assert(process.env.PRIVATE_KEY);
|
||||
|
||||
return {
|
||||
chainId: process.env.COSMOS_CHAIN_ID || 'laconic_9000-1',
|
||||
chainId: process.env.COSMOS_CHAIN_ID || DEFAULT_CHAIN_ID,
|
||||
privateKey: process.env.PRIVATE_KEY,
|
||||
restEndpoint: process.env.LACONICD_REST_ENDPOINT || 'http://localhost:1317',
|
||||
gqlEndpoint: process.env.LACONICD_GQL_ENDPOINT || 'http://localhost:9473/api',
|
||||
|
@ -18,7 +18,7 @@ const utilTests = () => {
|
||||
let watcherId: string;
|
||||
|
||||
beforeAll(async () => {
|
||||
registry = new Registry(restEndpoint, gqlEndpoint, chainId);
|
||||
registry = new Registry(gqlEndpoint, restEndpoint, chainId);
|
||||
|
||||
// Create bond.
|
||||
bondId = await registry.getNextBondId(privateKey);
|
||||
|
Loading…
Reference in New Issue
Block a user