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 1 commit
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
6 changes: 6 additions & 0 deletions bindings/core/src/method/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ pub enum UtilsMethod {
serial_number: u32,
token_scheme_type: u8,
},
/// Computes the hash of the given protocol parameters.
#[serde(rename_all = "camelCase")]
ProtocolParametersHash {
/// Network Protocol Parameters
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
protocol_parameters: ProtocolParameters,
},
/// Computes the signing hash of a transaction.
TransactionSigningHash {
/// The transaction.
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
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: {
protocol_parameters: ProtocolParameters;
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
};
}

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 protocol_parameters A ProtocolParameters instance.
* @returns The hash of the protocol parameters as a hex-encoded string.
*/
static protocolParametersHash(
protocol_parameters: ProtocolParameters,
): HexEncodedString {
return callUtilsMethod({
name: 'protocolParametersHash',
data: {
protocol_parameters,
},
});
}

/**
* Compute the signing hash of a transaction.
*
Expand Down
33 changes: 12 additions & 21 deletions bindings/nodejs/tests/types/protocol_parameters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,25 @@
import { plainToInstance, Type } from 'class-transformer';
import { describe, it } from '@jest/globals';
import { expect } from '@jest/globals';
import * as protocol_parameters from '../../../../sdk/tests/types/fixtures/protocol_parameters.json';
import { ProtocolParameters, WorkScoreParameters, ManaParameters } from '../../lib/types/models/info/node-info-protocol';
import { StorageScoreParameters } from '../../lib/types/models';
import { Utils } from '../../lib/utils/utils';
import * as protocol_parameters from '../../../../sdk/tests/types/fixtures/protocol_parameters.json';

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

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

// TODO: is there a way around `as unknown`? The string->bigint parameters are the issue.
const params = protocol_parameters.params as unknown as ProtocolParameters;

// Check whether parameters were correctly set
expect(params.type).toEqual(0);
expect(params.version).toEqual(3);
expect(params.networkName).toEqual("TestJungle");
expect(params.bech32Hrp).toEqual("tgl");
it('compares ProtocolParameters bytes from a fixture', async () => {
// TODO: serialize to ProtocolParameters to bytes
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
});

// TODO: is there a way around `as unknown`? The string->bigint parameters are the issue.
const storageScoreParams = protocol_parameters.params.storageScoreParameters as unknown as StorageScoreParameters;
it('compares ProtocolParameters hash from a fixture', async () => {
// TODO: do we want to hash from binding side? Feels unnecessary tbh.
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved

expect(storageScoreParams.storageCost).toEqual("0");
expect(storageScoreParams.factorData).toEqual(0);
expect(storageScoreParams.offsetOutputOverhead).toEqual("0");
expect(storageScoreParams.offsetEd25519BlockIssuerKey).toEqual("0");
expect(storageScoreParams.offsetStakingFeature).toEqual("0");
expect(storageScoreParams.offsetDelegation).toEqual("0");
const params = protocol_parameters.params as unknown as ProtocolParameters;
const hash = Utils.protocolParametersHash(params);

const workScoreParameters = protocol_parameters.params.workScoreParameters as WorkScoreParameters;
const manaParameters = protocol_parameters.params.manaParameters as ManaParameters;
const expected_hash = protocol_parameters.hash;

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