mirror of
https://github.com/lens-protocol/core.git
synced 2026-04-22 03:02:03 -04:00
test: SetFollowModule foundry tests
This commit is contained in:
20
TestsList.md
20
TestsList.md
@@ -274,20 +274,20 @@ Scenarios
|
||||
Setting Follow Module
|
||||
Generic
|
||||
Negatives
|
||||
[ ] UserTwo should fail to set the follow module for the profile owned by User
|
||||
[ ] User should fail to set a follow module that is not whitelisted
|
||||
[ ] User should fail to set a follow module with invalid follow module data format
|
||||
[X] UserTwo should fail to set the follow module for the profile owned by User
|
||||
[X] User should fail to set a follow module that is not whitelisted
|
||||
[X] User should fail to set a follow module with invalid follow module data format
|
||||
Scenarios
|
||||
[ ] User should set a whitelisted follow module, fetching the profile follow module should return the correct address, user then sets it to the zero address and fetching returns the zero address
|
||||
[X] User should set a whitelisted follow module, fetching the profile follow module should return the correct address, user then sets it to the zero address and fetching returns the zero address
|
||||
Meta-tx
|
||||
Negatives
|
||||
[ ] TestWallet should fail to set a follow module with sig with signature deadline mismatch
|
||||
[ ] TestWallet should fail to set a follow module with sig with invalid deadline
|
||||
[ ] TestWallet should fail to set a follow module with sig with invalid nonce
|
||||
[ ] TestWallet should fail to set a follow module with sig with an unwhitelisted follow module
|
||||
[ ] TestWallet should sign attempt to set follow module with sig, then cancel with empty permitForAll, then fail to set follow module with sig
|
||||
[X] TestWallet should fail to set a follow module with sig with signature deadline mismatch
|
||||
[X] TestWallet should fail to set a follow module with sig with invalid deadline
|
||||
[X] TestWallet should fail to set a follow module with sig with invalid nonce
|
||||
[X] TestWallet should fail to set a follow module with sig with an unwhitelisted follow module
|
||||
[X] TestWallet should sign attempt to set follow module with sig, then cancel with empty permitForAll, then fail to set follow module with sig
|
||||
Scenarios
|
||||
[ ] TestWallet should set a whitelisted follow module with sig, fetching the profile follow module should return the correct address
|
||||
[X] TestWallet should set a whitelisted follow module with sig, fetching the profile follow module should return the correct address
|
||||
|
||||
Collect NFT
|
||||
Negatives
|
||||
|
||||
@@ -6,11 +6,6 @@ import '../../contracts/mocks/MockFollowModule.sol';
|
||||
|
||||
contract MiscTest is BaseTest {
|
||||
// Negatives
|
||||
function testSetFollowModuleNotExecutorFails() public {
|
||||
vm.expectRevert(Errors.ExecutorInvalid.selector);
|
||||
hub.setFollowModule(newProfileId, address(0), '');
|
||||
}
|
||||
|
||||
function testSetDefaultProfileNotExecutorFails() public {
|
||||
vm.expectRevert(Errors.ExecutorInvalid.selector);
|
||||
hub.setDefaultProfile(profileOwner, newProfileId);
|
||||
@@ -32,20 +27,6 @@ contract MiscTest is BaseTest {
|
||||
}
|
||||
|
||||
// Positives
|
||||
function testExecutorSetFollowModule() public {
|
||||
assertEq(hub.getFollowModule(newProfileId), address(0));
|
||||
vm.prank(profileOwner);
|
||||
hub.setDelegatedExecutorApproval(otherSigner, true);
|
||||
|
||||
address mockFollowModule = address(new MockFollowModule());
|
||||
vm.prank(governance);
|
||||
hub.whitelistFollowModule(mockFollowModule, true);
|
||||
|
||||
vm.prank(otherSigner);
|
||||
hub.setFollowModule(newProfileId, mockFollowModule, abi.encode(1));
|
||||
assertEq(hub.getFollowModule(newProfileId), mockFollowModule);
|
||||
}
|
||||
|
||||
function testExecutorSetDefaultProfile() public {
|
||||
assertEq(hub.getDefaultProfile(profileOwner), 0);
|
||||
vm.prank(profileOwner);
|
||||
@@ -88,52 +69,6 @@ contract MiscTest is BaseTest {
|
||||
|
||||
// Meta-tx
|
||||
// Negatives
|
||||
function testSetFollowModuleWithSigInvalidSignerFails() public {
|
||||
uint256 nonce = 0;
|
||||
uint256 deadline = type(uint256).max;
|
||||
bytes32 digest = _getSetFollowModuleTypedDataHash(
|
||||
newProfileId,
|
||||
address(0),
|
||||
'',
|
||||
nonce,
|
||||
deadline
|
||||
);
|
||||
|
||||
vm.expectRevert(Errors.SignatureInvalid.selector);
|
||||
hub.setFollowModuleWithSig(
|
||||
DataTypes.SetFollowModuleWithSigData({
|
||||
delegatedSigner: address(0),
|
||||
profileId: newProfileId,
|
||||
followModule: address(0),
|
||||
followModuleInitData: '',
|
||||
sig: _getSigStruct(otherSignerKey, digest, deadline)
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
function testSetFollowModuleWithSigNotExecutorFails() public {
|
||||
uint256 nonce = 0;
|
||||
uint256 deadline = type(uint256).max;
|
||||
bytes32 digest = _getSetFollowModuleTypedDataHash(
|
||||
newProfileId,
|
||||
address(0),
|
||||
'',
|
||||
nonce,
|
||||
deadline
|
||||
);
|
||||
|
||||
vm.expectRevert(Errors.ExecutorInvalid.selector);
|
||||
hub.setFollowModuleWithSig(
|
||||
DataTypes.SetFollowModuleWithSigData({
|
||||
delegatedSigner: otherSigner,
|
||||
profileId: newProfileId,
|
||||
followModule: address(0),
|
||||
followModuleInitData: '',
|
||||
sig: _getSigStruct(otherSignerKey, digest, deadline)
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
function testSetDefaultProfileWithSigInvalidSignerFails() public {
|
||||
uint256 nonce = 0;
|
||||
uint256 deadline = type(uint256).max;
|
||||
@@ -293,66 +228,6 @@ contract MiscTest is BaseTest {
|
||||
}
|
||||
|
||||
// Postivies
|
||||
function testSetFollowModuleWithSig() public {
|
||||
address mockFollowModule = address(new MockFollowModule());
|
||||
vm.prank(governance);
|
||||
hub.whitelistFollowModule(mockFollowModule, true);
|
||||
|
||||
uint256 nonce = 0;
|
||||
uint256 deadline = type(uint256).max;
|
||||
|
||||
bytes32 digest = _getSetFollowModuleTypedDataHash(
|
||||
newProfileId,
|
||||
mockFollowModule,
|
||||
abi.encode(1),
|
||||
nonce,
|
||||
deadline
|
||||
);
|
||||
|
||||
assertEq(hub.getFollowModule(newProfileId), address(0));
|
||||
hub.setFollowModuleWithSig(
|
||||
DataTypes.SetFollowModuleWithSigData({
|
||||
delegatedSigner: address(0),
|
||||
profileId: newProfileId,
|
||||
followModule: mockFollowModule,
|
||||
followModuleInitData: abi.encode(1),
|
||||
sig: _getSigStruct(profileOwnerKey, digest, deadline)
|
||||
})
|
||||
);
|
||||
assertEq(hub.getFollowModule(newProfileId), mockFollowModule);
|
||||
}
|
||||
|
||||
function testExecutorSetFollowModuleWithSig() public {
|
||||
vm.prank(profileOwner);
|
||||
hub.setDelegatedExecutorApproval(otherSigner, true);
|
||||
|
||||
address mockFollowModule = address(new MockFollowModule());
|
||||
vm.prank(governance);
|
||||
hub.whitelistFollowModule(mockFollowModule, true);
|
||||
|
||||
uint256 nonce = 0;
|
||||
uint256 deadline = type(uint256).max;
|
||||
bytes32 digest = _getSetFollowModuleTypedDataHash(
|
||||
newProfileId,
|
||||
mockFollowModule,
|
||||
abi.encode(1),
|
||||
nonce,
|
||||
deadline
|
||||
);
|
||||
|
||||
assertEq(hub.getFollowModule(newProfileId), address(0));
|
||||
hub.setFollowModuleWithSig(
|
||||
DataTypes.SetFollowModuleWithSigData({
|
||||
delegatedSigner: otherSigner,
|
||||
profileId: newProfileId,
|
||||
followModule: mockFollowModule,
|
||||
followModuleInitData: abi.encode(1),
|
||||
sig: _getSigStruct(otherSignerKey, digest, deadline)
|
||||
})
|
||||
);
|
||||
assertEq(hub.getFollowModule(newProfileId), mockFollowModule);
|
||||
}
|
||||
|
||||
function testSetDefaultProfileWithSig() public {
|
||||
uint256 nonce = 0;
|
||||
uint256 deadline = type(uint256).max;
|
||||
|
||||
182
test/foundry/SetFollowModule.t.sol
Normal file
182
test/foundry/SetFollowModule.t.sol
Normal file
@@ -0,0 +1,182 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.13;
|
||||
|
||||
import './base/BaseTest.t.sol';
|
||||
import '../../contracts/mocks/MockFollowModule.sol';
|
||||
import './helpers/SignatureHelpers.sol';
|
||||
|
||||
// TODO: Refactor out all `hub.` calls (if we decide to go this route)
|
||||
contract SetFollowModuleTest is BaseTest, SignatureHelpers, SigSetup {
|
||||
address mockFollowModule;
|
||||
|
||||
function setUp() public virtual override(SigSetup, TestSetup) {
|
||||
TestSetup.setUp();
|
||||
SigSetup.setUp();
|
||||
mockFollowModule = address(new MockFollowModule());
|
||||
vm.prank(governance);
|
||||
hub.whitelistFollowModule(mockFollowModule, true);
|
||||
}
|
||||
|
||||
function _setFollowModulehWithSig(address delegatedSigner, uint256 signerPrivKey)
|
||||
internal
|
||||
virtual
|
||||
{
|
||||
_setFollowModulehWithSig(delegatedSigner, signerPrivKey, deadline, deadline);
|
||||
}
|
||||
|
||||
function _setFollowModulehWithSig(
|
||||
address delegatedSigner,
|
||||
uint256 signerPrivKey,
|
||||
uint256 digestDeadline,
|
||||
uint256 sigDeadline
|
||||
) internal virtual {
|
||||
bytes32 digest = _getSetFollowModuleTypedDataHash(
|
||||
newProfileId,
|
||||
mockFollowModule,
|
||||
abi.encode(1),
|
||||
nonce,
|
||||
digestDeadline
|
||||
);
|
||||
|
||||
hub.setFollowModuleWithSig(
|
||||
DataTypes.SetFollowModuleWithSigData({
|
||||
delegatedSigner: delegatedSigner,
|
||||
profileId: newProfileId,
|
||||
followModule: mockFollowModule,
|
||||
followModuleInitData: abi.encode(1),
|
||||
sig: _getSigStruct(signerPrivKey, digest, sigDeadline)
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// Negatives
|
||||
function testCannotSetFollowModuleNotExecutor() public {
|
||||
vm.expectRevert(Errors.ExecutorInvalid.selector);
|
||||
hub.setFollowModule(newProfileId, address(0), '');
|
||||
}
|
||||
|
||||
function testCannotSetFollowModuleNotWhitelisted() public {
|
||||
vm.expectRevert(Errors.FollowModuleNotWhitelisted.selector);
|
||||
vm.prank(profileOwner);
|
||||
hub.setFollowModule(newProfileId, address(1), '');
|
||||
}
|
||||
|
||||
function testCannotSetFollowModuleWithWrongInitData() public {
|
||||
vm.expectRevert(bytes(''));
|
||||
vm.prank(profileOwner);
|
||||
hub.setFollowModule(newProfileId, mockFollowModule, '');
|
||||
}
|
||||
|
||||
// Positives
|
||||
function testSetFollowModule() public {
|
||||
vm.prank(profileOwner);
|
||||
hub.setFollowModule(newProfileId, mockFollowModule, abi.encode(1));
|
||||
assertEq(hub.getFollowModule(newProfileId), mockFollowModule);
|
||||
|
||||
vm.prank(profileOwner);
|
||||
hub.setFollowModule(newProfileId, address(0), '');
|
||||
assertEq(hub.getFollowModule(newProfileId), address(0));
|
||||
}
|
||||
|
||||
function testExecutorSetFollowModule() public {
|
||||
assertEq(hub.getFollowModule(newProfileId), address(0));
|
||||
vm.prank(profileOwner);
|
||||
hub.setDelegatedExecutorApproval(otherSigner, true);
|
||||
|
||||
address mockFollowModule = address(new MockFollowModule());
|
||||
vm.prank(governance);
|
||||
hub.whitelistFollowModule(mockFollowModule, true);
|
||||
|
||||
vm.prank(otherSigner);
|
||||
hub.setFollowModule(newProfileId, mockFollowModule, abi.encode(1));
|
||||
assertEq(hub.getFollowModule(newProfileId), mockFollowModule);
|
||||
}
|
||||
|
||||
// Meta-tx
|
||||
// Negatives
|
||||
function testCannotSetFollowModuleNotWhitelistedWithSig() public {
|
||||
vm.expectRevert(Errors.FollowModuleNotWhitelisted.selector);
|
||||
bytes32 digest = _getSetFollowModuleTypedDataHash(
|
||||
newProfileId,
|
||||
address(1),
|
||||
'',
|
||||
nonce,
|
||||
deadline
|
||||
);
|
||||
|
||||
hub.setFollowModuleWithSig(
|
||||
DataTypes.SetFollowModuleWithSigData({
|
||||
delegatedSigner: address(0),
|
||||
profileId: newProfileId,
|
||||
followModule: address(1),
|
||||
followModuleInitData: '',
|
||||
sig: _getSigStruct(profileOwnerKey, digest, deadline)
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
function testCannotPublishWithSigInvalidSigner() public {
|
||||
vm.expectRevert(Errors.SignatureInvalid.selector);
|
||||
_setFollowModulehWithSig({delegatedSigner: address(0), signerPrivKey: otherSignerKey});
|
||||
}
|
||||
|
||||
function testCannotPublishWithSigInvalidNonce() public {
|
||||
nonce = _getSigNonce(otherSigner) + 1;
|
||||
vm.expectRevert(Errors.SignatureInvalid.selector);
|
||||
_setFollowModulehWithSig({delegatedSigner: address(0), signerPrivKey: otherSignerKey});
|
||||
}
|
||||
|
||||
function testCannotPublishWithSigInvalidDeadline() public {
|
||||
vm.expectRevert(Errors.SignatureInvalid.selector);
|
||||
_setFollowModulehWithSig({
|
||||
delegatedSigner: address(0),
|
||||
signerPrivKey: profileOwnerKey,
|
||||
digestDeadline: type(uint256).max,
|
||||
sigDeadline: block.timestamp + 10
|
||||
});
|
||||
}
|
||||
|
||||
function testCannotPublishIfNonceWasIncrementedWithAnotherAction() public {
|
||||
assertEq(_getSigNonce(profileOwner), nonce, 'Wrong nonce before posting');
|
||||
|
||||
_setFollowModulehWithSig({delegatedSigner: address(0), signerPrivKey: profileOwnerKey});
|
||||
|
||||
assertTrue(_getSigNonce(profileOwner) != nonce, 'Wrong nonce after posting');
|
||||
|
||||
vm.expectRevert(Errors.SignatureInvalid.selector);
|
||||
_setFollowModulehWithSig({delegatedSigner: address(0), signerPrivKey: profileOwnerKey});
|
||||
}
|
||||
|
||||
function testCannotPublishWithSigExpiredDeadline() public {
|
||||
deadline = 10;
|
||||
vm.warp(20);
|
||||
|
||||
vm.expectRevert(Errors.SignatureExpired.selector);
|
||||
_setFollowModulehWithSig({delegatedSigner: address(0), signerPrivKey: otherSignerKey});
|
||||
}
|
||||
|
||||
function testCannotPublishWithSigNotExecutor() public {
|
||||
vm.expectRevert(Errors.ExecutorInvalid.selector);
|
||||
_setFollowModulehWithSig({delegatedSigner: otherSigner, signerPrivKey: otherSignerKey});
|
||||
}
|
||||
|
||||
function testSetFollowModuleWithSigNotExecutorFails() public {
|
||||
vm.expectRevert(Errors.ExecutorInvalid.selector);
|
||||
_setFollowModulehWithSig({delegatedSigner: otherSigner, signerPrivKey: otherSignerKey});
|
||||
}
|
||||
|
||||
// Postivies
|
||||
function testPublishWithSig() public {
|
||||
assertEq(hub.getFollowModule(newProfileId), address(0));
|
||||
_setFollowModulehWithSig({delegatedSigner: address(0), signerPrivKey: profileOwnerKey});
|
||||
assertEq(hub.getFollowModule(newProfileId), mockFollowModule);
|
||||
}
|
||||
|
||||
function testExecutorPublishWithSig() public {
|
||||
_setDelegatedExecutorApproval(profileOwner, otherSigner, true);
|
||||
|
||||
assertEq(hub.getFollowModule(newProfileId), address(0));
|
||||
_setFollowModulehWithSig({delegatedSigner: otherSigner, signerPrivKey: otherSignerKey});
|
||||
assertEq(hub.getFollowModule(newProfileId), mockFollowModule);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user