test: more MultistateHub foundry tests and some refactoring

This commit is contained in:
vicnaum
2022-12-05 21:10:43 +01:00
parent 39fa427ebb
commit eb3a52887b
8 changed files with 400 additions and 93 deletions

View File

@@ -75,21 +75,21 @@ Scenarios
// Replaced dispatcher with DelegatedExecutor for the following two tests:
[X] Governance should pause the hub, setting dispatcher should fail, then governance unpauses the hub and setting dispatcher should work
[X] Governance should pause the hub, setting dispatcher with sig should fail, then governance unpauses the hub and setting dispatcher with sig should work
[ ] Governance should pause the hub, setting profile URI should fail, then governance unpauses the hub and setting profile URI should work
[ ] Governance should pause the hub, setting profile URI with sig should fail, then governance unpauses the hub and setting profile URI should work
[ ] Governance should pause the hub, setting follow NFT URI should fail, then governance unpauses the hub and setting follow NFT URI should work
[ ] Governance should pause the hub, setting follow NFT URI with sig should fail, then governance unpauses the hub and setting follow NFT URI should work
[ ] Governance should pause the hub, posting should fail, then governance unpauses the hub and posting should work
[ ] Governance should pause the hub, posting with sig should fail, then governance unpauses the hub and posting with sig should work
[ ] Governance should pause the hub, commenting should fail, then governance unpauses the hub and commenting should work
[ ] Governance should pause the hub, commenting with sig should fail, then governance unpauses the hub and commenting with sig should work
[ ] Governance should pause the hub, mirroring should fail, then governance unpauses the hub and mirroring should work
[ ] Governance should pause the hub, mirroring with sig should fail, then governance unpauses the hub and mirroring with sig should work
[ ] Governance should pause the hub, burning should fail, then governance unpauses the hub and burning should work
[ ] Governance should pause the hub, following should fail, then governance unpauses the hub and following should work
[ ] Governance should pause the hub, following with sig should fail, then governance unpauses the hub and following with sig should work
[ ] Governance should pause the hub, collecting should fail, then governance unpauses the hub and collecting should work
[ ] Governance should pause the hub, collecting with sig should fail, then governance unpauses the hub and collecting with sig should work
[X] Governance should pause the hub, setting profile URI should fail, then governance unpauses the hub and setting profile URI should work
[X] Governance should pause the hub, setting profile URI with sig should fail, then governance unpauses the hub and setting profile URI should work
[X] Governance should pause the hub, setting follow NFT URI should fail, then governance unpauses the hub and setting follow NFT URI should work
[X] Governance should pause the hub, setting follow NFT URI with sig should fail, then governance unpauses the hub and setting follow NFT URI should work
[X] Governance should pause the hub, posting should fail, then governance unpauses the hub and posting should work
[X] Governance should pause the hub, posting with sig should fail, then governance unpauses the hub and posting with sig should work
[X] Governance should pause the hub, commenting should fail, then governance unpauses the hub and commenting should work
[X] Governance should pause the hub, commenting with sig should fail, then governance unpauses the hub and commenting with sig should work
[X] Governance should pause the hub, mirroring should fail, then governance unpauses the hub and mirroring should work
[X] Governance should pause the hub, mirroring with sig should fail, then governance unpauses the hub and mirroring with sig should work
[X] Governance should pause the hub, burning should fail, then governance unpauses the hub and burning should work
[X] Governance should pause the hub, following should fail, then governance unpauses the hub and following should work
[X] Governance should pause the hub, following with sig should fail, then governance unpauses the hub and following with sig should work
[X] Governance should pause the hub, collecting should fail, then governance unpauses the hub and collecting should work
[X] Governance should pause the hub, collecting with sig should fail, then governance unpauses the hub and collecting with sig should work
PublishingPaused State
Scenarios
[ ] Governance should pause publishing, profile creation should work

View File

@@ -133,8 +133,7 @@ contract CollectingTest_Generic is CollectingTest_Base {
uint256 startNftId = _checkCollectNFTBefore();
// delegate power to executor
vm.prank(profileOwner);
_setDelegatedExecutorApproval(otherSigner, true);
_setDelegatedExecutorApproval(profileOwner, otherSigner, true);
// collect from executor
vm.startPrank(otherSigner);
@@ -148,10 +147,9 @@ contract CollectingTest_Generic is CollectingTest_Base {
uint256 startNftId = _checkCollectNFTBefore();
// mirror, then delegate power to executor
vm.startPrank(profileOwner);
vm.prank(profileOwner);
hub.mirror(mockMirrorData);
_setDelegatedExecutorApproval(otherSigner, true);
vm.stopPrank();
_setDelegatedExecutorApproval(profileOwner, otherSigner, true);
// collect from executor
vm.startPrank(otherSigner);
@@ -253,8 +251,7 @@ contract CollectingTest_WithSig is CollectingTest_Base {
uint256 startNftId = _checkCollectNFTBefore();
// delegate power to executor
vm.prank(profileOwner);
_setDelegatedExecutorApproval(otherSigner, true);
_setDelegatedExecutorApproval(profileOwner, otherSigner, true);
// collect from executor
uint256 nftId = _mockCollectWithSig({
@@ -269,10 +266,9 @@ contract CollectingTest_WithSig is CollectingTest_Base {
uint256 startNftId = _checkCollectNFTBefore();
// mirror, then delegate power to executor
vm.startPrank(profileOwner);
vm.prank(profileOwner);
hub.mirror(mockMirrorData);
_setDelegatedExecutorApproval(otherSigner, true);
vm.stopPrank();
_setDelegatedExecutorApproval(profileOwner, otherSigner, true);
// collect from executor
uint256 nftId = _mockCollectWithSig({

View File

@@ -3,22 +3,27 @@ pragma solidity ^0.8.13;
import './base/BaseTest.t.sol';
import {Strings} from '@openzeppelin/contracts/utils/Strings.sol';
import './helpers/SignatureHelpers.sol';
contract FollowTest is BaseTest {
contract FollowTest is BaseTest, SignatureHelpers {
using Strings for uint256;
// Negatives
function testFollowNotExecutorFails() public {
vm.prank(otherSigner);
vm.expectRevert(Errors.ExecutorInvalid.selector);
hub.follow(me, _toUint256Array(newProfileId), _toBytesArray(''));
_follow({msgSender: otherSigner, onBehalfOf: me, profileId: newProfileId, data: ''});
}
// Positives
function testFollow() public {
assertEq(hub.getFollowNFT(newProfileId), address(0));
uint256[] memory nftIds = hub.follow(me, _toUint256Array(newProfileId), _toBytesArray(''));
uint256[] memory nftIds = _follow({
msgSender: me,
onBehalfOf: me,
profileId: newProfileId,
data: ''
});
FollowNFT nft = FollowNFT(hub.getFollowNFT(newProfileId));
string memory expectedName = string(
@@ -37,8 +42,12 @@ contract FollowTest is BaseTest {
function testExecutorFollow() public {
hub.setDelegatedExecutorApproval(otherSigner, true);
vm.prank(otherSigner);
uint256[] memory nftIds = hub.follow(me, _toUint256Array(newProfileId), _toBytesArray(''));
uint256[] memory nftIds = _follow({
msgSender: otherSigner,
onBehalfOf: me,
profileId: newProfileId,
data: ''
});
FollowNFT nft = FollowNFT(hub.getFollowNFT(newProfileId));
assertEq(nftIds.length, 1);
@@ -58,7 +67,7 @@ contract FollowTest is BaseTest {
bytes32 digest = _getFollowTypedDataHash(profileIds, datas, nonce, deadline);
vm.expectRevert(Errors.SignatureInvalid.selector);
hub.followWithSig(
_followWithSig(
_buildFollowWithSigData({
delegatedSigner: address(0),
follower: profileOwner,
@@ -79,7 +88,7 @@ contract FollowTest is BaseTest {
bytes32 digest = _getFollowTypedDataHash(profileIds, datas, nonce, deadline);
vm.expectRevert(Errors.ExecutorInvalid.selector);
hub.followWithSig(
_followWithSig(
_buildFollowWithSigData({
delegatedSigner: otherSigner,
follower: profileOwner,
@@ -102,7 +111,7 @@ contract FollowTest is BaseTest {
uint256 deadline = type(uint256).max;
bytes32 digest = _getFollowTypedDataHash(profileIds, datas, nonce, deadline);
uint256[] memory nftIds = hub.followWithSig(
uint256[] memory nftIds = _followWithSig(
_buildFollowWithSigData({
delegatedSigner: address(0),
follower: otherSigner,
@@ -138,7 +147,7 @@ contract FollowTest is BaseTest {
uint256 deadline = type(uint256).max;
bytes32 digest = _getFollowTypedDataHash(profileIds, datas, nonce, deadline);
uint256[] memory nftIds = hub.followWithSig(
uint256[] memory nftIds = _followWithSig(
_buildFollowWithSigData({
delegatedSigner: profileOwner,
follower: otherSigner,
@@ -153,15 +162,4 @@ contract FollowTest is BaseTest {
assertEq(nftIds[0], 1);
assertEq(nft.ownerOf(1), otherSigner);
}
// Private functions
function _buildFollowWithSigData(
address delegatedSigner,
address follower,
uint256[] memory profileIds,
bytes[] memory datas,
DataTypes.EIP712Signature memory sig
) private pure returns (DataTypes.FollowWithSigData memory) {
return DataTypes.FollowWithSigData(delegatedSigner, follower, profileIds, datas, sig);
}
}

View File

@@ -221,7 +221,7 @@ contract MiscTest is BaseTest {
function testSetFollowNFTURIWithSigInvalidSignerFails() public {
uint256 nonce = 0;
uint256 deadline = type(uint256).max;
bytes32 digest = _getSetFollowNFTURITypedDatahash(newProfileId, MOCK_URI, nonce, deadline);
bytes32 digest = _getSetFollowNFTURITypedDataHash(newProfileId, MOCK_URI, nonce, deadline);
vm.expectRevert(Errors.SignatureInvalid.selector);
hub.setFollowNFTURIWithSig(
@@ -237,7 +237,7 @@ contract MiscTest is BaseTest {
function testSetFollowNFTURIWithSigNotExecutorFails() public {
uint256 nonce = 0;
uint256 deadline = type(uint256).max;
bytes32 digest = _getSetFollowNFTURITypedDatahash(newProfileId, MOCK_URI, nonce, deadline);
bytes32 digest = _getSetFollowNFTURITypedDataHash(newProfileId, MOCK_URI, nonce, deadline);
vm.expectRevert(Errors.ExecutorInvalid.selector);
hub.setFollowNFTURIWithSig(
@@ -440,7 +440,7 @@ contract MiscTest is BaseTest {
function testSetFollowNFTURIWithSig() public {
uint256 nonce = 0;
uint256 deadline = type(uint256).max;
bytes32 digest = _getSetFollowNFTURITypedDatahash(newProfileId, 'test', nonce, deadline);
bytes32 digest = _getSetFollowNFTURITypedDataHash(newProfileId, 'test', nonce, deadline);
assertEq(hub.getFollowNFTURI(newProfileId), MOCK_URI);
hub.setFollowNFTURIWithSig(
@@ -460,7 +460,7 @@ contract MiscTest is BaseTest {
uint256 nonce = 0;
uint256 deadline = type(uint256).max;
bytes32 digest = _getSetFollowNFTURITypedDatahash(newProfileId, 'test', nonce, deadline);
bytes32 digest = _getSetFollowNFTURITypedDataHash(newProfileId, 'test', nonce, deadline);
assertEq(hub.getFollowNFTURI(newProfileId), MOCK_URI);
hub.setFollowNFTURIWithSig(

View File

@@ -2,7 +2,7 @@
pragma solidity ^0.8.13;
import './base/BaseTest.t.sol';
import {SigSetup} from './helpers/SignatureHelpers.sol';
import './helpers/SignatureHelpers.sol';
contract MultiStateHubTest_Common is BaseTest {
// Negatives
@@ -109,9 +109,14 @@ contract MultiStateHubTest_Common is BaseTest {
}
contract MultiStateHubTest_PausedState_Direct is BaseTest {
uint256 postId;
function setUp() public virtual override {
super.setUp();
vm.prank(profileOwner);
postId = _post(mockPostData);
vm.prank(governance);
_setState(DataTypes.ProtocolState.Paused);
}
@@ -126,8 +131,53 @@ contract MultiStateHubTest_PausedState_Direct is BaseTest {
_setDelegatedExecutorApproval(profileOwner, executor, approved);
}
function _mockSetProfileImageURI() internal virtual {
_setProfileImageURI(profileOwner, newProfileId, MOCK_URI);
}
function _mockSetFollowNFTURI() internal virtual {
_setFollowNFTURI(profileOwner, newProfileId, MOCK_URI);
}
function _mockPost() internal virtual {
vm.prank(profileOwner);
_post(mockPostData);
}
function _mockComment() internal virtual {
mockCommentData.pubIdPointed = postId;
vm.prank(profileOwner);
_comment(mockCommentData);
}
function _mockMirror() internal virtual {
mockMirrorData.pubIdPointed = postId;
vm.prank(profileOwner);
_mirror(mockMirrorData);
}
function _mockBurn() internal virtual {
_burn(profileOwner, newProfileId);
}
function _mockFollow() internal virtual {
_follow({msgSender: me, onBehalfOf: me, profileId: newProfileId, data: ''});
}
// TODO: The following two functions were copy-pasted from CollectingTest.t.sol
// TODO: Consider extracting them somewhere else to be used by both of tests
function _mockCollect() internal virtual {
vm.prank(profileOwner);
_collect(
mockCollectData.collector,
mockCollectData.profileId,
mockCollectData.pubId,
mockCollectData.data
);
}
// Negatives
function testCantTransferProfileWhilePaused() public virtual {
function testCannotTransferProfileWhilePaused() public virtual {
vm.expectRevert(Errors.Paused.selector);
_transferProfile({
msgSender: profileOwner,
@@ -137,7 +187,7 @@ contract MultiStateHubTest_PausedState_Direct is BaseTest {
});
}
function testCantCreateProfileWhilePaused() public virtual {
function testCannotCreateProfileWhilePaused() public virtual {
vm.expectRevert(Errors.Paused.selector);
_createProfile(address(this));
@@ -147,7 +197,7 @@ contract MultiStateHubTest_PausedState_Direct is BaseTest {
_createProfile(address(this));
}
function testCantSetFollowModuleWhilePaused() public {
function testCannotSetFollowModuleWhilePaused() public {
vm.expectRevert(Errors.Paused.selector);
_mockSetFollowModule();
@@ -155,10 +205,9 @@ contract MultiStateHubTest_PausedState_Direct is BaseTest {
_setState(DataTypes.ProtocolState.Unpaused);
_mockSetFollowModule();
// TODO: Consider if we should check if the follow module was set (or its enough to do that in Follow module tests)
}
function testCantSetDelegatedExecutorWhilePaused() public {
function testCannotSetDelegatedExecutorWhilePaused() public {
vm.expectRevert(Errors.Paused.selector);
_mockSetDelegatedExecutorApproval();
@@ -166,12 +215,94 @@ contract MultiStateHubTest_PausedState_Direct is BaseTest {
_setState(DataTypes.ProtocolState.Unpaused);
_mockSetDelegatedExecutorApproval();
// TODO: Consider if we should check if the delegated executor was set (or its enough to do that in DE tests)
// assertEq(hub.isDelegatedExecutorApproved(profileOwner, executor), approved);
}
function testCannotSetProfileImageURIWhilePaused() public {
vm.expectRevert(Errors.Paused.selector);
_mockSetProfileImageURI();
vm.prank(governance);
_setState(DataTypes.ProtocolState.Unpaused);
_mockSetProfileImageURI();
}
function testCannotSetFollowNFTURIWhilePaused() public {
vm.expectRevert(Errors.Paused.selector);
_mockSetFollowNFTURI();
vm.prank(governance);
_setState(DataTypes.ProtocolState.Unpaused);
_mockSetFollowNFTURI();
}
function testCannotPostWhilePaused() public {
vm.expectRevert(Errors.PublishingPaused.selector);
_mockPost();
vm.prank(governance);
_setState(DataTypes.ProtocolState.Unpaused);
_mockPost();
}
function testCannotCommentWhilePaused() public {
vm.expectRevert(Errors.PublishingPaused.selector);
_mockComment();
vm.prank(governance);
_setState(DataTypes.ProtocolState.Unpaused);
_mockComment();
}
function testCannotMirrorWhilePaused() public {
vm.expectRevert(Errors.PublishingPaused.selector);
_mockMirror();
vm.prank(governance);
_setState(DataTypes.ProtocolState.Unpaused);
_mockMirror();
}
function testCannotBurnWhilePaused() public {
vm.expectRevert(Errors.Paused.selector);
_mockBurn();
vm.prank(governance);
_setState(DataTypes.ProtocolState.Unpaused);
_mockBurn();
}
function testCannotFollowWhilePaused() public {
vm.expectRevert(Errors.Paused.selector);
_mockFollow();
vm.prank(governance);
_setState(DataTypes.ProtocolState.Unpaused);
_mockFollow();
}
function testCannotCollectWhilePaused() public {
vm.expectRevert(Errors.Paused.selector);
_mockCollect();
vm.prank(governance);
_setState(DataTypes.ProtocolState.Unpaused);
_mockCollect();
}
}
contract MultiStateHubTest_PausedState_WithSig is MultiStateHubTest_PausedState_Direct, SigSetup {
contract MultiStateHubTest_PausedState_WithSig is
MultiStateHubTest_PausedState_Direct,
SignatureHelpers,
SigSetup
{
function setUp() public override(MultiStateHubTest_PausedState_Direct, SigSetup) {
MultiStateHubTest_PausedState_Direct.setUp();
SigSetup.setUp();
@@ -186,16 +317,15 @@ contract MultiStateHubTest_PausedState_WithSig is MultiStateHubTest_PausedState_
deadline
);
return
_setFollowModuleWithSig(
DataTypes.SetFollowModuleWithSigData({
delegatedSigner: address(0),
profileId: newProfileId,
followModule: address(0),
followModuleInitData: '',
sig: _getSigStruct(profileOwnerKey, digest, deadline)
})
);
_setFollowModuleWithSig(
DataTypes.SetFollowModuleWithSigData({
delegatedSigner: address(0),
profileId: newProfileId,
followModule: address(0),
followModuleInitData: '',
sig: _getSigStruct(profileOwnerKey, digest, deadline)
})
);
}
// Positives
@@ -220,8 +350,123 @@ contract MultiStateHubTest_PausedState_WithSig is MultiStateHubTest_PausedState_
);
}
// Methods that cannot be called with sig
function testCantTransferProfileWhilePaused() public override {}
function _mockSetProfileImageURI() internal override {
bytes32 digest = _getSetProfileImageURITypedDataHash(
newProfileId,
MOCK_URI,
nonce,
deadline
);
function testCantCreateProfileWhilePaused() public override {}
_setProfileImageURIWithSig(
DataTypes.SetProfileImageURIWithSigData({
delegatedSigner: address(0),
profileId: newProfileId,
imageURI: MOCK_URI,
sig: _getSigStruct(profileOwnerKey, digest, deadline)
})
);
}
function _mockSetFollowNFTURI() internal override {
bytes32 digest = _getSetFollowNFTURITypedDataHash(newProfileId, MOCK_URI, nonce, deadline);
_setFollowNFTURIWithSig(
DataTypes.SetFollowNFTURIWithSigData({
delegatedSigner: address(0),
profileId: newProfileId,
followNFTURI: MOCK_URI,
sig: _getSigStruct(profileOwnerKey, digest, deadline)
})
);
}
function _mockPost() internal override {
bytes32 digest = _getPostTypedDataHash(mockPostData, nonce, deadline);
_postWithSig(
_buildPostWithSigData({
delegatedSigner: address(0),
postData: mockPostData,
sig: _getSigStruct(profileOwnerKey, digest, deadline)
})
);
}
function _mockComment() internal override {
mockCommentData.pubIdPointed = postId;
bytes32 digest = _getCommentTypedDataHash(mockCommentData, nonce, deadline);
_commentWithSig(
_buildCommentWithSigData({
delegatedSigner: address(0),
commentData: mockCommentData,
sig: _getSigStruct(profileOwnerKey, digest, deadline)
})
);
}
function _mockMirror() internal override {
mockMirrorData.pubIdPointed = postId;
bytes32 digest = _getMirrorTypedDataHash(mockMirrorData, nonce, deadline);
_mirrorWithSig(
_buildMirrorWithSigData({
delegatedSigner: address(0),
mirrorData: mockMirrorData,
sig: _getSigStruct(profileOwnerKey, digest, deadline)
})
);
}
function _mockBurn() internal override {
bytes32 digest = _getBurnTypedDataHash(newProfileId, nonce, deadline);
_burnWithSig({
profileId: newProfileId,
sig: _getSigStruct(profileOwnerKey, digest, deadline)
});
}
function _mockFollow() internal override {
bytes32 digest = _getFollowTypedDataHash(
_toUint256Array(newProfileId),
_toBytesArray(''),
nonce,
deadline
);
uint256[] memory nftIds = _followWithSig(
_buildFollowWithSigData({
delegatedSigner: address(0),
follower: otherSigner,
profileIds: _toUint256Array(newProfileId),
datas: _toBytesArray(''),
sig: _getSigStruct(otherSignerKey, digest, deadline)
})
);
}
function _mockCollect() internal override {
bytes32 digest = _getCollectTypedDataHash(
mockCollectData.profileId,
mockCollectData.pubId,
mockCollectData.data,
nonce,
deadline
);
_collectWithSig(
_buildCollectWithSigData({
delegatedSigner: address(0),
collectData: mockCollectData,
sig: _getSigStruct(profileOwnerKey, digest, deadline)
})
);
}
// Methods that cannot be called with sig
function testCannotTransferProfileWhilePaused() public override {}
function testCannotCreateProfileWhilePaused() public override {}
}

View File

@@ -4,7 +4,6 @@ pragma solidity ^0.8.13;
import './base/BaseTest.t.sol';
import './helpers/SignatureHelpers.sol';
import {PublishingHelpers} from './helpers/PublishingHelpers.sol';
import {SigSetup} from './helpers/SignatureHelpers.sol';
contract PublishingTest_Post is BaseTest, SignatureHelpers, PublishingHelpers, SigSetup {
function replicateInitData() internal virtual {}
@@ -183,8 +182,7 @@ contract PublishingTest_Post is BaseTest, SignatureHelpers, PublishingHelpers, S
}
function testExecutorPublish() public {
vm.prank(profileOwner);
_setDelegatedExecutorApproval(otherSigner, true);
_setDelegatedExecutorApproval(profileOwner, otherSigner, true);
uint256 expectedPubId = _getPubCount(newProfileId) + 1;
@@ -197,8 +195,7 @@ contract PublishingTest_Post is BaseTest, SignatureHelpers, PublishingHelpers, S
}
function testExecutorPublishWithSig() public {
vm.prank(profileOwner);
_setDelegatedExecutorApproval(otherSigner, true);
_setDelegatedExecutorApproval(profileOwner, otherSigner, true);
uint256 expectedPubId = _getPubCount(newProfileId) + 1;
uint256 pubId = _publishWithSig({

View File

@@ -93,7 +93,7 @@ contract BaseTest is TestSetup {
return _calculateDigest(structHash);
}
function _getSetFollowNFTURITypedDatahash(
function _getSetFollowNFTURITypedDataHash(
uint256 profileId,
string memory followNFTURI,
uint256 nonce,
@@ -111,6 +111,17 @@ contract BaseTest is TestSetup {
return _calculateDigest(structHash);
}
function _getBurnTypedDataHash(
uint256 profileId,
uint256 nonce,
uint256 deadline
) internal view returns (bytes32) {
bytes32 structHash = keccak256(
abi.encode(BURN_WITH_SIG_TYPEHASH, profileId, nonce, deadline)
);
return _calculateDigest(structHash);
}
function _getPostTypedDataHash(
uint256 profileId,
string memory contentURI,
@@ -385,24 +396,21 @@ contract BaseTest is TestSetup {
return hub.collectWithSig(collectWithSigData);
}
function _setDelegatedExecutorApproval(address executor, bool approved) internal {
hub.setDelegatedExecutorApproval(executor, approved);
function _follow(
address msgSender,
address onBehalfOf,
uint256 profileId,
bytes memory data
) internal returns (uint256[] memory) {
vm.prank(msgSender);
return hub.follow(onBehalfOf, _toUint256Array(profileId), _toBytesArray(data));
}
function _getPub(uint256 profileId, uint256 pubId)
function _followWithSig(DataTypes.FollowWithSigData memory vars)
internal
view
returns (DataTypes.PublicationStruct memory)
returns (uint256[] memory)
{
return hub.getPub(profileId, pubId);
}
function _getSigNonce(address signer) internal view returns (uint256) {
return hub.sigNonces(signer);
}
function _getPubCount(uint256 profileId) internal view returns (uint256) {
return hub.getPubCount(profileId);
return hub.followWithSig(vars);
}
function _createProfile(address newProfileOwner) internal returns (uint256) {
@@ -461,7 +469,60 @@ contract BaseTest is TestSetup {
function _setFollowModuleWithSig(DataTypes.SetFollowModuleWithSigData memory vars) internal {
hub.setFollowModuleWithSig(vars);
}
function _setProfileImageURI(
address msgSender,
uint256 profileId,
string memory imageURI
) internal {
vm.prank(msgSender);
hub.setProfileImageURI(profileId, imageURI);
}
function _setProfileImageURIWithSig(DataTypes.SetProfileImageURIWithSigData memory vars)
internal
{
hub.setProfileImageURIWithSig(vars);
}
function _setFollowNFTURI(
address msgSender,
uint256 profileId,
string memory followNFTURI
) internal {
vm.prank(msgSender);
hub.setFollowNFTURI(profileId, followNFTURI);
}
function _setFollowNFTURIWithSig(DataTypes.SetFollowNFTURIWithSigData memory vars) internal {
hub.setFollowNFTURIWithSig(vars);
}
function _burn(address msgSender, uint256 profileId) internal {
vm.prank(msgSender);
hub.burn(profileId);
}
function _burnWithSig(uint256 profileId, DataTypes.EIP712Signature memory sig) internal {
hub.burnWithSig(profileId, sig);
}
function _getPub(uint256 profileId, uint256 pubId)
internal
view
returns (DataTypes.PublicationStruct memory)
{
return hub.getPub(profileId, pubId);
}
function _getSigNonce(address signer) internal view returns (uint256) {
return hub.sigNonces(signer);
}
function _getPubCount(uint256 profileId) internal view returns (uint256) {
return hub.getPubCount(profileId);
}
function _getCollectCount(uint256 profileId, uint256 pubId) internal view returns (uint256) {
address collectNft = hub.getCollectNFT(profileId, pubId);
if (collectNft == address(0)) {

View File

@@ -162,4 +162,14 @@ contract SignatureHelpers {
sig: sig
});
}
function _buildFollowWithSigData(
address delegatedSigner,
address follower,
uint256[] memory profileIds,
bytes[] memory datas,
DataTypes.EIP712Signature memory sig
) internal pure returns (DataTypes.FollowWithSigData memory) {
return DataTypes.FollowWithSigData(delegatedSigner, follower, profileIds, datas, sig);
}
}