-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
328 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testTimeout: 15_000, | ||
testTimeout: 30_000, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { EventBus } from '../src/client/event/event-bus'; | ||
import { describe, expect, test } from '@jest/globals'; | ||
|
||
interface EventObject { | ||
a: number; | ||
b: string; | ||
c: bigint; | ||
} | ||
|
||
describe('event bus', () => { | ||
test('pub/sub works', async () => { | ||
const eventBus = EventBus.getInstance(); | ||
const eventName = 'some_event'; | ||
const eventObject: EventObject = { | ||
a: 1, | ||
b: 'two', | ||
c: 3n, | ||
}; | ||
let eventReceived = false; | ||
eventBus.register(eventName, (receivedEventObject: EventObject) => { | ||
eventReceived = eventObject == receivedEventObject; | ||
}); | ||
eventBus.dispatch(eventName, eventObject); | ||
await new Promise((resolve) => setTimeout(resolve, 500)); | ||
expect(eventReceived).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Kusama } from '../src/client/model/substrate/network'; | ||
import { formatNumber } from '../src/client/util/format'; | ||
import { describe, expect, test } from '@jest/globals'; | ||
|
||
describe('format', () => { | ||
test('number formatting works with ticker', async () => { | ||
const formatted = formatNumber(123456789n, 5, 2, Kusama.tokenTicker); | ||
expect(formatted).toBe('1,234.56 KSM'); | ||
}); | ||
test('number formatting works without ticker', async () => { | ||
const formatted = formatNumber(123456789n, 5, 2); | ||
expect(formatted).toBe('1,234.56'); | ||
}); | ||
test('number formatting works with no format decimals', async () => { | ||
const formatted = formatNumber(123456789n, 5, 0); | ||
expect(formatted).toBe('1,234'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { describe, expect, test } from '@jest/globals'; | ||
import { generateIdenticonSVGHTML } from '../src/client/util/identicon'; | ||
|
||
describe('identicon', () => { | ||
test('generates correct identicon', async () => { | ||
const expectedSVG = `<svg style="width; 25; height: 25;" viewBox='0 0 64 64'><circle cx=32 cy=32 fill="#eee" r=32 /><circle cx=32 cy=8 fill="hsl(196, 62%, 53%)" r=5 /><circle cx=32 cy=20 fill="hsl(191, 62%, 53%)" r=5 /><circle cx=21.607695154586736 cy=14 fill="hsl(219, 62%, 35%)" r=5 /><circle cx=11.215390309173472 cy=20 fill="hsl(33, 62%, 15%)" r=5 /><circle cx=21.607695154586736 cy=26 fill="hsl(118, 62%, 15%)" r=5 /><circle cx=11.215390309173472 cy=32 fill="hsl(157, 62%, 53%)" r=5 /><circle cx=11.215390309173472 cy=44 fill="hsl(202, 62%, 35%)" r=5 /><circle cx=21.607695154586736 cy=38 fill="hsl(191, 62%, 53%)" r=5 /><circle cx=21.607695154586736 cy=50 fill="hsl(67, 62%, 35%)" r=5 /><circle cx=32 cy=56 fill="hsl(50, 62%, 15%)" r=5 /><circle cx=32 cy=44 fill="hsl(129, 62%, 75%)" r=5 /><circle cx=42.392304845413264 cy=50 fill="hsl(67, 62%, 35%)" r=5 /><circle cx=52.78460969082653 cy=44 fill="hsl(202, 62%, 35%)" r=5 /><circle cx=42.392304845413264 cy=38 fill="hsl(191, 62%, 53%)" r=5 /><circle cx=52.78460969082653 cy=32 fill="hsl(157, 62%, 53%)" r=5 /><circle cx=52.78460969082653 cy=20 fill="hsl(33, 62%, 15%)" r=5 /><circle cx=42.392304845413264 cy=26 fill="hsl(118, 62%, 15%)" r=5 /><circle cx=42.392304845413264 cy=14 fill="hsl(219, 62%, 35%)" r=5 /><circle cx=32 cy=32 fill="hsl(95, 62%, 75%)" r=5 /></svg>`; | ||
const generatedSVG = generateIdenticonSVGHTML( | ||
'21vLqCuvXweuKw9nw6qfAQnFkmBnxLWA3RU5cMBGuzsdEJ4A', | ||
25, | ||
); | ||
expect(generatedSVG).toBe(expectedSVG); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { describe, expect, test } from '@jest/globals'; | ||
import { cloneJSONSafeObject } from '../src/client/util/object'; | ||
import { validators } from './data/validators'; | ||
|
||
// prettier-ignore | ||
(BigInt.prototype as any).toJSON = function () { // eslint-disable-line @typescript-eslint/no-explicit-any | ||
return this.toString(); | ||
}; | ||
|
||
describe('object', () => { | ||
test('clone object works', async () => { | ||
const cloneValidator1 = cloneJSONSafeObject(validators[0]); | ||
expect(JSON.stringify(cloneValidator1)).toEqual(JSON.stringify(validators[0])); | ||
}); | ||
test('clone array works', async () => { | ||
const cloneValidators = cloneJSONSafeObject(validators); | ||
expect(JSON.stringify(cloneValidators)).toEqual(JSON.stringify(validators)); | ||
}); | ||
}); |
Oops, something went wrong.