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
16 changes: 8 additions & 8 deletions packages/common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ export type DecodedOutput = {
}

export interface TxNanoHeader {
id: string;
nc_seqnum: number;
nc_id: string;
nc_method: string;
nc_address: string;
id: string;
nc_seqnum: number;
nc_id: string;
nc_method: string;
nc_address: string;
}

export type TxHeader = TxNanoHeader;
Expand Down Expand Up @@ -227,9 +227,9 @@ export class Balance {
totalAmountSent = 0n,
unlockedAmount = 0n,
lockedAmount = 0n,
lockExpires: number|null = null,
unlockedAuthorities: Authorities|null = null,
lockedAuthorities: Authorities|null = null
lockExpires: number | null = null,
unlockedAuthorities: Authorities | null = null,
lockedAuthorities: Authorities | null = null
) {
this.totalAmountSent = totalAmountSent;
this.unlockedAmount = unlockedAmount;
Expand Down
1 change: 1 addition & 0 deletions packages/wallet-service/src/nodeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function convertApiVersionData(data: FullNodeApiVersionResponse): FullNod
return {
version: data.version,
network: data.network,
nanoContractsEnabled: data.nano_contracts_enabled ?? false,
minWeight: data.min_weight,
minTxWeight: data.min_tx_weight,
minTxWeightCoefficient: data.min_tx_weight_coefficient,
Expand Down
1 change: 1 addition & 0 deletions packages/wallet-service/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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(),
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
2 changes: 2 additions & 0 deletions packages/wallet-service/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export interface EnvironmentConfig {
export interface FullNodeVersionData {
version: string;
network: string;
nanoContractsEnabled: boolean;
minWeight: number;
minTxWeight: number;
minTxWeightCoefficient: number;
Expand All @@ -107,6 +108,7 @@ export interface FullNodeVersionData {
export interface FullNodeApiVersionResponse {
version: string;
network: string;
nano_contracts_enabled?: boolean;
min_weight: number;
min_tx_weight: number;
min_tx_weight_coefficient: number; // float
Expand Down
1 change: 1 addition & 0 deletions packages/wallet-service/tests/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,7 @@ test('GET /version', async () => {
const mockData: FullNodeApiVersionResponse = {
version: '0.38.0',
network: 'mainnet',
nano_contracts_enabled: true,
min_weight: 14,
min_tx_weight: 14,
min_tx_weight_coefficient: 1.6,
Expand Down
2 changes: 2 additions & 0 deletions packages/wallet-service/tests/commons.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ test('getFullnodeData with an uninitialized version_data database should call th
const mockData = {
version: '0.38.0',
network: 'mainnet',
nano_contracts_enabled: true,
min_weight: 14,
min_tx_weight: 14,
min_tx_weight_coefficient: 1.6,
Expand Down Expand Up @@ -561,6 +562,7 @@ test('getFullnodeData with an initialized version_data database should query dat
const mockedVersionData: FullNodeApiVersionResponse = {
version: '0.38.0',
network: 'mainnet',
nano_contracts_enabled: true,
min_weight: 14,
min_tx_weight: 14,
min_tx_weight_coefficient: 1.6,
Expand Down
2 changes: 2 additions & 0 deletions packages/wallet-service/tests/db.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,7 @@ test('updateVersionData', async () => {
const mockData: FullNodeApiVersionResponse = {
version: '0.38.0',
network: 'mainnet',
nano_contracts_enabled: true,
min_weight: 14,
min_tx_weight: 14,
min_tx_weight_coefficient: 1.6,
Expand Down Expand Up @@ -1655,6 +1656,7 @@ test('getVersionData', async () => {
const mockData: FullNodeApiVersionResponse = {
version: '0.38.0',
network: 'mainnet',
nano_contracts_enabled: true,
min_weight: 14,
min_tx_weight: 14,
min_tx_weight_coefficient: 1.6,
Expand Down
34 changes: 33 additions & 1 deletion packages/wallet-service/tests/nodeConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import { convertApiVersionData, getRawFullnodeData } from '@src/nodeConfig';
const mysql = getDbConnection();

const VERSION_DATA: FullNodeApiVersionResponse = {
version: '0.63.1',
version: '0.65.2-alpha.1',
network: 'mainnet',
nano_contracts_enabled: true,
min_weight: 14,
min_tx_weight: 14,
min_tx_weight_coefficient: 1.6,
Expand Down Expand Up @@ -63,6 +64,7 @@ test('convertApiVersionData', async () => {
expect(convertApiVersionData(OLD_VERSION_DATA)).toStrictEqual({
version: OLD_VERSION_DATA.version,
network: OLD_VERSION_DATA.network,
nanoContractsEnabled: false,
minWeight: OLD_VERSION_DATA.min_weight,
minTxWeight: OLD_VERSION_DATA.min_tx_weight,
minTxWeightCoefficient: OLD_VERSION_DATA.min_tx_weight_coefficient,
Expand All @@ -79,6 +81,7 @@ test('convertApiVersionData', async () => {
expect(convertApiVersionData(VERSION_DATA)).toStrictEqual({
version: VERSION_DATA.version,
network: VERSION_DATA.network,
nanoContractsEnabled: VERSION_DATA.nano_contracts_enabled,
minWeight: VERSION_DATA.min_weight,
minTxWeight: VERSION_DATA.min_tx_weight,
minTxWeightCoefficient: VERSION_DATA.min_tx_weight_coefficient,
Expand All @@ -92,3 +95,32 @@ test('convertApiVersionData', async () => {
nativeTokenSymbol: VERSION_DATA.native_token.symbol,
});
});

test('convertApiVersionData handles nano_contracts_enabled correctly', async () => {
// Test with nano_contracts_enabled = false
const versionWithNanoFalse: FullNodeApiVersionResponse = {
...OLD_VERSION_DATA,
nano_contracts_enabled: false,
};
expect(convertApiVersionData(versionWithNanoFalse).nanoContractsEnabled).toBe(false);

// Test with nano_contracts_enabled = true
const versionWithNanoTrue: FullNodeApiVersionResponse = {
...OLD_VERSION_DATA,
nano_contracts_enabled: true,
};
expect(convertApiVersionData(versionWithNanoTrue).nanoContractsEnabled).toBe(true);

// Test with nano_contracts_enabled = undefined (should default to false)
const versionWithNanoUndefined: FullNodeApiVersionResponse = {
...OLD_VERSION_DATA,
nano_contracts_enabled: undefined,
};
expect(convertApiVersionData(versionWithNanoUndefined).nanoContractsEnabled).toBe(false);

// Test without nano_contracts_enabled field (should default to false)
const versionWithoutNano: FullNodeApiVersionResponse = {
...OLD_VERSION_DATA,
};
expect(convertApiVersionData(versionWithoutNano).nanoContractsEnabled).toBe(false);
});
26 changes: 26 additions & 0 deletions packages/wallet-service/tests/txProposal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ beforeEach(async () => {
max_number_inputs: 255,
max_number_outputs: 255,
decimal_places: 2,
nano_contracts_enabled: true,
genesis_block_hash: 'cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe',
genesis_tx1_hash: 'cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe',
genesis_tx2_hash: 'cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe',
Expand Down Expand Up @@ -216,6 +217,7 @@ test('POST /txproposals with too many outputs should fail with ApiError.TOO_MANY
token_deposit_percentage: 0.01,
reward_spend_min_blocks: 300,
max_number_inputs: 255,
nano_contracts_enabled: true,
max_number_outputs: 2, // mocking to force a failure
decimal_places: 2,
genesis_block_hash: 'cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe',
Expand Down Expand Up @@ -769,6 +771,7 @@ test('PUT /txproposals/{proposalId} with an invalid txHex should fail and update
success: true,
version: '0.38.0',
network: 'mainnet',
nano_contracts_enabled: true,
min_weight: 14,
min_tx_weight: 14,
min_tx_weight_coefficient: 1.6,
Expand All @@ -777,6 +780,11 @@ test('PUT /txproposals/{proposalId} with an invalid txHex should fail and update
reward_spend_min_blocks: 300,
max_number_inputs: 255,
max_number_outputs: 255,
decimal_places: 2,
genesis_block_hash: 'cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe',
genesis_tx1_hash: 'cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe',
genesis_tx2_hash: 'cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe',
native_token: { name: 'Hathor', symbol: 'HTR' },
},
}),
});
Expand Down Expand Up @@ -913,6 +921,7 @@ test('PUT /txproposals/{proposalId} should update tx_proposal to SEND_ERROR on f
success: true,
version: '0.38.0',
network: 'mainnet',
nano_contracts_enabled: true,
min_weight: 14,
min_tx_weight: 14,
min_tx_weight_coefficient: 1.6,
Expand All @@ -921,6 +930,11 @@ test('PUT /txproposals/{proposalId} should update tx_proposal to SEND_ERROR on f
reward_spend_min_blocks: 300,
max_number_inputs: 255,
max_number_outputs: 255,
decimal_places: 2,
genesis_block_hash: 'cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe',
genesis_tx1_hash: 'cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe',
genesis_tx2_hash: 'cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe',
native_token: { name: 'Hathor', symbol: 'HTR' },
},
}),
});
Expand Down Expand Up @@ -1551,6 +1565,7 @@ test('PUT /txproposals/{proposalId} with txhex', async () => {
success: true,
version: '0.38.0',
network: 'mainnet',
nano_contracts_enabled: true,
min_weight: 14,
min_tx_weight: 14,
min_tx_weight_coefficient: 1.6,
Expand All @@ -1559,6 +1574,11 @@ test('PUT /txproposals/{proposalId} with txhex', async () => {
reward_spend_min_blocks: 300,
max_number_inputs: 255,
max_number_outputs: 255,
decimal_places: 2,
genesis_block_hash: 'cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe',
genesis_tx1_hash: 'cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe',
genesis_tx2_hash: 'cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe',
native_token: { name: 'Hathor', symbol: 'HTR' },
},
}),
});
Expand Down Expand Up @@ -1693,6 +1713,7 @@ test('PUT /txproposals/{proposalId} with a different txhex than the one sent in
success: true,
version: '0.38.0',
network: 'mainnet',
nano_contracts_enabled: true,
min_weight: 14,
min_tx_weight: 14,
min_tx_weight_coefficient: 1.6,
Expand All @@ -1701,6 +1722,11 @@ test('PUT /txproposals/{proposalId} with a different txhex than the one sent in
reward_spend_min_blocks: 300,
max_number_inputs: 255,
max_number_outputs: 255,
decimal_places: 2,
genesis_block_hash: 'cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe',
genesis_tx1_hash: 'cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe',
genesis_tx2_hash: 'cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe',
native_token: { name: 'Hathor', symbol: 'HTR' },
},
}),
});
Expand Down