From b35c61be5eb229b5996c9b690262f1d6f2717bdc Mon Sep 17 00:00:00 2001 From: b00ste Date: Thu, 21 Sep 2023 15:20:39 +0300 Subject: [PATCH] test: update tests --- .../Interactions/BatchExecute.test.ts | 45 +++++++++---------- .../SetData/PermissionSetData.test.ts | 14 +++--- .../internals/Execute.internal.ts | 2 - 3 files changed, 29 insertions(+), 32 deletions(-) diff --git a/tests/LSP6KeyManager/Interactions/BatchExecute.test.ts b/tests/LSP6KeyManager/Interactions/BatchExecute.test.ts index 97604cf17..315c01a94 100644 --- a/tests/LSP6KeyManager/Interactions/BatchExecute.test.ts +++ b/tests/LSP6KeyManager/Interactions/BatchExecute.test.ts @@ -430,8 +430,11 @@ export const shouldBehaveLikeBatchExecute = ( }); describe('if specifying some value for each values[index]', () => { - it('should revert with Key Manager error `CannotSendValueToSetData` when sending value while setting data', async () => { - const amountToFund = ethers.utils.parseEther('2'); + it('should pass when sending value while setting data', async () => { + const msgValues = [ethers.utils.parseEther('2'), ethers.utils.parseEther('2')]; + const totalMsgValue = msgValues.reduce((accumulator, currentValue) => + accumulator.add(currentValue), + ); const dataKeys = [ ethers.utils.keccak256(ethers.utils.toUtf8Bytes('key1')), @@ -439,10 +442,6 @@ export const shouldBehaveLikeBatchExecute = ( ]; const dataValues = ['0xaaaaaaaa', '0xbbbbbbbb']; - const keyManagerBalanceBefore = await ethers.provider.getBalance( - context.keyManager.address, - ); - const firstSetDataPayload = context.universalProfile.interface.encodeFunctionData( 'setData', [dataKeys[0], dataValues[0]], @@ -453,25 +452,15 @@ export const shouldBehaveLikeBatchExecute = ( [dataKeys[1], dataValues[1]], ); - // this error occurs when calling `setData(...)` with msg.value, - // since these functions on ERC725Y are not payable await expect( context.keyManager .connect(context.mainController) - .executeBatch([1, 1], [firstSetDataPayload, secondSetDataPayload], { - value: amountToFund, + .executeBatch(msgValues, [firstSetDataPayload, secondSetDataPayload], { + value: totalMsgValue, }), - ).to.be.revertedWithCustomError(context.keyManager, 'CannotSendValueToSetData'); - - const keyManagerBalanceAfter = await ethers.provider.getBalance( - context.keyManager.address, - ); + ).to.changeEtherBalances([context.universalProfile.address], [totalMsgValue]); - expect(keyManagerBalanceAfter).to.equal(keyManagerBalanceBefore); - - // the Key Manager must not hold any funds and must always forward any funds sent to it. - // it's balance must always be 0 after any execution - expect(await provider.getBalance(context.keyManager.address)).to.equal(0); + expect(await context.universalProfile.getDataBatch(dataKeys)).to.deep.equal(dataValues); }); }); }); @@ -504,10 +493,8 @@ export const shouldBehaveLikeBatchExecute = ( context.keyManager.connect(context.mainController).executeBatch(msgValues, payloads, { value: totalValues, }), - ).to.changeEtherBalances( - [context.universalProfile.address, recipient], - [0, msgValues[1]], - ); + ).to.changeEtherBalances([context.universalProfile.address, recipient], msgValues); + expect(await context.universalProfile.getData(dataKey)).to.equal(dataValue); }); }); @@ -535,11 +522,19 @@ export const shouldBehaveLikeBatchExecute = ( accumulator.add(currentValue), ); + await context.keyManager + .connect(context.mainController) + .executeBatch(msgValues, payloads, { + value: totalValues, + }); + await expect( context.keyManager.connect(context.mainController).executeBatch(msgValues, payloads, { value: totalValues, }), - ).to.be.revertedWithCustomError(context.keyManager, 'CannotSendValueToSetData'); + ).to.changeEtherBalances([context.universalProfile.address, recipient], msgValues); + + expect(await context.universalProfile.getData(dataKey)).to.equal(dataValue); }); }); }); diff --git a/tests/LSP6KeyManager/SetData/PermissionSetData.test.ts b/tests/LSP6KeyManager/SetData/PermissionSetData.test.ts index 1ba77695e..bb0154297 100644 --- a/tests/LSP6KeyManager/SetData/PermissionSetData.test.ts +++ b/tests/LSP6KeyManager/SetData/PermissionSetData.test.ts @@ -159,8 +159,8 @@ export const shouldBehaveLikePermissionSetData = (buildContext: () => Promise { - it('should revert with Key Manager error `CannotSendValueToSetData`', async () => { - const key = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('My Key')); + it('should pass', async () => { + const key = ethers.utils.keccak256(ethers.utils.toUtf8Bytes('My First Key')); const value = ethers.utils.hexlify(ethers.utils.toUtf8Bytes('Hello Lukso!!!')); const payload = context.universalProfile.interface.encodeFunctionData('setData', [ @@ -172,7 +172,9 @@ export const shouldBehaveLikePermissionSetData = (buildContext: () => Promise Promise { - it('should revert with Key Manager error `CannotSendValueToSetData`', async () => { + it('should pass', async () => { const keys = [ ethers.utils.keccak256(ethers.utils.toUtf8Bytes('My First Key')), ethers.utils.keccak256(ethers.utils.toUtf8Bytes('My Second Key')), @@ -529,7 +531,9 @@ export const shouldBehaveLikePermissionSetData = (buildContext: () => Promise Promise Promise