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

Bindings: Add ProtocolParameters tests #1508

Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
762d07b
update and re-endable protocol parameters test
Alex6323 Oct 25, 2023
39a94ea
python: protocol parameters from/to dict
Alex6323 Oct 25, 2023
57293ad
Merge branch '2.0' into bindings/add-protocol-parameters-test
Alex6323 Oct 27, 2023
75873bb
Merge branch '2.0' into bindings/add-protocol-parameters-test
thibault-martinez Oct 30, 2023
e9aac65
protocol_parameters.json
thibault-martinez Oct 30, 2023
5a458ae
Use hex encoded bytes
thibault-martinez Oct 31, 2023
6ea6d21
Merge branch '2.0' into bindings/add-protocol-parameters-test
Alex6323 Nov 10, 2023
d07e216
Merge branch '2.0' into bindings/add-protocol-parameters-test
thibault-martinez Nov 15, 2023
7d5cbf2
Merge branch '2.0' into bindings/add-protocol-parameters-test
thibault-martinez Nov 16, 2023
9a320ec
Fix params_serde_hash
thibault-martinez Nov 16, 2023
6bdae0b
Merge branch '2.0' into bindings/add-protocol-parameters-test
thibault-martinez Nov 22, 2023
c2b126b
Cleanup rust test
thibault-martinez Nov 22, 2023
334fe61
Merge branch '2.0' into bindings/add-protocol-parameters-test
Alex6323 Nov 24, 2023
a288a2b
Add MultiAddress packable test
thibault-martinez Nov 26, 2023
3f634f1
add python test
Alex6323 Dec 1, 2023
ab3ed5c
Merge branch '2.0' into bindings/add-protocol-parameters-test
Alex6323 Dec 1, 2023
d2fa78a
add nodejs test
Alex6323 Dec 1, 2023
b4ebc82
add protocol_parameters.spec.ts
Alex6323 Dec 1, 2023
5a0ad4e
partially ready
Alex6323 Dec 1, 2023
013f3cf
add protocol parameters hash method
Alex6323 Dec 1, 2023
85662ff
comments
Alex6323 Dec 1, 2023
e526c00
rm some imports
Alex6323 Dec 1, 2023
4c81dde
some fixes
Alex6323 Dec 1, 2023
7037102
add python hash check
Alex6323 Dec 1, 2023
d2a2100
Merge branch '2.0' into bindings/add-protocol-parameters-test
Alex6323 Dec 1, 2023
ebbfa48
doc fixes
Alex6323 Dec 1, 2023
ade6640
fmt
Alex6323 Dec 4, 2023
f83bebf
Merge branch '2.0' into bindings/add-protocol-parameters-test
thibault-martinez Dec 4, 2023
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
26 changes: 5 additions & 21 deletions bindings/core/src/method/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,92 +30,72 @@ use crate::OmittedDebug;
pub enum UtilsMethod {
/// Transforms bech32 to hex
Bech32ToHex {
/// Bech32 encoded address
bech32: Bech32Address,
},
/// Transforms a hex encoded address to a bech32 encoded address
#[serde(rename_all = "camelCase")]
HexToBech32 {
/// Hex encoded bech32 address
hex: String,
/// Human readable part
bech32_hrp: Hrp,
},
/// Transforms an account id to a bech32 encoded address
#[serde(rename_all = "camelCase")]
AccountIdToBech32 {
/// Account ID
account_id: AccountId,
/// Human readable part
bech32_hrp: Hrp,
},
/// Transforms an nft id to a bech32 encoded address
#[serde(rename_all = "camelCase")]
NftIdToBech32 {
/// Nft ID
nft_id: NftId,
/// Human readable part
bech32_hrp: Hrp,
},
/// Transforms a hex encoded public key to a bech32 encoded address
#[serde(rename_all = "camelCase")]
HexPublicKeyToBech32Address {
/// Hex encoded public key
hex: String,
/// Human readable part
bech32_hrp: Hrp,
},
/// Returns a valid Address parsed from a String.
ParseBech32Address {
/// Address
address: Bech32Address,
},
/// Checks if a String is a valid bech32 encoded address.
IsAddressValid {
/// Address
address: String,
},
/// Generates a new mnemonic.
GenerateMnemonic,
/// Returns a hex encoded seed for a mnemonic.
MnemonicToHexSeed {
/// Mnemonic
#[derivative(Debug(format_with = "OmittedDebug::omitted_fmt"))]
mnemonic: String,
},
/// Returns a block ID from a block and slot protocol parameters
#[serde(rename_all = "camelCase")]
BlockId {
/// Block
block: BlockDto,
/// Network Protocol Parameters
protocol_parameters: ProtocolParameters,
},
/// Returns the transaction ID (Blake2b256 hash of the provided transaction payload)
TransactionId {
/// Transaction Payload
payload: SignedTransactionPayloadDto,
},
/// Computes the account ID
#[serde(rename_all = "camelCase")]
ComputeAccountId {
/// Output ID
output_id: OutputId,
},
/// Computes the Foundry ID
#[serde(rename_all = "camelCase")]
ComputeFoundryId {
/// Alias id
account_id: AccountId,
/// Serial number
serial_number: u32,
/// Token scheme kind
token_scheme_type: u8,
},
/// Computes the NFT ID
#[serde(rename_all = "camelCase")]
ComputeNftId {
/// Output ID
output_id: OutputId,
},
/// Computes the output ID from transaction id and output index
Expand All @@ -127,9 +107,13 @@ pub enum UtilsMethod {
serial_number: u32,
token_scheme_type: u8,
},
/// Computes the hash of the given protocol parameters.
#[serde(rename_all = "camelCase")]
ProtocolParametersHash {
protocol_parameters: ProtocolParameters,
},
/// Computes the signing hash of a transaction.
TransactionSigningHash {
/// The transaction.
transaction: TransactionDto,
},
/// Computes the minimum required amount of an output.
Expand Down
3 changes: 3 additions & 0 deletions bindings/core/src/method_handler/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response
let foundry_id = FoundryId::build(&AccountAddress::new(account_id), serial_number, token_scheme_type);
Response::TokenId(TokenId::from(foundry_id))
}
UtilsMethod::ProtocolParametersHash { protocol_parameters } => {
Response::Hash(protocol_parameters.hash().to_string())
}
UtilsMethod::TransactionSigningHash { transaction } => {
Response::Hash(Transaction::try_from_dto(transaction)?.signing_hash().to_string())
}
Expand Down
24 changes: 18 additions & 6 deletions bindings/nodejs/lib/types/models/info/node-info-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,18 @@ export interface ProtocolParameters {
* Work Score Parameters lists the work score of each type, it is used to denote the computation costs of processing an object.
*/
workScoreParameters: WorkScoreParameters;
/**
* The parameters used by mana calculation.
*/
manaParameters: ManaParameters;
/**
* Current supply of base token.
*/
tokenSupply: u64;
/**
* Genesis Slot defines the slot of the genesis.
*/
genesisSlot: number;
/**
* The genesis timestamp at which the slots start to count.
*/
Expand All @@ -63,10 +71,6 @@ export interface ProtocolParameters {
* The number of slots in an epoch expressed as an exponent of 2.
*/
slotsPerEpochExponent: number;
/**
* The parameters used by mana calculation.
*/
manaParameters: ManaParameters;
/**
* The unbonding period in epochs before an account can stop staking.
*/
Expand All @@ -80,9 +84,13 @@ export interface ProtocolParameters {
*/
punishmentEpochs: number;
/**
* Determine if a block is eligible by evaluating issuingTime and commitments in its pastcone to ATT and lastCommittedSlot respectively.
* Liveness Threshold Lower Bound is used by tip-selection to determine if a block is eligible by evaluating issuingTimes.
*/
livenessThreshold: number;
livenessThresholdLowerBound: number;
/**
* Liveness Threshold Upper Bound is used by tip-selection to determine if a block is eligible by evaluating issuingTimes.
*/
livenessThresholdUpperBound: number;
/**
* MinCommittableAge is the minimum age relative to the accepted tangle time slot index that a slot can be committed.
*/
Expand All @@ -107,6 +115,10 @@ export interface ProtocolParameters {
* Rewards Parameters defines the parameters that are used to calculate Mana rewards.
*/
rewardsParameters: RewardsParameters;
/**
* Target Committee Size defines the target size of the committee. If there's fewer candidates the actual committee size could be smaller in a given epoch.
*/
targetCommitteeSize: number;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions bindings/nodejs/lib/types/utils/bridge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
__NftIdToBech32Method__,
__HexPublicKeyToBech32AddressMethod__,
__IsAddressValidMethod__,
__ProtocolParametersHashMethod__,
__TransactionSigningHashMethod__,
__VerifyEd25519SignatureMethod__,
__VerifySecp256k1EcdsaSignatureMethod__,
Expand Down Expand Up @@ -45,6 +46,7 @@ export type __UtilsMethods__ =
| __NftIdToBech32Method__
| __HexPublicKeyToBech32AddressMethod__
| __IsAddressValidMethod__
| __ProtocolParametersHashMethod__
| __TransactionSigningHashMethod__
| __VerifyEd25519SignatureMethod__
| __VerifySecp256k1EcdsaSignatureMethod__
Expand Down
7 changes: 7 additions & 0 deletions bindings/nodejs/lib/types/utils/bridge/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ export interface __IsAddressValidMethod__ {
};
}

export interface __ProtocolParametersHashMethod__ {
name: 'protocolParametersHash';
data: {
protocolParameters: ProtocolParameters;
};
}

export interface __TransactionSigningHashMethod__ {
name: 'transactionSigningHash';
data: {
Expand Down
17 changes: 17 additions & 0 deletions bindings/nodejs/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,23 @@ export class Utils {
});
}

/**
* Compute the hash of an instance of ProtocolParameters.
*
* @param protocolParameters A ProtocolParameters instance.
* @returns The hash of the protocol parameters as a hex-encoded string.
*/
static protocolParametersHash(
protocolParameters: ProtocolParameters,
): HexEncodedString {
return callUtilsMethod({
name: 'protocolParametersHash',
data: {
protocolParameters,
},
});
}

/**
* Compute the signing hash of a transaction.
*
Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"typescript": "^4.9.4"
},
"devDependencies": {
"@napi-rs/cli": "^1.0.0",
"@types/jest": "^29.4.0",
"@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7",
Expand All @@ -48,8 +49,7 @@
"typedoc": "^0.24.6",
"typedoc-plugin-markdown": "^3.14.0",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4",
"@napi-rs/cli": "^1.0.0"
"webpack-cli": "^5.1.4"
},
"overrides": {
"tar@<=4.4.17": "^4.4.19",
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/tests/client/examples.spec.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 { describe, it } from '@jest/globals';
import { expect, describe, it } from '@jest/globals';
import {
Client,
utf8ToHex,
Expand Down
21 changes: 21 additions & 0 deletions bindings/nodejs/tests/types/protocol_parameters.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import 'reflect-metadata';

import { expect, describe, it } from '@jest/globals';
import * as protocol_parameters from '../../../../sdk/tests/types/fixtures/protocol_parameters.json';
import { ProtocolParameters } from '../../lib/types/models/info/node-info-protocol';
import { Utils } from '../../';

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

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

const params = protocol_parameters.params as unknown as ProtocolParameters;
const hash = Utils.protocolParametersHash(params);
const expected_hash = protocol_parameters.hash;

expect(hash).toEqual(expected_hash);
});
});
Loading
Loading