From a1cc49e1adc28622e5d01f6701ba729745561891 Mon Sep 17 00:00:00 2001 From: Alejo Acosta Date: Thu, 19 Sep 2024 11:29:10 -0300 Subject: [PATCH] add unit test for paymentcode serialization --- src/_tests/unit/qihdwallet.unit.test.ts | 49 ++++++++++++++++++++++++ testcases/qi-serialization.json.gz | Bin 1019 -> 1049 bytes 2 files changed, 49 insertions(+) diff --git a/src/_tests/unit/qihdwallet.unit.test.ts b/src/_tests/unit/qihdwallet.unit.test.ts index 1d4f532e..666ed19c 100644 --- a/src/_tests/unit/qihdwallet.unit.test.ts +++ b/src/_tests/unit/qihdwallet.unit.test.ts @@ -91,6 +91,55 @@ describe('QiHDWallet: Test serialization and deserialization of QiHDWallet', fun } }); +describe('QiHDWallet: Test serialization and deserialization of QiHDWallet with payment codes', function () { + this.timeout(10000); + it('tests serialization and deserialization with payment codes and addresses', async function () { + // Create Alice's wallet + const aliceMnemonic = Mnemonic.fromPhrase( + 'empower cook violin million wool twelve involve nice donate author mammal salt royal shiver birth olympic embody hello beef suit isolate mixed text spot', + ); + const aliceQiWallet = QiHDWallet.fromMnemonic(aliceMnemonic); + + // Create Bob's wallet + const bobMnemonic = Mnemonic.fromPhrase( + 'innocent perfect bus miss prevent night oval position aspect nut angle usage expose grace juice', + ); + const bobQiWallet = QiHDWallet.fromMnemonic(bobMnemonic); + + // Get payment codes + const alicePaymentCode = await aliceQiWallet.getPaymentCode(0); + const bobPaymentCode = await bobQiWallet.getPaymentCode(0); + + // Generate addresses + await aliceQiWallet.generateSendAddress(bobPaymentCode, Zone.Cyprus1); + await aliceQiWallet.generateReceiveAddress(bobPaymentCode, Zone.Cyprus1); + + // Serialize Alice's wallet + const serializedAliceWallet = aliceQiWallet.serialize(); + + // Deserialize Alice's wallet + const deserializedAliceWallet = await QiHDWallet.deserialize(serializedAliceWallet); + + // Assertions + assert.strictEqual( + await deserializedAliceWallet.getPaymentCode(0), + alicePaymentCode, + 'Payment code should match after deserialization', + ); + + assert.deepStrictEqual( + deserializedAliceWallet.receiverPaymentCodeInfo, + aliceQiWallet.receiverPaymentCodeInfo, + 'Receiver payment code info should match', + ); + assert.deepStrictEqual( + deserializedAliceWallet.senderPaymentCodeInfo, + aliceQiWallet.senderPaymentCodeInfo, + 'Sender payment code info should match', + ); + }); +}); + describe('QiHDWallet: Test transaction signing', function () { const tests = loadTests('qi-transaction'); for (const test of tests) { diff --git a/testcases/qi-serialization.json.gz b/testcases/qi-serialization.json.gz index 3c34289f83fba49e8fa402ff61fa55aa08c42f62..42fe4a16cec3dc1cc5f7a52de24079f3504cc8a9 100644 GIT binary patch literal 1049 zcmV+!1m^o6iwFp3H0)*o1953Bb7gXAVQgu7VRUJ4ZZ2wbZ*Bn9mQ8aaHxP#J{uL_D zKIo(Ml^cwqDwRtPxo!ENkJd7knGwYdw%L^bdxUK;ut1EnsoET1gqrSZJ$he_zT6P< zSNRY!>RgMXU&!duH4P5ru^#5c#kj=2$DY(3sn(0-s%N)^6W2u|Mz^ntZHH~{>aa=1 zc99=(NkYzll7~7sC9kcUrp_IC%()@MBQ_6M%01-Gv!o%3xpM;&w;JYoNm|#ot|7f^ z2C~fS&2U~nl$yR?mX>m}ZWnbR*!mpTWR6XfiAPMNU)2Mt``m1bwe=H5GT_rd`b8eL zy)N9+wSDRI%ggWW;$LDeguLp85~R29v)^*}f`vX&I(nOazP*&qPG_@^W%JY7e3$+5 zynkCyUJZ*}cf*+_ZNnw{K3nF8r@8Cruca9mAeAs3)?AKX&GQL1xhPnCQA8nV2lbY*w{AD zC}tc;FDs!`!639i#i`O^ItDXgBAlVZjzzTjeic%W%i1;dH;j8!M#XmhYjZnMj~4T# z>+yeJ_R?!8+x*9RvFX+-yPMt}YkRIChgw*y{BOA4nom-&GI*Y>6f!6S=n<6BUQ!ll z1m+YMQJEr7<4p`0Vo|BkG_hzYszWvWTcMvjtM-J(OTPz!Fn8V84Tt2K9uGpNY;&N& z^I(LONLj&POOqTNryCi9G0r5=(HB1i5DHSklwx86P=nJU=ul$Zg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