Skip to content

Commit

Permalink
Merge pull request #112 from polkadot-cloud/rb-init-tests
Browse files Browse the repository at this point in the history
feat: init tests
  • Loading branch information
Ross Bulat authored Jun 10, 2024
2 parents 82881dc + ddfa525 commit b9397c2
Show file tree
Hide file tree
Showing 8 changed files with 497 additions and 172 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ jobs:
cache: 'yarn'
node-version: ${{ matrix.node-version }}
- run: yarn install
- run: yarn test
- run: yarn build
- run: yarn lint
5 changes: 5 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://json.schemastore.org/mocharc.json",
"require": "tsx",
"spec": "test/**/*.spec.ts"
}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build": "tsc && vite build",
"clear": "rm -rf node_modules build tsconfig.tsbuildinfo yarn.lock",
"lint": "eslint . --fix && npx prettier --write .",
"test": "mocha",
"test:storage": "tsup src/test/storageQueries.ts && node dist/storageQueries.cjs",
"preview": "vite preview"
},
Expand Down Expand Up @@ -51,6 +52,7 @@
"usehooks-ts": "^3.1.0"
},
"devDependencies": {
"@types/mocha": "^10.0.6",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
"@types/styled-components": "^5.1.34",
Expand All @@ -70,10 +72,12 @@
"eslint-plugin-react-refresh": "^0.4.6",
"eslint-plugin-unused-imports": "^3.1.0",
"gh-pages": "^6.1.1",
"mocha": "^10.4.0",
"prettier": "^3.2.5",
"prettier-plugin-organize-imports": "^3.2.4",
"sass": "^1.77.3",
"tsup": "^8.0.2",
"tsx": "^4.15.1",
"typescript": "^5.2.2",
"vite": "^5.2.10",
"vite-plugin-checker": "^0.6.4",
Expand Down
22 changes: 0 additions & 22 deletions src/test/base58check.ts

This file was deleted.

File renamed without changes.
33 changes: 33 additions & 0 deletions test/base58.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2024 @polkadot-cloud/polkadot-developer-console authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import assert from 'assert';
import { u8aToHex, u8aToNumber } from '@polkadot/util';
import { base58Decode, base58Encode } from '@polkadot/util-crypto';

// Test decoding and encoding of an account. Extracts the SS58 Prefix and public key, before
// encoding back to the correct address.

describe('Encoding ', () => {
it('encoding and decoding should work correctly.', () => {
const encoded = '1hYiMW8KSfUYChzCQSPGXvMSyKVqmyvMXqohjKr3oU5PCXF';

const decoded = base58Decode(encoded);
const decodedHex = u8aToHex(decoded);
const ss58 = u8aToNumber(decoded.subarray(0, 1));
const publicKey = u8aToHex(decoded.subarray(2));
const encodedKey = base58Encode(decoded);

assert.equal(
decodedHex,
'0x001eec92559de5be4295be18caa79400d49466b8b06a4c819e766a7b79ad3b846d9476'
);
assert.equal(ss58, '0');
assert.equal(
publicKey,
'0xec92559de5be4295be18caa79400d49466b8b06a4c819e766a7b79ad3b846d9476'
);

assert.equal(encodedKey, encoded);
});
});
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
"include": [
"src",
"test",
],
"references": [{ "path": "./tsconfig.node.json" }]
}
Loading

0 comments on commit b9397c2

Please sign in to comment.