Skip to content
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
36 changes: 13 additions & 23 deletions packages/js-dash-sdk/src/SDK/Client/Platform/Platform.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect } from 'chai';
// import { getLatestProtocolVersion } from '@dashevo/wasm-dpp';
import { getLatestProtocolVersion } from '@dashevo/wasm-dpp';
import { Platform } from './index';
import 'mocha';
import Client from '../Client';

Check warning on line 5 in packages/js-dash-sdk/src/SDK/Client/Platform/Platform.spec.ts

View workflow job for this annotation

GitHub Actions / JS packages (dash) / Linting

Using exported name 'Client' as identifier for default export

describe('Dash - Platform', () => {
it('should provide expected class', () => {
Expand All @@ -10,40 +10,30 @@
expect(Platform.constructor.name).to.be.equal('Function');
});

// TODO(versioning): obsolete now?
it.skip('should set protocol version for DPP though options', async () => {
it('should use the protocol version passed through options', async () => {
const platform = new Platform({
client: new Client(),
client: new Client({ network: 'testnet' }),
network: 'testnet',
driveProtocolVersion: 42,
driveProtocolVersion: 1,
});

await platform.initialize();
// expect(platform.dpp.getProtocolVersion()).to.equal(42);

expect(platform.protocolVersion).to.equal(1);
});

// TODO(versioning): obsolete now?
it.skip('should set protocol version for DPP using mapping', async () => {
it('should default to the latest protocol version on testnet', async () => {
// Regression: testnet must not be pinned to an old protocol version.
// wasm-dpp deserializes fetched contracts at this version, and an old
// version downgrades a V1 config (sized_integer_types) to V0, which the
// network rejects on contract update ("config version 0 is not supported").
const platform = new Platform({
client: new Client(),
client: new Client({ network: 'testnet' }),
network: 'testnet',
});

// @ts-ignore
// const testnetProtocolVersion = Platform.networkToProtocolVersion.get('testnet');

await platform.initialize();
// expect(platform.dpp.getProtocolVersion()).to.equal(testnetProtocolVersion);
});

// TODO(versioning): obsolete now?
it.skip('should set protocol version for DPP using latest version', async () => {
const platform = new Platform({
client: new Client(),
network: 'unknown',
});

await platform.initialize();
// expect(platform.dpp.getProtocolVersion()).to.equal(latestProtocolVersion);
expect(platform.protocolVersion).to.equal(getLatestProtocolVersion());
});
});
18 changes: 5 additions & 13 deletions packages/js-dash-sdk/src/SDK/Client/Platform/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
import type { DPPModule } from '@dashevo/wasm-dpp';
import crypto from 'crypto';

import Client from '../Client';

Check warning on line 5 in packages/js-dash-sdk/src/SDK/Client/Platform/Platform.ts

View workflow job for this annotation

GitHub Actions / JS packages (dash) / Linting

Using exported name 'Client' as identifier for default export

Check warning on line 5 in packages/js-dash-sdk/src/SDK/Client/Platform/Platform.ts

View workflow job for this annotation

GitHub Actions / JS packages (dash) / Linting

Dependency cycle via "./Platform:10"
import { IStateTransitionResult } from './IStateTransitionResult';

import createAssetLockTransaction from './createAssetLockTransaction';

Check warning on line 8 in packages/js-dash-sdk/src/SDK/Client/Platform/Platform.ts

View workflow job for this annotation

GitHub Actions / JS packages (dash) / Linting

Using exported name 'createAssetLockTransaction' as identifier for default export

Check warning on line 8 in packages/js-dash-sdk/src/SDK/Client/Platform/Platform.ts

View workflow job for this annotation

GitHub Actions / JS packages (dash) / Linting

Dependency cycle detected

import broadcastDocument from './methods/documents/broadcast';

Check warning on line 10 in packages/js-dash-sdk/src/SDK/Client/Platform/Platform.ts

View workflow job for this annotation

GitHub Actions / JS packages (dash) / Linting

Dependency cycle detected
import createDocument from './methods/documents/create';

Check warning on line 11 in packages/js-dash-sdk/src/SDK/Client/Platform/Platform.ts

View workflow job for this annotation

GitHub Actions / JS packages (dash) / Linting

Dependency cycle detected
import getDocument from './methods/documents/get';

Check warning on line 12 in packages/js-dash-sdk/src/SDK/Client/Platform/Platform.ts

View workflow job for this annotation

GitHub Actions / JS packages (dash) / Linting

Dependency cycle detected

import publishContract from './methods/contracts/publish';

Check warning on line 14 in packages/js-dash-sdk/src/SDK/Client/Platform/Platform.ts

View workflow job for this annotation

GitHub Actions / JS packages (dash) / Linting

Dependency cycle detected
import updateContract from './methods/contracts/update';
import createContract from './methods/contracts/create';
import getContract from './methods/contracts/get';
Expand Down Expand Up @@ -148,10 +148,6 @@

client: Client;

private static readonly networkToProtocolVersion: Map<string, number> = new Map([
['testnet', 1],
]);

protected fetcher: Fetcher;

public nonceManager: NonceManager;
Expand Down Expand Up @@ -214,15 +210,11 @@
await Platform.initializeDppModule();

if (this.protocolVersion === undefined) {
// use mapped protocol version otherwise
// fallback to one that set in dpp as the last option

const mappedProtocolVersion = Platform.networkToProtocolVersion.get(
this.client.network,
);

this.protocolVersion = mappedProtocolVersion !== undefined
? mappedProtocolVersion : getLatestProtocolVersion();
// Default to the latest protocol version supported by the bundled DPP.
// This version also drives how fetched contracts are deserialized; an
// older version would downgrade a V1 config (sized_integer_types) to V0
// and make contract updates fail network validation.
this.protocolVersion = getLatestProtocolVersion();
}

// eslint-disable-next-line
Expand Down
Loading