Skip to content

Commit

Permalink
More housekeeping (#1119)
Browse files Browse the repository at this point in the history
* Update knip

* Remove some unused dependencies

* Clean up, share and remove some unused exports

* Update changelog
  • Loading branch information
webpro authored Oct 26, 2023
1 parent 90ca6f4 commit 2a0e92c
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 249 deletions.
6 changes: 6 additions & 0 deletions .changeset/cyan-poets-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@kadena/chainweb-node-client': none
'@kadena/chainwebjs': none
---

Housekeeping
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"devDependencies": {
"@changesets/cli": "^2.26.2",
"@kadena-dev/markdown": "workspace:*",
"knip": "^2.32.4",
"knip": "^2.38.1",
"only-allow": "^1.2.1",
"prettier": "~3.0.3",
"prettier-plugin-organize-imports": "^3.2.3",
Expand Down
1 change: 0 additions & 1 deletion packages/libs/bootstrap-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"@kadena/types": "workspace:*",
"@microsoft/api-extractor": "^7.38.0",
"@rushstack/eslint-config": "~3.3.0",
"@types/isomorphic-fetch": "~0.0.36",
"@types/node": "^18.17.14",
"eslint": "^8.45.0",
"prettier": "~3.0.3",
Expand Down
4 changes: 1 addition & 3 deletions packages/libs/chainweb-node-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
"dependencies": {
"@kadena/cryptography-utils": "workspace:*",
"@kadena/pactjs": "workspace:*",
"cross-fetch": "~3.1.5",
"node-fetch": "~2.6.2"
"cross-fetch": "~3.1.5"
},
"devDependencies": {
"@kadena-dev/eslint-config": "workspace:*",
Expand All @@ -57,7 +56,6 @@
"@kadena/types": "workspace:*",
"@microsoft/api-extractor": "^7.38.0",
"@rushstack/eslint-config": "~3.3.0",
"@types/isomorphic-fetch": "~0.0.36",
"@types/node": "^18.17.14",
"eslint": "^8.45.0",
"msw": "^1.3.2",
Expand Down
1 change: 0 additions & 1 deletion packages/libs/chainweb-node-client/src/spv.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { Response } from 'cross-fetch';
import fetch from 'cross-fetch';
import type { ISPVRequestBody, SPVResponse } from './interfaces/PactAPI';
import { parseResponseTEXT } from './parseResponseTEXT';
Expand Down
30 changes: 3 additions & 27 deletions packages/libs/chainweb-node-client/src/tests/listen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,11 @@ import type {
} from '../interfaces/PactAPI';
import { listen } from '../listen';
import { testURL } from './mockdata/Pact';
import { localCommandResult } from './mockdata/execCommand';

const restHandlers = [
rest.post(`${testURL}/api/v1/listen`, (req, res, ctx) => {
return res.once(
ctx.status(200),
ctx.json({
reqKey: 'pMohh9G2NT1jQn4byK1iwvoLopbnU86NeNPSUq8I0ik',
txId: null,
result: {
data: 3,
status: 'success',
},
gas: 0,
continuation: null,
metaData: null,
logs: 'wsATyGqckuIvlm89hhd2j4t6RMkCrcwJe_oeCYr7Th8',
}),
);
return res.once(ctx.status(200), ctx.json(localCommandResult));
}),
];

Expand All @@ -40,18 +27,7 @@ test('/listen should return result of tx queried', async () => {
listen: 'ATGCYPMNzdGcFh9Iik73KfMkgURIxaF91Ze4sHFsH8Q',
};

const commandResult1: ListenResponse = {
reqKey: 'pMohh9G2NT1jQn4byK1iwvoLopbnU86NeNPSUq8I0ik',
txId: null,
result: {
data: 3,
status: 'success',
},
gas: 0,
continuation: null,
metaData: null,
logs: 'wsATyGqckuIvlm89hhd2j4t6RMkCrcwJe_oeCYr7Th8',
};
const commandResult1: ListenResponse = localCommandResult;
const localReq: IListenRequestBody = requestKey;
const responseExpected: ListenResponse = commandResult1;
const responseActual: ICommandResult | Response = await listen(
Expand Down
49 changes: 5 additions & 44 deletions packages/libs/chainweb-node-client/src/tests/local.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,15 @@ import type {
} from '../interfaces/PactAPI';
import { local } from '../local';
import { pactTestCommand, testURL } from './mockdata/Pact';
import { localCommandResult } from './mockdata/execCommand';

const restHandlers = [
rest.post(`${testURL}/api/v1/local`, (req, res, ctx) => {
const isPreflight = req.url.searchParams.get('preflight') === 'true';
return res(
ctx.status(200),
ctx.json({
preflightResult: {
reqKey: 'pMohh9G2NT1jQn4byK1iwvoLopbnU86NeNPSUq8I0ik',
txId: null,
result: {
data: 3,
status: 'success',
},
gas: 0,
continuation: null,
metaData: null,
logs: 'wsATyGqckuIvlm89hhd2j4t6RMkCrcwJe_oeCYr7Th8',
},
preflightResult: localCommandResult,
...(isPreflight ? { preflightWarnings: [] } : {}),
}),
);
Expand Down Expand Up @@ -66,16 +56,7 @@ test('local should return preflight result of tx queried ', async () => {
const signedCommand1: ICommand = ensureSignedCommand(sampleCommand1);

const commandResult1: ILocalCommandResult = {
reqKey: 'pMohh9G2NT1jQn4byK1iwvoLopbnU86NeNPSUq8I0ik',
txId: null,
result: {
data: 3,
status: 'success',
},
gas: 0,
continuation: null,
metaData: null,
logs: 'wsATyGqckuIvlm89hhd2j4t6RMkCrcwJe_oeCYr7Th8',
...localCommandResult,
preflightWarnings: [],
};
const responseExpected: ILocalCommandResult = commandResult1;
Expand Down Expand Up @@ -107,18 +88,7 @@ test('local with `{preflight: false}` option returns non-preflight result', asyn
};
const signedCommand1: ICommand = ensureSignedCommand(sampleCommand1);

const commandResult1: ILocalCommandResult = {
reqKey: 'pMohh9G2NT1jQn4byK1iwvoLopbnU86NeNPSUq8I0ik',
txId: null,
result: {
data: 3,
status: 'success',
},
gas: 0,
continuation: null,
metaData: null,
logs: 'wsATyGqckuIvlm89hhd2j4t6RMkCrcwJe_oeCYr7Th8',
};
const commandResult1: ILocalCommandResult = localCommandResult;
const responseExpected: LocalResultWithoutPreflight = commandResult1;
const responseActual = await local(signedCommand1, testURL, {
preflight: false,
Expand All @@ -143,16 +113,7 @@ test('local with `{signatureVerification: false}` option returns preflight resul
};

const commandResult1: ILocalCommandResult = {
reqKey: 'pMohh9G2NT1jQn4byK1iwvoLopbnU86NeNPSUq8I0ik',
txId: null,
result: {
data: 3,
status: 'success',
},
gas: 0,
continuation: null,
metaData: null,
logs: 'wsATyGqckuIvlm89hhd2j4t6RMkCrcwJe_oeCYr7Th8',
...localCommandResult,
preflightWarnings: [],
};
const responseExpected = commandResult1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,74 +1,6 @@
// Test Case 1 - 01-system.yaml code from https://github.com/kadena-io/pact/blob/master/examples/accounts/scripts/01-system.yaml
import type {
EnvData,
ICommand,
ICommandPayload,
IKeyPair,
IMetaData,
Nonce,
PactCode,
SignatureWithHash,
} from '@kadena/types';

export const keyPair: IKeyPair = {
publicKey: 'ba54b224d1924dd98403f5c751abdd10de6cd81b0121800bf7bdbdcfaec7388d',
secretKey: '8693e641ae2bbe9ea802c736f42027b03f86afe63cae315e7169c9c496c17332',
};

export const keyPairs: Array<IKeyPair> = [keyPair];
export const nonce: Nonce = 'step01';

export const pactCode: PactCode =
'(define-keyset \'k (read-keyset "accounts-admin-keyset"))\n(module system \'k\n (defun get-system-time ()\n (time "2017-10-31T12:00:00Z")))\n(get-system-time)';

export const envData: EnvData = {
'accounts-admin-keyset': [
'ba54b224d1924dd98403f5c751abdd10de6cd81b0121800bf7bdbdcfaec7388d',
],
};

export const meta: IMetaData = {
creationTime: 0,
ttl: 0,
gasLimit: 0,
chainId: '0',
gasPrice: 0,
sender: '',
};

export const payload: ICommandPayload = {
networkId: null,
payload: {
exec: {
data: envData,
code: pactCode,
},
},
signers: [
{
pubKey:
'ba54b224d1924dd98403f5c751abdd10de6cd81b0121800bf7bdbdcfaec7388d',
},
],
meta: {
creationTime: 0,
ttl: 0,
gasLimit: 0,
chainId: '0',
gasPrice: 0,
sender: '',
},
nonce: JSON.stringify(nonce),
};

export const signature: SignatureWithHash = {
hash: 'pMohh9G2NT1jQn4byK1iwvoLopbnU86NeNPSUq8I0ik',
pubKey: 'ba54b224d1924dd98403f5c751abdd10de6cd81b0121800bf7bdbdcfaec7388d',
sig: '26d765e3b812d59d80ffbd034d4fc4a1a24f8d0c3929586575617089e5098d967955d348608b515ae9ff7871b46726ffc71252d53b9e562d5bcf3bfe66292906',
};

export const stringifiedPayload: string =
'{"networkId":null,"payload":{"exec":{"data":{"accounts-admin-keyset":["ba54b224d1924dd98403f5c751abdd10de6cd81b0121800bf7bdbdcfaec7388d"]},"code":"(define-keyset \'k (read-keyset \\"accounts-admin-keyset\\"))\\n(module system \'k\\n (defun get-system-time ()\\n (time \\"2017-10-31T12:00:00Z\\")))\\n(get-system-time)"}},"signers":[{"pubKey":"ba54b224d1924dd98403f5c751abdd10de6cd81b0121800bf7bdbdcfaec7388d"}],"meta":{"creationTime":0,"ttl":0,"gasLimit":0,"chainId":"0","gasPrice":0,"sender":""},"nonce":"\\"step01\\""}';
import type { ICommand } from '@kadena/types';
import type { ILocalCommandResult } from '../../interfaces/PactAPI';

export const command: ICommand = {
hash: 'pMohh9G2NT1jQn4byK1iwvoLopbnU86NeNPSUq8I0ik',
Expand All @@ -79,3 +11,16 @@ export const command: ICommand = {
],
cmd: '{"networkId":null,"payload":{"exec":{"data":{"accounts-admin-keyset":["ba54b224d1924dd98403f5c751abdd10de6cd81b0121800bf7bdbdcfaec7388d"]},"code":"(define-keyset \'k (read-keyset \\"accounts-admin-keyset\\"))\\n(module system \'k\\n (defun get-system-time ()\\n (time \\"2017-10-31T12:00:00Z\\")))\\n(get-system-time)"}},"signers":[{"pubKey":"ba54b224d1924dd98403f5c751abdd10de6cd81b0121800bf7bdbdcfaec7388d"}],"meta":{"creationTime":0,"ttl":0,"gasLimit":0,"chainId":"0","gasPrice":0,"sender":""},"nonce":"\\"step01\\""}',
};

export const localCommandResult: ILocalCommandResult = {
reqKey: 'pMohh9G2NT1jQn4byK1iwvoLopbnU86NeNPSUq8I0ik',
txId: null,
result: {
data: 3,
status: 'success',
},
gas: 0,
continuation: null,
metaData: null,
logs: 'wsATyGqckuIvlm89hhd2j4t6RMkCrcwJe_oeCYr7Th8',
};
27 changes: 3 additions & 24 deletions packages/libs/chainweb-node-client/src/tests/poll.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,14 @@ import { setupServer } from 'msw/node';
import type { IPollRequestBody, IPollResponse } from '../interfaces/PactAPI';
import { poll } from '../poll';
import { testURL } from './mockdata/Pact';
import { localCommandResult } from './mockdata/execCommand';

const restHandlers = [
rest.post(`${testURL}/api/v1/poll`, (req, res, ctx) => {
return res.once(
ctx.status(200),
ctx.json({
pMohh9G2NT1jQn4byK1iwvoLopbnU86NeNPSUq8I0ik: {
reqKey: 'pMohh9G2NT1jQn4byK1iwvoLopbnU86NeNPSUq8I0ik',
txId: null,
result: {
data: 3,
status: 'success',
},
gas: 0,
continuation: null,
metaData: null,
logs: 'wsATyGqckuIvlm89hhd2j4t6RMkCrcwJe_oeCYr7Th8',
},
pMohh9G2NT1jQn4byK1iwvoLopbnU86NeNPSUq8I0ik: localCommandResult,
}),
);
}),
Expand All @@ -39,18 +29,7 @@ test('/poll should return request keys of txs submitted', async () => {
};

const commandResult: IPollResponse = {
pMohh9G2NT1jQn4byK1iwvoLopbnU86NeNPSUq8I0ik: {
reqKey: 'pMohh9G2NT1jQn4byK1iwvoLopbnU86NeNPSUq8I0ik',
txId: null,
result: {
data: 3,
status: 'success',
},
gas: 0,
continuation: null,
metaData: null,
logs: 'wsATyGqckuIvlm89hhd2j4t6RMkCrcwJe_oeCYr7Th8',
},
pMohh9G2NT1jQn4byK1iwvoLopbnU86NeNPSUq8I0ik: localCommandResult,
};
const localReq: IPollRequestBody = signedCommand;
const responseExpected: IPollResponse = commandResult;
Expand Down
1 change: 0 additions & 1 deletion packages/libs/chainwebjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"base64url": "^3.0.1",
"cross-fetch": "~3.1.5",
"eventsource": "~2.0.2",
"node-fetch": "~2.6.2",
"p-retry": "^4.5.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/libs/chainwebjs/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export async function parseResponse<T>(response: Response): Promise<T> {
*
* @alpha
*/
export function base64json(txt: string): string {
function base64json(txt: string): string {
return JSON.parse(base64url.decode(txt));
}

Expand Down
Loading

0 comments on commit 2a0e92c

Please sign in to comment.