Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(types)!: camelCase enum serialization; Bump polkadot/api@v4 w. ESM #467

Merged
merged 3 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
"plugins": ["@babel/plugin-transform-modules-commonjs"]
}
5 changes: 3 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
preset: 'ts-jest',
testPathIgnorePatterns: ['/build/', '/node_modules/', '/docs/']
preset: 'ts-jest/presets/js-with-babel',
transformIgnorePatterns: ['<rootDir>/node_modules/(?!@polkadot|@babel/runtime/helpers/esm/)'],
testPathIgnorePatterns: ['/build/', '/node_modules/', '/docs/'],
};
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
"test": "jest --silent"
},
"dependencies": {
"@polkadot/api": "^3.11.1",
"@polkadot/api": "^4.0.3",
"@polkadot/apps-config": "^0.83.1",
"@polkadot/util-crypto": "^5.9.2",
"@polkadot/util-crypto": "^6.0.5",
"@substrate/calc": "^0.2.0",
"confmgr": "^1.0.6",
"express": "^4.17.1",
Expand All @@ -47,14 +47,15 @@
"winston": "^3.3.3"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.13.8",
"@types/express": "^4.17.11",
"@types/express-serve-static-core": "^4.17.18",
"@types/http-errors": "^1.6.3",
"@types/jest": "^26.0.20",
"@types/morgan": "^1.9.2",
"@types/triple-beam": "^1.3.2",
"@typescript-eslint/eslint-plugin": "4.16.1",
"@typescript-eslint/parser": "4.16.1",
"@typescript-eslint/eslint-plugin": "4.17.0",
"@typescript-eslint/parser": "4.17.0",
"eslint": "^7.21.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
Expand All @@ -63,9 +64,9 @@
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"standard-version": "^9.1.1",
"ts-jest": "^26.5.1",
"ts-jest": "^26.5.3",
"tsc-watch": "^4.2.9",
"typescript": "4.1.4"
"typescript": "4.2.3"
},
"resolutions": {
"node-forge": ">=0.10.0",
Expand Down
30 changes: 15 additions & 15 deletions src/sanitize/sanitizeNumbers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ describe('sanitizeNumbers', () => {
'0x0102030405060708091011121314151617181920212223242526272829303132',
});
expect(sanitizeNumbers(data)).toStrictEqual({
Keccak256:
keccak256:
'0x0102030405060708091011121314151617181920212223242526272829303132',
});
});
Expand Down Expand Up @@ -570,8 +570,8 @@ describe('sanitizeNumbers', () => {
);

expect(sanitizeNumbers(test)).toStrictEqual({
B: {
D: MAX_U64,
b: {
d: MAX_U64,
},
});
});
Expand Down Expand Up @@ -641,7 +641,7 @@ describe('sanitizeNumbers', () => {
// });
it('handles Ok()', () => {
const ok = kusamaRegistry.createType('DispatchResult');
expect(sanitizeNumbers(ok)).toStrictEqual({ Ok: [] });
expect(sanitizeNumbers(ok)).toStrictEqual({ ok: [] });
});

// it('converts Error(u128)', () => {
Expand All @@ -655,7 +655,7 @@ describe('sanitizeNumbers', () => {
Err: maxU128,
});
expect(sanitizeNumbers(error)).toStrictEqual({
Err: MAX_U128,
err: MAX_U128,
});
});

Expand All @@ -667,10 +667,10 @@ describe('sanitizeNumbers', () => {
// });
it('handles Error(Text)', () => {
const error = new ResultConstructor(kusamaRegistry, {
Err: message,
err: message,
});
expect(sanitizeNumbers(error)).toStrictEqual({
Err: message.toString(),
err: message.toString(),
});
});

Expand All @@ -686,7 +686,7 @@ describe('sanitizeNumbers', () => {
ok: maxU128,
});

expect(sanitizeNumbers(ok)).toStrictEqual({ Ok: MAX_U128 });
expect(sanitizeNumbers(ok)).toStrictEqual({ ok: MAX_U128 });
});

// it('handles Ok(Text)', () => {
Expand All @@ -699,10 +699,10 @@ describe('sanitizeNumbers', () => {
it('handles Ok(Text)', () => {
const R = Result.with({ Err: 'Text', Ok: 'Text' });
const ok = new R(kusamaRegistry, {
Ok: message,
ok: message,
});
expect(sanitizeNumbers(ok)).toStrictEqual({
Ok: message.toString(),
ok: message.toString(),
});
});
});
Expand Down Expand Up @@ -924,12 +924,12 @@ describe('sanitizeNumbers', () => {
],
index: '0x0000',
},
phase: { ApplyExtrinsic: '0' },
phase: { applyExtrinsic: '0' },
topics: [],
},
{
event: { data: null, index: '0x0000' },
phase: { ApplyExtrinsic: '0' },
phase: { applyExtrinsic: '0' },
topics: [],
},
]);
Expand All @@ -951,7 +951,7 @@ describe('sanitizeNumbers', () => {
'0x6502'
);
expect(sanitizeNumbers(extrinsicEra)).toStrictEqual({
MortalEra: ['64', '38'],
mortalEra: ['64', '38'],
});
});

Expand Down Expand Up @@ -1170,10 +1170,10 @@ describe('sanitizeNumbers', () => {
const open = kusamaRegistry.createType('ElectionStatus', {
open: 420420,
});
expect(sanitizeNumbers(open)).toStrictEqual({ Open: '420420' });
expect(sanitizeNumbers(open)).toStrictEqual({ open: '420420' });

const close = kusamaRegistry.createType('ElectionStatus', 'close');
expect(sanitizeNumbers(close)).toStrictEqual({ Close: null });
expect(sanitizeNumbers(close)).toStrictEqual({ close: null });
});
});

Expand Down
8 changes: 6 additions & 2 deletions src/sanitize/sanitizeNumbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AbstractArray } from '@polkadot/types/codec/AbstractArray';
import { AbstractInt } from '@polkadot/types/codec/AbstractInt';
import { Json } from '@polkadot/types/codec/Json';
import { CodecMap } from '@polkadot/types/codec/Map';
import { isObject } from '@polkadot/util';
import { isObject, stringCamelCase } from '@polkadot/util';
import * as BN from 'bn.js';
import { InternalServerError } from 'http-errors';

Expand Down Expand Up @@ -68,7 +68,11 @@ function sanitizeCodec(value: Codec): AnyJson {
return value.toJSON();
}

return { [value.type]: sanitizeNumbers(value.value) };
return {
// Replicating camelCaseing introduced in https://github.com/polkadot-js/api/pull/3024
// Specifically see: https://github.com/polkadot-js/api/blob/516fbd4a90652841d4e81636e74ca472e2dc5621/packages/types/src/codec/Enum.ts#L346
[stringCamelCase(value.type)]: sanitizeNumbers(value.value),
};
}

if (value instanceof BTreeSet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"height": "789629"
},
"controller": "1zugcapKRuHy2C1PceJxTvXWiq6FHEDm2xa5XSU7KYP3rJE",
"rewardDestination": "Controller",
"rewardDestination": {
"controller": null
},
"numSlashingSpans": "0",
"staking": {
"stash": "1zugcapKRuHy2C1PceJxTvXWiq6FHEDm2xa5XSU7KYP3rJE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@
},
"data": [
{
"Ok": []
"ok": []
}
],
"docs": " A proxy was executed correctly, with the given [result]."
Expand Down
2 changes: 1 addition & 1 deletion src/services/test-helpers/responses/node/network.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"nodeRoles": [
{
"Full": null
"full": null
}
],
"isSyncing": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"name": "PublicPropCount",
"modifier": "Default",
"type": {
"Plain": "PropIndex"
"plain": "PropIndex"
},
"fallback": "0x00000000",
"documentation": " The number of (public) proposals that have been made so far."
Expand All @@ -19,7 +19,7 @@
"name": "PublicProps",
"modifier": "Default",
"type": {
"Plain": "Vec<(PropIndex,Hash,AccountId)>"
"plain": "Vec<(PropIndex,Hash,AccountId)>"
},
"fallback": "0x00",
"documentation": " The public proposals. Unsorted. The second item is the proposal's hash."
Expand All @@ -28,7 +28,7 @@
"name": "DepositOf",
"modifier": "Optional",
"type": {
"Map": {
"map": {
"hasher": "Twox64Concat",
"key": "PropIndex",
"value": "(Vec<AccountId>,BalanceOf)",
Expand All @@ -42,7 +42,7 @@
"name": "Preimages",
"modifier": "Optional",
"type": {
"Map": {
"map": {
"hasher": "Identity",
"key": "Hash",
"value": "PreimageStatus",
Expand All @@ -56,7 +56,7 @@
"name": "ReferendumCount",
"modifier": "Default",
"type": {
"Plain": "ReferendumIndex"
"plain": "ReferendumIndex"
},
"fallback": "0x00000000",
"documentation": " The next free referendum index, aka the number of referenda started so far."
Expand All @@ -65,7 +65,7 @@
"name": "LowestUnbaked",
"modifier": "Default",
"type": {
"Plain": "ReferendumIndex"
"plain": "ReferendumIndex"
},
"fallback": "0x00000000",
"documentation": " The lowest referendum index representing an unbaked referendum. Equal to\n `ReferendumCount` if there isn't a unbaked referendum."
Expand All @@ -74,7 +74,7 @@
"name": "ReferendumInfoOf",
"modifier": "Optional",
"type": {
"Map": {
"map": {
"hasher": "Twox64Concat",
"key": "ReferendumIndex",
"value": "ReferendumInfo",
Expand All @@ -88,7 +88,7 @@
"name": "VotingOf",
"modifier": "Default",
"type": {
"Map": {
"map": {
"hasher": "Twox64Concat",
"key": "AccountId",
"value": "Voting",
Expand All @@ -102,7 +102,7 @@
"name": "Locks",
"modifier": "Optional",
"type": {
"Map": {
"map": {
"hasher": "Twox64Concat",
"key": "AccountId",
"value": "BlockNumber",
Expand All @@ -116,7 +116,7 @@
"name": "LastTabledWasExternal",
"modifier": "Default",
"type": {
"Plain": "bool"
"plain": "bool"
},
"fallback": "0x00",
"documentation": " True if the last referendum tabled was submitted externally. False if it was a public\n proposal."
Expand All @@ -125,7 +125,7 @@
"name": "NextExternal",
"modifier": "Optional",
"type": {
"Plain": "(Hash,VoteThreshold)"
"plain": "(Hash,VoteThreshold)"
},
"fallback": "0x00",
"documentation": " The referendum to be tabled whenever it would be valid to table an external proposal.\n This happens when a referendum needs to be tabled and one of two conditions are met:\n - `LastTabledWasExternal` is `false`; or\n - `PublicProps` is empty."
Expand All @@ -134,7 +134,7 @@
"name": "Blacklist",
"modifier": "Optional",
"type": {
"Map": {
"map": {
"hasher": "Identity",
"key": "Hash",
"value": "(BlockNumber,Vec<AccountId>)",
Expand All @@ -148,7 +148,7 @@
"name": "Cancellations",
"modifier": "Default",
"type": {
"Map": {
"map": {
"hasher": "Identity",
"key": "Hash",
"value": "bool",
Expand All @@ -162,7 +162,7 @@
"name": "StorageVersion",
"modifier": "Optional",
"type": {
"Plain": "Releases"
"plain": "Releases"
},
"fallback": "0x00",
"documentation": " Storage version of the pallet.\n\n New networks start with last version."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"name": "ReferendumInfoOf",
"modifier": "Optional",
"type": {
"Map": {
"map": {
"hasher": "Twox64Concat",
"key": "ReferendumIndex",
"value": "ReferendumInfo",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"nextActiveEraEstimate": "803868",
"electionStatus": {
"status": {
"Close": null
"close": null
},
"toggleEstimate": "801318"
},
Expand Down
Loading