Skip to content

Commit

Permalink
feat: update auranw to aura; use aurajs@0.1.7, jest-mock@29.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fibonacci998 committed Dec 12, 2023
1 parent 17201a6 commit ab7da59
Show file tree
Hide file tree
Showing 18 changed files with 3,419 additions and 12,286 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ jobs:
with:
node-version: '16.14'
registry-url: https://npm.pkg.github.com/aura-nw
- name: Install Yarn
run: npm install -g yarn
- name: Cache node modules
id: cache-npm
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: ~/.npm
path: ./node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
[ -n "$CI" ] && exit 0

set -eux
yarn test
npm run test
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ FROM node:16-alpine
WORKDIR /app

# Install dependencies
COPY package.json package-lock.json yarn.lock ./
RUN yarn install
COPY package.json package-lock.json ./
RUN npm install

# Copy source
COPY . .

# Build and cleanup
ENV NODE_ENV=production
RUN yarn build
RUN npm run build

# Start server
CMD ["yarn", "start"]
CMD ["npm", "start"]
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ hasura metadata apply
[Config list network](network.json) to config list network with LCD, RPC, database
[Config chain](config.json) to setup job crawl and select chain id to crawl

## YARN scripts
## Scripts

- `yarn dev`: Start development mode (load all services locally with hot-reload & REPL)
- `yarn build`: Build .dist folder to start production mode
- `yarn start`: Start production mode (set `SERVICES` env variable to load certain services)
- `yarn lint`: Run ESLint
- `yarn test`: Run jest
- `npm run dev`: Start development mode (load all services locally with hot-reload & REPL)
- `npm run build`: Build .dist folder to start production mode
- `npm run start`: Start production mode (set `SERVICES` env variable to load certain services)
- `npm run lint`: Run ESLint
- `npm run test`: Run jest
6,480 changes: 3,369 additions & 3,111 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
"db:migrate:test:latest": "env DOTENV_CONFIG_PATH=./.env NODE_ENV=test ts-node --require dotenv/config ./node_modules/.bin/knex migrate:latest",
"db:migrate:test:rollback": "env DOTENV_CONFIG_PATH=./.env NODE_ENV=test ts-node --require dotenv/config ./node_modules/.bin/knex migrate:rollback",
"db:seed:make": "env DOTENV_CONFIG_PATH=./.env ts-node --require dotenv/config ./node_modules/.bin/knex seed:make",
"build": "yarn clean; tsc --project tsconfig.build.json",
"build": "npm run clean; tsc --project tsconfig.build.json",
"up": "docker-compose up -d",
"stop": "docker-compose stop",
"prepare": "husky install",
"jest": "NODE_OPTIONS='--loader ts-node/esm' jest",
"test": "docker compose up -d aurad && yarn jest --verbose --runInBand --forceExit && docker compose stop aurad && docker rm aurad_erascope",
"test-ci": "yarn jest --verbose --runInBand --forceExit",
"test-watch": "yarn jest --watch",
"test-coverage": "yarn jest --coverage",
"test": "docker compose up aurad -d && npm run jest -- --verbose --runInBand --forceExit && docker compose stop aurad && docker rm aurad_erascope",
"test-ci": "npm run jest -- --verbose --runInBand --forceExit",
"test-watch": "npm run jest --watch",
"test-coverage": "npm run jest --coverage",
"lint": "echo 'Running lint for repository' && eslint ."
},
"nodemonConfig": {
Expand All @@ -43,7 +43,7 @@
"ext": "ts, js"
},
"dependencies": {
"@aura-nw/aurajs": "^0.1.6",
"@aura-nw/aurajs": "0.1.7",
"@bull-board/api": "^5.1.1",
"@bull-board/express": "^5.1.1",
"@cosmjs/cosmwasm-stargate": "^0.30.0",
Expand Down Expand Up @@ -121,6 +121,7 @@
"husky": "^8.0.0",
"jest": "^29.3.1",
"jest-light-runner": "^0.4.1",
"jest-mock": "29.5.0",
"moleculer-repl": "^0.7.3",
"prettier": "^2.7.1",
"ts-jest": "^29.0.3",
Expand Down
2 changes: 1 addition & 1 deletion src/common/types/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Long from 'long';

export interface IAuraJSClientFactory {
auranw: any;
aura: any;

Check warning on line 4 in src/common/types/interfaces.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
cosmwasm: any;

Check warning on line 5 in src/common/types/interfaces.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
ibc: any;

Check warning on line 6 in src/common/types/interfaces.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
}
Expand Down
18 changes: 9 additions & 9 deletions src/common/utils/aurajs_client.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { auranw, cosmwasm, ibc } from '@aura-nw/aurajs';
import { aura, cosmwasm, ibc } from '@aura-nw/aurajs';
import { IAuraJSClientFactory } from '../types/interfaces';
import network from '../../../network.json' assert { type: 'json' };
import config from '../../../config.json' assert { type: 'json' };

export default class AuraJsClient {
public lcdClient: IAuraJSClientFactory = {
auranw: null,
aura: null,
cosmwasm: null,
ibc: null,
};

public rpcClient: IAuraJSClientFactory = {
auranw: null,
aura: null,
cosmwasm: null,
ibc: null,
};
Expand All @@ -23,9 +23,9 @@ export async function getLcdClient() {
const lcd =
network.find((net: any) => net.chainId === config.chainId)?.LCD[0] || '';

if (!client.lcdClient.auranw) {
const auranwClient = auranw.ClientFactory;
client.lcdClient.auranw = await auranwClient.createLCDClient({
if (!client.lcdClient.aura) {
const auraClient = aura.ClientFactory;
client.lcdClient.aura = await auraClient.createLCDClient({
restEndpoint: lcd,
});
}
Expand All @@ -48,9 +48,9 @@ export async function getRpcClient() {
const rpc =
network.find((net: any) => net.chainId === config.chainId)?.RPC[0] || '';

if (!client.rpcClient.auranw) {
const auranwClient = auranw.ClientFactory;
client.rpcClient.auranw = await auranwClient.createRPCQueryClient({
if (!client.rpcClient.aura) {
const auraClient = aura.ClientFactory;
client.rpcClient.aura = await auraClient.createRPCQueryClient({
rpcEndpoint: rpc,
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/crawl-block/crawl_block.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default class CrawlBlockService extends BullableService {

// set version cosmos sdk to registry
const nodeInfo: GetNodeInfoResponseSDKType =
await this._lcdClient.auranw.cosmos.base.tendermint.v1beta1.getNodeInfo();
await this._lcdClient.aura.cosmos.base.tendermint.v1beta1.getNodeInfo();
const cosmosSdkVersion = nodeInfo.application_version?.cosmos_sdk_version;
if (cosmosSdkVersion) {
this._registry.setCosmosSdkVersionByString(cosmosSdkVersion);
Expand All @@ -81,7 +81,7 @@ export default class CrawlBlockService extends BullableService {
async handleJobCrawlBlock() {
// Get latest block in network
const responseGetLatestBlock: GetLatestBlockResponseSDKType =
await this._lcdClient.auranw.cosmos.base.tendermint.v1beta1.getLatestBlock();
await this._lcdClient.aura.cosmos.base.tendermint.v1beta1.getLatestBlock();
const latestBlockNetwork = parseInt(
responseGetLatestBlock.block?.header?.height
? responseGetLatestBlock.block?.header?.height.toString()
Expand Down
11 changes: 5 additions & 6 deletions src/services/crawl-proposal/crawl_proposal.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default class CrawlProposalService extends BullableService {
proposalIds
);
const nodeInfo: GetNodeInfoResponseSDKType =
await this._lcdClient.auranw.cosmos.base.tendermint.v1beta1.getNodeInfo();
await this._lcdClient.aura.cosmos.base.tendermint.v1beta1.getNodeInfo();
const cosmosSdkVersion =
nodeInfo.application_version?.cosmos_sdk_version ?? 'v0.45.99';
await Promise.all(
Expand All @@ -88,15 +88,14 @@ export default class CrawlProposalService extends BullableService {
let proposal;
if (Utils.compareVersion(cosmosSdkVersion, 'v0.45.99') === -1) {
proposal =
await this._lcdClient.auranw.cosmos.gov.v1beta1.proposal({
await this._lcdClient.aura.cosmos.gov.v1beta1.proposal({
proposalId,
});
} else {
// use gov.v1 to call proposal
proposal =
await this._lcdClient.auranw.cosmos.gov.v1.proposal({
proposalId,
});
proposal = await this._lcdClient.aura.cosmos.gov.v1.proposal({
proposalId,
});
proposal.proposal = {
...proposal.proposal,
proposal_id: proposal.proposal.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default class CrawlTallyProposalService extends BullableService {
);
});

const pool = await this._lcdClient.auranw.cosmos.staking.v1beta1.pool();
const pool = await this._lcdClient.aura.cosmos.staking.v1beta1.pool();
const result: JsonRpcSuccessResponse[] = await Promise.all(batchQueries);
const proposalTally: QueryTallyResultResponse[] = result.map(
(res: JsonRpcSuccessResponse) =>
Expand Down
6 changes: 3 additions & 3 deletions src/services/crawl-tx/aura.registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Registry, TsProtoGeneratedType } from '@cosmjs/proto-signing';
import { defaultRegistryTypes as defaultStargateTypes } from '@cosmjs/stargate';
import { wasmTypes } from '@cosmjs/cosmwasm-stargate/build/modules';
import { ibc, cosmos, auranw } from '@aura-nw/aurajs';
import { ibc, cosmos, aura } from '@aura-nw/aurajs';
import { toBase64, fromUtf8, fromBase64, toUtf8 } from '@cosmjs/encoding';
import { LoggerInstance } from 'moleculer';
import _ from 'lodash';
Expand All @@ -20,7 +20,7 @@ export default class AuraRegistry {

public ibc: any;

public auranw: any;
public aura: any;

public cosmosSdkVersion: SemVer = new SemVer('v0.45.17');

Expand All @@ -32,7 +32,7 @@ export default class AuraRegistry {
this._logger = logger;
this.cosmos = cosmos;
this.ibc = ibc;
this.auranw = auranw;
this.aura = aura;
this.setDefaultRegistry();
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/crawl-tx/crawl_tx.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ export default class CrawlTxService extends BullableService {
const lcdClient = await getLcdClient();
// set version cosmos sdk to registry
const nodeInfo: GetNodeInfoResponseSDKType =
await lcdClient.auranw.cosmos.base.tendermint.v1beta1.getNodeInfo();
await lcdClient.aura.cosmos.base.tendermint.v1beta1.getNodeInfo();
const cosmosSdkVersion = nodeInfo.application_version?.cosmos_sdk_version;
if (cosmosSdkVersion) {
this._registry.setCosmosSdkVersionByString(cosmosSdkVersion);
Expand Down
2 changes: 1 addition & 1 deletion src/services/crawl-validator/crawl_delegators.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class CrawlDelegatorsService extends BullableService {
countTotal: true,
};
const validatorDelegationInfo =
await this._lcdClient.auranw.cosmos.staking.v1beta1.validatorDelegations({
await this._lcdClient.aura.cosmos.staking.v1beta1.validatorDelegations({
validatorAddr: _payload.address,
pagination,
});
Expand Down
4 changes: 2 additions & 2 deletions src/services/crawl-validator/crawl_signing_info.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class CrawlSigningInfoService extends BullableService {

if (foundValidators.length > 0) {
const paramSlashing =
await this._lcdClient.auranw.cosmos.slashing.v1beta1.params();
await this._lcdClient.aura.cosmos.slashing.v1beta1.params();

let resultCallApi;
let done = false;
Expand All @@ -59,7 +59,7 @@ export default class CrawlSigningInfoService extends BullableService {

while (!done) {
resultCallApi =
await this._lcdClient.auranw.cosmos.slashing.v1beta1.signingInfos({
await this._lcdClient.aura.cosmos.slashing.v1beta1.signingInfos({
pagination,
});

Expand Down
4 changes: 2 additions & 2 deletions src/services/crawl-validator/crawl_validator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default class CrawlValidatorService extends BullableService {

while (!done) {
resultCallApi =
await this._lcdClient.auranw.cosmos.staking.v1beta1.validators({
await this._lcdClient.aura.cosmos.staking.v1beta1.validators({
pagination,
});

Expand Down Expand Up @@ -196,7 +196,7 @@ export default class CrawlValidatorService extends BullableService {
private async loadCustomInfo(validators: Validator[]): Promise<Validator[]> {
const batchQueries: any[] = [];

const pool = await this._lcdClient.auranw.cosmos.staking.v1beta1.pool();
const pool = await this._lcdClient.aura.cosmos.staking.v1beta1.pool();

validators.forEach((validator: Validator) => {
const request: QueryDelegationRequest = {
Expand Down
8 changes: 4 additions & 4 deletions src/services/statistics/dashboard_statistics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ export default class DashboardStatisticsService extends BullableService {
]);

const [communityPool, inflation, distribution, supply] = await Promise.all([
this._lcdClient.auranw.cosmos.distribution.v1beta1.communityPool(),
this._lcdClient.auranw.cosmos.mint.v1beta1.inflation(),
this._lcdClient.auranw.cosmos.distribution.v1beta1.params(),
this._lcdClient.auranw.cosmos.bank.v1beta1.supplyOf({
this._lcdClient.aura.cosmos.distribution.v1beta1.communityPool(),
this._lcdClient.aura.cosmos.mint.v1beta1.inflation(),
this._lcdClient.aura.cosmos.distribution.v1beta1.params(),
this._lcdClient.aura.cosmos.bank.v1beta1.supplyOf({
denom: config.networkDenom,
}),
]);
Expand Down
Loading

0 comments on commit ab7da59

Please sign in to comment.