Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gyuguen committed Mar 17, 2024
1 parent 99f76d7 commit 55ef90b
Show file tree
Hide file tree
Showing 24 changed files with 1,552 additions and 486 deletions.
25 changes: 25 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
overrides: [
{
env: {
node: true,
},
files: [".eslintrc.{js,cjs}"],
parserOptions: {
sourceType: "script",
},
},
],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
plugins: ["@typescript-eslint"],
rules: {},
};
69 changes: 34 additions & 35 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,47 @@ name: ci

on:
push:
branches: # only for pushes on master
- master
pull_request: # for all PRs regardless of its base branch
branches: # only for pushes on master
- master
pull_request: # for all PRs regardless of its base branch

jobs:
build-test:

runs-on: ubuntu-latest

env:
CHAIN_ID: testing
MNEMONIC: ${{ secrets.TEST_MNEMONIC }}

steps:
- uses: actions/checkout@v2

- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x

- name: Install dependencies
run: yarn install

- name: Build
run: yarn build

- name: Run a panacea-core docker container
run: |
docker run --rm -d \
-e CHAIN_ID="${CHAIN_ID}" \
-e MNEMONIC="${MNEMONIC}" \
-p 26657:26657 \
-v $(pwd)/scripts:/root/scripts \
--name core \
ghcr.io/medibloc/panacea-core:master \
bash /root/scripts/panacea-core/init.sh
wget -qO- https://raw.githubusercontent.com/eficode/wait-for/v2.1.2/wait-for | sh -s -- localhost:26657 -t 30
- name: Run tests
env:
PANACEAD_ENABLED: true
TENDERMINT_URL: http://localhost:26657
run: yarn test
- uses: actions/checkout@v2

- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x

- name: Install dependencies
run: yarn install

- name: Build
run: yarn build

- name: Run a panacea-core docker container
run: |
docker run --rm -d \
-e CHAIN_ID="${CHAIN_ID}" \
-e MNEMONIC="${MNEMONIC}" \
-p 26657:26657 \
-v $(pwd)/scripts:/root/scripts \
--name core \
ghcr.io/medibloc/panacea-core:master \
bash /root/scripts/panacea-core/init.sh
wget -qO- https://raw.githubusercontent.com/eficode/wait-for/v2.1.2/wait-for | sh -s -- localhost:26657 -t 30
- name: Run tests
env:
PANACEAD_ENABLED: true
TENDERMINT_URL: http://localhost:26657
run: yarn test
8 changes: 8 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules

build

*.js

src/proto
third_party
53 changes: 53 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Changelog

## Unreleased

TBD

### Features

- []() feat:

## [v2.0.4](https://github.com/medibloc/panacea-js/releases/tag/v2.0.4) - 2023-07-05

### Features

- [\#71](https://github.com/medibloc/panacea-js/pull/71) feat: export jwt in index.ts

## [v2.0.3](https://github.com/medibloc/panacea-js/releases/tag/v2.0.3) - 2023-03-13

### Features

- [\#68](https://github.com/medibloc/panacea-js/pull/68) feat: add DID Auth in JWT

## [v2.0.2](https://github.com/medibloc/panacea-js/releases/tag/v2.0.2) - 2022-08-18

### Features

- [\#64](https://github.com/medibloc/panacea-js/pull/64) feat: implement a function to convert a mnemonic to a secp256k1 private key

## [v2.0.1](https://github.com/medibloc/panacea-js/releases/tag/v2.0.1) - 2022-06-03

### Features

- [\#60](https://github.com/medibloc/panacea-js/pull/60) feat: add explicit `fee` parameters

## [v2.0.0](https://github.com/medibloc/panacea-js/releases/tag/v2.0.0) - 2021-07-20

### Features

- [\#37](https://github.com/medibloc/panacea-js/pull/37) feat: Support Panacea v2 based on Cosmos v0.42 Stargate

## [v1.3.1](https://github.com/medibloc/panacea-js/releases/tag/v1.3.1) - 2020-11-25

### Bug fixes

- [\#24](https://github.com/medibloc/panacea-js/pull/24) Follow up the new Cosmos REST spec for DID operations

## [v1.3.0](https://github.com/medibloc/panacea-js/releases/tag/v1.3.0) - 2020-10-30

### Features

- [\#5](https://github.com/medibloc/panacea-js/pull/5)~[\#18](https://github.com/medibloc/panacea-js/pull/18) Support DID operations
- [\#11](https://github.com/medibloc/panacea-js/pull/11), [\#19](https://github.com/medibloc/panacea-js/pull/19) Switch to Typescript
- [\#22](https://github.com/medibloc/panacea-js/pull/22) Follow up the new Cosmos v0.36.0+ REST spec
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// jest.config.js
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
preset: "ts-jest",
testEnvironment: "node",
};
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@
"proto-gen": "./protocgen.sh",
"build": "tsc",
"test": "jest",
"lint": "eslint src test --ext .ts,.tsx",
"prepublishOnly": "npm run build"
"lint": "eslint src --ext .ts",
"prettify": "prettier --write ."
},
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/node": "^20.11.27",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"eslint": "^8.57.0",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"ts-jest": "^29.1.2",
"ts-proto": "^1.169.1",
"typescript": "^5.4.2"
Expand Down
93 changes: 69 additions & 24 deletions src/__tests__/group-signing-panacea-client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import {DirectSecp256k1HdWallet} from "@cosmjs/proto-signing";
import {v4 as uuidv4} from "uuid";
import {TextEncoder} from "util";
import {Secp256k1HdWallet} from "@cosmjs/amino";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { v4 as uuidv4 } from "uuid";
import { TextEncoder } from "util";
import { Secp256k1HdWallet } from "@cosmjs/amino";
import assert from "assert";
import {panacead} from './utils/test-utils';
import {panaceaWalletOpts, SigningPanaceaClient} from '../client/signing-panacea-client';
import {GroupSigningPanaceaClient} from '../client/group-signing-panacea-client';
import {MsgAddWriterRequest, MsgCreateTopicRequest} from '../proto/panacea/aol/v2/tx';
import { panacead } from "./utils/test-utils";
import {
panaceaWalletOpts,
SigningPanaceaClient,
GroupSigningPanaceaClient,
} from "../client";

jest.setTimeout(60000);

Expand All @@ -16,31 +18,49 @@ describe("GroupSigningPanaceaClient", () => {
let feePayerWallet: DirectSecp256k1HdWallet;

beforeAll(async () => {
ownerWallet = await DirectSecp256k1HdWallet.fromMnemonic(panacead.mnemonic, panaceaWalletOpts);
writerWallet = await DirectSecp256k1HdWallet.generate(24, panaceaWalletOpts);
feePayerWallet = await DirectSecp256k1HdWallet.fromMnemonic(panacead.mnemonic, panaceaWalletOpts);
ownerWallet = await DirectSecp256k1HdWallet.fromMnemonic(
panacead.mnemonic,
panaceaWalletOpts,
);
writerWallet = await DirectSecp256k1HdWallet.generate(
24,
panaceaWalletOpts,
);
feePayerWallet = await DirectSecp256k1HdWallet.fromMnemonic(
panacead.mnemonic,
panaceaWalletOpts,
);
});

describe("connectWithSigners", () => {
it("works", async () => {
const client = await GroupSigningPanaceaClient.connectWithSigners(panacead.tendermintUrl, [feePayerWallet, writerWallet]);
const client = await GroupSigningPanaceaClient.connectWithSigners(
panacead.tendermintUrl,
[feePayerWallet, writerWallet],
);
expect(client).toBeTruthy();
client.disconnect();
});

it("doesn't work without signer", async () => {
const fn = async () => {
await GroupSigningPanaceaClient.connectWithSigners(panacead.tendermintUrl, []);
}
await GroupSigningPanaceaClient.connectWithSigners(
panacead.tendermintUrl,
[],
);
};

await expect(fn()).rejects.toThrow(Error);
});

it("doesn't work with OfflineAminoSigner", async () => {
const wallet = await Secp256k1HdWallet.generate(24, panaceaWalletOpts);
const fn = async () => {
await GroupSigningPanaceaClient.connectWithSigners(panacead.tendermintUrl, [wallet]);
}
await GroupSigningPanaceaClient.connectWithSigners(
panacead.tendermintUrl,
[wallet],
);
};

await expect(fn()).rejects.toThrow(Error);
});
Expand All @@ -60,21 +80,32 @@ describe("GroupSigningPanaceaClient", () => {
const [firstFeePayerAccount] = await feePayerWallet.getAccounts();
feePayerAddress = firstFeePayerAccount.address;

const client = await SigningPanaceaClient.connectWithSigner(panacead.tendermintUrl, ownerWallet);
const client = await SigningPanaceaClient.connectWithSigner(
panacead.tendermintUrl,
ownerWallet,
);
const amount = {
denom: "umed",
amount: "5000000",
}
const res = await client.sendTokens(ownerAddress, writerAddress, [amount], "auto")
};
const res = await client.sendTokens(
ownerAddress,
writerAddress,
[amount],
"auto",
);
expect(res).toBeTruthy();

topicName = uuidv4();
});

describe("addRecord", () => {
beforeAll(async () => {
const client = await SigningPanaceaClient.connectWithSigner(panacead.tendermintUrl, ownerWallet);
const fee = client.createFee(200000)
const client = await SigningPanaceaClient.connectWithSigner(
panacead.tendermintUrl,
ownerWallet,
);
const fee = client.createFee(200000);

const req = {
topicName: topicName,
Expand All @@ -95,16 +126,30 @@ describe("GroupSigningPanaceaClient", () => {
});

it("works with a fee payer", async () => {
const client = await GroupSigningPanaceaClient.connectWithSigners(panacead.tendermintUrl, [feePayerWallet, writerWallet]);
const client = await GroupSigningPanaceaClient.connectWithSigners(
panacead.tendermintUrl,
[feePayerWallet, writerWallet],
);

const key = new TextEncoder().encode("key1");
const value = new TextEncoder().encode("value1");

const fee = client.createFee(200000);
const res = await client.addRecordWithFeePayer(ownerAddress, topicName, key, value, writerAddress, feePayerAddress, fee, "");
const res = await client.addRecordWithFeePayer(
ownerAddress,
topicName,
key,
value,
writerAddress,
feePayerAddress,
fee,
"",
);
expect(res).toBeTruthy();

const record = await client.getPanaceaClient().getRecord(ownerAddress, topicName, 0);
const record = await client
.getPanaceaClient()
.getRecord(ownerAddress, topicName, 0);
assert(record);
expect(record.writerAddress).toEqual(writerAddress);
expect(record.key).toEqual(key);
Expand Down
23 changes: 12 additions & 11 deletions src/__tests__/panacea-client.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import {PanaceaClient} from '../client/panacea-client';
import {panacead} from './utils/test-utils';
import {DirectSecp256k1HdWallet} from '@cosmjs/proto-signing';
import {panaceaWalletOpts} from '../client/signing-panacea-client';
import { PanaceaClient } from "../client/panacea-client";
import { panacead } from "./utils/test-utils";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { panaceaWalletOpts } from "../client/signing-panacea-client";

describe('Panacea client', () => {
it('connect', async () => {
describe("Panacea client", () => {
it("connect", async () => {
const client = await PanaceaClient.connect(panacead.tendermintUrl);
expect(client).toBeTruthy();
});

describe('AOL', () => {
describe("AOL", () => {
let ownerAddress: string;
let client: PanaceaClient;

beforeAll(async () => {
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(panacead.mnemonic, panaceaWalletOpts);
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(
panacead.mnemonic,
panaceaWalletOpts,
);
const [firstAddress] = await wallet.getAccounts();
ownerAddress = firstAddress.address;
client = await PanaceaClient.connect(panacead.tendermintUrl);
Expand All @@ -30,7 +33,5 @@ describe('Panacea client', () => {
expect(topic).toBeUndefined();
});
});


});
});
});
Loading

0 comments on commit 55ef90b

Please sign in to comment.