From 7f786ea2f02b94d7ebd71ac9675ab46c6cc22118 Mon Sep 17 00:00:00 2001 From: Skydev0h Date: Thu, 15 Feb 2024 20:45:55 +0200 Subject: [PATCH] Added a test for separate auth disable by extension --- tests/wallet-v5-extensions.spec.ts | 89 ++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/tests/wallet-v5-extensions.spec.ts b/tests/wallet-v5-extensions.spec.ts index 78c94f0..4d2f30d 100644 --- a/tests/wallet-v5-extensions.spec.ts +++ b/tests/wallet-v5-extensions.spec.ts @@ -426,4 +426,93 @@ describe('Wallet V5 extensions auth', () => { const receiverBalanceAfter = (await blockchain.getContract(testReceiver)).balance; expect(receiverBalanceAfter).toEqual(receiverBalanceBefore + forwardValue - fee); }); + + it('Add ext; disallow signature auth by ext; re-allow and self-delete by extension; do signed transfer', async () => { + await walletV5.sendInternalSignedMessage(sender, { + value: toNano(0.1), + body: createBody(packActionsList([ + new ActionAddExtension(sender.address!) + ])) + }); + + const isSignatureAuthAllowed = await walletV5.getIsSignatureAuthAllowed(); + expect(isSignatureAuthAllowed).toEqual(-1); + + const receipt0 = await walletV5.sendInternalMessageFromExtension(sender, { + value: toNano('0.1'), + body: packActionsList([ + new ActionSetSignatureAuthAllowed(false) + ]) + }); + + expect(receipt0.transactions.length).toEqual(2); + accountForGas(receipt0.transactions); + + expect( + ( + (receipt0.transactions[1].description as TransactionDescriptionGeneric) + .computePhase as TransactionComputeVm + ).exitCode + ).toEqual(0); + + const isSignatureAuthAllowed0 = await walletV5.getIsSignatureAuthAllowed(); + expect(isSignatureAuthAllowed0).toEqual(0); + + const receipt = await walletV5.sendInternalMessageFromExtension(sender, { + value: toNano('0.1'), + body: packActionsList([ + new ActionRemoveExtension(sender.address!), + new ActionSetSignatureAuthAllowed(true) + ]) + }); + + expect(receipt.transactions.length).toEqual(2); + accountForGas(receipt.transactions); + + expect( + ( + (receipt.transactions[1].description as TransactionDescriptionGeneric) + .computePhase as TransactionComputeVm + ).exitCode + ).toEqual(0); + + const isSignatureAuthAllowed1 = await walletV5.getIsSignatureAuthAllowed(); + expect(isSignatureAuthAllowed1).toEqual(-1); + + const contract_seqno = await walletV5.getSeqno(); + expect(contract_seqno).toEqual(seqno + 2); + + // Allowing or disallowing signature auth increments seqno, need to re-read + seqno = contract_seqno; + + const testReceiver = Address.parse('EQAvDfWFG0oYX19jwNDNBBL1rKNT9XfaGP9HyTb5nb2Eml6y'); + const forwardValue = toNano(0.001); + + const receiverBalanceBefore = (await blockchain.getContract(testReceiver)).balance; + + const msg = createMsgInternal({ dest: testReceiver, value: forwardValue }); + + const actionsList2 = packActionsList([ + new ActionSendMsg(SendMode.PAY_GAS_SEPARATELY, msg) + ]); + + const receipt2 = await walletV5.sendInternal(sender, { + sendMode: SendMode.PAY_GAS_SEPARATELY, + value: toNano(0.1), + body: createBody(actionsList2) + }); + + expect(receipt2.transactions.length).toEqual(3); + accountForGas(receipt2.transactions); + + expect(receipt2.transactions).toHaveTransaction({ + from: walletV5.address, + to: testReceiver, + value: forwardValue + }); + + const fee = receipt2.transactions[2].totalFees.coins; + const receiverBalanceAfter = (await blockchain.getContract(testReceiver)).balance; + expect(receiverBalanceAfter).toEqual(receiverBalanceBefore + forwardValue - fee); + }); });