Skip to content

Commit

Permalink
test: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
b00ste committed Oct 10, 2023
1 parent f09e813 commit b35c61b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 32 deletions.
45 changes: 20 additions & 25 deletions tests/LSP6KeyManager/Interactions/BatchExecute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,19 +430,18 @@ 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')),
ethers.utils.keccak256(ethers.utils.toUtf8Bytes('key2')),
];
const dataValues = ['0xaaaaaaaa', '0xbbbbbbbb'];

const keyManagerBalanceBefore = await ethers.provider.getBalance(
context.keyManager.address,
);

const firstSetDataPayload = context.universalProfile.interface.encodeFunctionData(
'setData',
[dataKeys[0], dataValues[0]],
Expand All @@ -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);
});
});
});
Expand Down Expand Up @@ -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);
});
});
Expand Down Expand Up @@ -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);
});
});
});
Expand Down
14 changes: 9 additions & 5 deletions tests/LSP6KeyManager/SetData/PermissionSetData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ export const shouldBehaveLikePermissionSetData = (buildContext: () => Promise<LS
});

describe('when sending value while setting data', async () => {
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', [
Expand All @@ -172,7 +172,9 @@ export const shouldBehaveLikePermissionSetData = (buildContext: () => Promise<LS
context.keyManager
.connect(canSetDataWithAllowedERC725YDataKeys)
.execute(payload, { value: 12 }),
).to.be.revertedWithCustomError(context.keyManager, 'CannotSendValueToSetData');
).to.changeEtherBalances([context.universalProfile.address], [12]);

expect(await context.universalProfile.getData(key)).to.equal(value);
});
});
});
Expand Down Expand Up @@ -505,7 +507,7 @@ export const shouldBehaveLikePermissionSetData = (buildContext: () => Promise<LS
});

describe('when sending value while setting data', async () => {
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')),
Expand All @@ -529,7 +531,9 @@ export const shouldBehaveLikePermissionSetData = (buildContext: () => Promise<LS

await expect(
context.keyManager.connect(context.mainController).execute(payload, { value: 12 }),
).to.be.revertedWithCustomError(context.keyManager, 'CannotSendValueToSetData');
).to.changeEtherBalances([context.universalProfile.address], [12]);

expect(await context.universalProfile.getDataBatch(keys)).to.deep.equal(values);
});
});
});
Expand Down
2 changes: 0 additions & 2 deletions tests/LSP6KeyManager/internals/Execute.internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export const testExecuteInternals = (buildContext: () => Promise<LSP6InternalsTe
await expect(
context.keyManagerInternalTester.verifyPermissions(
context.mainController.address,
0,
calldata,
),
).to.not.be.reverted;
Expand Down Expand Up @@ -78,7 +77,6 @@ export const testExecuteInternals = (buildContext: () => Promise<LSP6InternalsTe
await expect(
context.keyManagerInternalTester.verifyPermissions(
context.mainController.address,
0,
invalidCalldata,
),
).to.be.reverted;
Expand Down

0 comments on commit b35c61b

Please sign in to comment.