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
6 changes: 5 additions & 1 deletion packages/wallet-service/src/nodeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ export function convertApiVersionData(data: FullNodeApiVersionResponse): FullNod
return {
version: data.version,
network: data.network,
nanoContractsEnabled: data.nano_contracts_enabled ?? false,
// NOTE: Due to a bug in older fullnode versions, nano_contracts_enabled may return
// string values ('disabled', 'enabled', 'feature_activation') instead of boolean.
// This will be fixed in future fullnode versions to return boolean only.
// Until then, we need to handle both string and boolean values.
nanoContractsEnabled: data.nano_contracts_enabled === true || data.nano_contracts_enabled === 'enabled' || data.nano_contracts_enabled === 'feature_activation',
minWeight: data.min_weight,
minTxWeight: data.min_tx_weight,
minTxWeightCoefficient: data.min_tx_weight_coefficient,
Expand Down
8 changes: 7 additions & 1 deletion packages/wallet-service/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ export const Sha256Schema = Joi.string().hex().length(64);
export const FullnodeVersionSchema = Joi.object<FullNodeApiVersionResponse>({
version: Joi.string().min(1).required(),
network: Joi.string().min(1).required(),
nano_contracts_enabled: Joi.boolean().required(),
// NOTE: Due to a bug in older fullnode versions, this field may be a string
// ('disabled', 'enabled', 'feature_activation') instead of boolean.
// Future fullnode versions will return boolean only.
nano_contracts_enabled: Joi.alternatives().try(
Joi.boolean(),
Joi.string().valid('disabled', 'enabled', 'feature_activation')
).required(),
min_weight: Joi.number().integer().positive().allow(0).required(),
min_tx_weight: Joi.number().integer().positive().allow(0).required(),
min_tx_weight_coefficient: Joi.number().positive().allow(0).required(),
Expand Down
11 changes: 7 additions & 4 deletions packages/wallet-service/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ export interface EnvironmentConfig {
firebaseTokenUri: string;
firebaseAuthProviderX509CertUrl: string;
firebaseClientX509CertUrl: string;
firebasePrivateKey: string|null;
firebasePrivateKey: string | null;
maxLoadWalletRetries: number;
logLevel: string;
createNftMaxRetries: number;
warnMaxReorgSize: number;
};
}

/**
* Fullnode converted version data.
Expand Down Expand Up @@ -108,7 +108,10 @@ export interface FullNodeVersionData {
export interface FullNodeApiVersionResponse {
version: string;
network: string;
nano_contracts_enabled?: boolean;
// NOTE: Due to a bug in older fullnode versions, this field may be a string
// ('disabled', 'enabled', 'feature_activation') instead of boolean.
// Future fullnode versions will return boolean only.
nano_contracts_enabled?: boolean | 'disabled' | 'enabled' | 'feature_activation';
min_weight: number;
min_tx_weight: number;
min_tx_weight_coefficient: number; // float
Expand All @@ -121,7 +124,7 @@ export interface FullNodeApiVersionResponse {
genesis_block_hash?: string,
genesis_tx1_hash?: string,
genesis_tx2_hash?: string,
native_token?: { name: string, symbol: string};
native_token?: { name: string, symbol: string };
}

export interface TxProposal {
Expand Down
21 changes: 21 additions & 0 deletions packages/wallet-service/tests/nodeConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,27 @@ test('convertApiVersionData handles nano_contracts_enabled correctly', async ()
};
expect(convertApiVersionData(versionWithNanoTrue).nanoContractsEnabled).toBe(true);

// Test with nano_contracts_enabled = 'disabled' (should be false)
const versionWithDisabled: FullNodeApiVersionResponse = {
...OLD_VERSION_DATA,
nano_contracts_enabled: 'disabled',
};
expect(convertApiVersionData(versionWithDisabled).nanoContractsEnabled).toBe(false);

// Test with nano_contracts_enabled = 'enabled' (should be true)
const versionWithEnabled: FullNodeApiVersionResponse = {
...OLD_VERSION_DATA,
nano_contracts_enabled: 'enabled',
};
expect(convertApiVersionData(versionWithEnabled).nanoContractsEnabled).toBe(true);

// Test with nano_contracts_enabled = 'feature_activation' (should be true)
const versionWithFeatureActivation: FullNodeApiVersionResponse = {
...OLD_VERSION_DATA,
nano_contracts_enabled: 'feature_activation',
};
expect(convertApiVersionData(versionWithFeatureActivation).nanoContractsEnabled).toBe(true);

// Test with nano_contracts_enabled = undefined (should default to false)
const versionWithNanoUndefined: FullNodeApiVersionResponse = {
...OLD_VERSION_DATA,
Expand Down