test: Publishing foundry tests refactor

This commit is contained in:
vicnaum
2022-10-25 19:47:25 +02:00
parent 3043e46900
commit a216524674
4 changed files with 474 additions and 398 deletions

View File

@@ -2,493 +2,266 @@
pragma solidity ^0.8.13;
import './base/BaseTest.t.sol';
import './helpers/SignatureHelpers.sol';
import './helpers/PublishingHelpers.sol';
contract SigSetup {
uint256 nonce;
uint256 deadline;
function setUp() public virtual {
nonce = 0;
deadline = type(uint256).max;
}
}
contract PublishingTest_Post is BaseTest, SignatureHelpers, PublishingHelpers, SigSetup {
function setUp() public override(SigSetup, TestSetup) {
TestSetup.setUp();
SigSetup.setUp();
}
contract PublishingTest is BaseTest {
// negatives
function testPostNotExecutorFails() public {
vm.expectRevert(Errors.ExecutorInvalid.selector);
hub.post(mockPostData);
_post(mockPostData);
}
function testCommentNotExecutorFails() public {
vm.prank(profileOwner);
hub.post(mockPostData);
vm.expectRevert(Errors.ExecutorInvalid.selector);
hub.comment(mockCommentData);
}
function testMirrorNotExecutorFails() public {
vm.prank(profileOwner);
hub.post(mockPostData);
vm.expectRevert(Errors.ExecutorInvalid.selector);
hub.mirror(mockMirrorData);
}
// positives
function testExecutorPost() public {
vm.prank(profileOwner);
hub.setDelegatedExecutorApproval(otherSigner, true);
vm.prank(otherSigner);
uint256 pubId = hub.post(mockPostData);
assertEq(pubId, 1);
DataTypes.PublicationStruct memory pub = hub.getPub(firstProfileId, pubId);
assertEq(pub.profileIdPointed, 0);
assertEq(pub.pubIdPointed, 0);
assertEq(pub.contentURI, mockPostData.contentURI);
assertEq(pub.referenceModule, mockPostData.referenceModule);
assertEq(pub.collectModule, mockPostData.collectModule);
assertEq(pub.collectNFT, address(0));
}
function testExecutorComment() public {
vm.startPrank(profileOwner);
hub.post(mockPostData);
hub.setDelegatedExecutorApproval(otherSigner, true);
vm.stopPrank();
vm.prank(otherSigner);
uint256 pubId = hub.comment(mockCommentData);
assertEq(pubId, 2);
DataTypes.PublicationStruct memory pub = hub.getPub(firstProfileId, pubId);
assertEq(pub.profileIdPointed, mockCommentData.profileIdPointed);
assertEq(pub.pubIdPointed, mockCommentData.pubIdPointed);
assertEq(pub.contentURI, mockCommentData.contentURI);
assertEq(pub.referenceModule, mockCommentData.referenceModule);
assertEq(pub.collectModule, mockCommentData.collectModule);
assertEq(pub.collectNFT, address(0));
}
function testExecutorMirror() public {
vm.startPrank(profileOwner);
hub.post(mockPostData);
hub.setDelegatedExecutorApproval(otherSigner, true);
vm.stopPrank();
vm.prank(otherSigner);
uint256 pubId = hub.mirror(mockMirrorData);
assertEq(pubId, 2);
DataTypes.PublicationStruct memory pub = hub.getPub(firstProfileId, pubId);
assertEq(pub.profileIdPointed, mockMirrorData.profileIdPointed);
assertEq(pub.pubIdPointed, mockMirrorData.pubIdPointed);
assertEq(pub.contentURI, '');
assertEq(pub.referenceModule, mockMirrorData.referenceModule);
assertEq(pub.collectModule, address(0));
assertEq(pub.collectNFT, address(0));
}
// Meta-tx
// Negatives
function testPostWithSigInvalidSignerFails() public {
uint256 nonce = 0;
uint256 deadline = type(uint256).max;
bytes32 digest = _getPostTypedDataHash(
firstProfileId,
mockURI,
address(mockCollectModule),
abi.encode(1),
address(0),
'',
nonce,
deadline
);
bytes32 digest = _getPostTypedDataHash(mockPostData, nonce, deadline);
vm.expectRevert(Errors.SignatureInvalid.selector);
hub.postWithSig(
_postWithSig(
_buildPostWithSigData({
delegatedSigner: address(0),
profileId: firstProfileId,
contentURI: mockURI,
collectModule: address(mockCollectModule),
collectModuleInitData: abi.encode(1),
referenceModule: address(0),
referenceModuleInitData: '',
postData: mockPostData,
sig: _getSigStruct(otherSignerKey, digest, deadline)
})
);
}
function testPostWithSigNotExecutorFails() public {
uint256 nonce = 0;
uint256 deadline = type(uint256).max;
bytes32 digest = _getPostTypedDataHash(
firstProfileId,
mockURI,
address(mockCollectModule),
abi.encode(1),
address(0),
'',
nonce,
deadline
);
bytes32 digest = _getPostTypedDataHash(mockPostData, nonce, deadline);
vm.expectRevert(Errors.ExecutorInvalid.selector);
hub.postWithSig(
_postWithSig(
_buildPostWithSigData({
delegatedSigner: otherSigner,
profileId: firstProfileId,
contentURI: mockURI,
collectModule: address(mockCollectModule),
collectModuleInitData: abi.encode(1),
referenceModule: address(0),
referenceModuleInitData: '',
postData: mockPostData,
sig: _getSigStruct(otherSignerKey, digest, deadline)
})
);
}
function testCommentWithSigInvalidSignerFails() public {
// positives
function testPost() public {
vm.prank(profileOwner);
hub.post(mockPostData);
uint256 pubId = _post(mockPostData);
assertEq(pubId, 1);
DataTypes.PublicationStruct memory pub = _getPub(firstProfileId, pubId);
_verifyPublication(pub, _expectedPubFromInitData(mockPostData));
}
function testExecutorPost() public {
vm.prank(profileOwner);
_setDelegatedExecutorApproval(otherSigner, true);
vm.prank(otherSigner);
uint256 pubId = _post(mockPostData);
assertEq(pubId, 1);
DataTypes.PublicationStruct memory pub = _getPub(firstProfileId, pubId);
_verifyPublication(pub, _expectedPubFromInitData(mockPostData));
}
function testExecutorPostWithSig() public {
vm.prank(profileOwner);
_setDelegatedExecutorApproval(otherSigner, true);
uint256 nonce = 0;
uint256 deadline = type(uint256).max;
bytes32 digest = _getCommentTypedDataHash(
firstProfileId,
mockURI,
firstProfileId,
1,
'',
address(mockCollectModule),
abi.encode(1),
address(0),
'',
nonce,
deadline
bytes32 digest = _getPostTypedDataHash(mockPostData, nonce, deadline);
uint256 pubId = _postWithSig(
_buildPostWithSigData({
delegatedSigner: otherSigner,
postData: mockPostData,
sig: _getSigStruct(otherSignerKey, digest, deadline)
})
);
assertEq(pubId, 1);
DataTypes.PublicationStruct memory pub = _getPub(firstProfileId, pubId);
_verifyPublication(pub, _expectedPubFromInitData(mockPostData));
}
}
contract PublishingTest_Comment is BaseTest, SignatureHelpers, PublishingHelpers, SigSetup {
function setUp() public override(SigSetup, TestSetup) {
TestSetup.setUp();
SigSetup.setUp();
vm.prank(profileOwner);
_post(mockPostData);
}
// Negatives
function testCommentNotExecutorFails() public {
vm.expectRevert(Errors.ExecutorInvalid.selector);
_comment(mockCommentData);
}
function testCommentWithSigInvalidSignerFails() public {
bytes32 digest = _getCommentTypedDataHash(mockCommentData, nonce, deadline);
DataTypes.EIP712Signature memory sig = _getSigStruct(otherSignerKey, digest, deadline);
vm.expectRevert(Errors.SignatureInvalid.selector);
hub.commentWithSig(
_commentWithSig(
_buildCommentWithSigData({
delegatedSigner: address(0),
profileId: firstProfileId,
contentURI: mockURI,
profileIdPointed: firstProfileId,
pubIdPointed: 1,
referenceModuleData: '',
collectModule: address(mockCollectModule),
collectModuleInitData: abi.encode(1),
referenceModule: address(0),
referenceModuleInitData: '',
commentData: mockCommentData,
sig: sig
})
);
}
function testCommentWithSigNotExecutorFails() public {
vm.prank(profileOwner);
hub.post(mockPostData);
uint256 nonce = 0;
uint256 deadline = type(uint256).max;
bytes32 digest = _getCommentTypedDataHash(
firstProfileId,
mockURI,
firstProfileId,
1,
'',
address(mockCollectModule),
abi.encode(1),
address(0),
'',
nonce,
deadline
);
bytes32 digest = _getCommentTypedDataHash(mockCommentData, nonce, deadline);
DataTypes.EIP712Signature memory sig = _getSigStruct(otherSignerKey, digest, deadline);
vm.expectRevert(Errors.ExecutorInvalid.selector);
hub.commentWithSig(
_commentWithSig(
_buildCommentWithSigData({
delegatedSigner: otherSigner,
profileId: firstProfileId,
contentURI: mockURI,
profileIdPointed: firstProfileId,
pubIdPointed: 1,
referenceModuleData: '',
collectModule: address(mockCollectModule),
collectModuleInitData: abi.encode(1),
referenceModule: address(0),
referenceModuleInitData: '',
commentData: mockCommentData,
sig: sig
})
);
}
function testMirrorWithSigInvalidSignerFails() public {
// positives
function testComment() public {
vm.prank(profileOwner);
hub.post(mockPostData);
uint256 pubId = _comment(mockCommentData);
assertEq(pubId, 2);
uint256 nonce = 0;
uint256 deadline = type(uint256).max;
bytes32 digest = _getMirrorTypedDataHash(
firstProfileId,
firstProfileId,
1,
'',
address(0),
'',
nonce,
deadline
DataTypes.PublicationStruct memory pub = _getPub(firstProfileId, pubId);
_verifyPublication(pub, _expectedPubFromInitData(mockCommentData));
}
function testExecutorComment() public {
vm.prank(profileOwner);
_setDelegatedExecutorApproval(otherSigner, true);
vm.prank(otherSigner);
uint256 pubId = _comment(mockCommentData);
assertEq(pubId, 2);
DataTypes.PublicationStruct memory pub = _getPub(firstProfileId, pubId);
_verifyPublication(pub, _expectedPubFromInitData(mockCommentData));
}
function testExecutorCommentWithSig() public {
vm.prank(profileOwner);
_setDelegatedExecutorApproval(otherSigner, true);
bytes32 digest = _getCommentTypedDataHash(mockCommentData, nonce, deadline);
DataTypes.EIP712Signature memory sig = _getSigStruct(otherSignerKey, digest, deadline);
uint256 pubId = _commentWithSig(
_buildCommentWithSigData({
delegatedSigner: otherSigner,
commentData: mockCommentData,
sig: sig
})
);
assertEq(pubId, 2);
DataTypes.PublicationStruct memory pub = _getPub(firstProfileId, pubId);
_verifyPublication(pub, _expectedPubFromInitData(mockCommentData));
}
}
contract PublishingTest_Mirror is BaseTest, SignatureHelpers, PublishingHelpers, SigSetup {
function setUp() public override(SigSetup, TestSetup) {
TestSetup.setUp();
SigSetup.setUp();
vm.prank(profileOwner);
_post(mockPostData);
}
// Negatives
function testMirrorNotExecutorFails() public {
vm.expectRevert(Errors.ExecutorInvalid.selector);
_mirror(mockMirrorData);
}
function testMirrorWithSigInvalidSignerFails() public {
bytes32 digest = _getMirrorTypedDataHash(mockMirrorData, nonce, deadline);
vm.expectRevert(Errors.SignatureInvalid.selector);
hub.mirrorWithSig(
_mirrorWithSig(
_buildMirrorWithSigData({
delegatedSigner: address(0),
profileId: firstProfileId,
profileIdPointed: firstProfileId,
pubIdPointed: 1,
referenceModuleData: '',
referenceModule: address(0),
referenceModuleInitData: '',
mirrorData: mockMirrorData,
sig: _getSigStruct(otherSignerKey, digest, deadline)
})
);
}
function testMirrorWithSigNotExecutorFails() public {
vm.prank(profileOwner);
hub.post(mockPostData);
uint256 nonce = 0;
uint256 deadline = type(uint256).max;
bytes32 digest = _getMirrorTypedDataHash(
firstProfileId,
firstProfileId,
1,
'',
address(0),
'',
nonce,
deadline
);
bytes32 digest = _getMirrorTypedDataHash(mockMirrorData, nonce, deadline);
vm.expectRevert(Errors.ExecutorInvalid.selector);
hub.mirrorWithSig(
_mirrorWithSig(
_buildMirrorWithSigData({
delegatedSigner: otherSigner,
profileId: firstProfileId,
profileIdPointed: firstProfileId,
pubIdPointed: 1,
referenceModuleData: '',
referenceModule: address(0),
referenceModuleInitData: '',
mirrorData: mockMirrorData,
sig: _getSigStruct(otherSignerKey, digest, deadline)
})
);
}
// Positives
function testExecutorPostWithSig() public {
function testMirror() public {
vm.prank(profileOwner);
hub.setDelegatedExecutorApproval(otherSigner, true);
uint256 nonce = 0;
uint256 deadline = type(uint256).max;
bytes32 digest = _getPostTypedDataHash(
firstProfileId,
mockURI,
address(mockCollectModule),
abi.encode(1),
address(0),
'',
nonce,
deadline
);
uint256 pubId = hub.postWithSig(
_buildPostWithSigData({
delegatedSigner: otherSigner,
profileId: firstProfileId,
contentURI: mockURI,
collectModule: address(mockCollectModule),
collectModuleInitData: abi.encode(1),
referenceModule: address(0),
referenceModuleInitData: '',
sig: _getSigStruct(otherSignerKey, digest, deadline)
})
);
assertEq(pubId, 1);
DataTypes.PublicationStruct memory pub = hub.getPub(firstProfileId, pubId);
assertEq(pub.profileIdPointed, 0);
assertEq(pub.pubIdPointed, 0);
assertEq(pub.contentURI, mockPostData.contentURI);
assertEq(pub.referenceModule, mockPostData.referenceModule);
assertEq(pub.collectModule, mockPostData.collectModule);
assertEq(pub.collectNFT, address(0));
}
function testExecutorCommentWithSig() public {
vm.startPrank(profileOwner);
hub.setDelegatedExecutorApproval(otherSigner, true);
hub.post(mockPostData);
vm.stopPrank();
uint256 nonce = 0;
uint256 deadline = type(uint256).max;
bytes32 digest = _getCommentTypedDataHash(
firstProfileId,
mockURI,
firstProfileId,
1,
'',
address(mockCollectModule),
abi.encode(1),
address(0),
'',
nonce,
deadline
);
DataTypes.EIP712Signature memory sig = _getSigStruct(otherSignerKey, digest, deadline);
uint256 pubId = hub.commentWithSig(
_buildCommentWithSigData({
delegatedSigner: otherSigner,
profileId: firstProfileId,
contentURI: mockURI,
profileIdPointed: firstProfileId,
pubIdPointed: 1,
referenceModuleData: '',
collectModule: address(mockCollectModule),
collectModuleInitData: abi.encode(1),
referenceModule: address(0),
referenceModuleInitData: '',
sig: sig
})
);
uint256 pubId = _mirror(mockMirrorData);
assertEq(pubId, 2);
DataTypes.PublicationStruct memory pub = hub.getPub(firstProfileId, pubId);
assertEq(pub.profileIdPointed, mockCommentData.profileIdPointed);
assertEq(pub.pubIdPointed, mockCommentData.pubIdPointed);
assertEq(pub.contentURI, mockCommentData.contentURI);
assertEq(pub.referenceModule, mockCommentData.referenceModule);
assertEq(pub.collectModule, mockCommentData.collectModule);
assertEq(pub.collectNFT, address(0));
DataTypes.PublicationStruct memory pub = _getPub(firstProfileId, pubId);
_verifyPublication(pub, _expectedPubFromInitData(mockMirrorData));
}
function testExecutorMirror() public {
vm.prank(profileOwner);
_setDelegatedExecutorApproval(otherSigner, true);
vm.prank(otherSigner);
uint256 pubId = _mirror(mockMirrorData);
assertEq(pubId, 2);
DataTypes.PublicationStruct memory pub = _getPub(firstProfileId, pubId);
_verifyPublication(pub, _expectedPubFromInitData(mockMirrorData));
}
function testExecutorMirrorWithSig() public {
vm.startPrank(profileOwner);
hub.setDelegatedExecutorApproval(otherSigner, true);
hub.post(mockPostData);
vm.stopPrank();
vm.prank(profileOwner);
_setDelegatedExecutorApproval(otherSigner, true);
uint256 nonce = 0;
uint256 deadline = type(uint256).max;
bytes32 digest = _getMirrorTypedDataHash(
firstProfileId,
firstProfileId,
1,
'',
address(0),
'',
nonce,
deadline
);
bytes32 digest = _getMirrorTypedDataHash(mockMirrorData, nonce, deadline);
uint256 pubId = hub.mirrorWithSig(
uint256 pubId = _mirrorWithSig(
_buildMirrorWithSigData({
delegatedSigner: otherSigner,
profileId: firstProfileId,
profileIdPointed: firstProfileId,
pubIdPointed: 1,
referenceModuleData: '',
referenceModule: address(0),
referenceModuleInitData: '',
mirrorData: mockMirrorData,
sig: _getSigStruct(otherSignerKey, digest, deadline)
})
);
assertEq(pubId, 2);
DataTypes.PublicationStruct memory pub = hub.getPub(firstProfileId, pubId);
assertEq(pub.profileIdPointed, mockMirrorData.profileIdPointed);
assertEq(pub.pubIdPointed, mockMirrorData.pubIdPointed);
assertEq(pub.contentURI, '');
assertEq(pub.referenceModule, mockMirrorData.referenceModule);
assertEq(pub.collectModule, address(0));
assertEq(pub.collectNFT, address(0));
}
// Private functions
function _buildPostWithSigData(
address delegatedSigner,
uint256 profileId,
string memory contentURI,
address collectModule,
bytes memory collectModuleInitData,
address referenceModule,
bytes memory referenceModuleInitData,
DataTypes.EIP712Signature memory sig
) private pure returns (DataTypes.PostWithSigData memory) {
return
DataTypes.PostWithSigData(
delegatedSigner,
profileId,
contentURI,
collectModule,
collectModuleInitData,
referenceModule,
referenceModuleInitData,
sig
);
}
function _buildCommentWithSigData(
address delegatedSigner,
uint256 profileId,
string memory contentURI,
uint256 profileIdPointed,
uint256 pubIdPointed,
bytes memory referenceModuleData,
address collectModule,
bytes memory collectModuleInitData,
address referenceModule,
bytes memory referenceModuleInitData,
DataTypes.EIP712Signature memory sig
) private pure returns (DataTypes.CommentWithSigData memory) {
return
DataTypes.CommentWithSigData(
delegatedSigner,
profileId,
contentURI,
profileIdPointed,
pubIdPointed,
referenceModuleData,
collectModule,
collectModuleInitData,
referenceModule,
referenceModuleInitData,
sig
);
}
function _buildMirrorWithSigData(
address delegatedSigner,
uint256 profileId,
uint256 profileIdPointed,
uint256 pubIdPointed,
bytes memory referenceModuleData,
address referenceModule,
bytes memory referenceModuleInitData,
DataTypes.EIP712Signature memory sig
) private pure returns (DataTypes.MirrorWithSigData memory) {
return
DataTypes.MirrorWithSigData(
delegatedSigner,
profileId,
profileIdPointed,
pubIdPointed,
referenceModuleData,
referenceModule,
referenceModuleInitData,
sig
);
DataTypes.PublicationStruct memory pub = _getPub(firstProfileId, pubId);
_verifyPublication(pub, _expectedPubFromInitData(mockMirrorData));
}
}

View File

@@ -2,6 +2,7 @@
pragma solidity ^0.8.13;
import './TestSetup.t.sol';
import '../../../contracts/libraries/DataTypes.sol';
contract BaseTest is TestSetup {
function _getSetDefaultProfileTypedDataHash(
@@ -136,6 +137,24 @@ contract BaseTest is TestSetup {
return _calculateDigest(structHash);
}
function _getPostTypedDataHash(
DataTypes.PostData memory postData,
uint256 nonce,
uint256 deadline
) internal view returns (bytes32) {
return
_getPostTypedDataHash({
profileId: postData.profileId,
contentURI: postData.contentURI,
collectModule: postData.collectModule,
collectModuleInitData: postData.collectModuleInitData,
referenceModule: postData.referenceModule,
referenceModuleInitData: postData.referenceModuleInitData,
nonce: nonce,
deadline: deadline
});
}
function _getCommentTypedDataHash(
uint256 profileId,
string memory contentURI,
@@ -168,6 +187,27 @@ contract BaseTest is TestSetup {
return _calculateDigest(structHash);
}
function _getCommentTypedDataHash(
DataTypes.CommentData memory commentData,
uint256 nonce,
uint256 deadline
) internal view returns (bytes32) {
return
_getCommentTypedDataHash({
profileId: commentData.profileId,
contentURI: commentData.contentURI,
profileIdPointed: commentData.profileIdPointed,
pubIdPointed: commentData.pubIdPointed,
referenceModuleData: commentData.referenceModuleData,
collectModule: commentData.collectModule,
collectModuleInitData: commentData.collectModuleInitData,
referenceModule: commentData.referenceModule,
referenceModuleInitData: commentData.referenceModuleInitData,
nonce: nonce,
deadline: deadline
});
}
function _getMirrorTypedDataHash(
uint256 profileId,
uint256 profileIdPointed,
@@ -194,6 +234,24 @@ contract BaseTest is TestSetup {
return _calculateDigest(structHash);
}
function _getMirrorTypedDataHash(
DataTypes.MirrorData memory mirrorData,
uint256 nonce,
uint256 deadline
) internal view returns (bytes32) {
return
_getMirrorTypedDataHash({
profileId: mirrorData.profileId,
profileIdPointed: mirrorData.profileIdPointed,
pubIdPointed: mirrorData.pubIdPointed,
referenceModuleData: mirrorData.referenceModuleData,
referenceModule: mirrorData.referenceModule,
referenceModuleInitData: mirrorData.referenceModuleInitData,
nonce: nonce,
deadline: deadline
});
}
function _getFollowTypedDataHash(
uint256[] memory profileIds,
bytes[] memory datas,
@@ -266,4 +324,49 @@ contract BaseTest is TestSetup {
ret[0] = n;
return ret;
}
function _post(DataTypes.PostData memory postData) internal returns (uint256) {
return hub.post(postData);
}
function _comment(DataTypes.CommentData memory commentData) internal returns (uint256) {
return hub.comment(commentData);
}
function _mirror(DataTypes.MirrorData memory mirrorData) internal returns (uint256) {
return hub.mirror(mirrorData);
}
function _postWithSig(DataTypes.PostWithSigData memory postWithSigData)
internal
returns (uint256)
{
return hub.postWithSig(postWithSigData);
}
function _commentWithSig(DataTypes.CommentWithSigData memory commentWithSigData)
internal
returns (uint256)
{
return hub.commentWithSig(commentWithSigData);
}
function _mirrorWithSig(DataTypes.MirrorWithSigData memory mirrorWithSigData)
internal
returns (uint256)
{
return hub.mirrorWithSig(mirrorWithSigData);
}
function _setDelegatedExecutorApproval(address executor, bool approved) internal {
hub.setDelegatedExecutorApproval(executor, approved);
}
function _getPub(uint256 profileId, uint256 pubId)
internal
view
returns (DataTypes.PublicationStruct memory)
{
return hub.getPub(profileId, pubId);
}
}

View File

@@ -0,0 +1,64 @@
import 'forge-std/Test.sol';
import 'contracts/libraries/DataTypes.sol';
contract PublishingHelpers is Test {
function _verifyPublication(
DataTypes.PublicationStruct memory pub,
DataTypes.PublicationStruct memory expectedPub
) internal {
assertEq(pub.profileIdPointed, expectedPub.profileIdPointed);
assertEq(pub.pubIdPointed, expectedPub.pubIdPointed);
assertEq(pub.contentURI, expectedPub.contentURI);
assertEq(pub.referenceModule, expectedPub.referenceModule);
assertEq(pub.collectModule, expectedPub.collectModule);
assertEq(pub.collectNFT, expectedPub.collectNFT);
}
function _expectedPubFromInitData(DataTypes.PostData memory postData)
internal
pure
returns (DataTypes.PublicationStruct memory)
{
return
DataTypes.PublicationStruct({
profileIdPointed: 0,
pubIdPointed: 0,
contentURI: postData.contentURI,
referenceModule: postData.referenceModule,
collectModule: postData.collectModule,
collectNFT: address(0)
});
}
function _expectedPubFromInitData(DataTypes.CommentData memory commentData)
internal
pure
returns (DataTypes.PublicationStruct memory)
{
return
DataTypes.PublicationStruct({
profileIdPointed: commentData.profileIdPointed,
pubIdPointed: commentData.pubIdPointed,
contentURI: commentData.contentURI,
referenceModule: commentData.referenceModule,
collectModule: commentData.collectModule,
collectNFT: address(0)
});
}
function _expectedPubFromInitData(DataTypes.MirrorData memory mirrorData)
internal
pure
returns (DataTypes.PublicationStruct memory)
{
return
DataTypes.PublicationStruct({
profileIdPointed: mirrorData.profileIdPointed,
pubIdPointed: mirrorData.pubIdPointed,
contentURI: '',
referenceModule: mirrorData.referenceModule,
collectModule: address(0),
collectNFT: address(0)
});
}
}

View File

@@ -0,0 +1,136 @@
import '../../../contracts/libraries/DataTypes.sol';
contract SignatureHelpers {
// Private functions
function _buildPostWithSigData(
address delegatedSigner,
uint256 profileId,
string memory contentURI,
address collectModule,
bytes memory collectModuleInitData,
address referenceModule,
bytes memory referenceModuleInitData,
DataTypes.EIP712Signature memory sig
) internal pure returns (DataTypes.PostWithSigData memory) {
return
DataTypes.PostWithSigData(
delegatedSigner,
profileId,
contentURI,
collectModule,
collectModuleInitData,
referenceModule,
referenceModuleInitData,
sig
);
}
function _buildPostWithSigData(
address delegatedSigner,
DataTypes.PostData memory postData,
DataTypes.EIP712Signature memory sig
) internal pure returns (DataTypes.PostWithSigData memory) {
return
_buildPostWithSigData(
delegatedSigner,
postData.profileId,
postData.contentURI,
postData.collectModule,
postData.collectModuleInitData,
postData.referenceModule,
postData.referenceModuleInitData,
sig
);
}
function _buildCommentWithSigData(
address delegatedSigner,
uint256 profileId,
string memory contentURI,
uint256 profileIdPointed,
uint256 pubIdPointed,
bytes memory referenceModuleData,
address collectModule,
bytes memory collectModuleInitData,
address referenceModule,
bytes memory referenceModuleInitData,
DataTypes.EIP712Signature memory sig
) internal pure returns (DataTypes.CommentWithSigData memory) {
return
DataTypes.CommentWithSigData(
delegatedSigner,
profileId,
contentURI,
profileIdPointed,
pubIdPointed,
referenceModuleData,
collectModule,
collectModuleInitData,
referenceModule,
referenceModuleInitData,
sig
);
}
function _buildCommentWithSigData(
address delegatedSigner,
DataTypes.CommentData memory commentData,
DataTypes.EIP712Signature memory sig
) internal pure returns (DataTypes.CommentWithSigData memory) {
return
_buildCommentWithSigData({
delegatedSigner: delegatedSigner,
profileId: commentData.profileId,
contentURI: commentData.contentURI,
profileIdPointed: commentData.profileIdPointed,
pubIdPointed: commentData.pubIdPointed,
referenceModuleData: commentData.referenceModuleData,
collectModule: commentData.collectModule,
collectModuleInitData: commentData.collectModuleInitData,
referenceModule: commentData.referenceModule,
referenceModuleInitData: commentData.referenceModuleInitData,
sig: sig
});
}
function _buildMirrorWithSigData(
address delegatedSigner,
uint256 profileId,
uint256 profileIdPointed,
uint256 pubIdPointed,
bytes memory referenceModuleData,
address referenceModule,
bytes memory referenceModuleInitData,
DataTypes.EIP712Signature memory sig
) internal pure returns (DataTypes.MirrorWithSigData memory) {
return
DataTypes.MirrorWithSigData(
delegatedSigner,
profileId,
profileIdPointed,
pubIdPointed,
referenceModuleData,
referenceModule,
referenceModuleInitData,
sig
);
}
function _buildMirrorWithSigData(
address delegatedSigner,
DataTypes.MirrorData memory mirrorData,
DataTypes.EIP712Signature memory sig
) internal pure returns (DataTypes.MirrorWithSigData memory) {
return
_buildMirrorWithSigData({
delegatedSigner: delegatedSigner,
profileId: mirrorData.profileId,
profileIdPointed: mirrorData.profileIdPointed,
pubIdPointed: mirrorData.pubIdPointed,
referenceModuleData: mirrorData.referenceModuleData,
referenceModule: mirrorData.referenceModule,
referenceModuleInitData: mirrorData.referenceModuleInitData,
sig: sig
});
}
}