Skip to content

Commit

Permalink
chore: fix tests for missing LSP1 Delegate permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ42 committed Feb 20, 2024
1 parent 462a5de commit f74db97
Show file tree
Hide file tree
Showing 21 changed files with 16,047 additions and 118 deletions.
2 changes: 1 addition & 1 deletion constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Set of constants values as defined in each LUKSO Standards Proposals (LSPs).
* @see https://github.com/lukso-network/LIPs/tree/main/LSPs
*/
// export * from './contracts';
export * from './contracts';

import { INTERFACE_ID_LSP0ERC725Account, LSP0_TYPE_IDS } from '@lukso/lsp0-contracts';
import { INTERFACE_ID_LSP1, LSP1DataKeys } from '@lukso/lsp1-contracts';
Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import './scripts/ci/check-deployer-balance';
import './scripts/ci/verify-all-contracts';

// Typescript types for web3.js
// import '@nomiclabs/hardhat-web3';
import '@nomiclabs/hardhat-web3';

/**
* @dev uncomment to generate contract docs in Markdown
Expand Down
15,930 changes: 15,920 additions & 10 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
"test:lsp20": "hardhat test --no-compile tests/LSP20CallVerification/LSP6/LSP20WithLSP6.test.ts",
"test:lsp20init": "hardhat test --no-compile tests/LSP20CallVerification/LSP6/LSP20WithLSP6Init.test.ts",
"test:lsp23": "hardhat test --no-compile tests/LSP23LinkedContractsDeployment/LSP23LinkedContractsDeployment.test.ts",
"test:lsp25": "hardhat test --no-compile tests/LSP25ExecuteRelayCall/LSP25MultiChannelNonce.test.ts",
"test:reentrancy": "hardhat test --no-compile tests/Reentrancy/Reentrancy.test.ts",
"test:reentrancyinit": "hardhat test --no-compile tests/Reentrancy/ReentrancyInit.test.ts",
"test:foundry": "forge test --no-match-test Skip -vvv --gas-report > gasreport.ansi",
Expand Down
4 changes: 2 additions & 2 deletions tests/LSP17Extensions/Extension4337/4337.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { fillAndSign } from '../helpers/UserOp';

describe('4337', function () {
let bundler: SignerWithAddress;
let deployer: Signer;
let deployer: SignerWithAddress;
let universalProfile: UniversalProfile;
let universalProfileAddress: string;
let keyManager: LSP6KeyManager;
Expand All @@ -36,7 +36,7 @@ describe('4337', function () {

before('setup', async function () {
const provider = ethers.provider;
deployer = provider.getSigner();
deployer = await provider.getSigner();
const deployerAddress = await deployer.getAddress();

[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export type LSP1DelegateTestContext = {
*/
async function getLSP10MapAndArrayKeysValue(account, lsp9Vault) {
const mapValue = await account.getData(
ethers.concat([ERC725YDataKeys.LSP10.LSP10VaultsMap, lsp9Vault.address]),
ethers.concat([ERC725YDataKeys.LSP10.LSP10VaultsMap, await lsp9Vault.getAddress()]),
);

const indexInHex = '0x' + mapValue.substr(10, mapValue.length);
Expand Down Expand Up @@ -2707,7 +2707,7 @@ export const shouldBehaveLikeLSP1Delegate = (
someVault.interface.encodeFunctionData('renounceOwnership');

// Skip 1000 blocks
await network.provider.send('hardhat_mine', [ethers.toBeHex(1000)]);
await network.provider.send('hardhat_mine', [ethers.toQuantity(1000)]);

// Call renounceOwnership for the first time
await context.universalProfile2
Expand Down Expand Up @@ -2930,7 +2930,7 @@ export const shouldBehaveLikeLSP1Delegate = (
LSP1_TYPE_IDS.LSP9OwnershipTransferred_SenderNotification,
abiCoder.encode(
['address', 'address'],
[testContext.universalProfile.getAddress(), newVaultOwner.address],
[await testContext.universalProfile.getAddress(), newVaultOwner.address],
),
expectedReturnedValues,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('LSP1UniversalReceiverDelegateUP', () => {

const [UP2, KM2] = await setupProfileWithKeyManagerWithURD(accounts.owner2);
const lsp1universalReceiverDelegateUP = LSP1_URD_UP as LSP1UniversalReceiverDelegateUP;

const universalProfile1 = UP1 as UniversalProfile;
const universalProfile2 = UP2 as UniversalProfile;
const lsp6KeyManager1 = KM1 as LSP6KeyManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,11 @@ export const shouldBehaveLikeLSP1Delegate = (buildContext: () => Promise<LSP1Tes
callPayload(context.lsp9Vault1, await lsp7TokenB.getAddress(), abi),
);
});

it('should keep the same lsp5keys: arrayLength 2, index 1, tokenB address in Vault1', async () => {
const [indexInMap, interfaceId, arrayLength, elementAddress] =
await getLSP5MapAndArrayKeysValue(context.lsp9Vault1, lsp7TokenB);

expect(indexInMap).to.equal(1);
expect(interfaceId).to.equal(INTERFACE_IDS.LSP7DigitalAsset);
expect(arrayLength).to.equal(ARRAY_LENGTH.TWO);
Expand Down Expand Up @@ -1807,7 +1809,7 @@ export const shouldBehaveLikeLSP1Delegate = (buildContext: () => Promise<LSP1Tes

const LSP9_ExecuteCalldata = context.lsp9Vault1.interface.encodeFunctionData('execute', [
OPERATION_TYPES.CALL,
LSP7.getAddress(),
await LSP7.getAddress(),
0,
LSP7_TransferCalldata,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const shouldBehaveLikePermissionChangeOwner = (
cannotChangeOwner = context.accounts[2];

newKeyManager = await new LSP6KeyManager__factory(context.mainController).deploy(
await context.universalProfile.getAddress(),
context.universalProfile.target,
);

permissionsKeys = [
Expand Down Expand Up @@ -69,7 +69,7 @@ export const shouldBehaveLikePermissionChangeOwner = (
await expect(
context.universalProfile
.connect(cannotChangeOwner)
.transferOwnership(newKeyManager.address),
.transferOwnership(await newKeyManager.getAddress()),
)
.to.be.revertedWithCustomError(context.keyManager, 'NotAuthorised')
.withArgs(cannotChangeOwner.address, 'TRANSFEROWNERSHIP');
Expand All @@ -80,7 +80,7 @@ export const shouldBehaveLikePermissionChangeOwner = (
before('`transferOwnership(...)` to new Key Manager', async () => {
await context.universalProfile
.connect(context.mainController)
.transferOwnership(newKeyManager.address);
.transferOwnership(await newKeyManager.getAddress());
});

after('reset ownership', async () => {
Expand All @@ -91,15 +91,15 @@ export const shouldBehaveLikePermissionChangeOwner = (

it('should have set newKeyManager as pendingOwner', async () => {
const pendingOwner = await context.universalProfile.pendingOwner();
expect(pendingOwner).to.equal(newKeyManager.address);
expect(pendingOwner).to.equal(await newKeyManager.getAddress());
});

it('owner should remain the current KeyManager', async () => {
const ownerBefore = await context.universalProfile.owner();

await context.universalProfile
.connect(context.mainController)
.transferOwnership(newKeyManager.address);
.transferOwnership(await newKeyManager.getAddress());

const ownerAfter = await context.universalProfile.owner();

Expand Down Expand Up @@ -160,7 +160,7 @@ export const shouldBehaveLikePermissionChangeOwner = (
before('`transferOwnership(...)` to new KeyManager', async () => {
await context.universalProfile
.connect(canChangeOwner)
.transferOwnership(newKeyManager.address);
.transferOwnership(await newKeyManager.getAddress());
});

after('reset ownership', async () => {
Expand All @@ -171,15 +171,15 @@ export const shouldBehaveLikePermissionChangeOwner = (

it('should have set newKeyManager as pendingOwner', async () => {
const pendingOwner = await context.universalProfile.pendingOwner();
expect(pendingOwner).to.equal(newKeyManager.address);
expect(pendingOwner).to.equal(await newKeyManager.getAddress());
});

it('owner should remain the current KeyManager', async () => {
const ownerBefore = await context.universalProfile.owner();

await context.universalProfile
.connect(canChangeOwner)
.transferOwnership(newKeyManager.address);
.transferOwnership(await newKeyManager.getAddress());

const ownerAfter = await context.universalProfile.owner();

Expand All @@ -194,10 +194,10 @@ export const shouldBehaveLikePermissionChangeOwner = (

await context.universalProfile
.connect(canChangeOwner)
.transferOwnership(overridenPendingOwner.address);
.transferOwnership(await overridenPendingOwner.getAddress());

const pendingOwner = await context.universalProfile.pendingOwner();
expect(pendingOwner).to.equal(overridenPendingOwner.address);
expect(pendingOwner).to.equal(await overridenPendingOwner.getAddress());
});
});
});
Expand Down Expand Up @@ -225,7 +225,7 @@ export const shouldBehaveLikePermissionChangeOwner = (
before(async () => {
await context.universalProfile
.connect(context.mainController)
.transferOwnership(newKeyManager.address);
.transferOwnership(await newKeyManager.getAddress());

pendingOwner = await context.universalProfile.pendingOwner();
});
Expand All @@ -239,7 +239,7 @@ export const shouldBehaveLikePermissionChangeOwner = (
it('should let you accept ownership if controller has permission', async () => {
await context.universalProfile.connect(canChangeOwner).acceptOwnership();

expect(await context.universalProfile.owner()).to.equal(newKeyManager.address);
expect(await context.universalProfile.owner()).to.equal(await newKeyManager.getAddress());
});

it("should have change the account's owner to the pendingOwner (= pending KeyManager)", async () => {
Expand Down Expand Up @@ -273,7 +273,7 @@ export const shouldBehaveLikePermissionChangeOwner = (

await expect(oldKeyManager.connect(context.mainController).execute(payload))
.to.be.revertedWithCustomError(newKeyManager, 'NoPermissionsSet')
.withArgs(oldKeyManager.address);
.withArgs(await oldKeyManager.getAddress());
});

it('should revert with error `NoPermissionsSet` when calling `execute(...)`', async () => {
Expand All @@ -289,7 +289,7 @@ export const shouldBehaveLikePermissionChangeOwner = (

await expect(oldKeyManager.connect(context.mainController).execute(payload))
.to.be.revertedWithCustomError(newKeyManager, 'NoPermissionsSet')
.withArgs(oldKeyManager.address);
.withArgs(await oldKeyManager.getAddress());
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export const shouldBehaveLikeAllowedFunctions = (buildContext: () => Promise<LSP

await context.universalProfile
.connect(addressCanCallOnlyTransferOnLSP8)
.execute(OPERATION_TYPES.CALL, lsp8Contract.address, 0, transferPayload);
.execute(OPERATION_TYPES.CALL, lsp8Contract.target, 0, transferPayload);

expect(await lsp8Contract.tokenOwnerOf(tokenIdToTransfer)).to.equal(recipient);
});
Expand All @@ -303,12 +303,12 @@ export const shouldBehaveLikeAllowedFunctions = (buildContext: () => Promise<LSP
await expect(
context.universalProfile
.connect(addressCanCallOnlyTransferOnLSP8)
.execute(OPERATION_TYPES.CALL, lsp8Contract.address, 0, authorizeOperatorPayload),
.execute(OPERATION_TYPES.CALL, lsp8Contract.target, 0, authorizeOperatorPayload),
)
.to.be.revertedWithCustomError(context.keyManager, 'NotAllowedCall')
.withArgs(
await addressCanCallOnlyTransferOnLSP8.getAddress(),
lsp8Contract.address,
lsp8Contract.target,
lsp8Contract.interface.getFunction('authorizeOperator').selector,
);
});
Expand All @@ -329,7 +329,7 @@ export const shouldBehaveLikeAllowedFunctions = (buildContext: () => Promise<LSP

await context.universalProfile
.connect(addressCanCallAnyLSP7FunctionAndOnlyAuthorizeOperatorOnLSP8)
.execute(OPERATION_TYPES.CALL, lsp7Contract.address, 0, mintPayload);
.execute(OPERATION_TYPES.CALL, lsp7Contract.target, 0, mintPayload);

expect(await lsp7Contract.balanceOf(recipient)).to.equal(amount);
});
Expand All @@ -355,16 +355,16 @@ export const shouldBehaveLikeAllowedFunctions = (buildContext: () => Promise<LSP

await context.universalProfile
.connect(addressCanCallAnyLSP7FunctionAndOnlyAuthorizeOperatorOnLSP8)
.execute(OPERATION_TYPES.CALL, lsp7Contract.address, 0, transferPayload);
.execute(OPERATION_TYPES.CALL, lsp7Contract.target, 0, transferPayload);

// CHECK that UP token balance has decreased
expect(
await lsp7Contract.balanceOf(await context.universalProfile.getAddress()),
).to.equal(previousUPTokenBalance.sub(amount));
).to.equal(previousUPTokenBalance - BigInt(amount));

// CHECK that recipient token balance has increased
expect(await lsp7Contract.balanceOf(recipient)).to.equal(
previousRecipientTokenBalance.add(amount),
previousRecipientTokenBalance + BigInt(amount),
);
});

Expand All @@ -379,7 +379,7 @@ export const shouldBehaveLikeAllowedFunctions = (buildContext: () => Promise<LSP

await context.universalProfile
.connect(addressCanCallAnyLSP7FunctionAndOnlyAuthorizeOperatorOnLSP8)
.execute(OPERATION_TYPES.CALL, lsp7Contract.address, 0, authorizeOperatorPayload);
.execute(OPERATION_TYPES.CALL, lsp7Contract.target, 0, authorizeOperatorPayload);

expect(
await lsp7Contract.authorizedAmountFor(
Expand All @@ -398,9 +398,9 @@ export const shouldBehaveLikeAllowedFunctions = (buildContext: () => Promise<LSP

await context.universalProfile
.connect(addressCanCallAnyLSP7FunctionAndOnlyAuthorizeOperatorOnLSP8)
.execute(OPERATION_TYPES.CALL, lsp7Contract.address, 0, setDataPayload);
.execute(OPERATION_TYPES.CALL, lsp7Contract.target, 0, setDataPayload);

expect(await lsp7Contract.callStatic.getData(key)).to.equal(value);
expect(await lsp7Contract.getData(key)).to.equal(value);
});
});

Expand All @@ -415,7 +415,7 @@ export const shouldBehaveLikeAllowedFunctions = (buildContext: () => Promise<LSP

await context.universalProfile
.connect(addressCanCallAnyLSP7FunctionAndOnlyAuthorizeOperatorOnLSP8)
.execute(OPERATION_TYPES.CALL, lsp8Contract.address, 0, authorizeOperatorPayload);
.execute(OPERATION_TYPES.CALL, lsp8Contract.target, 0, authorizeOperatorPayload);

expect(await lsp8Contract.isOperatorFor(recipient, tokenIdToApprove)).to.be.true;
});
Expand All @@ -434,12 +434,12 @@ export const shouldBehaveLikeAllowedFunctions = (buildContext: () => Promise<LSP
await expect(
context.universalProfile
.connect(addressCanCallAnyLSP7FunctionAndOnlyAuthorizeOperatorOnLSP8)
.execute(OPERATION_TYPES.CALL, lsp8Contract.address, 0, transferPayload),
.execute(OPERATION_TYPES.CALL, lsp8Contract.target, 0, transferPayload),
)
.to.be.revertedWithCustomError(context.keyManager, 'NotAllowedCall')
.withArgs(
await addressCanCallAnyLSP7FunctionAndOnlyAuthorizeOperatorOnLSP8.getAddress(),
lsp8Contract.address,
lsp8Contract.target,
lsp8Contract.interface.getFunction('transfer').selector,
);
});
Expand All @@ -458,12 +458,12 @@ export const shouldBehaveLikeAllowedFunctions = (buildContext: () => Promise<LSP
await expect(
context.universalProfile
.connect(addressCanCallAnyLSP7FunctionAndOnlyAuthorizeOperatorOnLSP8)
.execute(OPERATION_TYPES.CALL, lsp8Contract.address, 0, mintPayload),
.execute(OPERATION_TYPES.CALL, lsp8Contract.target, 0, mintPayload),
)
.to.be.revertedWithCustomError(context.keyManager, 'NotAllowedCall')
.withArgs(
await addressCanCallAnyLSP7FunctionAndOnlyAuthorizeOperatorOnLSP8.getAddress(),
lsp8Contract.address,
lsp8Contract.target,
lsp8Contract.interface.getFunction('mint').selector,
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,18 @@ export const shouldBehaveLikeAllowedStandards = (buildContext: () => Promise<LSP

describe('when trying to interact an ERC725Account (LSP0)', () => {
it('should allow to transfer LYX', async () => {
const initialAccountBalance = await provider.getBalance(otherUniversalProfile.address);
const initialAccountBalance = await provider.getBalance(otherUniversalProfile.target);

await context.universalProfile
.connect(addressCanInteractOnlyWithERC1271)
.execute(
OPERATION_TYPES.CALL,
otherUniversalProfile.address,
otherUniversalProfile.target,
ethers.parseEther('1'),
'0x',
);

const newAccountBalance = await provider.getBalance(otherUniversalProfile.address);
const newAccountBalance = await provider.getBalance(otherUniversalProfile.target);
expect(newAccountBalance).to.be.gt(initialAccountBalance);
});
});
Expand Down Expand Up @@ -246,15 +246,15 @@ export const shouldBehaveLikeAllowedStandards = (buildContext: () => Promise<LSP
.connect(addressCanInteractOnlyWithLSP7)
.execute(
OPERATION_TYPES.CALL,
otherUniversalProfile.address,
otherUniversalProfile.target,
ethers.parseEther('1'),
'0x',
),
)
.to.be.revertedWithCustomError(context.keyManager, 'NotAllowedCall')
.withArgs(
addressCanInteractOnlyWithLSP7.address,
otherUniversalProfile.address,
otherUniversalProfile.target,
'0x00000000',
);
});
Expand Down Expand Up @@ -339,7 +339,7 @@ export const shouldBehaveLikeAllowedStandards = (buildContext: () => Promise<LSP

await context.universalProfile
.connect(addressCanInteractOnlyWithLSP7)
.execute(OPERATION_TYPES.CALL, lsp7TokenB.address, 0, transferPayload);
.execute(OPERATION_TYPES.CALL, lsp7TokenB.target, 0, transferPayload);

expect(await lsp7TokenB.balanceOf(recipient)).to.equal(amount);
expect(await lsp7TokenB.balanceOf(await context.universalProfile.getAddress())).to.equal(
Expand All @@ -361,7 +361,7 @@ export const shouldBehaveLikeAllowedStandards = (buildContext: () => Promise<LSP

await context.universalProfile
.connect(addressCanInteractOnlyWithLSP7)
.execute(OPERATION_TYPES.CALL, lsp7TokenC.address, 0, transferPayload);
.execute(OPERATION_TYPES.CALL, lsp7TokenC.target, 0, transferPayload);

expect(await lsp7TokenC.balanceOf(recipient)).to.equal(amount);
expect(await lsp7TokenC.balanceOf(await context.universalProfile.getAddress())).to.equal(
Expand Down
Loading

0 comments on commit f74db97

Please sign in to comment.