Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIP BlockId tests #1607

Merged
merged 78 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
c514afa
uncomment block id tests
Alex6323 Nov 10, 2023
70644c9
move json as fixtures into own .json files
Alex6323 Nov 10, 2023
3753570
Merge branch '2.0' into chore/tests/block-id
thibault-martinez Nov 26, 2023
4aa8bbf
Remove bindings fixtures
thibault-martinez Nov 26, 2023
18524de
Cleanup fixtures
thibault-martinez Nov 26, 2023
4a9620b
Cleanup tests
thibault-martinez Nov 26, 2023
3af258f
Merge branch '2.0' into chore/tests/block-id
thibault-martinez Nov 27, 2023
392fb8b
Uncomment tests
thibault-martinez Nov 27, 2023
24d100e
Add TODO
thibault-martinez Nov 27, 2023
fd96253
Merge branch '2.0' into chore/tests/block-id
Alex6323 Nov 29, 2023
695ac06
Merge branch '2.0' into chore/tests/block-id
Alex6323 Nov 30, 2023
918e51d
Merge branch '2.0' into chore/tests/block-id
Alex6323 Nov 30, 2023
91235a3
Merge branch '2.0' into chore/tests/block-id
Alex6323 Dec 5, 2023
565758e
Merge branch '2.0' into chore/tests/block-id
Alex6323 Dec 6, 2023
8bd6062
python: basic block tagged data payload
Alex6323 Dec 6, 2023
519bfcf
python: it's a signed block
Alex6323 Dec 6, 2023
762b6ca
python: basic block transaction payload
Alex6323 Dec 6, 2023
8c99094
python: validation block
Alex6323 Dec 6, 2023
109d70f
nodejs: basic block tagged data payload
Alex6323 Dec 6, 2023
359db00
nodejs: basic block transaction payload
Alex6323 Dec 6, 2023
beb9f62
nodejs: validation block
Alex6323 Dec 6, 2023
1c77a11
Merge branch '2.0' into chore/tests/block-id
Alex6323 Dec 6, 2023
d2035a0
simplify
Alex6323 Dec 6, 2023
6a4f41b
Merge branch '2.0' into chore/tests/block-id
Alex6323 Dec 6, 2023
12a79a4
nodejs: fix some block tests
Alex6323 Dec 8, 2023
d247175
Merge branch '2.0' into chore/tests/block-id
Alex6323 Dec 8, 2023
d13f493
remove temporary stuff
Alex6323 Dec 8, 2023
8673bd3
nits
Alex6323 Dec 8, 2023
71ea79e
back to interfaces
Alex6323 Dec 8, 2023
dfcbea0
format
Alex6323 Dec 8, 2023
091ce0a
nit
Alex6323 Dec 8, 2023
4bd270e
cleanup
Alex6323 Dec 8, 2023
ccd1273
rename instead of serde rename
Alex6323 Dec 8, 2023
19aaef4
reverted u64
Dec 12, 2023
5bd5307
Merge branch '2.0' into chore/tests/block-id
Dec 12, 2023
03854d0
Merge branch '2.0' into chore/tests/block-id
Alex6323 Dec 12, 2023
0331515
update test vectors
Alex6323 Dec 13, 2023
e9c1737
Merge branch '2.0' into chore/tests/block-id
Alex6323 Dec 15, 2023
a3090b6
Merge branch '2.0' into chore/tests/block-id
Alex6323 Jan 8, 2024
167aad5
Merge branch '2.0' into chore/tests/block-id
Alex6323 Jan 17, 2024
9911f17
Merge branch '2.0' into chore/tests/block-id
Alex6323 Jan 18, 2024
699afe0
attempt to fix tests
Alex6323 Jan 18, 2024
e5658ae
Merge branch '2.0' into chore/tests/block-id
thibault-martinez Jan 18, 2024
7d1f288
Update JSONs
thibault-martinez Jan 18, 2024
af55bc1
Remove FIXMEs
thibault-martinez Jan 18, 2024
2549030
Merge branch '2.0' into chore/tests/block-id
thibault-martinez Jan 19, 2024
3ffd794
Merge branch '2.0' into chore/tests/block-id
thibault-martinez Jan 19, 2024
643eb92
Fix test
thibault-martinez Jan 19, 2024
2342134
copyright
Alex6323 Jan 19, 2024
a2c7b82
nodejs: re-enable validation block test
Alex6323 Jan 19, 2024
29b8471
fix 1/3 python block id tests
Alex6323 Jan 19, 2024
c296133
allow passing args to pytest
Alex6323 Jan 19, 2024
b76cad8
Merge branch '2.0' into chore/tests/block-id
Alex6323 Jan 22, 2024
8c34827
Merge branch '2.0' into chore/tests/block-id
Alex6323 Jan 23, 2024
f96bb87
Python: fix serialization/deserialization
Alex6323 Jan 25, 2024
05e2640
Merge branch '2.0' into chore/tests/block-id
Alex6323 Jan 25, 2024
0d53fc8
linter, review
Alex6323 Jan 25, 2024
36b2f64
format
Alex6323 Jan 25, 2024
6d89240
format (are you serious?)
Alex6323 Jan 25, 2024
7edd5de
lint tests
Alex6323 Jan 25, 2024
7203cee
format annoying lints
Alex6323 Jan 25, 2024
d639118
assign id method for block
Alex6323 Jan 25, 2024
a6596a8
Merge branch '2.0' into chore/tests/block-id
Alex6323 Jan 25, 2024
bb38c49
yarn lint
Alex6323 Jan 25, 2024
fed8ea1
Merge branch '2.0' into chore/tests/block-id
Jan 25, 2024
a3bd1f1
type field first
Alex6323 Jan 25, 2024
b43b3e8
get rid of to_dict
Alex6323 Jan 26, 2024
806aeec
Merge branch '2.0' into chore/tests/block-id
Alex6323 Jan 26, 2024
1a9ec07
update fixture
Alex6323 Jan 26, 2024
b8261bd
format
Alex6323 Jan 26, 2024
36c3d74
Merge branch '2.0' into chore/tests/block-id
Alex6323 Jan 28, 2024
6d9b7be
python: fix lint
Alex6323 Jan 28, 2024
8401470
python: fix metadata feature output tests
Alex6323 Jan 28, 2024
4e4cec4
apply review suggestion
Alex6323 Jan 29, 2024
88c4de3
Merge branch '2.0' into chore/tests/block-id
Alex6323 Jan 29, 2024
1e92843
Merge branch '2.0' into chore/tests/block-id
thibault-martinez Jan 29, 2024
3ef3f71
Merge branch '2.0' into chore/tests/block-id
thibault-martinez Jan 30, 2024
33658e5
Nits
thibault-martinez Jan 30, 2024
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
2 changes: 1 addition & 1 deletion bindings/nodejs/lib/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ export class Client {
* Get the token supply.
*/
async getTokenSupply(): Promise<u64> {
return (await this.getProtocolParameters()).tokenSupply;
return BigInt((await this.getProtocolParameters()).tokenSupply);
}

/**
Expand Down
20 changes: 17 additions & 3 deletions bindings/nodejs/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import 'reflect-metadata';
import { callUtilsMethod } from './bindings';
import {
Block,
BlockId,
BlockError,
ClientError,
ClientErrorName,
Expand All @@ -15,8 +17,9 @@ import {
UTXOInput,
WalletError,
WalletErrorName,
ProtocolParameters,
} from './types';
import { bigIntToHex } from './utils';
import { bigIntToHex, Utils } from './utils';

// Allow bigint to be serialized as hex string.
//
Expand All @@ -27,8 +30,8 @@ import { bigIntToHex } from './utils';
return bigIntToHex(this);
};

// Assign the util method on UTXOInput here,
// to prevent loading bindings (callUtilsMethod) when importing UTXOInput just for typing.
// Assign the util method on UTXOInput here to prevent loading bindings (callUtilsMethod)
// when importing UTXOInput just for typing.
Object.assign(UTXOInput, {
/**
* Creates a `UTXOInput` from an output id.
Expand All @@ -44,6 +47,17 @@ Object.assign(UTXOInput, {
},
});

// Assign the util method on Block here to prevent loading bindings (callUtilsMethod)
// when importing Block just for typing.
Object.assign(Block, {
/**
* Returns the block id for the given block.
*/
id(block: Block, params: ProtocolParameters): BlockId {
return Utils.blockId(block, params);
},
});

export * from './client';
export * from './secret_manager';
export * from './types';
Expand Down
10 changes: 10 additions & 0 deletions bindings/nodejs/lib/types/block/core/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { BlockBody } from './block-body';
import { BasicBlockBody } from './basic';
import { ValidationBlockBody } from './validation';
import { BlockBodyDiscriminator } from '.';
import { ProtocolParameters, BlockId } from '../../..';

/**
* The block header.
Expand Down Expand Up @@ -118,6 +119,15 @@ class Block {
asValidation(): ValidationBlockBody {
return this.body.asValidation();
}

/**
* Returns the block id.
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
static id(block: Block, params: ProtocolParameters): BlockId {
// Implementation injected in lib/index.ts, as it uses bindings.
return null as unknown as BlockId;
}
}

function parseBlock(data: any): Block {
Expand Down
27 changes: 19 additions & 8 deletions bindings/nodejs/lib/types/models/info/node-info-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

import type { StorageScoreParameters } from '../storage-score';
import { EpochIndex } from '../../block/slot';
import { u64 } from '../../utils';
import { u64 } from '../../utils/type-aliases';

/**
* The Protocol Info.
*/
export interface ProtocolInfo {
interface ProtocolInfo {
/**
* The start epoch of the set of protocol parameters.
*/
Expand All @@ -22,7 +22,7 @@ export interface ProtocolInfo {
/**
* The Protocol Parameters.
*/
export interface ProtocolParameters {
interface ProtocolParameters {
/**
* Set to value 0 to denote a IOTA 2.0 protocol parameter.
*/
Expand Down Expand Up @@ -129,7 +129,7 @@ export interface ProtocolParameters {
/**
* Rewards Parameters defines the parameters that are used to calculate Mana rewards.
*/
export interface RewardsParameters {
interface RewardsParameters {
/**
* Profit Margin Exponent is used for shift operation for calculation of profit margin.
*/
Expand Down Expand Up @@ -164,7 +164,7 @@ export interface RewardsParameters {
/**
* Work Score Parameters lists the work score of each type, it is used to denote the computation costs of processing an object.
*/
export interface WorkScoreParameters {
interface WorkScoreParameters {
/**
* DataByte accounts for the network traffic per kibibyte.
*/
Expand Down Expand Up @@ -210,7 +210,7 @@ export interface WorkScoreParameters {
/**
* ManaParameters defines the parameters used by mana calculation.
*/
export interface ManaParameters {
interface ManaParameters {
/**
* The number of bits used to represent Mana.
*/
Expand Down Expand Up @@ -244,7 +244,7 @@ export interface ManaParameters {
/**
* Congestion Control Parameters defines the parameters used to calculate the Reference Mana Cost (RMC).
*/
export interface CongestionControlParameters {
interface CongestionControlParameters {
/**
* The minimum value of the reference Mana cost.
*/
Expand Down Expand Up @@ -282,7 +282,7 @@ export interface CongestionControlParameters {
/**
* The version signaling parameters.
*/
export interface VersionSignalingParameters {
interface VersionSignalingParameters {
/**
* The size of the window in epochs to find which version of protocol parameters was most signaled, from currentEpoch - windowSize to currentEpoch.
*/
Expand All @@ -296,3 +296,14 @@ export interface VersionSignalingParameters {
*/
activationOffset: number;
}

export {
ProtocolInfo,
ProtocolParameters,
RewardsParameters,
WorkScoreParameters,
StorageScoreParameters,
ManaParameters,
VersionSignalingParameters,
CongestionControlParameters,
};
2 changes: 1 addition & 1 deletion bindings/nodejs/lib/types/models/storage-score.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { u64 } from '../../utils';
import { u64 } from '../utils/type-aliases';

/**
* Defines the parameters of storage score calculations on objects which take node resources.
Expand Down
38 changes: 38 additions & 0 deletions bindings/nodejs/tests/types/block.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import 'reflect-metadata';

import { expect, describe, it } from '@jest/globals';
import * as basic_block_tagged_data_payload_json from '../../../../sdk/tests/types/fixtures/basic_block_tagged_data_payload.json';
import * as basic_block_transaction_payload_json from '../../../../sdk/tests/types/fixtures/basic_block_transaction_payload.json';
import * as validation_block_json from '../../../../sdk/tests/types/fixtures/validation_block.json';
import * as protocol_parameters_json from '../../../../sdk/tests/types/fixtures/protocol_parameters.json';
import { Block, BlockId, parseBlock, ProtocolParameters } from '../../';

describe('Block tests', () => {

it('compares basic block tagged data payload from a fixture', async () => {
const block = parseBlock(basic_block_tagged_data_payload_json.block);
expect(block).toBeInstanceOf(Block);
const params: ProtocolParameters = JSON.parse(JSON.stringify(protocol_parameters_json.params));
const expected_id = basic_block_tagged_data_payload_json.id as BlockId;
expect(Block.id(block, params)).toEqual(expected_id);
});

it('compares basic block transaction payload from a fixture', async () => {
const block = parseBlock(basic_block_transaction_payload_json.block);
expect(block).toBeInstanceOf(Block);
const params: ProtocolParameters = JSON.parse(JSON.stringify(protocol_parameters_json.params));
const expected_id = basic_block_transaction_payload_json.id as BlockId;
expect(Block.id(block, params)).toEqual(expected_id);
});

it('compares validation block from a fixture', async () => {
const block = parseBlock(validation_block_json.block);
expect(block).toBeInstanceOf(Block);
const params: ProtocolParameters = JSON.parse(JSON.stringify(protocol_parameters_json.params));
const expected_id = validation_block_json.id as BlockId;
expect(Block.id(block, params)).toEqual(expected_id);
});
});
2 changes: 1 addition & 1 deletion bindings/nodejs/tests/types/protocol_parameters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('ProtocolParameters tests', () => {

it('compares ProtocolParameters hash from a fixture', async () => {

const params = protocol_parameters.params as unknown as ProtocolParameters;
const params: ProtocolParameters = JSON.parse(JSON.stringify(protocol_parameters.params));
const hash = Utils.protocolParametersHash(params);
const expected_hash = protocol_parameters.hash;

Expand Down
Loading
Loading