diff --git a/bindings/nodejs/lib/client/client.ts b/bindings/nodejs/lib/client/client.ts index 082c52bbfa..efd05be088 100644 --- a/bindings/nodejs/lib/client/client.ts +++ b/bindings/nodejs/lib/client/client.ts @@ -426,7 +426,7 @@ export class Client { * Get the token supply. */ async getTokenSupply(): Promise { - return (await this.getProtocolParameters()).tokenSupply; + return BigInt((await this.getProtocolParameters()).tokenSupply); } /** diff --git a/bindings/nodejs/lib/index.ts b/bindings/nodejs/lib/index.ts index b18db57f65..ccef3753e8 100644 --- a/bindings/nodejs/lib/index.ts +++ b/bindings/nodejs/lib/index.ts @@ -5,6 +5,8 @@ import 'reflect-metadata'; import { callUtilsMethod } from './bindings'; import { + Block, + BlockId, BlockError, ClientError, ClientErrorName, @@ -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. // @@ -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. @@ -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'; diff --git a/bindings/nodejs/lib/types/block/core/block.ts b/bindings/nodejs/lib/types/block/core/block.ts index 529afa73ca..079a11dd64 100644 --- a/bindings/nodejs/lib/types/block/core/block.ts +++ b/bindings/nodejs/lib/types/block/core/block.ts @@ -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. @@ -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 { diff --git a/bindings/nodejs/lib/types/models/info/node-info-protocol.ts b/bindings/nodejs/lib/types/models/info/node-info-protocol.ts index 02a85a991d..aed21c61ea 100644 --- a/bindings/nodejs/lib/types/models/info/node-info-protocol.ts +++ b/bindings/nodejs/lib/types/models/info/node-info-protocol.ts @@ -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. */ @@ -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. */ @@ -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. */ @@ -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. */ @@ -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. */ @@ -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. */ @@ -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. */ @@ -296,3 +296,14 @@ export interface VersionSignalingParameters { */ activationOffset: number; } + +export { + ProtocolInfo, + ProtocolParameters, + RewardsParameters, + WorkScoreParameters, + StorageScoreParameters, + ManaParameters, + VersionSignalingParameters, + CongestionControlParameters, +}; diff --git a/bindings/nodejs/lib/types/models/storage-score.ts b/bindings/nodejs/lib/types/models/storage-score.ts index ebfe1bb183..aa9b975136 100644 --- a/bindings/nodejs/lib/types/models/storage-score.ts +++ b/bindings/nodejs/lib/types/models/storage-score.ts @@ -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. diff --git a/bindings/nodejs/tests/client/examples.spec.ts b/bindings/nodejs/tests/client/examples.spec.ts index 365f2fd882..66de590254 100644 --- a/bindings/nodejs/tests/client/examples.spec.ts +++ b/bindings/nodejs/tests/client/examples.spec.ts @@ -1,7 +1,6 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -import { expect, describe, it } from '@jest/globals'; import { Client, utf8ToHex, @@ -215,7 +214,7 @@ describe.skip('Main examples', () => { ), ], }); - + //let payload = await secretManager.signTransaction(prepared); const unsignedBlock = await client.buildBasicBlock("", undefined); const signedBlock = await secretManager.signBlock(unsignedBlock, chain); diff --git a/bindings/nodejs/tests/types/block.spec.ts b/bindings/nodejs/tests/types/block.spec.ts new file mode 100644 index 0000000000..91d13a178c --- /dev/null +++ b/bindings/nodejs/tests/types/block.spec.ts @@ -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); + }); +}); diff --git a/bindings/nodejs/tests/types/protocol_parameters.spec.ts b/bindings/nodejs/tests/types/protocol_parameters.spec.ts index 83a27dff15..cc63ccd212 100644 --- a/bindings/nodejs/tests/types/protocol_parameters.spec.ts +++ b/bindings/nodejs/tests/types/protocol_parameters.spec.ts @@ -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; diff --git a/bindings/nodejs/yarn.lock b/bindings/nodejs/yarn.lock index 4848fd4754..f79b9a09dc 100644 --- a/bindings/nodejs/yarn.lock +++ b/bindings/nodejs/yarn.lock @@ -15,7 +15,7 @@ "@jridgewell/gen-mapping" "^0.3.0" "@jridgewell/trace-mapping" "^0.3.9" -"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.22.13", "@babel/code-frame@^7.23.5": +"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.23.5": version "7.23.5" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.23.5.tgz#9009b69a8c602293476ad598ff53e4562e15c244" integrity sha512-CgH3s1a96LipHCmSUmYFPwY7MNx8C3avkq7i4Wl3cfa662ldtUe4VM1TPXX70pfmrlWTb6jLqTYrZyT2ZTJBgA== @@ -29,20 +29,20 @@ integrity sha512-uU27kfDRlhfKl+w1U6vp16IuvSLtjAxdArVXPa9BvLkrr7CYIsxH5adpHObeAGY/41+syctUWOZ140a2Rvkgjw== "@babel/core@^7.11.6", "@babel/core@^7.12.3": - version "7.23.7" - resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.23.7.tgz#4d8016e06a14b5f92530a13ed0561730b5c6483f" - integrity sha512-+UpDgowcmqe36d4NwqvKsyPMlOLNGMsfMmQ5WGCu+siCe3t3dfe9njrzGfdN4qq+bcNUt0+Vw6haRxBOycs4dw== + version "7.23.9" + resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.23.9.tgz#b028820718000f267870822fec434820e9b1e4d1" + integrity sha512-5q0175NOjddqpvvzU+kDiSOAk4PfdO6FvwCWoQ6RO7rTzEe8vlo+4HVfcnAREhD4npMs0e9uZypjTwzZPCf/cw== dependencies: "@ampproject/remapping" "^2.2.0" "@babel/code-frame" "^7.23.5" "@babel/generator" "^7.23.6" "@babel/helper-compilation-targets" "^7.23.6" "@babel/helper-module-transforms" "^7.23.3" - "@babel/helpers" "^7.23.7" - "@babel/parser" "^7.23.6" - "@babel/template" "^7.22.15" - "@babel/traverse" "^7.23.7" - "@babel/types" "^7.23.6" + "@babel/helpers" "^7.23.9" + "@babel/parser" "^7.23.9" + "@babel/template" "^7.23.9" + "@babel/traverse" "^7.23.9" + "@babel/types" "^7.23.9" convert-source-map "^2.0.0" debug "^4.1.0" gensync "^1.0.0-beta.2" @@ -142,14 +142,14 @@ resolved "https://registry.yarnpkg.com/@babel/helper-validator-option/-/helper-validator-option-7.23.5.tgz#907a3fbd4523426285365d1206c423c4c5520307" integrity sha512-85ttAOMLsr53VgXkTbkx8oA6YTfT4q7/HzXSLEYmjcSTJPMPQtvq1BD79Byep5xMUYbGRzEpDsjUf3dyp54IKw== -"@babel/helpers@^7.23.7": - version "7.23.8" - resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.23.8.tgz#fc6b2d65b16847fd50adddbd4232c76378959e34" - integrity sha512-KDqYz4PiOWvDFrdHLPhKtCThtIcKVy6avWD2oG4GEvyQ+XDZwHD4YQd+H2vNMnq2rkdxsDkU82T+Vk8U/WXHRQ== +"@babel/helpers@^7.23.9": + version "7.23.9" + resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.23.9.tgz#c3e20bbe7f7a7e10cb9b178384b4affdf5995c7d" + integrity sha512-87ICKgU5t5SzOT7sBMfCOZQ2rHjRU+Pcb9BoILMYz600W6DkVRLFBPwQ18gwUVvggqXivaUakpnxWQGbpywbBQ== dependencies: - "@babel/template" "^7.22.15" - "@babel/traverse" "^7.23.7" - "@babel/types" "^7.23.6" + "@babel/template" "^7.23.9" + "@babel/traverse" "^7.23.9" + "@babel/types" "^7.23.9" "@babel/highlight@^7.23.4": version "7.23.4" @@ -160,10 +160,10 @@ chalk "^2.4.2" js-tokens "^4.0.0" -"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.22.15", "@babel/parser@^7.23.6": - version "7.23.6" - resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.23.6.tgz#ba1c9e512bda72a47e285ae42aff9d2a635a9e3b" - integrity sha512-Z2uID7YJ7oNvAI20O9X0bblw7Qqs8Q2hFy0R9tAfnfLkp5MW0UH9eUvnDSnFwKZ0AvgS1ucqR4KzvVHgnke1VQ== +"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.23.9": + version "7.23.9" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.23.9.tgz#7b903b6149b0f8fa7ad564af646c4c38a77fc44b" + integrity sha512-9tcKgqKbs3xGJ+NtKF2ndOBBLVwPjl1SHxPQkd36r3Dlirw3xWUeGaTbqr7uGZcTaxkVNwc+03SVP7aCdWrTlA== "@babel/plugin-syntax-async-generators@^7.8.4": version "7.8.4" @@ -263,19 +263,19 @@ dependencies: "@babel/helper-plugin-utils" "^7.22.5" -"@babel/template@^7.22.15", "@babel/template@^7.3.3": - version "7.22.15" - resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.22.15.tgz#09576efc3830f0430f4548ef971dde1350ef2f38" - integrity sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w== +"@babel/template@^7.22.15", "@babel/template@^7.23.9", "@babel/template@^7.3.3": + version "7.23.9" + resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.23.9.tgz#f881d0487cba2828d3259dcb9ef5005a9731011a" + integrity sha512-+xrD2BWLpvHKNmX2QbpdpsBaWnRxahMwJjO+KZk2JOElj5nSmKezyS1B4u+QbHMTX69t4ukm6hh9lsYQ7GHCKA== dependencies: - "@babel/code-frame" "^7.22.13" - "@babel/parser" "^7.22.15" - "@babel/types" "^7.22.15" + "@babel/code-frame" "^7.23.5" + "@babel/parser" "^7.23.9" + "@babel/types" "^7.23.9" -"@babel/traverse@^7.23.2", "@babel/traverse@^7.23.7": - version "7.23.7" - resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.23.7.tgz#9a7bf285c928cb99b5ead19c3b1ce5b310c9c305" - integrity sha512-tY3mM8rH9jM0YHFGyfC0/xf+SB5eKUu7HPj7/k3fpi9dAlsMc5YbQvDi0Sh2QTPXqMhyaAtzAr807TIyfQrmyg== +"@babel/traverse@^7.23.2", "@babel/traverse@^7.23.9": + version "7.23.9" + resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.23.9.tgz#2f9d6aead6b564669394c5ce0f9302bb65b9d950" + integrity sha512-I/4UJ9vs90OkBtY6iiiTORVMyIhJ4kAVmsKo9KFc8UOxMeUfi2hvtIBsET5u9GizXE6/GFSuKCTNfgCswuEjRg== dependencies: "@babel/code-frame" "^7.23.5" "@babel/generator" "^7.23.6" @@ -283,15 +283,15 @@ "@babel/helper-function-name" "^7.23.0" "@babel/helper-hoist-variables" "^7.22.5" "@babel/helper-split-export-declaration" "^7.22.6" - "@babel/parser" "^7.23.6" - "@babel/types" "^7.23.6" + "@babel/parser" "^7.23.9" + "@babel/types" "^7.23.9" debug "^4.3.1" globals "^11.1.0" -"@babel/types@^7.0.0", "@babel/types@^7.20.7", "@babel/types@^7.22.15", "@babel/types@^7.22.5", "@babel/types@^7.23.0", "@babel/types@^7.23.6", "@babel/types@^7.3.3": - version "7.23.6" - resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.23.6.tgz#be33fdb151e1f5a56877d704492c240fc71c7ccd" - integrity sha512-+uarb83brBzPKN38NX1MkB6vb6+mwvR6amUulqAE7ccQw1pEl+bCia9TbdG1lsnFP7lZySvUn37CHyXQdfTwzg== +"@babel/types@^7.0.0", "@babel/types@^7.20.7", "@babel/types@^7.22.15", "@babel/types@^7.22.5", "@babel/types@^7.23.0", "@babel/types@^7.23.6", "@babel/types@^7.23.9", "@babel/types@^7.3.3": + version "7.23.9" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.23.9.tgz#1dd7b59a9a2b5c87f8b41e52770b5ecbf492e002" + integrity sha512-dQjSq/7HaSjRM43FFGnv5keM2HsxpmyV1PfaSVm0nzzjwwTmjOe6J4bC8e3+pTEIgHaHj+1ZlLThRJ2auc/w1Q== dependencies: "@babel/helper-string-parser" "^7.23.4" "@babel/helper-validator-identifier" "^7.22.20" @@ -773,16 +773,16 @@ integrity sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA== "@types/node@*": - version "20.11.6" - resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.6.tgz#6adf4241460e28be53836529c033a41985f85b6e" - integrity sha512-+EOokTnksGVgip2PbYbr3xnR7kZigh4LbybAfBAw5BpnQ+FqBYUsvCEjYd70IXKlbohQ64mzEYmMtlWUY8q//Q== + version "20.11.10" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.10.tgz#6c3de8974d65c362f82ee29db6b5adf4205462f9" + integrity sha512-rZEfe/hJSGYmdfX9tvcPMYeYPW2sNl50nsw4jZmRcaG0HIAb0WYEpsB05GOb53vjqpyE9GUhlDQ4jLSoB5q9kg== dependencies: undici-types "~5.26.4" "@types/node@^18.15.12": - version "18.19.9" - resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.9.tgz#6c2624c3a05bfa3a2735c533f95597ffacbb5608" - integrity sha512-oZFKlC8l5YtzGQNT4zC2PiSSKzQVZ8bAwwd+EYdPLtyk0nSEq6O16SkK+rkkT2eflDAbormJgEF3QnH3oDrTSw== + version "18.19.10" + resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.10.tgz#4de314ab66faf6bc8ba691021a091ddcdf13a158" + integrity sha512-IZD8kAM02AW1HRDTPOlz3npFava678pr8Ie9Vp8uRhBROXAv8MXT2pCnGZZAKYdromsNQLHQcfWQ6EOatVLtqA== dependencies: undici-types "~5.26.4" @@ -1243,9 +1243,9 @@ aws4@^1.8.0: integrity sha512-NmWvPnx0F1SfrQbYwOi7OeaNGokp9XhzNioJ/CSBs8Qa4vxug81mhJEAVZwxXuBmYB5KDRfMq/F3RR0BIU7sWg== axios@^1.6.5: - version "1.6.6" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.6.tgz#878db45401d91fe9e53aed8ac962ed93bde8dd1c" - integrity sha512-XZLZDFfXKM9U/Y/B4nNynfCRUqNyVZ4sBC/n9GDRCkq9vd2mIvKjKKsbIh1WPmHmNbg6ND7cTBY3Y2+u1G3/2Q== + version "1.6.7" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.7.tgz#7b48c2e27c96f9c68a2f8f31e2ab19f59b06b0a7" + integrity sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA== dependencies: follow-redirects "^1.15.4" form-data "^4.0.0" @@ -1372,12 +1372,12 @@ braces@^3.0.2: fill-range "^7.0.1" browserslist@^4.21.10, browserslist@^4.22.2: - version "4.22.2" - resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.22.2.tgz#704c4943072bd81ea18997f3bd2180e89c77874b" - integrity sha512-0UgcrvQmBDvZHFGdYUehrCNIazki7/lUP3kkoi/r3YB2amZbFM9J43ZRkJTXBUZK4gmx56+Sqk9+Vs9mwZx9+A== + version "4.22.3" + resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.22.3.tgz#299d11b7e947a6b843981392721169e27d60c5a6" + integrity sha512-UAp55yfwNv0klWNapjs/ktHoguxuQNGnOzxYmfnXIS+8AsRDZkSDxg7R1AX3GKzn078SBI5dzwzj/Yx0Or0e3A== dependencies: - caniuse-lite "^1.0.30001565" - electron-to-chromium "^1.4.601" + caniuse-lite "^1.0.30001580" + electron-to-chromium "^1.4.648" node-releases "^2.0.14" update-browserslist-db "^1.0.13" @@ -1452,10 +1452,10 @@ camelcase@^6.2.0: resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.3.0.tgz#5685b95eb209ac9c0c177467778c9c84df58ba9a" integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA== -caniuse-lite@^1.0.30001565: - version "1.0.30001580" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001580.tgz#e3c76bc6fe020d9007647044278954ff8cd17d1e" - integrity sha512-mtj5ur2FFPZcCEpXFy8ADXbDACuNFXg6mxVDqp7tqooX6l3zwm+d8EPoeOSIFRDvHs8qu7/SLFOGniULkcH2iA== +caniuse-lite@^1.0.30001580: + version "1.0.30001581" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001581.tgz#0dfd4db9e94edbdca67d57348ebc070dece279f4" + integrity sha512-whlTkwhqV2tUmP3oYhtNfaWGYHDdS3JYFQBKXxcUR9qqPWsRhFHhoISO2Xnl/g0xyKzht9mI1LZpiNWfMzHixQ== caseless@~0.12.0: version "0.12.0" @@ -1831,10 +1831,10 @@ electron-build-env@^0.2.0: commander "^2.9.0" mkdirp "^0.5.1" -electron-to-chromium@^1.4.601: - version "1.4.645" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.645.tgz#117f964252eb2f0ff00fc7360cb3080e2cf66e3c" - integrity sha512-EeS1oQDCmnYsRDRy2zTeC336a/4LZ6WKqvSaM1jLocEk5ZuyszkQtCpsqvuvaIXGOUjwtvF6LTcS8WueibXvSw== +electron-to-chromium@^1.4.648: + version "1.4.650" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.650.tgz#b38ef9de16991b9f7b924246770576ab91ab3d64" + integrity sha512-sYSQhJCJa4aGA1wYol5cMQgekDBlbVfTRavlGZVr3WZpDdOPcp6a6xUnFfrt8TqZhsBYYbDxJZCjGfHuGupCRQ== emittery@^0.13.1: version "0.13.1" @@ -2175,9 +2175,9 @@ fastest-levenshtein@^1.0.12: integrity sha512-eRnCtTTtGZFpQCwhJiUOuxPQWRXVKYDn0b2PeHfXL6/Zi53SLAzAHfVhVWK2AryC/WH05kGfxhFIPvTF0SXQzg== fastq@^1.6.0: - version "1.16.0" - resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.16.0.tgz#83b9a9375692db77a822df081edb6a9cf6839320" - integrity sha512-ifCoaXsDrsdkWTtiNJX5uzHDsrck5TzfKKDcuFFTIrrc/BS076qgEIfoIy1VeZqViznfKiysPYTh/QeHtnIsYA== + version "1.17.0" + resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.17.0.tgz#ca5e1a90b5e68f97fc8b61330d5819b82f5fab03" + integrity sha512-zGygtijUMT7jnk3h26kUms3BkSDp4IfIKjmnqI2tvx6nuBfiF1UqOxbnLfzdv+apBy+53oaImsKtMw/xYbW+1w== dependencies: reusify "^1.0.4" diff --git a/bindings/python/iota_sdk/__init__.py b/bindings/python/iota_sdk/__init__.py index bb1d14d4e5..f5ee09fd6c 100644 --- a/bindings/python/iota_sdk/__init__.py +++ b/bindings/python/iota_sdk/__init__.py @@ -44,7 +44,6 @@ from .types.payload import * from .types.send_params import * from .types.token_scheme import * -from .types.transaction import * from .types.transaction_with_metadata import * from .types.transaction_data import * from .types.transaction_options import * diff --git a/bindings/python/iota_sdk/client/_utils.py b/bindings/python/iota_sdk/client/_utils.py index 79c9e8007e..e0be939390 100644 --- a/bindings/python/iota_sdk/client/_utils.py +++ b/bindings/python/iota_sdk/client/_utils.py @@ -92,5 +92,5 @@ def block_id(self, block: Block) -> HexStr: """ Return a block ID (Blake2b256 hash of block bytes) from a block. """ return self._call_method('blockId', { - 'block': block.to_dict(), + 'block': block, }) diff --git a/bindings/python/iota_sdk/secret_manager/secret_manager.py b/bindings/python/iota_sdk/secret_manager/secret_manager.py index 07158e3baa..1925fbd635 100644 --- a/bindings/python/iota_sdk/secret_manager/secret_manager.py +++ b/bindings/python/iota_sdk/secret_manager/secret_manager.py @@ -9,9 +9,9 @@ from iota_sdk.types.block.block import Block, UnsignedBlock from iota_sdk.types.common import HexStr from iota_sdk.types.node_info import ProtocolParameters +from iota_sdk.types.payload import SignedTransactionPayload from iota_sdk.types.signature import Ed25519Signature, Bip44 from iota_sdk.types.transaction_data import PreparedTransactionData -from iota_sdk.types.payload import SignedTransactionPayload class LedgerNanoSecretManager(dict): diff --git a/bindings/python/iota_sdk/types/address.py b/bindings/python/iota_sdk/types/address.py index b2ca48ef4a..1bb1eeb958 100644 --- a/bindings/python/iota_sdk/types/address.py +++ b/bindings/python/iota_sdk/types/address.py @@ -36,11 +36,11 @@ class Ed25519Address: Attributes: pub_key_hash: The hex encoded Ed25519 public key hash. """ - pub_key_hash: HexStr type: int = field( default_factory=lambda: int( AddressType.ED25519), init=False) + pub_key_hash: HexStr @json @@ -50,11 +50,11 @@ class AccountAddress: Attributes: account_id: The hex encoded account id. """ - account_id: HexStr type: int = field( default_factory=lambda: int( AddressType.ACCOUNT), init=False) + account_id: HexStr @json @@ -64,8 +64,8 @@ class NFTAddress: Attributes: nft_id: The hex encoded NFT id. """ - nft_id: HexStr type: int = field(default_factory=lambda: int(AddressType.NFT), init=False) + nft_id: HexStr @json @@ -75,11 +75,11 @@ class AnchorAddress: Attributes: anchor_id: The hex encoded anchor id. """ - anchor_id: HexStr type: int = field( default_factory=lambda: int( AddressType.ANCHOR), init=False) + anchor_id: HexStr @json @@ -89,14 +89,14 @@ class ImplicitAccountCreationAddress: Attributes: address: The hex encoded Ed25519 Address. """ - address: Ed25519Address type: int = field(default_factory=lambda: int( AddressType.IMPLICIT_ACCOUNT_CREATION), init=False) + address: Ed25519Address def to_dict(self) -> dict: + """Converts an implicit account creation address to the dictionary representation. """ - Converts an implicit account creation address to the dictionary representation. - """ + return { "type": self.type, "pubKeyHash": self.address.pub_key_hash @@ -104,9 +104,9 @@ def to_dict(self) -> dict: @staticmethod def from_dict(addr_dict: dict): + """Creates an implicit account creation address from a dictionary representation. """ - Creates an implicit account creation address from a dictionary representation. - """ + return ImplicitAccountCreationAddress( Ed25519Address(addr_dict['pubKeyHash'])) @@ -133,10 +133,10 @@ class MultiAddress: addresses: The weighted unlocked addresses. threshold: The threshold that needs to be reached by the unlocked addresses in order to unlock the multi address. """ - addresses: List[WeightedAddress] - threshold: int type: int = field(default_factory=lambda: int( AddressType.MULTI), init=False) + addresses: List[WeightedAddress] + threshold: int @json @@ -147,10 +147,10 @@ class RestrictedAddress: address: The inner restricted Address. allowed_capabilities: The allowed capabilities bitflags. """ - address: Union[Ed25519Address, AccountAddress, NFTAddress] - allowed_capabilities: Optional[HexStr] = field(default=None, init=False) type: int = field(default_factory=lambda: int( AddressType.RESTRICTED), init=False) + address: Union[Ed25519Address, AccountAddress, NFTAddress] + allowed_capabilities: Optional[HexStr] = field(default=None, init=False) def with_allowed_capabilities(self, capabilities: bytes): """Sets the allowed capabilities from a byte array. diff --git a/bindings/python/iota_sdk/types/block/block.py b/bindings/python/iota_sdk/types/block/block.py index ac78ee9ba5..766fcba107 100644 --- a/bindings/python/iota_sdk/types/block/block.py +++ b/bindings/python/iota_sdk/types/block/block.py @@ -3,7 +3,7 @@ from __future__ import annotations from dataclasses import dataclass, field -from typing import TypeAlias, Union +from typing import Any, Dict, TypeAlias, Union from dataclasses_json import config from iota_sdk.utils import Utils from iota_sdk.types.common import HexStr, json, SlotIndex @@ -11,6 +11,7 @@ from iota_sdk.types.signature import Signature from iota_sdk.types.block.body.basic import BasicBlockBody from iota_sdk.types.block.body.validation import ValidationBlockBody +from iota_sdk.types.block.body.type import BlockBodyType @json @@ -52,6 +53,21 @@ class UnsignedBlock: body: BlockBody +def deserialize_block_body(d: Dict[str, Any]) -> BlockBody: + """ + Takes a dictionary as input and returns an instance of a specific class based on the value of the 'type' key in the dictionary. + + Arguments: + * `d`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value. + """ + body_type = d['type'] + if body_type == BlockBodyType.Basic: + return BasicBlockBody.from_dict(d) + if body_type == BlockBodyType.Validation: + return ValidationBlockBody.from_dict(d) + raise Exception(f'invalid block body type: {body_type}') + + @json @dataclass class Block: @@ -64,7 +80,9 @@ class Block: signature: The Block signature. """ header: BlockHeader - body: BlockBody + body: BlockBody = field(metadata=config( + decoder=deserialize_block_body + )) signature: Signature def id(self, params: ProtocolParameters) -> HexStr: diff --git a/bindings/python/iota_sdk/types/block/body/basic.py b/bindings/python/iota_sdk/types/block/body/basic.py index 52a1110189..efea797300 100644 --- a/bindings/python/iota_sdk/types/block/body/basic.py +++ b/bindings/python/iota_sdk/types/block/body/basic.py @@ -7,7 +7,7 @@ from dataclasses_json import config from iota_sdk.types.block.body.type import BlockBodyType from iota_sdk.types.common import HexStr, json -from iota_sdk.types.payload import Payload +from iota_sdk.types.payload import Payload, deserialize_payload @json @@ -23,13 +23,15 @@ class BasicBlockBody: max_burned_mana: The amount of Mana the Account identified by the AccountId is at most willing to burn for this block. payload: The optional payload of this block. """ + type: int = field( + default_factory=lambda: int(BlockBodyType.Basic), + init=False) strong_parents: List[HexStr] max_burned_mana: int = field(metadata=config( encoder=str )) weak_parents: Optional[List[HexStr]] = None shallow_like_parents: Optional[List[HexStr]] = None - payload: Optional[Payload] = None - type: int = field( - default_factory=lambda: int(BlockBodyType.Basic), - init=False) + payload: Optional[Payload] = field(default=None, metadata=config( + decoder=deserialize_payload + )) diff --git a/bindings/python/iota_sdk/types/block/body/validation.py b/bindings/python/iota_sdk/types/block/body/validation.py index b963fcdeb4..130eda5ff3 100644 --- a/bindings/python/iota_sdk/types/block/body/validation.py +++ b/bindings/python/iota_sdk/types/block/body/validation.py @@ -22,11 +22,11 @@ class ValidationBlockBody: highest_supported_version: The highest supported protocol version the issuer of this block supports. protocol_parameters_hash: The hash of the protocol parameters for the Highest Supported Version. """ + type: int = field( + default_factory=lambda: int(BlockBodyType.Validation), + init=False) strong_parents: List[HexStr] highest_supported_version: int protocol_parameters_hash: HexStr weak_parents: Optional[List[HexStr]] = None shallow_like_parents: Optional[List[HexStr]] = None - type: int = field( - default_factory=lambda: int(BlockBodyType.Validation), - init=False) diff --git a/bindings/python/iota_sdk/types/block_issuer_key.py b/bindings/python/iota_sdk/types/block_issuer_key.py index 613ce5fcc1..c2162bf39a 100644 --- a/bindings/python/iota_sdk/types/block_issuer_key.py +++ b/bindings/python/iota_sdk/types/block_issuer_key.py @@ -2,8 +2,8 @@ # SPDX-License-Identifier: Apache-2.0 from enum import IntEnum -from dataclasses import dataclass, field from typing import Any, Dict, List, TypeAlias +from dataclasses import dataclass, field from iota_sdk.types.common import HexStr, json @@ -23,11 +23,11 @@ class Ed25519PublicKeyHashBlockIssuerKey: Attributes: pub_key_hash: The hex encoded Ed25519 public key hash. """ - pub_key_hash: HexStr type: int = field( default_factory=lambda: int( BlockIssuerKeyType.Ed25519PublicKeyHash), init=False) + pub_key_hash: HexStr BlockIssuerKey: TypeAlias = Ed25519PublicKeyHashBlockIssuerKey diff --git a/bindings/python/iota_sdk/types/context_input.py b/bindings/python/iota_sdk/types/context_input.py index 61d3f7cebb..19015f3a28 100644 --- a/bindings/python/iota_sdk/types/context_input.py +++ b/bindings/python/iota_sdk/types/context_input.py @@ -25,11 +25,11 @@ class CommitmentContextInput: type: The type of context input. commitment_id: The commitment identifier to reference. """ - commitment_id: HexStr type: int = field( default_factory=lambda: int( ContextInputType.Commitment), init=False) + commitment_id: HexStr @json @@ -42,11 +42,11 @@ class BlockIssuanceCreditContextInput: type: The type of context input. account_id: The ID of the Account for which this input provides the BIC. """ - account_id: HexStr type: int = field( default_factory=lambda: int( ContextInputType.BlockIssuanceCredit), init=False) + account_id: HexStr @json @@ -58,11 +58,11 @@ class RewardContextInput: type: The type of context input. index: The index of the transaction input for which to claim rewards. """ - index: int type: int = field( default_factory=lambda: int( ContextInputType.Reward), init=False) + index: int ContextInput: TypeAlias = Union[CommitmentContextInput, @@ -76,7 +76,7 @@ def deserialize_context_input(d: Dict[str, Any]) -> ContextInput: Arguments: * `d`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value. """ - context_input_type = dict['type'] + context_input_type = d['type'] if context_input_type == ContextInputType.Commitment: return CommitmentContextInput.from_dict(d) if context_input_type == ContextInputType.BlockIssuanceCredit: diff --git a/bindings/python/iota_sdk/types/feature.py b/bindings/python/iota_sdk/types/feature.py index 01eb0c4abd..5dc4cfb5f5 100644 --- a/bindings/python/iota_sdk/types/feature.py +++ b/bindings/python/iota_sdk/types/feature.py @@ -40,14 +40,14 @@ class SenderFeature: Attributes: address: A given sender address. """ - address: Address = field( - metadata=config( - decoder=deserialize_address - )) type: int = field( default_factory=lambda: int( FeatureType.Sender), init=False) + address: Address = field( + metadata=config( + decoder=deserialize_address + )) @json @@ -57,14 +57,14 @@ class IssuerFeature: Attributes: address: A given issuer address. """ - address: Address = field( - metadata=config( - decoder=deserialize_address - )) type: int = field( default_factory=lambda: int( FeatureType.Issuer), init=False) + address: Address = field( + metadata=config( + decoder=deserialize_address + )) @json @@ -72,13 +72,13 @@ class IssuerFeature: class MetadataFeature: """Defines metadata, arbitrary binary data, that will be stored in the output. Attributes: - data: Some hex encoded metadata. + entries: A key-value map where the keys are graphic ASCII strings and the values hex-encoded binary data. """ - data: HexStr type: int = field( default_factory=lambda: int( FeatureType.Metadata), init=False) + entries: Dict[str, HexStr] @json @@ -88,8 +88,8 @@ class TagFeature: Attributes: tag: A hex encoded tag used to index the output. """ - tag: HexStr type: int = field(default_factory=lambda: int(FeatureType.Tag), init=False) + tag: HexStr @json @@ -99,13 +99,13 @@ class NativeTokenFeature: id: The unique identifier of the native token. amount: The amount of native tokens. """ + type: int = field(default_factory=lambda: int( + FeatureType.NativeToken), init=False) id: HexStr amount: int = field(metadata=config( encoder=hex, decoder=hex_str_decoder, )) - type: int = field(default_factory=lambda: int( - FeatureType.NativeToken), init=False) @json @@ -116,12 +116,12 @@ class BlockIssuerFeature: expiry_slot: The slot index at which the Block Issuer Feature expires and can be removed. block_issuer_keys: The Block Issuer Keys. """ - expiry_slot: SlotIndex - block_issuer_keys: List[BlockIssuerKey] type: int = field( default_factory=lambda: int( FeatureType.BlockIssuer), init=False) + expiry_slot: SlotIndex + block_issuer_keys: List[BlockIssuerKey] @json @@ -134,6 +134,10 @@ class StakingFeature: start_epoch: The epoch index in which the staking started. end_epoch: The epoch index in which the staking ends. """ + type: int = field( + default_factory=lambda: int( + FeatureType.Staking), + init=False) staked_amount: int = field(metadata=config( encoder=str )) @@ -142,10 +146,6 @@ class StakingFeature: )) start_epoch: EpochIndex end_epoch: EpochIndex - type: int = field( - default_factory=lambda: int( - FeatureType.Staking), - init=False) Feature: TypeAlias = Union[SenderFeature, IssuerFeature, diff --git a/bindings/python/iota_sdk/types/input.py b/bindings/python/iota_sdk/types/input.py index 37f515de53..53da298111 100644 --- a/bindings/python/iota_sdk/types/input.py +++ b/bindings/python/iota_sdk/types/input.py @@ -2,8 +2,9 @@ # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations -from dataclasses import dataclass from enum import IntEnum +from typing import Dict, List, TypeAlias, Union, Any +from dataclasses import dataclass, field from iota_sdk.types.common import HexStr, json @@ -26,6 +27,35 @@ class UtxoInput: transaction_id: The transaction id that created the output. transaction_output_index: The output index. """ - type: int + type: int = field( + default_factory=lambda: int( + InputType.Utxo), + init=False) transaction_id: HexStr transaction_output_index: int + + +Input: TypeAlias = Union[UtxoInput] + + +def deserialize_input(d: Dict[str, Any]) -> Input: + """ + Takes a dictionary as input and returns an instance of a specific class based on the value of the 'type' key in the dictionary. + + Arguments: + * `d`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value. + """ + input_type = d['type'] + if input_type == InputType.Utxo: + return UtxoInput.from_dict(d) + raise Exception(f'invalid input type: {input_type}') + + +def deserialize_inputs(dicts: List[Dict[str, Any]]) -> List[Input]: + """ + Takes a list of dictionaries as input and returns a list with specific instances of classes based on the value of the 'type' key in the dictionary. + + Arguments: + * `dicts`: A list of dictionaries that are expected to have a key called 'type' which specifies the type of the returned value. + """ + return list(map(deserialize_input, dicts)) diff --git a/bindings/python/iota_sdk/types/output.py b/bindings/python/iota_sdk/types/output.py index 005ed65c54..51720d9e75 100644 --- a/bindings/python/iota_sdk/types/output.py +++ b/bindings/python/iota_sdk/types/output.py @@ -48,6 +48,10 @@ class BasicOutput: type : The type of output. """ + type: int = field( + default_factory=lambda: int( + OutputType.Basic), + init=False) amount: int = field(metadata=config( encoder=str )) @@ -63,10 +67,6 @@ class BasicOutput: metadata=config( decoder=deserialize_features )) - type: int = field( - default_factory=lambda: int( - OutputType.Basic), - init=False) @json @@ -91,6 +91,10 @@ class AccountOutput: type : The type of output. """ + type: int = field( + default_factory=lambda: int( + OutputType.Account), + init=False) amount: int = field(metadata=config( encoder=str )) @@ -113,10 +117,6 @@ class AccountOutput: metadata=config( decoder=deserialize_features )) - type: int = field( - default_factory=lambda: int( - OutputType.Account), - init=False) @json @@ -141,6 +141,10 @@ class AnchorOutput: type : The type of output. """ + type: int = field( + default_factory=lambda: int( + OutputType.Anchor), + init=False) amount: int = field(metadata=config( encoder=str )) @@ -164,10 +168,6 @@ class AnchorOutput: metadata=config( decoder=deserialize_features )) - type: int = field( - default_factory=lambda: int( - OutputType.Anchor), - init=False) @json @@ -190,6 +190,10 @@ class FoundryOutput: type : The type of output. """ + type: int = field( + default_factory=lambda: int( + OutputType.Foundry), + init=False) amount: int = field(metadata=config( encoder=str )) @@ -204,10 +208,6 @@ class FoundryOutput: metadata=config( decoder=deserialize_features )) - type: int = field( - default_factory=lambda: int( - OutputType.Foundry), - init=False) @json @@ -230,6 +230,7 @@ class NftOutput: type : The type of output. """ + type: int = field(default_factory=lambda: int(OutputType.Nft), init=False) amount: int = field(metadata=config( encoder=str )) @@ -252,7 +253,6 @@ class NftOutput: metadata=config( decoder=deserialize_features )) - type: int = field(default_factory=lambda: int(OutputType.Nft), init=False) @json @@ -269,6 +269,8 @@ class DelegationOutput: unlock_conditions: Define how the output can be unlocked in a transaction. type: The type of output. """ + type: int = field(default_factory=lambda: int( + OutputType.Delegation), init=False) amount: int = field(metadata=config( encoder=str )) @@ -282,8 +284,6 @@ class DelegationOutput: unlock_conditions: List[AddressUnlockCondition] = field(metadata=config( decoder=deserialize_unlock_conditions )) - type: int = field(default_factory=lambda: int( - OutputType.Delegation), init=False) Output: TypeAlias = Union[BasicOutput, diff --git a/bindings/python/iota_sdk/types/payload.py b/bindings/python/iota_sdk/types/payload.py index 5187545c6a..581f17bc45 100644 --- a/bindings/python/iota_sdk/types/payload.py +++ b/bindings/python/iota_sdk/types/payload.py @@ -3,11 +3,16 @@ from __future__ import annotations from enum import IntEnum -from typing import Any, Dict, List, TypeAlias, Union +from typing import Any, Dict, List, Optional, TypeAlias, Union from dataclasses import dataclass, field from dataclasses_json import config -from iota_sdk.types.common import HexStr, json -from iota_sdk.types.transaction import Transaction +from iota_sdk.types.common import HexStr, json, SlotIndex +from iota_sdk.types.mana import ManaAllotment +from iota_sdk.types.input import UtxoInput, deserialize_inputs +from iota_sdk.types.context_input import ContextInput, deserialize_context_inputs +from iota_sdk.types.output import Output, deserialize_outputs + + from iota_sdk.types.unlock import Unlock, deserialize_unlocks @@ -33,12 +38,94 @@ class TaggedDataPayload: tag: The tag part of the tagged data payload. data: The data part of the tagged data payload. """ - tag: HexStr - data: HexStr type: int = field( default_factory=lambda: int( PayloadType.TaggedData), init=False) + tag: HexStr + data: HexStr + + +def deserialize_payload(d: Dict[str, Any]) -> Payload: + """Takes a dictionary as input and returns an instance of a specific class based on the value of the 'type' key in the dictionary. + + Arguments: + * `d`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value. + """ + payload_type = d['type'] + if payload_type == PayloadType.TaggedData: + return TaggedDataPayload.from_dict(d) + if payload_type == PayloadType.SignedTransaction: + return SignedTransactionPayload.from_dict(d) + if payload_type == PayloadType.CandidacyAnnouncement: + return CandidacyAnnouncementPayload.from_dict(d) + raise Exception(f'invalid payload type: {payload_type}') + + +def deserialize_payloads( + dicts: List[Dict[str, Any]]) -> List[Payload]: + """Takes a list of dictionaries as input and returns a list with specific instances of classes based on the value of the 'type' key in the dictionary. + + Arguments: + * `dicts`: A list of dictionaries that are expected to have a key called 'type' which specifies the type of the returned value. + """ + return list(map(deserialize_payload, dicts)) + + +def deserialize_tagged_data_payload(d: Dict[str, Any]) -> Payload: + """Takes a dictionary as input and returns an instance of a specific class based on the value of the 'type' key in the dictionary. + + Arguments: + * `d`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value. + """ + payload_type = d['type'] + if payload_type == PayloadType.TaggedData: + return TaggedDataPayload.from_dict(d) + raise Exception(f'invalid payload type: {payload_type}') + + +@json +@dataclass +class Transaction: + """A transaction consuming inputs, creating outputs and carrying an optional payload. + + Attributes: + network_id: The unique value denoting whether the block was meant for mainnet, shimmer, testnet, or a private network. + It consists of the first 8 bytes of the BLAKE2b-256 hash of the network name. + creation_slot: The slot index in which the transaction was created. + context_inputs: The inputs that provide additional contextual information for the execution of a transaction. + inputs: The inputs to consume in order to fund the outputs of the Transaction Payload. + allotments: The allotments of Mana which which will be added upon commitment of the slot. + capabilities: The capability bitflags of the transaction. + outputs: The outputs that are created by the Transaction Payload + payload: An optional tagged data payload + """ + network_id: str + creation_slot: SlotIndex + inputs: List[UtxoInput] = field(metadata=config( + decoder=deserialize_inputs + )) + outputs: List[Output] = field(metadata=config( + decoder=deserialize_outputs + )) + capabilities: Optional[HexStr] = None + context_inputs: Optional[List[ContextInput]] = field(default=None, metadata=config( + decoder=deserialize_context_inputs + )) + allotments: Optional[List[ManaAllotment]] = None + payload: Optional[Payload] = field(default=None, metadata=config( + decoder=deserialize_tagged_data_payload + )) + + def with_capabilities(self, capabilities: bytes): + """Sets the transaction capabilities from a byte array. + Attributes: + capabilities: The transaction capabilities bitflags. + """ + if any(c != 0 for c in capabilities): + self.capabilities = '0x' + capabilities.hex() + else: + self.capabilities = None @json @@ -50,14 +137,14 @@ class SignedTransactionPayload: transaction: The transaction. unlocks: The unlocks of the transaction. """ - transaction: Transaction - unlocks: List[Unlock] = field(metadata=config( - decoder=deserialize_unlocks - )) type: int = field( default_factory=lambda: int( PayloadType.SignedTransaction), init=False) + transaction: Transaction + unlocks: List[Unlock] = field(metadata=config( + decoder=deserialize_unlocks + )) @json @@ -73,31 +160,3 @@ class CandidacyAnnouncementPayload: Payload: TypeAlias = Union[TaggedDataPayload, SignedTransactionPayload, CandidacyAnnouncementPayload] - - -def deserialize_payload(d: Dict[str, Any]) -> Payload: - """ - Takes a dictionary as input and returns an instance of a specific class based on the value of the 'type' key in the dictionary. - - Arguments: - * `d`: A dictionary that is expected to have a key called 'type' which specifies the type of the returned value. - """ - payload_type = d['type'] - if payload_type == PayloadType.TaggedData: - return TaggedDataPayload.from_dict(d) - if payload_type == PayloadType.SignedTransaction: - return SignedTransactionPayload.from_dict(d) - if payload_type == PayloadType.CandidacyAnnouncement: - return CandidacyAnnouncementPayload.from_dict(d) - raise Exception(f'invalid payload type: {payload_type}') - - -def deserialize_payloads( - dicts: List[Dict[str, Any]]) -> List[Payload]: - """ - Takes a list of dictionaries as input and returns a list with specific instances of classes based on the value of the 'type' key in the dictionary. - - Arguments: - * `dicts`: A list of dictionaries that are expected to have a key called 'type' which specifies the type of the returned value. - """ - return list(map(deserialize_payload, dicts)) diff --git a/bindings/python/iota_sdk/types/signature.py b/bindings/python/iota_sdk/types/signature.py index 1ccf1b3551..6bff6dadf4 100644 --- a/bindings/python/iota_sdk/types/signature.py +++ b/bindings/python/iota_sdk/types/signature.py @@ -16,9 +16,9 @@ class Ed25519Signature: signature: The Ed25519 signature of some message. type: The Ed25519 signature type. """ + type: int = field(default=0, init=False) public_key: HexStr signature: HexStr - type: int = field(default=0, init=False) Signature: TypeAlias = Ed25519Signature diff --git a/bindings/python/iota_sdk/types/token_scheme.py b/bindings/python/iota_sdk/types/token_scheme.py index 3a60e9282d..3e58fb293c 100644 --- a/bindings/python/iota_sdk/types/token_scheme.py +++ b/bindings/python/iota_sdk/types/token_scheme.py @@ -18,6 +18,7 @@ class SimpleTokenScheme: maximum_supply: The maximum supply of the token. type: The type code of the token scheme. """ + type: int = field(default=0, init=False) minted_tokens: int = field(metadata=config( encoder=hex, decoder=hex_str_decoder, @@ -30,7 +31,6 @@ class SimpleTokenScheme: encoder=hex, decoder=hex_str_decoder, )) - type: int = field(default=0, init=False) TokenScheme: TypeAlias = SimpleTokenScheme diff --git a/bindings/python/iota_sdk/types/transaction.py b/bindings/python/iota_sdk/types/transaction.py deleted file mode 100644 index ed7db9fe23..0000000000 --- a/bindings/python/iota_sdk/types/transaction.py +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright 2023 IOTA Stiftung -# SPDX-License-Identifier: Apache-2.0 - -from __future__ import annotations -from typing import TYPE_CHECKING, Optional, List - -from dataclasses import dataclass, field - -from iota_sdk.types.common import HexStr, json, SlotIndex -from iota_sdk.types.mana import ManaAllotment -from iota_sdk.types.input import UtxoInput -from iota_sdk.types.context_input import ContextInput -from iota_sdk.types.output import Output - -# Required to prevent circular import -if TYPE_CHECKING: - from iota_sdk.types.payload import Payload - - -@json -@dataclass -class Transaction: - """A transaction consuming inputs, creating outputs and carrying an optional payload. - - Attributes: - network_id: The unique value denoting whether the block was meant for mainnet, shimmer, testnet, or a private network. - It consists of the first 8 bytes of the BLAKE2b-256 hash of the network name. - creation_slot: The slot index in which the transaction was created. - context_inputs: The inputs that provide additional contextual information for the execution of a transaction. - inputs: The inputs to consume in order to fund the outputs of the Transaction Payload. - allotments: The allotments of Mana which which will be added upon commitment of the slot. - capabilities: The capability bitflags of the transaction. - outputs: The outputs that are created by the Transaction Payload - payload: An optional tagged data payload - """ - network_id: str - creation_slot: SlotIndex - inputs: List[UtxoInput] - capabilities: Optional[HexStr] = field(default=None, init=False) - outputs: List[Output] - context_inputs: Optional[List[ContextInput]] = None - allotments: Optional[List[ManaAllotment]] = None - payload: Optional[Payload] = None - - def with_capabilities(self, capabilities: bytes): - """Sets the transaction capabilities from a byte array. - Attributes: - capabilities: The transaction capabilities bitflags. - """ - if any(c != 0 for c in capabilities): - self.capabilities = '0x' + capabilities.hex() - else: - self.capabilities = None diff --git a/bindings/python/iota_sdk/types/transaction_data.py b/bindings/python/iota_sdk/types/transaction_data.py index 0f38781bb4..2b1d09c4d3 100644 --- a/bindings/python/iota_sdk/types/transaction_data.py +++ b/bindings/python/iota_sdk/types/transaction_data.py @@ -7,8 +7,7 @@ from iota_sdk.types.address import Address from iota_sdk.types.output import Output from iota_sdk.types.output_metadata import OutputMetadata -from iota_sdk.types.transaction import Transaction -from iota_sdk.types.payload import SignedTransactionPayload +from iota_sdk.types.payload import Transaction, SignedTransactionPayload from iota_sdk.types.signature import Bip44 from iota_sdk.types.common import json diff --git a/bindings/python/iota_sdk/types/unlock.py b/bindings/python/iota_sdk/types/unlock.py index 507bc35118..5cb7a33fc9 100644 --- a/bindings/python/iota_sdk/types/unlock.py +++ b/bindings/python/iota_sdk/types/unlock.py @@ -37,11 +37,11 @@ class UnlockType(IntEnum): class SignatureUnlock: """An unlock holding a signature unlocking one or more inputs. """ - signature: Ed25519Signature type: int = field( default_factory=lambda: int( UnlockType.Signature), init=False) + signature: Ed25519Signature @json @@ -49,11 +49,11 @@ class SignatureUnlock: class ReferenceUnlock: """An unlock which must reference a previous unlock which unlocks also the input at the same index as this Reference Unlock. """ - reference: int type: int = field( default_factory=lambda: int( UnlockType.Reference), init=False) + reference: int @json @@ -61,11 +61,11 @@ class ReferenceUnlock: class AccountUnlock: """An unlock which must reference a previous unlock which unlocks the account that the input is locked to. """ - reference: int type: int = field( default_factory=lambda: int( UnlockType.Account), init=False) + reference: int @json @@ -73,11 +73,11 @@ class AccountUnlock: class AnchorUnlock: """An unlock which must reference a previous unlock which unlocks the anchor that the input is locked to. """ - reference: int type: int = field( default_factory=lambda: int( UnlockType.Anchor), init=False) + reference: int @json @@ -85,8 +85,8 @@ class AnchorUnlock: class NftUnlock: """An unlock which must reference a previous unlock which unlocks the NFT that the input is locked to. """ - reference: int type: int = field(default_factory=lambda: int(UnlockType.Nft), init=False) + reference: int # pylint: disable=missing-function-docstring,unused-argument @@ -101,13 +101,13 @@ def deserialize_unlocks(dicts: List[Dict[str, Any]]) -> List[Unlock]: class MultiUnlock: """Unlocks a MultiAddress with a list of other unlocks. """ - unlocks: List[Unlock] = field(metadata=config( - decoder=deserialize_unlocks - )) type: int = field( default_factory=lambda: int( UnlockType.Multi), init=False) + unlocks: List[Unlock] = field(metadata=config( + decoder=deserialize_unlocks + )) @json @@ -156,8 +156,9 @@ def deserialize_unlock(d: Dict[str, Any]) -> Unlock: return EmptyUnlock.from_dict(d) raise Exception(f'invalid unlock type: {unlock_type}') - # pylint: disable=function-redefined + + def deserialize_unlocks(dicts: List[Dict[str, Any]]) -> List[Unlock]: """ Takes a list of dictionaries as input and returns a list with specific instances of classes based on the value of the 'type' key in the dictionary. diff --git a/bindings/python/iota_sdk/types/unlock_condition.py b/bindings/python/iota_sdk/types/unlock_condition.py index 92972d95ed..e553b2c069 100644 --- a/bindings/python/iota_sdk/types/unlock_condition.py +++ b/bindings/python/iota_sdk/types/unlock_condition.py @@ -39,14 +39,14 @@ class AddressUnlockCondition: Args: address: An address unlocked with a private key. """ - address: Address = field( - metadata=config( - decoder=deserialize_address - )) type: int = field( default_factory=lambda: int( UnlockConditionType.Address), init=False) + address: Address = field( + metadata=config( + decoder=deserialize_address + )) @json @@ -57,6 +57,8 @@ class StorageDepositReturnUnlockCondition: amount: The amount of base coins the consuming transaction must deposit to `return_address`. return_address: The address to return the amount to. """ + type: int = field(default_factory=lambda: int( + UnlockConditionType.StorageDepositReturn), init=False) amount: int = field(metadata=config( encoder=str )) @@ -64,8 +66,6 @@ class StorageDepositReturnUnlockCondition: metadata=config( decoder=deserialize_address )) - type: int = field(default_factory=lambda: int( - UnlockConditionType.StorageDepositReturn), init=False) @json @@ -75,11 +75,11 @@ class TimelockUnlockCondition: Args: slot_index: Slot index that defines when the output can be consumed. """ - slot_index: SlotIndex type: int = field( default_factory=lambda: int( UnlockConditionType.Timelock), init=False) + slot_index: SlotIndex @json @@ -91,15 +91,15 @@ class ExpirationUnlockCondition: after that only the address defined in Return Address. return_address: The return address if the output was not claimed in time. """ + type: int = field( + default_factory=lambda: int( + UnlockConditionType.Expiration), + init=False) slot_index: SlotIndex return_address: Address = field( metadata=config( decoder=deserialize_address )) - type: int = field( - default_factory=lambda: int( - UnlockConditionType.Expiration), - init=False) @json @@ -109,12 +109,12 @@ class StateControllerAddressUnlockCondition: Args: address: The state controller address that owns the output. """ + type: int = field(default_factory=lambda: int( + UnlockConditionType.StateControllerAddress), init=False) address: Address = field( metadata=config( decoder=deserialize_address )) - type: int = field(default_factory=lambda: int( - UnlockConditionType.StateControllerAddress), init=False) @json @@ -124,12 +124,12 @@ class GovernorAddressUnlockCondition: Args: address: The governor address that owns the output. """ + type: int = field(default_factory=lambda: int( + UnlockConditionType.GovernorAddress), init=False) address: Address = field( metadata=config( decoder=deserialize_address )) - type: int = field(default_factory=lambda: int( - UnlockConditionType.GovernorAddress), init=False) @json @@ -139,9 +139,9 @@ class ImmutableAccountAddressUnlockCondition: Args: address: The permanent account address that owns this output. """ - address: AccountAddress type: int = field(default_factory=lambda: int( UnlockConditionType.ImmutableAccountAddress), init=False) + address: AccountAddress UnlockCondition: TypeAlias = Union[AddressUnlockCondition, StorageDepositReturnUnlockCondition, TimelockUnlockCondition, diff --git a/bindings/python/iota_sdk/utils.py b/bindings/python/iota_sdk/utils.py index 2e6d5719e2..a5880784f3 100644 --- a/bindings/python/iota_sdk/utils.py +++ b/bindings/python/iota_sdk/utils.py @@ -10,14 +10,13 @@ from iota_sdk.types.address import Address, deserialize_address from iota_sdk.types.common import HexStr from iota_sdk.types.decayed_mana import DecayedMana -from iota_sdk.types.transaction import Transaction +from iota_sdk.types.payload import Transaction, SignedTransactionPayload from iota_sdk.types.node_info import ProtocolParameters from iota_sdk.types.output import Output from iota_sdk.types.output_id import OutputId from iota_sdk.types.unlock import Unlock -from iota_sdk.external import call_utils_method -from iota_sdk.types.payload import SignedTransactionPayload from iota_sdk.types.transaction_data import InputSigningData +from iota_sdk.external import call_utils_method # Required to prevent circular import if TYPE_CHECKING: @@ -171,7 +170,7 @@ def block_id(block: Block, params: ProtocolParameters) -> HexStr: """ return _call_method('blockId', { 'block': block, - 'protocol_parameters': params, + 'protocolParameters': params, }) @staticmethod diff --git a/bindings/python/tests/test_block.py b/bindings/python/tests/test_block.py index 87c751bc44..560ce1480c 100644 --- a/bindings/python/tests/test_block.py +++ b/bindings/python/tests/test_block.py @@ -1,299 +1,39 @@ # Copyright 2023 IOTA Stiftung # SPDX-License-Identifier: Apache-2.0 -from typing import get_args -import pytest -from iota_sdk import BasicBlockBody, BlockBodyType, Block, Payload, PayloadType - - -def test_basic_block_with_tagged_data_payload(): - block_dict = { - "type": 0, - "strongParents": [ - "0x17c297a273facf4047e244a65eb34ee33b1f1698e1fff28679466fa2ad81c0e8", - "0x9858e80fa0b37b6d9397e23d1f58ce53955a9be1aa8020c0d0e11672996c6db9"], - "weakParents": [], - "shallowLikeParents": [], - "maxBurnedMana": "180500", - "payload": { - "type": 0, - "tag": "0x484f524e4554205370616d6d6572", - "data": "0x57652061726520616c6c206d616465206f662073746172647573742e0a436f756e743a20353436333730330a54696d657374616d703a20323032332d30372d31395430373a32323a32385a0a54697073656c656374696f6e3a20343732c2b573"}} - block = BasicBlockBody.from_dict(block_dict) - assert block.to_dict() == block_dict - assert isinstance(block.payload, get_args(Payload)) - assert block.payload.type == PayloadType.TaggedData - assert block.max_burned_mana == 180500 - - block_to_dict = block.to_dict() - # Make sure encoding is done correctly - assert block_to_dict == block_dict - - -def test_block_with_tagged_data_payload(): - block_dict = { - "header": { - "protocolVersion": 3, - "networkId": "10549460113735494767", - "issuingTime": "1675563954966263210", - "slotCommitmentId": "0x498bf08a5ed287bc87340341ffab28706768cd3a7035ae5e33932d9a12bb30940000000000000000", - "latestFinalizedSlot": 21, - "issuerId": "0x3370746f30705b7d0b42597459714d45241e5a64761b09627c447b751c7e145c", - }, - "body": { - "type": 0, - "strongParents": [ - "0x304442486c7a05361408585e4b5f7a67441c437528755a70041e0e557a6d4b2d7d4362083d492b57", - "0x5f736978340a243d381b343b160b316a6b7d4b1e3c0355492e2e72113c2b126600157e69113c0b5c" - ], - "weakParents": [ - "0x0b5a48384f382f4a49471c4860683c6f0a0d446f012e1b117c4e405f5e24497c72691f43535c0b42" - ], - "shallowLikeParents": [ - "0x163007217803006078040b0f51507d3572355a457839095e572f125500401b7d220c772b56165a12" - ], - "maxBurnedMana": "180500", - "payload": { - "type": 0, - "tag": "0x68656c6c6f20776f726c64", - "data": "0x01020304" - } - }, - "signature": { - "type": 0, - "publicKey": "0x024b6f086177156350111d5e56227242034e596b7e3d0901180873740723193c", - "signature": "0x7c274e5e771d5d60202d334f06773d3672484b1e4e6f03231b4e69305329267a4834374b0f2e0d5c6c2f7779620f4f534c773b1679400c52303d1f23121a4049" - } - } - block = Block.from_dict(block_dict) - assert block.to_dict() == block_dict - assert isinstance(block.body, BasicBlockBody) - assert block.body.type == BlockBodyType.Basic - assert isinstance(block.body.payload, get_args(Payload)) - assert block.body.payload.type == PayloadType.TaggedData - # TODO: determine the actual hash of the block - # assert block.id() == "0x7ce5ad074d4162e57f83cfa01cd2303ef5356567027ce0bcee0c9f57bc11656e" - - -@pytest.mark.skip(reason="https://github.com/iotaledger/iota-sdk/issues/1387") -def test_basic_block_with_tx_payload(): - block_dict = { - "type": 0, - "strongParents": ["0x27532565d4c8cc886dfc6a2238e8d2a72369672bb1d1d762c33b72d41b0b07b8", - "0x604e6996bd1ec110642fec5b9c980d4b126eba5683e80a6e2cb905ded0cebd98", - "0x6a14368f99e875aee0e7078d9e2ec2ba6c4fff6a3cd63c73a9b2c296d4a8e697", - "0xc3f20eb06ce8be091579e2fbe6c109d108983fb0eff2c768e98c61e6fe71b4b7"], - "weakParents": [], - "shallowLikeParents": [], - "maxBurnedMana": "180500", - "payload": {"type": 1, - "transaction": { - "networkId": "1856588631910923207", - "inputs": [{"type": 0, - "transactionId": "0xc6765035e75e319e9cd55ab16e7619f6cd658e7f421c71d9fe276c77fdf3f5b3", - "transactionOutputIndex": 1}], - "outputs": [{"type": 3, - "amount": "1000000", - "unlockConditions": [{"type": 0, - "address": {"type": 0, - "pubKeyHash": "0xa119005b26d46fc74cf9188b3cef8d01623e68146741ee698cabefd425dc01be"}}]}, - {"type": 3, - "amount": "995000000", - "unlockConditions": [{"type": 0, - "address": {"type": 0, - "pubKeyHash": "0xa119005b26d46fc74cf9188b3cef8d01623e68146741ee698cabefd425dc01be"}}]}]}, - "unlocks": [{"type": 0, - "signature": {"type": 0, - "publicKey": "0xa7af600976f440ec97d7bddbf17eacf0bfbf710e8cfb4ae3eae475d4ae8e1b16", - "signature": "0x6bbe2eed95300a3d707af1bb17e04f83087fe31261256020fd00c24a54543c084079bed29c6d1479ee5acfd1e2fa32316e88c4c1577b4fbea3fe247f71114500"}}]}} - block = BasicBlockBody.from_dict(block_dict) - assert block.to_dict() == block_dict - assert isinstance(block.payload, get_args(Payload)) - assert block.payload.type == PayloadType.SignedTransaction - - -@pytest.mark.skip(reason="https://github.com/iotaledger/iota-sdk/issues/1387") -def test_basic_block_with_tx_payload_all_output_types(): - block_dict = { - "type": 0, - "strongParents": [ - "0x053296e7434e8a4d602f8db30a5aaf16c01140212fe79d8132137cda1c38a60a", "0x559ec1d9a31c55bd27588ada2ade70fb5b13764ddd600e29c3b018761ba30e15", "0xe78e8cdbbeda89e3408eed51b77e0db5ba035f5f3bf79a8365435bba40697693", "0xee9d6e45dbc080694e6c827fecbc31ad9f654cf57404bc98f4cbca033f8e3139"], "weakParents": [], "shallowLikeParents": [], "payload": { - "type": 1, "transaction": { - "networkId": "1856588631910923207", "inputs": [ - { - "type": 0, "transactionId": "0xa49f5a764c3fe22f702b5b238a75a648faae1863f61c14fac51ba58d26acb823", "transactionOutputIndex": 9}, { - "type": 0, "transactionId": "0x6f23b39ebe433f8b522d2e4360186cd3e6b21baf46c0a591c801161e505330b4", "transactionOutputIndex": 0}, { - "type": 0, "transactionId": "0x6f23b39ebe433f8b522d2e4360186cd3e6b21baf46c0a591c801161e505330b4", "transactionOutputIndex": 1}, { - "type": 0, "transactionId": "0x6f23b39ebe433f8b522d2e4360186cd3e6b21baf46c0a591c801161e505330b4", "transactionOutputIndex": 2}], "inputsCommitment": "0xb6913235037feeeb74ea54ca0354bd7daee95e5a4fc65b67c960e5f0df6a339f", "outputs": [ - { - "type": 4, "amount": "1000000", "accountId": "0xf90a577f1bae4587fdb00752a847b3a2a9d623743993e9e7abdd0440a004caee", "foundryCounter": 1, "unlockConditions": [ - { - "type": 4, "address": { - "type": 0, "pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"}}, { - "type": 5, "address": { - "type": 0, "pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"}}], "features": [ - { - "type": 0, "address": { - "type": 0, "pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"}}, { - "type": 2, "data": "0x010203"}], "immutableFeatures": [ - { - "type": 1, "address": { - "type": 0, "pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"}}]}, { - "type": 5, "amount": "1000000", "serialNumber": 1, "tokenScheme": { - "type": 0, "mintedTokens": "0x32", "meltedTokens": "0x0", "maximumSupply": "0x64"}, "unlockConditions": [ - { - "type": 6, "address": { - "type": 8, "accountId": "0xf90a577f1bae4587fdb00752a847b3a2a9d623743993e9e7abdd0440a004caee"}}]}, { - "type": 6, "amount": "1000000", "nftId": "0xbe01be2aa284eb07d1ec4ab8099c86c6cac38d8207d440dafa9560feeac49c62", "unlockConditions": [ - { - "type": 0, "address": { - "type": 0, "pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"}}]}, { - "type": 3, "amount": "1000000", "nativeTokens": [ - { - "id": "0x08f90a577f1bae4587fdb00752a847b3a2a9d623743993e9e7abdd0440a004caee0100000000", "amount": "0x32"}], "unlockConditions": [ - { - "type": 0, "address": { - "type": 0, "pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"}}]}, { - "type": 3, "amount": "1000000", "unlockConditions": [ - { - "type": 0, "address": { - "type": 0, "pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"}}]}, { - "type": 3, "amount": "1000000", "unlockConditions": [ - { - "type": 0, "address": { - "type": 0, "pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"}}], "features": [ - { - "type": 2, "data": "0x0d25"}]}, { - "type": 3, "amount": "234100", "unlockConditions": [ - { - "type": 0, "address": { - "type": 0, "pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"}}, { - "type": 1, "returnAddress": { - "type": 0, "pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"}, "amount": "234000"}]}, { - "type": 3, "amount": "1000000", "unlockConditions": [ - { - "type": 0, "address": { - "type": 0, "pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"}}, { - "type": 3, "returnAddress": { - "type": 0, "pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"}, "slotIndex": 1}]}, { - "type": 3, "amount": "1000000", "unlockConditions": [ - { - "type": 0, "address": { - "type": 0, "pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"}}, { - "type": 2, "slotIndex": 1}]}, { - "type": 3, "amount": "5578452198", "nativeTokens": [ - { - "id": "0x080021bcfa2252a500348f73c939722d65c0354eab33b753ab09bc80a7f592c9a40100000000", "amount": "0x41"}, { - "id": "0x0808fb702d67fdb320b5959f152c0f962630515d904c71ed09447c341a6cc171de0100000000", "amount": "0x50"}, { - "id": "0x0808fb702d67fdb320b5959f152c0f962630515d904c71ed09447c341a6cc171de0200000000", "amount": "0x64"}, { - "id": "0x0808fb702d67fdb320b5959f152c0f962630515d904c71ed09447c341a6cc171de0300000000", "amount": "0x64"}, { - "id": "0x080906d8ff0afdcb941cd3867186c8f23d5c889c7a1a8842a001871c8f76bcaf890100000000", "amount": "0xa"}, { - "id": "0x08179dc4b298721f8bb60a591d5a00edc6e62ed941c133c4a4415b1ccc7d3804d90100000000", "amount": "0x42"}, { - "id": "0x081d30f89a8655ce7514b5724ebae8c8f2160a223a6d8c91edca72de5e1477337b0100000000", "amount": "0x1a"}, { - "id": "0x0822ceb3166ad125d310e6660f5fc292356f87f2f9566e982ea22154cec3847b3f0100000000", "amount": "0x64"}, { - "id": "0x0822ceb3166ad125d310e6660f5fc292356f87f2f9566e982ea22154cec3847b3f0200000000", "amount": "0x3e8"}, { - "id": "0x08261d3aa7f731a9ff784d6f239bfdc505bbe9902d8eace89c91c8e58429c200cb0100000000", "amount": "0x42"}, { - "id": "0x082a1d58d3d725f9d3af50699c2cfa022274b199a9f4060b2331bf059e285bd2730100000000", "amount": "0x313030"}, { - "id": "0x082ae3fdb7c757dbaae9d9463b63e7e3897f145c8c4a149bfe0ce4d316dc78f2500100000000", "amount": "0x1a"}, { - "id": "0x082ae3fdb7c757dbaae9d9463b63e7e3897f145c8c4a149bfe0ce4d316dc78f2500200000000", "amount": "0x3d2"}, { - "id": "0x082cdf4c519401df914bf8ab3ebd1a1bb18da5babe7be82188f586a9c9a7bbdc160100000000", "amount": "0x64"}, { - "id": "0x083156fbacf47e0b3ccaa5f4ffcbb9ae333fefcb4016261edfb302668eae242b050100000000", "amount": "0x64"}, { - "id": "0x0833b41872b4ef228c10a99456fb08088a52a71f3ff23330287f6c8978bc5dd6df0100000000", "amount": "0x64"}, { - "id": "0x083637f9940377b8e461d66e09f73e61b4186dd63deca2ed518b8ea87c410492e80100000000", "amount": "0x3c"}, { - "id": "0x083c39ef7bd9a2eb640df6a36319a7fd51d4ca190ffd5d14572c9ebb54bdc6ecab0100000000", "amount": "0x64"}, { - "id": "0x083c39ef7bd9a2eb640df6a36319a7fd51d4ca190ffd5d14572c9ebb54bdc6ecab0200000000", "amount": "0x45"}, { - "id": "0x08475073881df12705fc6f18f228385ac3d499d21e5e36333c78f3c7e124c4b1e60100000000", "amount": "0x64"}, { - "id": "0x084bd1dbdfecb771b4c56aa196cf90ca722ef489f5c12f2e11adb0fad4da8020060100000000", "amount": "0x5a"}, { - "id": "0x084bd1dbdfecb771b4c56aa196cf90ca722ef489f5c12f2e11adb0fad4da8020060200000000", "amount": "0x64"}, { - "id": "0x084bd1dbdfecb771b4c56aa196cf90ca722ef489f5c12f2e11adb0fad4da8020060300000000", "amount": "0x64"}, { - "id": "0x0856ed1d7e6c86cf41c2978a700db8fe2686500f7d6e35f7ef15aecdb799833e5c0100000000", "amount": "0x64"}, { - "id": "0x085c6b799750bdf7e5a5c81144465a0676bc11dab74b997444ca369949341720e80100000000", "amount": "0x64"}, { - "id": "0x085fbfe07b06a54fda8ab7b6c72c49a34c4dcafaf1e5ba1f145fb06da1bba72a8d0100000000", "amount": "0xa"}, { - "id": "0x086a62922fd743b541c987020d2cb2942cf789bcefe41572854119180cb8e037a90100000000", "amount": "0x46"}, { - "id": "0x086f7011adb53642e8ed7db230c2307fe980f4aff2685c22f7c84a61ec558f691b0100000000", "amount": "0x3c"}, { - "id": "0x086f7011adb53642e8ed7db230c2307fe980f4aff2685c22f7c84a61ec558f691b0200000000", "amount": "0x3de"}, { - "id": "0x0871493f8559908cf5825e1a0334fa184f0e8b42136e472ec7e2e8127bc14202f70100000000", "amount": "0x46"}, { - "id": "0x08722b1bf4f0295866c8bc75590d83b7422e47739e4b0048126fae45d0b5d330f90100000000", "amount": "0x64"}, { - "id": "0x08722b1bf4f0295866c8bc75590d83b7422e47739e4b0048126fae45d0b5d330f90200000000", "amount": "0x3e8"}, { - "id": "0x089694cbf1a422b1262d3b34810b7b0a53f49b6b0856388f8121b5d681b23c38e10100000000", "amount": "0x14"}, { - "id": "0x089694cbf1a422b1262d3b34810b7b0a53f49b6b0856388f8121b5d681b23c38e10200000000", "amount": "0x64"}, { - "id": "0x089694cbf1a422b1262d3b34810b7b0a53f49b6b0856388f8121b5d681b23c38e10300000000", "amount": "0x3e8"}, { - "id": "0x089694cbf1a422b1262d3b34810b7b0a53f49b6b0856388f8121b5d681b23c38e10400000000", "amount": "0x64"}, { - "id": "0x089786a7641d1268cb3b1cc7b514828f1511e3ae0b885835d284d3af85e1c3d3950100000000", "amount": "0x3e8"}, { - "id": "0x0897e215b1e3ccb05c63842dc38db5007241cca966f341d674db2d9e886dc0ed410100000000", "amount": "0x64"}, { - "id": "0x089ad7373abf3a4dda4a8a2e64b112ac25dca24efcf51346f8b2d0212961234d0b0100000000", "amount": "0x64"}, { - "id": "0x089c130fa264a23492f5876e4c2673154689fa8e30945c7b60c59050b20336d2b70100000000", "amount": "0x32"}, { - "id": "0x089c130fa264a23492f5876e4c2673154689fa8e30945c7b60c59050b20336d2b70200000000", "amount": "0x64"}, { - "id": "0x089cfeccd4b71fc3d425755d972c1671346903dab3fda81ee54b807b752487d8250100000000", "amount": "0x3e8"}, { - "id": "0x08aa2f74dc19d68bd3eb44f5b6648548b42b55f88c62374993301fd15c9ccf21270100000000", "amount": "0x32"}, { - "id": "0x08aa2f74dc19d68bd3eb44f5b6648548b42b55f88c62374993301fd15c9ccf21270200000000", "amount": "0x31303030"}, { - "id": "0x08ac83d1ce645b025a4a412f22e573973aadb50de1f8407d87b3cca4ed3e779a360100000000", "amount": "0x28"}, { - "id": "0x08d1bcfd507246eac6d93fee125e36e5eb8f62afc25bfff09785b6bcc560cf5dc00100000000", "amount": "0x3e8"}, { - "id": "0x08dc44610c24f32f26330440f3f0d4afb562a8dfd81afe7c2f79024f8f1b9e21940100000000", "amount": "0x63"}, { - "id": "0x08dda479a9d366af826f1a8e3f3290a6c230c39b8d2d1ba165bf737c71856e92640100000000", "amount": "0x14"}, { - "id": "0x08ea1cab7a1ba4ae5bdca654fdfe618fc92337030ecbae1d1f6b2b1fe4c6b569940200000000", "amount": "0x64"}, { - "id": "0x08ec6d781c5bdb7faebfa66dc529dc46e82a26fb90c5a5de07ee77d357d62529360100000000", "amount": "0x32"}, { - "id": "0x08f1802858831220b282ccc4c557676d61f79833869de378ce9a81f736976ce39f0100000000", "amount": "0x32"}, { - "id": "0x08f708a29e9619e847916de76c2e167e87a704c235dcbd7cda018865be7f561b5a0100000000", "amount": "0x4c"}, { - "id": "0x08f708a29e9619e847916de76c2e167e87a704c235dcbd7cda018865be7f561b5a0200000000", "amount": "0x20"}, { - "id": "0x08fb64703098e00d81c5962f28d8504eae5998cf99ab4e37af0d3ea99180b2f6580100000000", "amount": "0x14"}, { - "id": "0x08fe4090ca7623deffc5a570898d0844fe9f4763175af2c88a00958b26525b2b420100000000", "amount": "0x22"}], "unlockConditions": [ - { - "type": 0, "address": { - "type": 0, "pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"}}]}]}, "unlocks": [ - { - "type": 0, "signature": { - "type": 0, "publicKey": "0x67b7fc3f78763c9394fc4fcdb52cf3a973b6e064bdc3defb40a6cb2c880e6f5c", "signature": "0xc9ec7eba19c11b7a76f33a7781415a2f28fc3cf077fff4627f8c49604c77a5c6b4b4688a56bbe6e35a38bd97f1d03f5589050bd1f3372fc0ad57f8cb26f0da0e"}}, { - "type": 1, "reference": 0}, { - "type": 2, "reference": 1}, { - "type": 1, "reference": 0}]}} - block = BasicBlockBody.from_dict(block_dict) - assert block.to_dict() == block_dict - assert isinstance(block.payload, get_args(Payload)) - assert block.payload.type == PayloadType.SignedTransaction - - -@pytest.mark.skip(reason="https://github.com/iotaledger/iota-sdk/issues/1387") -def test_basic_block_with_tx_payload_with_tagged_data_payload(): - block_dict = { - "type": 0, - "strongParents": ["0x4bbba1f1fbfa58d8e65c018d0518da1c3ab57f05ffdd9c2e20565a99b42948df", - "0x9962a18f0161f6b883cb1e36b936684793867d97dc9ac226a929d8e434385e96", - "0xe532853c4a1e03e00a37c78a42afebf3570b1bb4a756c5ad651c0f0377548348", - "0xedbd8bd428bcff342de0656e368a881022dd353b51f272ed40c604c86915d97d"], - "weakParents": [], - "shallowLikeParents": [], - "maxBurnedMana": "180500", - "payload": {"type": 1, - "transaction": { - "networkId": "1856588631910923207", - "inputs": [{"type": 0, - "transactionId": "0xeccfbdb73c0a4c9c0301b53a17e5aa301fbf0b079db9e88ff0e32e9e64214b28", - "transactionOutputIndex": 5}, - {"type": 0, - "transactionId": "0xf8052938858750c9c69b92b615a685fa2bb5833912b264142fc724e9510b0d0e", - "transactionOutputIndex": 0}], - "inputsCommitment": "0x9702f2a625db14db2f67289828a9fdbe342477393572b9165b19964b2449061a", - "outputs": [{"type": 3, - "amount": "1000000", - "unlockConditions": [{"type": 0, - "address": {"type": 0, - "pubKeyHash": "0x60200bad8137a704216e84f8f9acfe65b972d9f4155becb4815282b03cef99fe"}}]}, - {"type": 3, - "amount": "50600", - "unlockConditions": [{"type": 0, - "address": {"type": 0, - "pubKeyHash": "0x74e8b1f10396eb5e8aeb16d666416802722436a88b5dd1a88e59c170b724c9cc"}}]}], - "payload": {"type": 5, - "tag": "0x746167", - "data": "0x64617461"}}, - "unlocks": [{"type": 0, - "signature": {"type": 0, - "publicKey": "0x67b7fc3f78763c9394fc4fcdb52cf3a973b6e064bdc3defb40a6cb2c880e6f5c", - "signature": "0x30cb012af3402be1b4b2ed18e2aba86839da06ba38ff3277c481e17c003f0199ba26f5613199e0d24035628bb2b69a6ea2a7682e41c30244996baf3a2adc1c00"}}, - {"type": 1, - "reference": 0}]}} - block = BasicBlockBody.from_dict(block_dict) - assert block.to_dict() == block_dict - assert isinstance(block.payload, get_args(Payload)) - assert block.payload.type == PayloadType.SignedTransaction +import json +from iota_sdk import Block, ProtocolParameters + +protocol_params_json = {} +with open('../../sdk/tests/types/fixtures/protocol_parameters.json', "r", encoding="utf-8") as params: + protocol_params_json = json.load(params) + + +def test_basic_block_tagged_data_payload(): + basic_block_tagged_data_payload_json = {} + with open('../../sdk/tests/types/fixtures/basic_block_tagged_data_payload.json', "r", encoding="utf-8") as payload: + basic_block_tagged_data_payload_json = json.load(payload) + block = Block.from_dict(basic_block_tagged_data_payload_json['block']) + protocol_params = ProtocolParameters.from_dict(protocol_params_json['params']) + expected_id = basic_block_tagged_data_payload_json['id'] + assert block.id(protocol_params) == expected_id + + +def test_basic_block_transaction_payload(): + basic_block_transaction_payload_json = {} + with open('../../sdk/tests/types/fixtures/basic_block_transaction_payload.json', "r", encoding="utf-8") as payload: + basic_block_transaction_payload_json = json.load(payload) + block = Block.from_dict(basic_block_transaction_payload_json['block']) + protocol_params = ProtocolParameters.from_dict(protocol_params_json['params']) + expected_id = basic_block_transaction_payload_json['id'] + assert block.id(protocol_params) == expected_id + + +def test_validation_block(): + validation_block_json = {} + with open('../../sdk/tests/types/fixtures/validation_block.json', "r", encoding="utf-8") as payload: + validation_block_json = json.load(payload) + block = Block.from_dict(validation_block_json['block']) + protocol_params = ProtocolParameters.from_dict(protocol_params_json['params']) + expected_id = validation_block_json['id'] + assert block.id(protocol_params) == expected_id diff --git a/bindings/python/tests/test_output.py b/bindings/python/tests/test_output.py index 848364011e..1c3822cd34 100644 --- a/bindings/python/tests/test_output.py +++ b/bindings/python/tests/test_output.py @@ -8,7 +8,9 @@ def test_feature(): feature_dict = { "type": 2, - "data": "0x426c61" + "entries": { + "data": "0x426c61", + } } metadata_feature = from_dict(MetadataFeature, feature_dict) assert metadata_feature.to_dict() == feature_dict @@ -163,7 +165,9 @@ def test_output(): }, { "type": 2, - "data": "0x6e6f2d6d65746164617461" + "entries": { + "data": "0x6e6f2d6d65746164617461" + } } ] } @@ -192,7 +196,9 @@ def test_output(): "immutableFeatures": [ { "type": 2, - "data": "0x4c9385555f70b41d47f000c08dbe6913" + "entries": { + "data": "0x4c9385555f70b41d47f000c08dbe6913" + } } ] } @@ -216,13 +222,17 @@ def test_output(): "features": [ { "type": 2, - "data": "0x547275657d" + "entries": { + "data": "0x547275657d" + } } ], "immutableFeatures": [ { "type": 2, - "data": "0x7b69735f6e66743a" + "entries": { + "data": "0x7b69735f6e66743a" + } } ] } diff --git a/sdk/tests/types/block_id.rs b/sdk/tests/types/block_id.rs index 748d472f4c..ddeeb136ad 100644 --- a/sdk/tests/types/block_id.rs +++ b/sdk/tests/types/block_id.rs @@ -3,7 +3,13 @@ use core::str::FromStr; -use iota_sdk::types::block::{rand::bytes::rand_bytes_array, slot::SlotIndex, BlockHash, BlockId}; +use iota_sdk::types::{ + block::{ + protocol::ProtocolParameters, rand::bytes::rand_bytes_array, slot::SlotIndex, Block, BlockDto, BlockHash, + BlockId, + }, + TryFromDto, +}; use packable::PackableExt; use pretty_assertions::assert_eq; @@ -60,275 +66,56 @@ fn memory_layout() { assert_eq!(block_id.as_ref(), memory_layout); } -// TODO: re-enable below tests when source is updated -// fn protocol_parameters() -> ProtocolParameters { -// ProtocolParameters::new(3, "test", "rms", StorageScoreParameters::default(), 0, 1695275822, 10, 0).unwrap() -// } - -// #[test] -// fn basic_block_id_tagged_data_payload() { -// // Test from https://github.com/iotaledger/tips-draft/blob/tip46/tips/TIP-0046/tip-0046.md#basic-block-id-tagged-data-payload - -// let block_json = serde_json::json!({ -// "protocolVersion": 3, -// "networkId": "10549460113735494767", -// "issuingTime": "1695275834000000000", -// "slotCommitmentId": "0x498bf08a5ed287bc87340341ffab28706768cd3a7035ae5e33932d9a12bb30940000000000000000", -// "latestFinalizedSlot": "21", -// "issuerId": "0x3370746f30705b7d0b42597459714d45241e5a64761b09627c447b751c7e145c", -// "block": { -// "type": 0, -// "strongParents": [ -// "0x304442486c7a05361408585e4b5f7a67441c437528755a70041e0e557a6d4b2d7d4362083d492b57", -// "0x5f736978340a243d381b343b160b316a6b7d4b1e3c0355492e2e72113c2b126600157e69113c0b5c" -// ], -// "weakParents": [ -// "0x0b5a48384f382f4a49471c4860683c6f0a0d446f012e1b117c4e405f5e24497c72691f43535c0b42" -// ], -// "shallowLikeParents": [ -// "0x163007217803006078040b0f51507d3572355a457839095e572f125500401b7d220c772b56165a12" -// ], -// "payload": { -// "type": 5, -// "tag": "0x68656c6c6f20776f726c64", -// "data": "0x01020304" -// }, -// "maxBurnedMana": "180500" -// }, -// "signature": { -// "type": 0, -// "publicKey": "0x024b6f086177156350111d5e56227242034e596b7e3d0901180873740723193c", -// "signature": -// "0x7c274e5e771d5d60202d334f06773d3672484b1e4e6f03231b4e69305329267a4834374b0f2e0d5c6c2f7779620f4f534c773b1679400c52303d1f23121a4049" -// } -// }); - -// let block_dto = serde_json::from_value::(block_json).unwrap(); -// let block = Block::try_from_dto(block_dto).unwrap(); -// let block_bytes = block.pack_to_vec(); - -// assert_eq!( -// block_bytes, -// [ -// 3, 111, 44, 91, 123, 20, 54, 103, 146, 0, 196, 223, 153, 99, 212, 134, 23, 73, 139, 240, 138, 94, 210, -// 135, 188, 135, 52, 3, 65, 255, 171, 40, 112, 103, 104, 205, 58, 112, 53, 174, 94, 51, 147, 45, 154, 18, -// 187, 48, 148, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 51, 112, 116, 111, 48, 112, 91, 125, 11, -// 66, 89, 116, 89, 113, 77, 69, 36, 30, 90, 100, 118, 27, 9, 98, 124, 68, 123, 117, 28, 126, 20, 92, 0, 2, -// 48, 68, 66, 72, 108, 122, 5, 54, 20, 8, 88, 94, 75, 95, 122, 103, 68, 28, 67, 117, 40, 117, 90, 112, 4, -// 30, 14, 85, 122, 109, 75, 45, 125, 67, 98, 8, 61, 73, 43, 87, 95, 115, 105, 120, 52, 10, 36, 61, 56, 27, -// 52, 59, 22, 11, 49, 106, 107, 125, 75, 30, 60, 3, 85, 73, 46, 46, 114, 17, 60, 43, 18, 102, 0, 21, 126, -// 105, 17, 60, 11, 92, 1, 11, 90, 72, 56, 79, 56, 47, 74, 73, 71, 28, 72, 96, 104, 60, 111, 10, 13, 68, -// 111, 1, 46, 27, 17, 124, 78, 64, 95, 94, 36, 73, 124, 114, 105, 31, 67, 83, 92, 11, 66, 1, 22, 48, 7, 33, -// 120, 3, 0, 96, 120, 4, 11, 15, 81, 80, 125, 53, 114, 53, 90, 69, 120, 57, 9, 94, 87, 47, 18, 85, 0, 64, -// 27, 125, 34, 12, 119, 43, 86, 22, 90, 18, 24, 0, 0, 0, 5, 0, 0, 0, 11, 104, 101, 108, 108, 111, 32, 119, -// 111, 114, 108, 100, 4, 0, 0, 0, 1, 2, 3, 4, 20, 193, 2, 0, 0, 0, 0, 0, 0, 2, 75, 111, 8, 97, 119, 21, 99, -// 80, 17, 29, 94, 86, 34, 114, 66, 3, 78, 89, 107, 126, 61, 9, 1, 24, 8, 115, 116, 7, 35, 25, 60, 124, 39, -// 78, 94, 119, 29, 93, 96, 32, 45, 51, 79, 6, 119, 61, 54, 114, 72, 75, 30, 78, 111, 3, 35, 27, 78, 105, -// 48, 83, 41, 38, 122, 72, 52, 55, 75, 15, 46, 13, 92, 108, 47, 119, 121, 98, 15, 79, 83, 76, 119, 59, 22, -// 121, 64, 12, 82, 48, 61, 31, 35, 18, 26, 64, 73 -// ] -// ); - -// let block_id = block.id(&protocol_parameters()).to_string(); - -// assert_eq!( -// block_id, -// "0xb2c397afa61262c10af75320a166d28be34debcc4449f272f90c8769681c0b710200000000000000" -// ); -// } - -// #[test] -// fn basic_block_id_transaction_payload() { -// // Test from https://github.com/iotaledger/tips-draft/blob/tip46/tips/TIP-0046/tip-0046.md#basic-block-id-transaction-payload - -// let block_json = serde_json::json!({ -// "protocolVersion": 3, -// "networkId": "10549460113735494767", -// "issuingTime": "1695275834000000000", -// "slotCommitmentId": "0x498bf08a5ed287bc87340341ffab28706768cd3a7035ae5e33932d9a12bb30940000000000000000", -// "latestFinalizedSlot": "21", -// "issuerId": "0x3370746f30705b7d0b42597459714d45241e5a64761b09627c447b751c7e145c", -// "block": { -// "type": 0, -// "strongParents": [ -// "0x304442486c7a05361408585e4b5f7a67441c437528755a70041e0e557a6d4b2d7d4362083d492b57", -// "0x5f736978340a243d381b343b160b316a6b7d4b1e3c0355492e2e72113c2b126600157e69113c0b5c" -// ], -// "weakParents": [ -// "0x0b5a48384f382f4a49471c4860683c6f0a0d446f012e1b117c4e405f5e24497c72691f43535c0b42" -// ], -// "shallowLikeParents": [ -// "0x163007217803006078040b0f51507d3572355a457839095e572f125500401b7d220c772b56165a12" -// ], -// "payload": { -// "type": 6, -// "essence": { -// "type": 2, -// "networkId": "3650798313638353144", -// "creationSlot": "28", -// "contextInputs": [], -// "inputs": [ -// { -// "type": 0, -// "transactionId": "0x24ff9b3038506fb1b406306a496001c3e24e2be07c838317922bf21d686a078f", -// "transactionOutputIndex": 10 -// } -// ], -// "inputsCommitment": "0xb70c6f86a1ea03a59a71d73dcd07e2082bbdf0ce971faa21748348bca22fb023", -// "outputs": [ -// { -// "type": 3, -// "amount": "10000", -// "mana": "0", -// "unlockConditions": [ -// { -// "type": 0, -// "address": { -// "type": 0, -// "pubKeyHash": "0xd9f84458286dc41cd34789dec566cd096cf47de991aa36a97aebfaea14128f6d" -// } -// } -// ] -// } -// ], -// "allotments": [], -// "capabilities": 0, -// "payload": { -// "type": 5, -// "tag": "0x1d7b3e11697264111e130b0e", -// "data": "0x1d7b3e11697264111e130b0e" -// } -// }, -// "unlocks": [ -// { -// "type": 0, -// "signature": { -// "type": 0, -// "publicKey": "0x803361fe1effc899dca7f931d8ad07c01ba23aaa93f986adb04d4c17cf6368d8", -// "signature": -// "0xccddbac3aaac413e0193e16da3449f30c183d0e7eaa7f303dc12ae0dbc9fb890e449a52f9056e7d952ea796fd3e5645f60d9eb98ed91cb3261720fb528d2a105" -// } -// } -// ] -// }, -// "maxBurnedMana": "180500" -// }, -// "signature": { -// "type": 0, -// "publicKey": "0x024b6f086177156350111d5e56227242034e596b7e3d0901180873740723193c", -// "signature": -// "0x7c274e5e771d5d60202d334f06773d3672484b1e4e6f03231b4e69305329267a4834374b0f2e0d5c6c2f7779620f4f534c773b1679400c52303d1f23121a4049" -// } -// }); - -// let block_dto = serde_json::from_value::(block_json).unwrap(); -// let block = Block::try_from_dto(block_dto).unwrap(); -// let block_bytes = block.pack_to_vec(); - -// assert_eq!( -// block_bytes, -// [ -// 3, 111, 44, 91, 123, 20, 54, 103, 146, 0, 196, 223, 153, 99, 212, 134, 23, 73, 139, 240, 138, 94, 210, -// 135, 188, 135, 52, 3, 65, 255, 171, 40, 112, 103, 104, 205, 58, 112, 53, 174, 94, 51, 147, 45, 154, 18, -// 187, 48, 148, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 51, 112, 116, 111, 48, 112, 91, 125, 11, -// 66, 89, 116, 89, 113, 77, 69, 36, 30, 90, 100, 118, 27, 9, 98, 124, 68, 123, 117, 28, 126, 20, 92, 0, 2, -// 48, 68, 66, 72, 108, 122, 5, 54, 20, 8, 88, 94, 75, 95, 122, 103, 68, 28, 67, 117, 40, 117, 90, 112, 4, -// 30, 14, 85, 122, 109, 75, 45, 125, 67, 98, 8, 61, 73, 43, 87, 95, 115, 105, 120, 52, 10, 36, 61, 56, 27, -// 52, 59, 22, 11, 49, 106, 107, 125, 75, 30, 60, 3, 85, 73, 46, 46, 114, 17, 60, 43, 18, 102, 0, 21, 126, -// 105, 17, 60, 11, 92, 1, 11, 90, 72, 56, 79, 56, 47, 74, 73, 71, 28, 72, 96, 104, 60, 111, 10, 13, 68, -// 111, 1, 46, 27, 17, 124, 78, 64, 95, 94, 36, 73, 124, 114, 105, 31, 67, 83, 92, 11, 66, 1, 22, 48, 7, 33, -// 120, 3, 0, 96, 120, 4, 11, 15, 81, 80, 125, 53, 114, 53, 90, 69, 120, 57, 9, 94, 87, 47, 18, 85, 0, 64, -// 27, 125, 34, 12, 119, 43, 86, 22, 90, 18, 32, 1, 0, 0, 6, 0, 0, 0, 2, 248, 88, 2, 55, 185, 61, 170, 50, -// 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 36, 255, 155, 48, 56, 80, 111, 177, 180, 6, 48, 106, 73, 96, 1, -// 195, 226, 78, 43, 224, 124, 131, 131, 23, 146, 43, 242, 29, 104, 106, 7, 143, 10, 0, 183, 12, 111, 134, -// 161, 234, 3, 165, 154, 113, 215, 61, 205, 7, 226, 8, 43, 189, 240, 206, 151, 31, 170, 33, 116, 131, 72, -// 188, 162, 47, 176, 35, 1, 0, 3, 16, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 217, 248, -// 68, 88, 40, 109, 196, 28, 211, 71, 137, 222, 197, 102, 205, 9, 108, 244, 125, 233, 145, 170, 54, 169, -// 122, 235, 250, 234, 20, 18, 143, 109, 0, 0, 0, 0, 33, 0, 0, 0, 5, 0, 0, 0, 12, 29, 123, 62, 17, 105, 114, -// 100, 17, 30, 19, 11, 14, 12, 0, 0, 0, 29, 123, 62, 17, 105, 114, 100, 17, 30, 19, 11, 14, 1, 0, 0, 0, -// 128, 51, 97, 254, 30, 255, 200, 153, 220, 167, 249, 49, 216, 173, 7, 192, 27, 162, 58, 170, 147, 249, -// 134, 173, 176, 77, 76, 23, 207, 99, 104, 216, 204, 221, 186, 195, 170, 172, 65, 62, 1, 147, 225, 109, -// 163, 68, 159, 48, 193, 131, 208, 231, 234, 167, 243, 3, 220, 18, 174, 13, 188, 159, 184, 144, 228, 73, -// 165, 47, 144, 86, 231, 217, 82, 234, 121, 111, 211, 229, 100, 95, 96, 217, 235, 152, 237, 145, 203, 50, -// 97, 114, 15, 181, 40, 210, 161, 5, 20, 193, 2, 0, 0, 0, 0, 0, 0, 2, 75, 111, 8, 97, 119, 21, 99, 80, 17, -// 29, 94, 86, 34, 114, 66, 3, 78, 89, 107, 126, 61, 9, 1, 24, 8, 115, 116, 7, 35, 25, 60, 124, 39, 78, 94, -// 119, 29, 93, 96, 32, 45, 51, 79, 6, 119, 61, 54, 114, 72, 75, 30, 78, 111, 3, 35, 27, 78, 105, 48, 83, -// 41, 38, 122, 72, 52, 55, 75, 15, 46, 13, 92, 108, 47, 119, 121, 98, 15, 79, 83, 76, 119, 59, 22, 121, 64, -// 12, 82, 48, 61, 31, 35, 18, 26, 64, 73 ] -// ); - -// let block_id = block.id(&protocol_parameters()).to_string(); - -// assert_eq!( -// block_id, -// "0x95f37c6a1e838133726aaefa8c33a65204bfe811000542f593a6b0b997bc78d90200000000000000" -// ); -// } - -// #[test] -// fn validation_block_id() { -// // Test from https://github.com/iotaledger/tips-draft/blob/tip46/tips/TIP-0046/tip-0046.md#validation-block-id - -// let block_json = serde_json::json!({ -// "protocolVersion": 3, -// "networkId": "10549460113735494767", -// "issuingTime": "1695275834000000000", -// "slotCommitmentId": "0x498bf08a5ed287bc87340341ffab28706768cd3a7035ae5e33932d9a12bb30940000000000000000", -// "latestFinalizedSlot": "0", -// "issuerId": "0x3370746f30705b7d0b42597459714d45241e5a64761b09627c447b751c7e145c", -// "block": { -// "type": 1, -// "strongParents": [ -// "0x304442486c7a05361408585e4b5f7a67441c437528755a70041e0e557a6d4b2d7d4362083d492b57", -// "0x5f736978340a243d381b343b160b316a6b7d4b1e3c0355492e2e72113c2b126600157e69113c0b5c" -// ], -// "weakParents": [ -// "0x0b5a48384f382f4a49471c4860683c6f0a0d446f012e1b117c4e405f5e24497c72691f43535c0b42" -// ], -// "shallowLikeParents": [ -// "0x163007217803006078040b0f51507d3572355a457839095e572f125500401b7d220c772b56165a12" -// ], -// "highestSupportedVersion": 3, -// "protocolParametersHash": "0xf6021fae654975db2e82c17444dc8d43573cb4222f506fb46ba46a097cf8c873" -// }, -// "signature": { -// "type": 0, -// "publicKey": "0x024b6f086177156350111d5e56227242034e596b7e3d0901180873740723193c", -// "signature": -// "0x7c274e5e771d5d60202d334f06773d3672484b1e4e6f03231b4e69305329267a4834374b0f2e0d5c6c2f7779620f4f534c773b1679400c52303d1f23121a4049" -// } -// }); - -// let block_dto = serde_json::from_value::(block_json).unwrap(); -// let block = Block::try_from_dto(block_dto).unwrap(); -// let block_bytes = block.pack_to_vec(); +fn protocol_parameters() -> ProtocolParameters { + let file = std::fs::read_to_string("./tests/types/fixtures/protocol_parameters.json").unwrap(); + let json = serde_json::from_str::(&file).unwrap(); + let params_json = &json["params"]; + let params = serde_json::from_value::(params_json.clone()).unwrap(); + assert_eq!(params.hash().to_string(), json["hash"]); + serde_json::from_value::(params_json.clone()).unwrap() +} -// assert_eq!( -// block_bytes, -// [ -// 3, 111, 44, 91, 123, 20, 54, 103, 146, 0, 196, 223, 153, 99, 212, 134, 23, 73, 139, 240, 138, 94, 210, -// 135, 188, 135, 52, 3, 65, 255, 171, 40, 112, 103, 104, 205, 58, 112, 53, 174, 94, 51, 147, 45, 154, 18, -// 187, 48, 148, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 51, 112, 116, 111, 48, 112, 91, 125, 11, -// 66, 89, 116, 89, 113, 77, 69, 36, 30, 90, 100, 118, 27, 9, 98, 124, 68, 123, 117, 28, 126, 20, 92, 1, 2, -// 48, 68, 66, 72, 108, 122, 5, 54, 20, 8, 88, 94, 75, 95, 122, 103, 68, 28, 67, 117, 40, 117, 90, 112, 4, -// 30, 14, 85, 122, 109, 75, 45, 125, 67, 98, 8, 61, 73, 43, 87, 95, 115, 105, 120, 52, 10, 36, 61, 56, 27, -// 52, 59, 22, 11, 49, 106, 107, 125, 75, 30, 60, 3, 85, 73, 46, 46, 114, 17, 60, 43, 18, 102, 0, 21, 126, -// 105, 17, 60, 11, 92, 1, 11, 90, 72, 56, 79, 56, 47, 74, 73, 71, 28, 72, 96, 104, 60, 111, 10, 13, 68, -// 111, 1, 46, 27, 17, 124, 78, 64, 95, 94, 36, 73, 124, 114, 105, 31, 67, 83, 92, 11, 66, 1, 22, 48, 7, 33, -// 120, 3, 0, 96, 120, 4, 11, 15, 81, 80, 125, 53, 114, 53, 90, 69, 120, 57, 9, 94, 87, 47, 18, 85, 0, 64, -// 27, 125, 34, 12, 119, 43, 86, 22, 90, 18, 3, 246, 2, 31, 174, 101, 73, 117, 219, 46, 130, 193, 116, 68, -// 220, 141, 67, 87, 60, 180, 34, 47, 80, 111, 180, 107, 164, 106, 9, 124, 248, 200, 115, 0, 2, 75, 111, 8, -// 97, 119, 21, 99, 80, 17, 29, 94, 86, 34, 114, 66, 3, 78, 89, 107, 126, 61, 9, 1, 24, 8, 115, 116, 7, 35, -// 25, 60, 124, 39, 78, 94, 119, 29, 93, 96, 32, 45, 51, 79, 6, 119, 61, 54, 114, 72, 75, 30, 78, 111, 3, -// 35, 27, 78, 105, 48, 83, 41, 38, 122, 72, 52, 55, 75, 15, 46, 13, 92, 108, 47, 119, 121, 98, 15, 79, 83, -// 76, 119, 59, 22, 121, 64, 12, 82, 48, 61, 31, 35, 18, 26, 64, 73 -// ] -// ); +#[test] +fn basic_block_tagged_data_payload_id() { + // Test vector from https://github.com/iotaledger/tips/blob/tip46/tips/TIP-0046/tip-0046.md#basic-block-id-tagged-data-payload + let file = std::fs::read_to_string("./tests/types/fixtures/basic_block_tagged_data_payload.json").unwrap(); + let json = serde_json::from_str::(&file).unwrap(); + let block_json = &json["block"]; + let block_dto = serde_json::from_value::(block_json.clone()).unwrap(); + let block = Block::try_from_dto(block_dto).unwrap(); + let block_bytes = block.pack_to_vec(); + + assert_eq!(prefix_hex::encode(&block_bytes), json["bytes"]); + assert_eq!(block, Block::unpack_unverified(block_bytes).unwrap()); + assert_eq!(block.id(&protocol_parameters()).to_string(), json["id"]); +} -// let block_id = block.id(&protocol_parameters()).to_string(); +#[test] +fn basic_block_transaction_payload_id() { + // Test vector from https://github.com/iotaledger/tips/blob/tip46/tips/TIP-0046/tip-0046.md#basic-block-id-transaction-payload + let file = std::fs::read_to_string("./tests/types/fixtures/basic_block_transaction_payload.json").unwrap(); + let json = serde_json::from_str::(&file).unwrap(); + let block_json = &json["block"]; + let block_dto = serde_json::from_value::(block_json.clone()).unwrap(); + let block = Block::try_from_dto(block_dto).unwrap(); + let block_bytes = block.pack_to_vec(); + + assert_eq!(prefix_hex::encode(&block_bytes), json["bytes"]); + assert_eq!(block, Block::unpack_unverified(block_bytes).unwrap()); + assert_eq!(block.id(&protocol_parameters()).to_string(), json["id"]); +} -// assert_eq!( -// block_id, -// "0xe7577f23f82595fcf5501d3858666e5efe2e3063d715b03e43cdd93ea69d6af60200000000000000" -// ); -// } +#[test] +fn validation_block_id() { + // Test vector from https://github.com/iotaledger/tips/blob/tip46/tips/TIP-0046/tip-0046.md#validation-block-id + let file = std::fs::read_to_string("./tests/types/fixtures/validation_block.json").unwrap(); + let json = serde_json::from_str::(&file).unwrap(); + let block_json = &json["block"]; + let block_dto = serde_json::from_value::(block_json.clone()).unwrap(); + let block = Block::try_from_dto(block_dto).unwrap(); + let block_bytes = block.pack_to_vec(); + + assert_eq!(prefix_hex::encode(&block_bytes), json["bytes"]); + assert_eq!(block, Block::unpack_unverified(block_bytes).unwrap()); + assert_eq!(block.id(&protocol_parameters()).to_string(), json["id"]); +} diff --git a/sdk/tests/types/fixtures/basic_block_tagged_data_payload.json b/sdk/tests/types/fixtures/basic_block_tagged_data_payload.json new file mode 100644 index 0000000000..feef909d98 --- /dev/null +++ b/sdk/tests/types/fixtures/basic_block_tagged_data_payload.json @@ -0,0 +1,36 @@ +{ + "block":{ + "header":{ + "protocolVersion":3, + "networkId":"8342982141227064571", + "issuingTime":"1695275942000000000", + "slotCommitmentId":"0x3a1e3b617060146e0362361a4b752833186108395f3b2b3d3e6c655e287d707601000000", + "latestFinalizedSlot":0, + "issuerId":"0x17432c5a7a672503480241125e3952414a7a320441080c624c264b004e09614a" + }, + "body":{ + "type":0, + "strongParents":[ + "0x27e0461873f37040c9e59c35ad8a106fa1b94f5ec9ef89499b31904f9a3de59be58dd44a", + "0x714821f8f257e0a502b71ac7ee57530bb9dc29fe12ff3936f925b835a297680400b76948", + "0x9951e512546cd9c9fbdab348b6cba91a601a29b50854e55a6e14f6803ca1d81ac7eff5ce", + "0xaaa7bacf26f1aa4754d42edeab45d6169ea723b7fdf0f6ff3b6ebe90d09dbff6bc553936", + "0xba75a143de4ac932986fbe7b1d78f639bc6ee8aee10d510d41572851530be884778052aa", + "0xea5315941f4337752905599710b55e64018c71f4d8f299d0636d50484d05e6ac5667b503" + ], + "payload":{ + "type":0, + "tag":"0x746167", + "data":"0x6c754128356c071e5549764a48427b" + }, + "maxBurnedMana":"864" + }, + "signature":{ + "type":0, + "publicKey":"0x2daefbcbadd044da470acd2f7fcf6fcb04b873cc801e7ee408018e1dfa0257ac", + "signature":"0x5d1301b9ab4c09b8be906028b45cba759caedfb7e7bd510ce12eea25c7aee374c7ac89e90845f650b22a32dda4adc7eb291e28e5149b02c644a8c1a9fcbd9109" + } + }, + "bytes":"0x03fb5c44ef0d3ac87300fc2cbf7cd486173a1e3b617060146e0362361a4b752833186108395f3b2b3d3e6c655e287d7076010000000000000017432c5a7a672503480241125e3952414a7a320441080c624c264b004e09614a000627e0461873f37040c9e59c35ad8a106fa1b94f5ec9ef89499b31904f9a3de59be58dd44a714821f8f257e0a502b71ac7ee57530bb9dc29fe12ff3936f925b835a297680400b769489951e512546cd9c9fbdab348b6cba91a601a29b50854e55a6e14f6803ca1d81ac7eff5ceaaa7bacf26f1aa4754d42edeab45d6169ea723b7fdf0f6ff3b6ebe90d09dbff6bc553936ba75a143de4ac932986fbe7b1d78f639bc6ee8aee10d510d41572851530be884778052aaea5315941f4337752905599710b55e64018c71f4d8f299d0636d50484d05e6ac5667b50300001800000000037461670f0000006c754128356c071e5549764a48427b6003000000000000002daefbcbadd044da470acd2f7fcf6fcb04b873cc801e7ee408018e1dfa0257ac5d1301b9ab4c09b8be906028b45cba759caedfb7e7bd510ce12eea25c7aee374c7ac89e90845f650b22a32dda4adc7eb291e28e5149b02c644a8c1a9fcbd9109", + "id":"0xc9416c8e21df6d48e03115de785e0d5b2e37080b24b0681a8b79081a413cecd40d000000" +} diff --git a/sdk/tests/types/fixtures/basic_block_transaction_payload.json b/sdk/tests/types/fixtures/basic_block_transaction_payload.json new file mode 100644 index 0000000000..e419f29b5e --- /dev/null +++ b/sdk/tests/types/fixtures/basic_block_transaction_payload.json @@ -0,0 +1,157 @@ +{ + "block": { + "header": { + "protocolVersion": 3, + "networkId": "8342982141227064571", + "issuingTime": "1695275942000000000", + "slotCommitmentId": "0x3a1e3b617060146e0362361a4b752833186108395f3b2b3d3e6c655e287d707601000000", + "latestFinalizedSlot": 0, + "issuerId": "0x17432c5a7a672503480241125e3952414a7a320441080c624c264b004e09614a" + }, + "body": { + "type": 0, + "strongParents": [ + "0x27e0461873f37040c9e59c35ad8a106fa1b94f5ec9ef89499b31904f9a3de59be58dd44a", + "0x714821f8f257e0a502b71ac7ee57530bb9dc29fe12ff3936f925b835a297680400b76948", + "0x9951e512546cd9c9fbdab348b6cba91a601a29b50854e55a6e14f6803ca1d81ac7eff5ce", + "0xaaa7bacf26f1aa4754d42edeab45d6169ea723b7fdf0f6ff3b6ebe90d09dbff6bc553936", + "0xba75a143de4ac932986fbe7b1d78f639bc6ee8aee10d510d41572851530be884778052aa", + "0xea5315941f4337752905599710b55e64018c71f4d8f299d0636d50484d05e6ac5667b503" + ], + "payload": { + "type": 1, + "transaction": { + "networkId": "8342982141227064571", + "creationSlot": 11, + "contextInputs": [ + { + "type": 0, + "commitmentId": "0x3a1e3b617060146e0362361a4b752833186108395f3b2b3d3e6c655e287d707601000000" + }, + { + "type": 1, + "accountId": "0x17432c5a7a672503480241125e3952414a7a320441080c624c264b004e09614a" + }, + { + "type": 2, + "index": 0 + } + ], + "inputs": [ + { + "type": 0, + "transactionId": "0xf09d3cd648a7246c7c1b2ba2f9182465ae5742b78c592392b4b455ab8ed7195200000000", + "transactionOutputIndex": 0 + }, + { + "type": 0, + "transactionId": "0xd2c5ccba12b6fad51652131289867492799c9fc5710244418aa6e955f8fa826100000000", + "transactionOutputIndex": 0 + } + ], + "allotments": [ + { + "accountId": "0x476820096e7038107d071a4e473f1e295f346e2d0824263e5e3e7d004f6b6915", + "mana": "2189" + }, + { + "accountId": "0x7e0d0a5848362b23120f55115b096774036d7610137a631413221f5573344507", + "mana": "2285" + } + ], + "capabilities": "0x01", + "outputs": [ + { + "type": 0, + "amount": "100000", + "mana": "0", + "unlockConditions": [ + { + "type": 0, + "address": { + "type": 0, + "pubKeyHash": "0xed1484f4d1f7d8c037087fed661dd92faccae1eed3c01182d6fdd6828cea144a" + } + } + ], + "features": [ + { + "type": 5, + "id": "0x086372557616532f714f104e5f44297b7a286d077956291a6d4f59081f484463712a64300c00", + "amount": "0x14be8149371263f4" + } + ] + }, + { + "type": 1, + "amount": "100000", + "mana": "5000", + "accountId": "0x0000000000000000000000000000000000000000000000000000000000000000", + "foundryCounter": 0, + "unlockConditions": [ + { + "type": 0, + "address": { + "type": 0, + "pubKeyHash": "0xed1484f4d1f7d8c037087fed661dd92faccae1eed3c01182d6fdd6828cea144a" + } + } + ], + "features": [ + { + "type": 2, + "entries": { + "hello": "0x776f726c64" + } + }, + { + "type": 6, + "expirySlot": 4294967295, + "blockIssuerKeys": [ + { + "type": 0, + "pubKeyHash": "0x295409de79016133647d4078cb01618a4ba018eb74ff613138d8ff8dc05de73c" + }, + { + "type": 0, + "pubKeyHash": "0x868f4c6ef7b5b1d55838cbfb8ae4f3a9776c53cdd3e3d33000094d72acab5a2f" + } + ] + }, + { + "type": 7, + "stakedAmount": "10000", + "fixedCost": "400", + "startEpoch": 0, + "endEpoch": 4294967295 + } + ] + } + ] + }, + "unlocks": [ + { + "type": 0, + "signature": { + "type": 0, + "publicKey": "0x2daefbcbadd044da470acd2f7fcf6fcb04b873cc801e7ee408018e1dfa0257ac", + "signature": "0x5bb409d59e01d2ea9f1a1fb67feb681d0d3ecb05787cadad2f89fdf13ef7ff03ad5cebf28df5dddd8510992596d98b133f86e14f76824e6ccc369a8f5df44806" + } + }, + { + "type": 1, + "reference": 0 + } + ] + }, + "maxBurnedMana": "864" + }, + "signature": { + "type": 0, + "publicKey": "0x2daefbcbadd044da470acd2f7fcf6fcb04b873cc801e7ee408018e1dfa0257ac", + "signature": "0xb4300837bafda6e0e590124b367a1beb87abd9afbde50bc2afe5e335c7118c13ba59ba58d082eb329c84f527a536bf2c1943b3bcf0444d770dcf7b05f135f50a" + } + }, + "bytes": "0x03fb5c44ef0d3ac87300fc2cbf7cd486173a1e3b617060146e0362361a4b752833186108395f3b2b3d3e6c655e287d7076010000000000000017432c5a7a672503480241125e3952414a7a320441080c624c264b004e09614a000627e0461873f37040c9e59c35ad8a106fa1b94f5ec9ef89499b31904f9a3de59be58dd44a714821f8f257e0a502b71ac7ee57530bb9dc29fe12ff3936f925b835a297680400b769489951e512546cd9c9fbdab348b6cba91a601a29b50854e55a6e14f6803ca1d81ac7eff5ceaaa7bacf26f1aa4754d42edeab45d6169ea723b7fdf0f6ff3b6ebe90d09dbff6bc553936ba75a143de4ac932986fbe7b1d78f639bc6ee8aee10d510d41572851530be884778052aaea5315941f4337752905599710b55e64018c71f4d8f299d0636d50484d05e6ac5667b5030000af02000001fb5c44ef0d3ac8730b0000000300003a1e3b617060146e0362361a4b752833186108395f3b2b3d3e6c655e287d7076010000000117432c5a7a672503480241125e3952414a7a320441080c624c264b004e09614a020000020000f09d3cd648a7246c7c1b2ba2f9182465ae5742b78c592392b4b455ab8ed7195200000000000000d2c5ccba12b6fad51652131289867492799c9fc5710244418aa6e955f8fa82610000000000000200476820096e7038107d071a4e473f1e295f346e2d0824263e5e3e7d004f6b69158d080000000000007e0d0a5848362b23120f55115b096774036d7610137a631413221f5573344507ed08000000000000010100000000020000a0860100000000000000000000000000010000ed1484f4d1f7d8c037087fed661dd92faccae1eed3c01182d6fdd6828cea144a0105086372557616532f714f104e5f44297b7a286d077956291a6d4f59081f484463712a64300c00f46312374981be1400000000000000000000000000000000000000000000000001a0860100000000008813000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000ed1484f4d1f7d8c037087fed661dd92faccae1eed3c01182d6fdd6828cea144a0302010568656c6c6f0500776f726c6406ffffffff0200295409de79016133647d4078cb01618a4ba018eb74ff613138d8ff8dc05de73c00868f4c6ef7b5b1d55838cbfb8ae4f3a9776c53cdd3e3d33000094d72acab5a2f071027000000000000900100000000000000000000ffffffff00020000002daefbcbadd044da470acd2f7fcf6fcb04b873cc801e7ee408018e1dfa0257ac5bb409d59e01d2ea9f1a1fb67feb681d0d3ecb05787cadad2f89fdf13ef7ff03ad5cebf28df5dddd8510992596d98b133f86e14f76824e6ccc369a8f5df448060100006003000000000000002daefbcbadd044da470acd2f7fcf6fcb04b873cc801e7ee408018e1dfa0257acb4300837bafda6e0e590124b367a1beb87abd9afbde50bc2afe5e335c7118c13ba59ba58d082eb329c84f527a536bf2c1943b3bcf0444d770dcf7b05f135f50a", + "id": "0xd4f66be3a8e0b980a6eb10ad969f7aca33313946833112c6b96cc3d7287ca01c0d000000" +} diff --git a/sdk/tests/types/fixtures/validation_block.json b/sdk/tests/types/fixtures/validation_block.json new file mode 100644 index 0000000000..3deb18ced4 --- /dev/null +++ b/sdk/tests/types/fixtures/validation_block.json @@ -0,0 +1,32 @@ +{ + "block":{ + "header":{ + "protocolVersion":3, + "networkId":"8342982141227064571", + "issuingTime":"1695275942000000000", + "slotCommitmentId":"0x3a1e3b617060146e0362361a4b752833186108395f3b2b3d3e6c655e287d707601000000", + "latestFinalizedSlot":500, + "issuerId":"0x17432c5a7a672503480241125e3952414a7a320441080c624c264b004e09614a" + }, + "body":{ + "type":1, + "strongParents":[ + "0x27e0461873f37040c9e59c35ad8a106fa1b94f5ec9ef89499b31904f9a3de59be58dd44a", + "0x714821f8f257e0a502b71ac7ee57530bb9dc29fe12ff3936f925b835a297680400b76948", + "0x9951e512546cd9c9fbdab348b6cba91a601a29b50854e55a6e14f6803ca1d81ac7eff5ce", + "0xaaa7bacf26f1aa4754d42edeab45d6169ea723b7fdf0f6ff3b6ebe90d09dbff6bc553936", + "0xba75a143de4ac932986fbe7b1d78f639bc6ee8aee10d510d41572851530be884778052aa", + "0xea5315941f4337752905599710b55e64018c71f4d8f299d0636d50484d05e6ac5667b503" + ], + "highestSupportedVersion":3, + "protocolParametersHash":"0x28ccbc633e0d22e19752f5e65c0d22055a7d59756bfa754b8839088e18a6a5a6" + }, + "signature":{ + "type":0, + "publicKey":"0x2daefbcbadd044da470acd2f7fcf6fcb04b873cc801e7ee408018e1dfa0257ac", + "signature":"0x1402b2660fbfbc710db145e85422cd2c0e444fa75d04565794b43258f92d7bc7cab001ed80ded7141b0fc8429997a0bb2e1e5ebf29cbc60e7b652a670efa7e05" + } + }, + "bytes":"0x03fb5c44ef0d3ac87300fc2cbf7cd486173a1e3b617060146e0362361a4b752833186108395f3b2b3d3e6c655e287d707601000000f401000017432c5a7a672503480241125e3952414a7a320441080c624c264b004e09614a010627e0461873f37040c9e59c35ad8a106fa1b94f5ec9ef89499b31904f9a3de59be58dd44a714821f8f257e0a502b71ac7ee57530bb9dc29fe12ff3936f925b835a297680400b769489951e512546cd9c9fbdab348b6cba91a601a29b50854e55a6e14f6803ca1d81ac7eff5ceaaa7bacf26f1aa4754d42edeab45d6169ea723b7fdf0f6ff3b6ebe90d09dbff6bc553936ba75a143de4ac932986fbe7b1d78f639bc6ee8aee10d510d41572851530be884778052aaea5315941f4337752905599710b55e64018c71f4d8f299d0636d50484d05e6ac5667b50300000328ccbc633e0d22e19752f5e65c0d22055a7d59756bfa754b8839088e18a6a5a6002daefbcbadd044da470acd2f7fcf6fcb04b873cc801e7ee408018e1dfa0257ac1402b2660fbfbc710db145e85422cd2c0e444fa75d04565794b43258f92d7bc7cab001ed80ded7141b0fc8429997a0bb2e1e5ebf29cbc60e7b652a670efa7e05", + "id":"0xe7f9f06c51f2e89e0a41c5b4acdea11fa31367f1e9aebb2f3aed7f24db87dbfc0d000000" +}