Align Data.Raw decoding with Substrate (32-bytes) (#3573)
* Align Data.Raw decoding with Substrate (32-bytes) * CHANGELOG * Encoding test updates * provider.disconnect * Adjust provider tests * Unique connection URLs * Dangling tests * detectOpenHandles * Additional * Remove rx test (catered for by Promise wrap) * Additional cleanups to tests
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
# CHANGELOG
|
||||
|
||||
## master
|
||||
|
||||
Changes:
|
||||
|
||||
- Align identity `Data` to limit to 32 bytes in the `Raw` enum (as per Substrate)
|
||||
- Cleanup internal tests (no dangling handles, cater for Jest 27)
|
||||
|
||||
|
||||
## 4.11.2 May 24, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended where users are having TS mismatches with type definitions created on older versions.
|
||||
|
||||
+3
-3
@@ -20,15 +20,15 @@
|
||||
"lint": "polkadot-dev-run-lint",
|
||||
"clean": "polkadot-dev-clean-build",
|
||||
"postinstall": "polkadot-dev-yarn-only",
|
||||
"test": "polkadot-dev-run-test --coverage --runInBand --testPathIgnorePatterns e2e",
|
||||
"test:one": "polkadot-dev-run-test",
|
||||
"test": "polkadot-dev-run-test --coverage --detectOpenHandles --runInBand --testPathIgnorePatterns e2e",
|
||||
"test:one": "polkadot-dev-run-test --detectOpenHandles",
|
||||
"test:watch": "polkadot-dev-run-test --watch"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.14.3",
|
||||
"@babel/register": "^7.13.16",
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/dev": "^0.62.16",
|
||||
"@polkadot/dev": "^0.62.17",
|
||||
"@polkadot/ts": "^0.3.66",
|
||||
"@polkadot/typegen": "workspace:packages/typegen",
|
||||
"@types/jest": "^26.0.23",
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/api": "4.11.3-0",
|
||||
"@polkadot/types": "4.11.3-0",
|
||||
"@polkadot/util": "^6.5.1",
|
||||
"@polkadot/x-rxjs": "^6.5.1",
|
||||
"@polkadot/util": "^6.5.2-1",
|
||||
"@polkadot/x-rxjs": "^6.5.2-1",
|
||||
"bn.js": "^4.11.9"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,13 +23,13 @@
|
||||
"@polkadot/api": "4.11.3-0",
|
||||
"@polkadot/rpc-core": "4.11.3-0",
|
||||
"@polkadot/types": "4.11.3-0",
|
||||
"@polkadot/util": "^6.5.1",
|
||||
"@polkadot/util-crypto": "^6.5.1",
|
||||
"@polkadot/x-rxjs": "^6.5.1",
|
||||
"@polkadot/util": "^6.5.2-1",
|
||||
"@polkadot/util-crypto": "^6.5.2-1",
|
||||
"@polkadot/x-rxjs": "^6.5.2-1",
|
||||
"bn.js": "^4.11.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^6.5.1",
|
||||
"@polkadot/keyring": "^6.5.2-1",
|
||||
"@polkadot/rpc-provider": "4.11.3-0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,10 @@ describe('derive', (): void => {
|
||||
api.isReady.subscribe(() => done());
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await api.disconnect();
|
||||
});
|
||||
|
||||
testFunction(api)('accounts', 'idAndIndex', []);
|
||||
testFunction(api)('accounts', 'idToIndex', []);
|
||||
testFunction(api)('accounts', 'indexes', []);
|
||||
@@ -80,7 +84,11 @@ describe('derive', (): void => {
|
||||
});
|
||||
|
||||
beforeAll((done): void => {
|
||||
api.isReady.subscribe((): void => done());
|
||||
api.isReady.subscribe(() => done());
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await api.disconnect();
|
||||
});
|
||||
|
||||
// override
|
||||
|
||||
@@ -21,15 +21,15 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/api-derive": "4.11.3-0",
|
||||
"@polkadot/keyring": "^6.5.1",
|
||||
"@polkadot/keyring": "^6.5.2-1",
|
||||
"@polkadot/metadata": "4.11.3-0",
|
||||
"@polkadot/rpc-core": "4.11.3-0",
|
||||
"@polkadot/rpc-provider": "4.11.3-0",
|
||||
"@polkadot/types": "4.11.3-0",
|
||||
"@polkadot/types-known": "4.11.3-0",
|
||||
"@polkadot/util": "^6.5.1",
|
||||
"@polkadot/util-crypto": "^6.5.1",
|
||||
"@polkadot/x-rxjs": "^6.5.1",
|
||||
"@polkadot/util": "^6.5.2-1",
|
||||
"@polkadot/util-crypto": "^6.5.2-1",
|
||||
"@polkadot/x-rxjs": "^6.5.2-1",
|
||||
"bn.js": "^4.11.9",
|
||||
"eventemitter3": "^4.0.7"
|
||||
}
|
||||
|
||||
@@ -349,13 +349,12 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
||||
}
|
||||
|
||||
this.#healthTimer = setInterval((): void => {
|
||||
this._rpcCore.system.health().toPromise().catch((error) => l.warn(`Health keepalive check failed: ${(error as Error).message}`));
|
||||
this._rpcCore.system.health().toPromise().catch(() => undefined);
|
||||
}, KEEPALIVE_INTERVAL);
|
||||
} catch (_error) {
|
||||
const error = new Error(`FATAL: Unable to initialize the API: ${(_error as Error).message}`);
|
||||
|
||||
l.error(error);
|
||||
l.error(_error);
|
||||
|
||||
this.emit('error', error);
|
||||
}
|
||||
|
||||
@@ -48,6 +48,10 @@ describe('ApiPromise', (): void => {
|
||||
provider = new MockProvider(registry);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await provider.disconnect();
|
||||
});
|
||||
|
||||
describe('initialization', (): void => {
|
||||
it('Create API instance with metadata map and makes the runtime, rpc, state & extrinsics available', async (): Promise<void> => {
|
||||
const rpcData = await provider.send<string>('state_getMetadata', []);
|
||||
@@ -62,6 +66,8 @@ describe('ApiPromise', (): void => {
|
||||
expect(api.query).toBeDefined();
|
||||
expect(api.tx).toBeDefined();
|
||||
expect(api.derive).toBeDefined();
|
||||
|
||||
await api.disconnect();
|
||||
});
|
||||
|
||||
it('Create API instance without metadata and makes the runtime, rpc, state & extrinsics available', async (): Promise<void> => {
|
||||
@@ -75,6 +81,8 @@ describe('ApiPromise', (): void => {
|
||||
expect(api.query).toBeDefined();
|
||||
expect(api.tx).toBeDefined();
|
||||
expect(api.derive).toBeDefined();
|
||||
|
||||
await api.disconnect();
|
||||
});
|
||||
|
||||
it('Create API instance will error on failure to await ready', async (): Promise<void> => {
|
||||
@@ -88,12 +96,17 @@ describe('ApiPromise', (): void => {
|
||||
}
|
||||
}
|
||||
|
||||
const api = new ErrorApiPromise();
|
||||
|
||||
try {
|
||||
await new ErrorApiPromise().isReadyOrError;
|
||||
await api.isReadyOrError;
|
||||
|
||||
fail('Expected an error but none occurred.');
|
||||
} catch {
|
||||
// Pass
|
||||
}
|
||||
|
||||
await api.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -103,31 +116,35 @@ describe('ApiPromise', (): void => {
|
||||
const SIG = '0x659effefbbe5ab4d7136ebb5084b959eb424e32b862307371be4721ac2c46334245af4f1476c36c5e5aff04396c2fdd2ce561ec90382821d4aa071b559b1db0f';
|
||||
|
||||
it('signs data using a specified keyring', async (): Promise<void> => {
|
||||
const api = new ApiPromise({ provider, registry });
|
||||
const api = await ApiPromise.create({ provider, registry });
|
||||
const sig = await api.sign(aliceEd, TEST);
|
||||
|
||||
expect(
|
||||
await api.sign(aliceEd, TEST)
|
||||
).toEqual(SIG);
|
||||
expect(sig).toEqual(SIG);
|
||||
|
||||
await api.disconnect();
|
||||
});
|
||||
|
||||
it('signs data using an external signer', async (): Promise<void> => {
|
||||
const api = new ApiPromise({
|
||||
const api = await ApiPromise.create({
|
||||
provider,
|
||||
registry,
|
||||
signer: new SingleAccountSigner(registry, aliceEd)
|
||||
});
|
||||
const sig = await api.sign(ADDR, TEST);
|
||||
|
||||
expect(
|
||||
await api.sign(ADDR, TEST)
|
||||
).toEqual(SIG);
|
||||
expect(sig).toEqual(SIG);
|
||||
|
||||
await api.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe('decorator.signAsync', (): void => {
|
||||
it('signs a transfer using an external signer', async (): Promise<void> => {
|
||||
const { transfer } = await createTransfer();
|
||||
const { api, transfer } = await createTransfer();
|
||||
|
||||
expect(transfer.signature.toHex()).toEqual(TRANSFER_SIG);
|
||||
|
||||
await api.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -137,6 +154,8 @@ describe('ApiPromise', (): void => {
|
||||
|
||||
expect(api.tx(transfer.toHex()).signature.toHex()).toEqual(TRANSFER_SIG);
|
||||
expect(api.tx(transfer).signature.toHex()).toEqual(TRANSFER_SIG);
|
||||
|
||||
await api.disconnect();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
import type { SubmittableExtrinsic } from '../submittable/types';
|
||||
|
||||
import { createTestPairs } from '@polkadot/keyring/testingPairs';
|
||||
import { MockProvider } from '@polkadot/rpc-provider/mock';
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
import { map, switchMap } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { SingleAccountSigner } from '../../test/util';
|
||||
import { ApiRx } from '.';
|
||||
|
||||
describe('ApiRx', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
const keyring = createTestPairs({ type: 'ed25519' });
|
||||
let provider: MockProvider;
|
||||
|
||||
beforeEach((): void => {
|
||||
jest.setTimeout(3000000);
|
||||
provider = new MockProvider(registry);
|
||||
});
|
||||
|
||||
describe('decorator.signAsync', (): void => {
|
||||
it('signs a transfer using an external signer', (): void => {
|
||||
const signer = new SingleAccountSigner(registry, keyring.alice_session);
|
||||
|
||||
ApiRx.create({ provider, registry, signer }).pipe(
|
||||
switchMap((api: ApiRx): Observable<SubmittableExtrinsic<'rxjs'>> =>
|
||||
api.tx.balances
|
||||
.transfer(keyring.eve.address, 12345)
|
||||
.signAsync(keyring.alice_session, {})
|
||||
),
|
||||
map((tx: SubmittableExtrinsic<'rxjs'>): void => {
|
||||
expect(tx.signature.toHex()).toEqual(
|
||||
'0x97f3cfe5088fcd575313e983f45d02b0f630e7b94ff9a3ac50e20cd096a8f554fda73d42ead891b5a1d3ce5607d83f20b0c6570b555e949cfb5763d0abcd590b'
|
||||
);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('allows the second argument to signAsync to be omitted', () => {
|
||||
const signer = new SingleAccountSigner(registry, keyring.alice_session);
|
||||
|
||||
ApiRx.create({ provider, registry, signer }).pipe(
|
||||
switchMap((api: ApiRx): Observable<SubmittableExtrinsic<'rxjs'>> =>
|
||||
api.tx.balances
|
||||
.transfer(keyring.eve.address, 12345)
|
||||
.signAsync(keyring.alice_session)
|
||||
),
|
||||
map((tx: SubmittableExtrinsic<'rxjs'>): void => {
|
||||
expect(tx.signature.toHex()).toEqual(
|
||||
'0x97f3cfe5088fcd575313e983f45d02b0f630e7b94ff9a3ac50e20cd096a8f554fda73d42ead891b5a1d3ce5607d83f20b0c6570b555e949cfb5763d0abcd590b'
|
||||
);
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -24,6 +24,8 @@ describe('misc quick tests', (): void => {
|
||||
console.error(JSON.stringify(
|
||||
await api.query.system.account('HUewJvzVuEeyaxH2vx9XiyAPKrpu1Zj5r5Pi9VrGiBVty7q')
|
||||
));
|
||||
|
||||
await api.disconnect();
|
||||
});
|
||||
|
||||
it.skip('handles map keys', async (): Promise<void> => {
|
||||
@@ -36,6 +38,8 @@ describe('misc quick tests', (): void => {
|
||||
console.error('# keys', keys.length);
|
||||
|
||||
console.timeEnd('map.keys');
|
||||
|
||||
await api.disconnect();
|
||||
});
|
||||
|
||||
it.skip('handles map entries', async (): Promise<void> => {
|
||||
@@ -48,6 +52,8 @@ describe('misc quick tests', (): void => {
|
||||
console.error('# entries', entries.length);
|
||||
|
||||
console.timeEnd('map.entries');
|
||||
|
||||
await api.disconnect();
|
||||
});
|
||||
|
||||
it.skip('handles doublemap entries', async (): Promise<void> => {
|
||||
@@ -57,6 +63,8 @@ describe('misc quick tests', (): void => {
|
||||
console.error(JSON.stringify(
|
||||
await api.query.staking.erasStakers.entries(activeEra.unwrapOrDefault().index)
|
||||
));
|
||||
|
||||
await api.disconnect();
|
||||
});
|
||||
|
||||
it.skip('does something in society', async (): Promise<void> => {
|
||||
@@ -65,6 +73,8 @@ describe('misc quick tests', (): void => {
|
||||
console.error(JSON.stringify(
|
||||
await api.query.society.defenderVotes('Dab4bfYTZRUDMWjYAUQuFbDreQ9mt7nULWu3Dw7jodbzVe9')
|
||||
));
|
||||
|
||||
await api.disconnect();
|
||||
});
|
||||
|
||||
it.skip('allows for range queries', async (): Promise<void> => {
|
||||
@@ -75,6 +85,8 @@ describe('misc quick tests', (): void => {
|
||||
(await api.query.staking.activeEra.range([header.parentHash, header.hash], 'Dab4bfYTZRUDMWjYAUQuFbDreQ9mt7nULWu3Dw7jodbzVe9'))
|
||||
.map(([block, value]) => [block, value.toRawType(), value.toHuman()])
|
||||
));
|
||||
|
||||
await api.disconnect();
|
||||
});
|
||||
|
||||
it('expose rpc and rx definition', async (): Promise<void> => {
|
||||
@@ -83,5 +95,7 @@ describe('misc quick tests', (): void => {
|
||||
console.error(api.rpc.payment.queryFeeDetails.meta);
|
||||
|
||||
console.error(api.rx.rpc.chain.getBlock.meta);
|
||||
|
||||
await api.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,11 +22,11 @@
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/types": "4.11.3-0",
|
||||
"@polkadot/types-known": "4.11.3-0",
|
||||
"@polkadot/util": "^6.5.1",
|
||||
"@polkadot/util-crypto": "^6.5.1",
|
||||
"@polkadot/util": "^6.5.2-1",
|
||||
"@polkadot/util-crypto": "^6.5.2-1",
|
||||
"bn.js": "^4.11.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^6.5.1"
|
||||
"@polkadot/keyring": "^6.5.2-1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
"@polkadot/metadata": "4.11.3-0",
|
||||
"@polkadot/rpc-provider": "4.11.3-0",
|
||||
"@polkadot/types": "4.11.3-0",
|
||||
"@polkadot/util": "^6.5.1",
|
||||
"@polkadot/x-rxjs": "^6.5.1"
|
||||
"@polkadot/util": "^6.5.2-1",
|
||||
"@polkadot/x-rxjs": "^6.5.2-1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^6.5.1"
|
||||
"@polkadot/keyring": "^6.5.2-1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,10 +12,16 @@ import { RpcCore } from '.';
|
||||
describe('Cached Observables', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
let rpc: RpcCore & RpcInterface;
|
||||
let provider: MockProvider;
|
||||
const keyring = createTestPairs();
|
||||
|
||||
beforeEach((): void => {
|
||||
rpc = new RpcCore('123', registry, new MockProvider(registry)) as (RpcCore & RpcInterface);
|
||||
provider = new MockProvider(registry);
|
||||
rpc = new RpcCore('123', registry, provider) as (RpcCore & RpcInterface);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await provider.disconnect();
|
||||
});
|
||||
|
||||
it('creates a single observable for subscriptions (multiple calls)', (): void => {
|
||||
|
||||
@@ -16,8 +16,9 @@ describe('Api', (): void => {
|
||||
).toThrow(/Expected Provider/);
|
||||
});
|
||||
|
||||
it('allows for the definition of user RPCs', (): void => {
|
||||
const rpc = new RpcCore('567', registry, new MockProvider(registry), {
|
||||
it('allows for the definition of user RPCs', async () => {
|
||||
const provider = new MockProvider(registry);
|
||||
const rpc = new RpcCore('567', registry, provider, {
|
||||
testing: {
|
||||
foo: {
|
||||
description: 'foo',
|
||||
@@ -42,5 +43,7 @@ describe('Api', (): void => {
|
||||
section: 'testing',
|
||||
type: 'Balance'
|
||||
});
|
||||
|
||||
await provider.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,9 +13,15 @@ import { RpcCore } from '.';
|
||||
describe('replay', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
let rpc: RpcCore & RpcInterface;
|
||||
let provider: MockProvider;
|
||||
|
||||
beforeEach((): void => {
|
||||
rpc = new RpcCore('653', registry, new MockProvider(registry)) as (RpcCore & RpcInterface);
|
||||
provider = new MockProvider(registry);
|
||||
rpc = new RpcCore('653', registry, provider) as (RpcCore & RpcInterface);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await provider.disconnect();
|
||||
});
|
||||
|
||||
it('subscribes via the rpc section', (done): void => {
|
||||
|
||||
@@ -6,28 +6,39 @@ import { of, timer } from '@polkadot/x-rxjs';
|
||||
import { drr } from '.';
|
||||
|
||||
describe('drr', (): void => {
|
||||
beforeEach((): void => {
|
||||
jest.setTimeout(15000);
|
||||
});
|
||||
|
||||
it('should not fire twice the same value', (done): void => {
|
||||
let count = 0;
|
||||
|
||||
of(1, 1).pipe(drr()).subscribe((): void => { ++count; });
|
||||
const sub = of(1, 1).pipe(drr({ delay: 500 })).subscribe((): void => { ++count; });
|
||||
|
||||
setTimeout((): void => {
|
||||
expect(count).toBe(1);
|
||||
done();
|
||||
sub.unsubscribe();
|
||||
|
||||
setTimeout(done, 2000);
|
||||
}, 50);
|
||||
});
|
||||
|
||||
it('should be a ReplaySubject(1)', (done): void => {
|
||||
const obs = timer(0, 100).pipe(drr()); // Starts at 0, increments every 100ms
|
||||
const obs = timer(0, 100).pipe(drr({ delay: 500 })); // Starts at 0, increments every 100ms
|
||||
|
||||
obs.subscribe(); // Fire the observable
|
||||
const sub = obs.subscribe(); // Fire the observable
|
||||
|
||||
// Subscribe another time after some time, i.e. after the observable has fired
|
||||
setTimeout((): void => {
|
||||
obs.subscribe((value): void => {
|
||||
const sub = obs.subscribe((value): void => {
|
||||
expect(value > 1).toBe(true);
|
||||
done();
|
||||
|
||||
setTimeout(done, 2000);
|
||||
});
|
||||
|
||||
sub.unsubscribe();
|
||||
}, 500);
|
||||
|
||||
sub.unsubscribe();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,16 +21,16 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/types": "4.11.3-0",
|
||||
"@polkadot/util": "^6.5.1",
|
||||
"@polkadot/util-crypto": "^6.5.1",
|
||||
"@polkadot/x-fetch": "^6.5.1",
|
||||
"@polkadot/x-global": "^6.5.1",
|
||||
"@polkadot/x-ws": "^6.5.1",
|
||||
"@polkadot/util": "^6.5.2-1",
|
||||
"@polkadot/util-crypto": "^6.5.2-1",
|
||||
"@polkadot/x-fetch": "^6.5.2-1",
|
||||
"@polkadot/x-global": "^6.5.2-1",
|
||||
"@polkadot/x-ws": "^6.5.2-1",
|
||||
"bn.js": "^4.11.9",
|
||||
"eventemitter3": "^4.0.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^6.5.1",
|
||||
"@polkadot/keyring": "^6.5.2-1",
|
||||
"@polkadot/metadata": "4.11.3-0",
|
||||
"mock-socket": "^9.0.3",
|
||||
"nock": "^13.0.11"
|
||||
|
||||
@@ -45,6 +45,8 @@ export class MockProvider implements ProviderInterface {
|
||||
|
||||
private emitter = new EventEmitter();
|
||||
|
||||
private intervalId?: NodeJS.Timeout | null;
|
||||
|
||||
public isUpdating = true;
|
||||
|
||||
private registry: Registry;
|
||||
@@ -104,8 +106,12 @@ export class MockProvider implements ProviderInterface {
|
||||
// noop
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/require-await
|
||||
public async disconnect (): Promise<void> {
|
||||
// noop
|
||||
if (this.intervalId) {
|
||||
clearInterval(this.intervalId);
|
||||
this.intervalId = null;
|
||||
}
|
||||
}
|
||||
|
||||
public get isConnected (): boolean {
|
||||
@@ -175,7 +181,7 @@ export class MockProvider implements ProviderInterface {
|
||||
const query = decorateStorage(this.registry, metadata.asLatest, metadata.version);
|
||||
|
||||
// Do something every 1 seconds
|
||||
setInterval((): void => {
|
||||
this.intervalId = setInterval((): void => {
|
||||
if (!this.isUpdating) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,10 @@ describe('on', (): void => {
|
||||
mock = new MockProvider(registry);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await mock.disconnect();
|
||||
});
|
||||
|
||||
it('it emits both connected and disconnected events', (done): void => {
|
||||
const events: Record<string, boolean> = { connected: false, disconnected: false };
|
||||
|
||||
|
||||
@@ -13,6 +13,10 @@ describe('send', (): void => {
|
||||
mock = new MockProvider(registry);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await mock.disconnect();
|
||||
});
|
||||
|
||||
it('fails on non-supported methods', (): Promise<any> => {
|
||||
return mock
|
||||
.send('something_invalid', [])
|
||||
|
||||
@@ -13,6 +13,10 @@ describe('subscribe', (): void => {
|
||||
mock = new MockProvider(registry);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await mock.disconnect();
|
||||
});
|
||||
|
||||
it('fails on unknown methods', (): Promise<number | void> => {
|
||||
return mock
|
||||
.subscribe('test', 'test_notFound')
|
||||
@@ -29,28 +33,28 @@ describe('subscribe', (): void => {
|
||||
});
|
||||
});
|
||||
|
||||
it('calls back with the last known value', (done): Promise<number> => {
|
||||
it('calls back with the last known value', (done): void => {
|
||||
mock.isUpdating = false;
|
||||
mock.subscriptions.chain_subscribeNewHead.lastValue = 'testValue';
|
||||
|
||||
return mock.subscribe('chain_newHead', 'chain_subscribeNewHead', (_: any, value: string): void => {
|
||||
mock.subscribe('chain_newHead', 'chain_subscribeNewHead', (_: any, value: string): void => {
|
||||
expect(value).toEqual('testValue');
|
||||
done();
|
||||
});
|
||||
}).catch(console.error);
|
||||
});
|
||||
|
||||
it('calls back with new headers', (done): Promise<number> => {
|
||||
return mock.subscribe('chain_newHead', 'chain_subscribeNewHead', (_: any, header: { number: number }): void => {
|
||||
it('calls back with new headers', (done): void => {
|
||||
mock.subscribe('chain_newHead', 'chain_subscribeNewHead', (_: any, header: { number: number }): void => {
|
||||
if (header.number === 4) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
}).catch(console.error);
|
||||
});
|
||||
|
||||
it('handles errors withing callbacks gracefully', (done): Promise<number> => {
|
||||
it('handles errors withing callbacks gracefully', (done): void => {
|
||||
let hasThrown = false;
|
||||
|
||||
return mock.subscribe('chain_newHead', 'chain_subscribeNewHead', (_: any, header: { number: number }): void => {
|
||||
mock.subscribe('chain_newHead', 'chain_subscribeNewHead', (_: any, header: { number: number }): void => {
|
||||
if (!hasThrown) {
|
||||
hasThrown = true;
|
||||
|
||||
@@ -60,6 +64,6 @@ describe('subscribe', (): void => {
|
||||
if (header.number === 3) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
}).catch(console.error);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,6 +20,10 @@ describe('unsubscribe', (): void => {
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await mock.disconnect();
|
||||
});
|
||||
|
||||
it('fails on unknown ids', (): Promise<boolean> => {
|
||||
return mock
|
||||
.unsubscribe('chain_newHead', 'chain_subscribeNewHead', 5)
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
|
||||
import type { Mock } from './../mock/types';
|
||||
|
||||
import { mockWs, TEST_WS_URL } from '../../test/mockWs';
|
||||
import { mockWs } from '../../test/mockWs';
|
||||
import { WsProvider } from './';
|
||||
|
||||
const TEST_WS_URL = 'ws://localhost-connect.spec.ts:9988';
|
||||
|
||||
function sleepMs (ms = 0): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
@@ -15,7 +17,7 @@ describe('onConnect', (): void => {
|
||||
|
||||
beforeEach((): void => {
|
||||
jest.setTimeout(30000);
|
||||
mocks = [mockWs([])];
|
||||
mocks = [mockWs([], TEST_WS_URL)];
|
||||
});
|
||||
|
||||
afterEach((): void => {
|
||||
@@ -27,9 +29,19 @@ describe('onConnect', (): void => {
|
||||
});
|
||||
});
|
||||
|
||||
it('Does not connect when autoConnect is false', (): void => {
|
||||
it('Does not connect when autoConnect is false', async () => {
|
||||
const provider: WsProvider = new WsProvider(TEST_WS_URL, 0);
|
||||
|
||||
await sleepMs(100); // Hack to give the provider time to connect
|
||||
expect(provider.isConnected).toBe(false);
|
||||
|
||||
await provider.connect();
|
||||
await sleepMs(100); // Hack to give the provider time to connect
|
||||
expect(provider.isConnected).toBe(true);
|
||||
|
||||
await provider.disconnect();
|
||||
|
||||
await sleepMs(100); // Hack to give the provider time to connect
|
||||
expect(provider.isConnected).toBe(false);
|
||||
});
|
||||
|
||||
@@ -38,6 +50,8 @@ describe('onConnect', (): void => {
|
||||
|
||||
await sleepMs(100); // Hack to give the provider time to connect
|
||||
expect(provider.isConnected).toBe(true);
|
||||
|
||||
await provider.disconnect();
|
||||
});
|
||||
|
||||
it('Creates a new WebSocket instance by calling the connect() method', async () => {
|
||||
@@ -50,7 +64,9 @@ describe('onConnect', (): void => {
|
||||
await sleepMs(100); // Hack to give the provider time to connect
|
||||
|
||||
expect(provider.isConnected).toBe(true);
|
||||
expect(mocks[0].server.clients().length).toBe(1);
|
||||
expect(mocks[0].server.clients()).toHaveLength(1);
|
||||
|
||||
await provider.disconnect();
|
||||
});
|
||||
|
||||
it('Connects to first endpoint when an array is given', async () => {
|
||||
@@ -60,22 +76,26 @@ describe('onConnect', (): void => {
|
||||
await sleepMs(100); // Hack to give the provider time to connect
|
||||
|
||||
expect(provider.isConnected).toBe(true);
|
||||
|
||||
await provider.disconnect();
|
||||
});
|
||||
|
||||
it('Connects to the second endpoint when the first is unreachable', async () => {
|
||||
/* eslint-disable @typescript-eslint/no-empty-function */
|
||||
jest.spyOn(console, 'error').mockImplementation((): void => {});
|
||||
|
||||
const endpoints: string[] = ['ws://localhost:9956', TEST_WS_URL];
|
||||
const endpoints: string[] = ['ws://localhost-connect.spec.ts:9956', TEST_WS_URL];
|
||||
const provider: WsProvider = new WsProvider(endpoints, 1);
|
||||
|
||||
await sleepMs(100); // Hack to give the provider time to connect
|
||||
|
||||
expect(provider.isConnected).toBe(true);
|
||||
|
||||
await provider.disconnect();
|
||||
});
|
||||
|
||||
it('Connects to the second endpoint when the first is dropped', async () => {
|
||||
const endpoints: string[] = [TEST_WS_URL, 'ws://localhost:9957'];
|
||||
const endpoints: string[] = [TEST_WS_URL, 'ws://localhost-connect.spec.ts:9957'];
|
||||
|
||||
mocks.push(mockWs([], endpoints[1]));
|
||||
|
||||
@@ -83,26 +103,27 @@ describe('onConnect', (): void => {
|
||||
|
||||
await sleepMs(100); // Hack to give the provider time to connect
|
||||
// Check that first server is connected
|
||||
expect(mocks[0].server.clients().length).toBe(1);
|
||||
expect(mocks[1].server.clients().length).toBe(0);
|
||||
expect(mocks[0].server.clients()).toHaveLength(1);
|
||||
expect(mocks[1].server.clients()).toHaveLength(0);
|
||||
|
||||
// Close connection from first server
|
||||
mocks[0].server.clients()[0].close();
|
||||
await sleepMs(100);
|
||||
|
||||
// Check that second server is connected
|
||||
expect(mocks[1].server.clients().length).toBe(1);
|
||||
expect(mocks[1].server.clients()).toHaveLength(1);
|
||||
expect(provider.isConnected).toBe(true);
|
||||
|
||||
await provider.disconnect();
|
||||
});
|
||||
|
||||
it('Round-robin of endpoints on WsProvider', async () => {
|
||||
const rounds = 5;
|
||||
const endpoints: string[] = [
|
||||
TEST_WS_URL,
|
||||
'ws://localhost:9956',
|
||||
'ws://localhost:9957',
|
||||
'ws://invalid:9956',
|
||||
'ws://localhost:9958'
|
||||
'ws://localhost-connect.spec.ts:9956',
|
||||
'ws://localhost-connect.spec.ts:9957',
|
||||
'ws://invalid-connect.spec.ts:9956',
|
||||
'ws://localhost-connect.spec.ts:9958'
|
||||
];
|
||||
|
||||
mocks.push(mockWs([], endpoints[1]));
|
||||
@@ -117,18 +138,20 @@ describe('onConnect', (): void => {
|
||||
];
|
||||
const provider: WsProvider = new WsProvider(endpoints, 1);
|
||||
|
||||
for (let round = 0; round < rounds; round++) {
|
||||
for (let index = 0; index < mocks.length; index++) {
|
||||
for (let round = 0; round < 5; round++) {
|
||||
for (let mock = 0; mock < mocks.length; mock++) {
|
||||
await sleepMs(100); // Hack to give the provider time to connect
|
||||
|
||||
// Check that first server is connected and the next one isn't
|
||||
expect(mocks[index].server.clients().length).toBe(1);
|
||||
expect(mockNext[index].server.clients().length).toBe(0);
|
||||
expect(mocks[mock].server.clients()).toHaveLength(1);
|
||||
expect(mockNext[mock].server.clients()).toHaveLength(0);
|
||||
expect(provider.isConnected).toBe(true);
|
||||
|
||||
// Close connection from first server
|
||||
mocks[index].server.clients()[0].close();
|
||||
mocks[mock].server.clients()[0].close();
|
||||
}
|
||||
}
|
||||
|
||||
await provider.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,25 +1,32 @@
|
||||
// Copyright 2017-2021 @polkadot/rpc-provider authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { mockWs, TEST_WS_URL } from '../../test/mockWs';
|
||||
import { mockWs } from '../../test/mockWs';
|
||||
import { Mock } from './../mock/types';
|
||||
import { WsProvider } from './';
|
||||
|
||||
let ws: WsProvider;
|
||||
const TEST_WS_URL = 'ws://localhost-index.spec.ts:9977';
|
||||
|
||||
let provider: WsProvider | null;
|
||||
let mock: Mock;
|
||||
|
||||
function createWs (requests: any[], autoConnect: number | undefined = 1000): WsProvider {
|
||||
mock = mockWs(requests);
|
||||
ws = new WsProvider(TEST_WS_URL, autoConnect);
|
||||
function createWs (requests: any[], autoConnect = 1000, headers?: Record<string, string>): WsProvider {
|
||||
mock = mockWs(requests, TEST_WS_URL);
|
||||
provider = new WsProvider(TEST_WS_URL, autoConnect, headers);
|
||||
|
||||
return ws;
|
||||
return provider;
|
||||
}
|
||||
|
||||
describe('Ws', (): void => {
|
||||
afterEach((): void => {
|
||||
afterEach(async () => {
|
||||
if (mock) {
|
||||
mock.done();
|
||||
}
|
||||
|
||||
if (provider) {
|
||||
await provider.disconnect();
|
||||
provider = null;
|
||||
}
|
||||
});
|
||||
|
||||
it('returns the connected state', (): void => {
|
||||
@@ -28,10 +35,8 @@ describe('Ws', (): void => {
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
it('allows you to initialize the provider with custom headers', (): void => {
|
||||
expect(
|
||||
(): WsProvider => new WsProvider(TEST_WS_URL, 1000, { foo: 'bar' })
|
||||
).not.toThrow();
|
||||
it('allows you to initialize the provider with custom headers', () => {
|
||||
createWs([], 100, { foo: 'bar' });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -42,10 +47,9 @@ describe('Endpoint Parsing', (): void => {
|
||||
});
|
||||
|
||||
it('Throws when WsProvider endpoint is an invalid string', () => {
|
||||
expect(() => {
|
||||
/* eslint-disable no-new */
|
||||
new WsProvider('http://127.0.0.1:9955', 0);
|
||||
}).toThrowError(/^Endpoint should start with /);
|
||||
expect(
|
||||
() => new WsProvider('http://127.0.0.1:9955', 0)
|
||||
).toThrowError(/^Endpoint should start with /);
|
||||
});
|
||||
|
||||
it('Succeeds when WsProvider endpoint is a valid array', () => {
|
||||
@@ -58,18 +62,16 @@ describe('Endpoint Parsing', (): void => {
|
||||
it('Throws when WsProvider endpoint is an empty array', () => {
|
||||
const endpoints: string[] = [];
|
||||
|
||||
expect(() => {
|
||||
/* eslint-disable no-new */
|
||||
new WsProvider(endpoints, 0);
|
||||
}).toThrowError('WsProvider requires at least one Endpoint');
|
||||
expect(
|
||||
() => new WsProvider(endpoints, 0)
|
||||
).toThrowError('WsProvider requires at least one Endpoint');
|
||||
});
|
||||
|
||||
it('Throws when WsProvider endpoint is an invalid array', () => {
|
||||
const endpoints: string[] = ['ws://127.0.0.1:9955', 'http://bad.co:9944', 'ws://mychain.com:9933'];
|
||||
|
||||
expect(() => {
|
||||
/* eslint-disable no-new */
|
||||
new WsProvider(endpoints, 0);
|
||||
}).toThrowError(/^Endpoint should start with /);
|
||||
expect(
|
||||
() => new WsProvider(endpoints, 0)
|
||||
).toThrowError(/^Endpoint should start with /);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,17 +3,19 @@
|
||||
|
||||
import type { Constructor } from '@polkadot/types/types';
|
||||
|
||||
import { mockWs, TEST_WS_URL } from '../../test/mockWs';
|
||||
import { mockWs } from '../../test/mockWs';
|
||||
import { Global, Mock } from './../mock/types';
|
||||
import { WsProvider } from './';
|
||||
|
||||
declare const global: Global;
|
||||
|
||||
let provider: WsProvider;
|
||||
const TEST_WS_URL = 'ws://localhost-send.spec.ts:9965';
|
||||
|
||||
let provider: WsProvider | null;
|
||||
let mock: Mock;
|
||||
|
||||
function createMock (requests: any[]): void {
|
||||
mock = mockWs(requests);
|
||||
mock = mockWs(requests, TEST_WS_URL);
|
||||
}
|
||||
|
||||
function createWs (autoConnect = 1000): Promise<WsProvider> {
|
||||
@@ -29,12 +31,17 @@ describe('send', (): void => {
|
||||
globalWs = global.WebSocket;
|
||||
});
|
||||
|
||||
afterEach((): void => {
|
||||
afterEach(async () => {
|
||||
global.WebSocket = globalWs;
|
||||
|
||||
if (mock) {
|
||||
mock.done();
|
||||
}
|
||||
|
||||
if (provider) {
|
||||
await provider.disconnect();
|
||||
provider = null;
|
||||
}
|
||||
});
|
||||
|
||||
it('handles internal errors', (): Promise<any> => {
|
||||
|
||||
@@ -6,13 +6,13 @@ import { WsProvider } from './';
|
||||
describe('state', (): void => {
|
||||
it('requires an ws:// prefixed endpoint', (): void => {
|
||||
expect(
|
||||
(): WsProvider => new WsProvider('http://', 0)
|
||||
() => new WsProvider('http://', 0)
|
||||
).toThrow(/with 'ws/);
|
||||
});
|
||||
|
||||
it('allows wss:// endpoints', (): void => {
|
||||
expect(
|
||||
(): WsProvider => new WsProvider('wss://', 0)
|
||||
() => new WsProvider('wss://', 0)
|
||||
).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,23 +3,25 @@
|
||||
|
||||
import type { Constructor } from '@polkadot/types/types';
|
||||
|
||||
import { mockWs, TEST_WS_URL } from '../../test/mockWs';
|
||||
import { mockWs } from '../../test/mockWs';
|
||||
import { Global, Mock } from './../mock/types';
|
||||
import { WsProvider } from './';
|
||||
|
||||
declare const global: Global;
|
||||
|
||||
let ws: WsProvider;
|
||||
const TEST_WS_URL = 'ws://localhost-subscribe.test.ts:9933';
|
||||
|
||||
let provider: WsProvider | null;
|
||||
let mock: Mock;
|
||||
|
||||
function createMock (requests: any[]): void {
|
||||
mock = mockWs(requests);
|
||||
mock = mockWs(requests, TEST_WS_URL);
|
||||
}
|
||||
|
||||
function createWs (autoConnect = 1000): Promise<WsProvider> {
|
||||
ws = new WsProvider(TEST_WS_URL, autoConnect);
|
||||
provider = new WsProvider(TEST_WS_URL, autoConnect);
|
||||
|
||||
return ws.isReady;
|
||||
return provider.isReady;
|
||||
}
|
||||
|
||||
describe('subscribe', (): void => {
|
||||
@@ -29,12 +31,17 @@ describe('subscribe', (): void => {
|
||||
globalWs = global.WebSocket;
|
||||
});
|
||||
|
||||
afterEach((): void => {
|
||||
afterEach(async () => {
|
||||
global.WebSocket = globalWs;
|
||||
|
||||
if (mock) {
|
||||
mock.done();
|
||||
}
|
||||
|
||||
if (provider) {
|
||||
await provider.disconnect();
|
||||
provider = null;
|
||||
}
|
||||
});
|
||||
|
||||
it('adds subscriptions', (): Promise<void> => {
|
||||
|
||||
@@ -3,23 +3,25 @@
|
||||
|
||||
import type { Constructor } from '@polkadot/types/types';
|
||||
|
||||
import { mockWs, TEST_WS_URL } from '../../test/mockWs';
|
||||
import { mockWs } from '../../test/mockWs';
|
||||
import { Global, Mock } from './../mock/types';
|
||||
import { WsProvider } from './';
|
||||
|
||||
declare const global: Global;
|
||||
|
||||
let ws: WsProvider;
|
||||
const TEST_WS_URL = 'ws://localhost-unsubscribe.test.ts:9933';
|
||||
|
||||
let provider: WsProvider | null;
|
||||
let mock: Mock;
|
||||
|
||||
function createMock (requests: any): void {
|
||||
mock = mockWs(requests);
|
||||
mock = mockWs(requests, TEST_WS_URL);
|
||||
}
|
||||
|
||||
function createWs (autoConnect = 1000): Promise<WsProvider> {
|
||||
ws = new WsProvider(TEST_WS_URL, autoConnect);
|
||||
provider = new WsProvider(TEST_WS_URL, autoConnect);
|
||||
|
||||
return ws.isReady;
|
||||
return provider.isReady;
|
||||
}
|
||||
|
||||
describe('subscribe', (): void => {
|
||||
@@ -29,12 +31,17 @@ describe('subscribe', (): void => {
|
||||
globalWs = global.WebSocket;
|
||||
});
|
||||
|
||||
afterEach((): void => {
|
||||
afterEach(async () => {
|
||||
global.WebSocket = globalWs;
|
||||
|
||||
if (mock) {
|
||||
mock.done();
|
||||
}
|
||||
|
||||
if (provider) {
|
||||
await provider.disconnect();
|
||||
provider = null;
|
||||
}
|
||||
});
|
||||
|
||||
it('removes subscriptions', (): Promise<boolean> => {
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
"@polkadot/metadata": "4.11.3-0",
|
||||
"@polkadot/rpc-provider": "4.11.3-0",
|
||||
"@polkadot/types": "4.11.3-0",
|
||||
"@polkadot/util": "^6.5.1",
|
||||
"@polkadot/util": "^6.5.2-1",
|
||||
"handlebars": "^4.7.7",
|
||||
"websocket": "^1.0.34",
|
||||
"yargs": "^17.0.1"
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types-known#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/networks": "^6.5.1",
|
||||
"@polkadot/networks": "^6.5.2-1",
|
||||
"@polkadot/types": "4.11.3-0",
|
||||
"@polkadot/util": "^6.5.1",
|
||||
"@polkadot/util": "^6.5.2-1",
|
||||
"bn.js": "^4.11.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -21,13 +21,13 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.0",
|
||||
"@polkadot/metadata": "4.11.3-0",
|
||||
"@polkadot/util": "^6.5.1",
|
||||
"@polkadot/util-crypto": "^6.5.1",
|
||||
"@polkadot/x-rxjs": "^6.5.1",
|
||||
"@polkadot/util": "^6.5.2-1",
|
||||
"@polkadot/util-crypto": "^6.5.2-1",
|
||||
"@polkadot/x-rxjs": "^6.5.2-1",
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"bn.js": "^4.11.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^6.5.1"
|
||||
"@polkadot/keyring": "^6.5.2-1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,4 +24,20 @@ describe('Data', (): void => {
|
||||
new Data(registry, { Raw: '0x0102030405060708' }).toHex()
|
||||
).toEqual('0x090102030405060708');
|
||||
});
|
||||
|
||||
it('throws on a very long string (only 32 bytes)', (): void => {
|
||||
expect(
|
||||
() => new Data(registry, { Raw: 'this is some very long string that is added here that will fail' })
|
||||
).toThrow('Data.Raw values are limited to a maximum length of 32 bytes');
|
||||
});
|
||||
|
||||
it('encodes a large value correctly (max 32)', (): void => {
|
||||
expect(
|
||||
// without the assert (and above test), add extra bytes to the end to check the encoding
|
||||
new Data(registry, { Raw: '0x0102030405060708091011121314151617181920212223242526272829303132' }).toHex()
|
||||
).toEqual(
|
||||
// first byte is 32 + 1 === 33 === 0x21
|
||||
'0x210102030405060708091011121314151617181920212223242526272829303132'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import type { H256 } from '../interfaces/runtime';
|
||||
import type { Registry } from '../types';
|
||||
|
||||
import { isString, isU8a, u8aToU8a } from '@polkadot/util';
|
||||
import { assert, isString, isU8a, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { Enum } from '../codec/Enum';
|
||||
import { Bytes } from './Bytes';
|
||||
@@ -57,6 +57,8 @@ export class Data extends Enum {
|
||||
Keccak256: 'H256', // 4
|
||||
ShaThree256: 'H256' // 5
|
||||
}, ...decodeData(registry, value));
|
||||
|
||||
assert(!this.isRaw || this.asRaw.length <= 32, 'Data.Raw values are limited to a maximum length of 32 bytes');
|
||||
}
|
||||
|
||||
get asBlakeTwo256 (): H256 {
|
||||
@@ -119,10 +121,12 @@ export class Data extends Enum {
|
||||
} else if (this.index === 1) {
|
||||
// don't add the length, just the data
|
||||
const data = this.value.toU8a(true);
|
||||
const length = Math.min(data.length, 32);
|
||||
const length = data.length >= 32
|
||||
? 32
|
||||
: data.length;
|
||||
const u8a = new Uint8Array(length + 1);
|
||||
|
||||
u8a.set([data.length + 1], 0);
|
||||
u8a.set([length + 1], 0);
|
||||
u8a.set(data.subarray(0, length), 1);
|
||||
|
||||
return u8a;
|
||||
|
||||
Reference in New Issue
Block a user