From 6100683a929c53d96b551f68309c0f5c4af899cf Mon Sep 17 00:00:00 2001 From: Bartek Wrona <wrona@syncad.com> Date: Wed, 26 Feb 2025 17:32:11 +0100 Subject: [PATCH] TS proto/protocol tests adjusted to transaction binary serialization interface changes. --- ts/wasm/__tests__/detailed/proto-protocol.ts | 2 +- ts/wasm/__tests__/detailed/protocol.ts | 19 +++++++++++++++---- .../__tests__/detailed/protocol_benchmarks.ts | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ts/wasm/__tests__/detailed/proto-protocol.ts b/ts/wasm/__tests__/detailed/proto-protocol.ts index db74bde54..c61e166af 100644 --- a/ts/wasm/__tests__/detailed/proto-protocol.ts +++ b/ts/wasm/__tests__/detailed/proto-protocol.ts @@ -33,7 +33,7 @@ test.describe('WASM Proto Protocol', () => { test('Should be able to serialize the transaction', async ({ wasmTest }) => { const retVal = await wasmTest(({ proto_protocol }, transaction) => { - return proto_protocol.cpp_serialize_transaction(transaction); + return proto_protocol.cpp_serialize_transaction(transaction, false); }, protoTx); expect(retVal.exception_message).toHaveLength(0); diff --git a/ts/wasm/__tests__/detailed/protocol.ts b/ts/wasm/__tests__/detailed/protocol.ts index cf2691faa..a638b1231 100644 --- a/ts/wasm/__tests__/detailed/protocol.ts +++ b/ts/wasm/__tests__/detailed/protocol.ts @@ -35,7 +35,7 @@ test.describe('WASM Protocol', () => { }); test('Should be able to generate binary metadata information - tx with vote operation', async ({ wasmTest }) => { const retVal = await wasmTest.dynamic(({ protocol }, transaction, parseChildrenFn) => { - const values = protocol.cpp_generate_binary_transaction_metadata(transaction, true); + const values = protocol.cpp_generate_binary_transaction_metadata(transaction, true, false); const parseBinaryChildren = eval(parseChildrenFn); @@ -50,7 +50,7 @@ test.describe('WASM Protocol', () => { }); test('Should be able to generate binary metadata information using hf26 pack type - tx with transfer', async ({ wasmTest }) => { const retVal = await wasmTest.dynamic(({ protocol }, transaction, parseChildrenFn) => { - const values = protocol.cpp_generate_binary_transaction_metadata(transaction, true); + const values = protocol.cpp_generate_binary_transaction_metadata(transaction, true, false); const parseBinaryChildren = eval(parseChildrenFn); @@ -66,7 +66,7 @@ test.describe('WASM Protocol', () => { test('Should be able to generate binary metadata information using legacy pack type - tx with transfer', async ({ wasmTest }) => { const retVal = await wasmTest.dynamic(({ protocol }, transaction, parseChildrenFn) => { - const values = protocol.cpp_generate_binary_transaction_metadata(transaction, false); + const values = protocol.cpp_generate_binary_transaction_metadata(transaction, false, false); const parseBinaryChildren = eval(parseChildrenFn); @@ -168,13 +168,24 @@ test.describe('WASM Protocol', () => { test('Should be able to serialize the transaction', async ({ wasmTest }) => { const retVal = await wasmTest(({ protocol }, transaction) => { - return protocol.cpp_serialize_transaction(transaction); + return protocol.cpp_serialize_transaction(transaction, false); }, transaction); expect(retVal.exception_message).toHaveLength(0); expect(retVal.content).toBe("ff86c404c24b152fb7610100046f746f6d076330666633336108657778686e6a626a98080000"); }); + test('Should be able to serialize the (stripped) transaction', async ({ wasmTest }) => { + const retVal = await wasmTest(({ protocol }, transaction) => { + /// Even transaction is unsigned, we can strip the signature container to preserve original binary form + // of the transaction i.e. specific to calculate its id + return protocol.cpp_serialize_transaction(transaction, true); + }, transaction); + + expect(retVal.exception_message).toHaveLength(0); + expect(retVal.content).toBe("ff86c404c24b152fb7610100046f746f6d076330666633336108657778686e6a626a980800"); + }); + test('Should be able to calculate sig digest of the transaction', async ({ wasmTest }) => { const retVal = await wasmTest(({ protocol }, transaction) => { return protocol.cpp_calculate_sig_digest(transaction, "beeab0de00000000000000000000000000000000000000000000000000000000"); diff --git a/ts/wasm/__tests__/detailed/protocol_benchmarks.ts b/ts/wasm/__tests__/detailed/protocol_benchmarks.ts index ff42b0a50..ede49df46 100644 --- a/ts/wasm/__tests__/detailed/protocol_benchmarks.ts +++ b/ts/wasm/__tests__/detailed/protocol_benchmarks.ts @@ -111,7 +111,7 @@ test.describe('WASM Protocol benchmarks', () => { utilFunctionTest('Serialize transaction', 7_500, () => { for(let i = 0; i < 7_500; ++i) - noDiscard += (protocol.cpp_serialize_transaction(transaction).content as string).length % 10 + i; + noDiscard += (protocol.cpp_serialize_transaction(transaction, false).content as string).length % 10 + i; return noDiscard; }); -- GitLab