Merge pull request #12 from aave/feat/ui-data-provider

This commit is contained in:
Zer0dot
2022-02-10 15:34:10 -05:00
committed by GitHub
2 changed files with 116 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.10;
import {ILensHub} from '../interfaces/ILensHub.sol';
import {DataTypes} from '../libraries/DataTypes.sol';
/**
* @dev This struct contains both a `ProfileStruct` and a `PublicationStruct`.
*
* @param profileStruct A standard profile struct.
* @param publicationStruct A standard publicationStruct.
*/
struct LatestData {
DataTypes.ProfileStruct profileStruct;
DataTypes.PublicationStruct publicationStruct;
}
/**
* @title UIDataProvider
* @author Lens Protocol
*
* @dev This is a helper contract to fetch a profile and its latest publication in a single call.
*/
contract UIDataProvider {
ILensHub immutable HUB;
constructor(ILensHub hub) {
HUB = hub;
}
/**
* @notice Returns the profile struct and latest publication struct associated with the passed
* profile ID.
*
* @param profileId The profile ID to query.
*
* @return A custom `LatestData` struct containing the `ProfileStruct` and the `PublicationStruct` queried.
*/
function getLatestData(uint256 profileId) external view returns (LatestData memory) {
DataTypes.ProfileStruct memory profileStruct = HUB.getProfile(profileId);
uint256 pubCount = profileStruct.pubCount;
return LatestData(profileStruct, HUB.getPub(profileId, pubCount));
}
}

View File

@@ -1,9 +1,11 @@
import '@nomiclabs/hardhat-ethers';
import { expect } from 'chai';
import { UIDataProvider__factory } from '../../typechain-types';
import { ZERO_ADDRESS } from '../helpers/constants';
import { ERRORS } from '../helpers/errors';
import {
approvalFollowModule,
deployer,
emptyCollectModule,
FIRST_PROFILE_ID,
followerOnlyReferenceModule,
@@ -639,4 +641,72 @@ makeSuiteCleanRoom('Misc', function () {
});
});
});
context('UI Data Provider', function () {
it('UI Data Provider should return expected values', async function () {
// First, create a profile,
await expect(
lensHub.createProfile({
to: userAddress,
handle: MOCK_PROFILE_HANDLE,
imageURI: MOCK_PROFILE_URI,
followModule: ZERO_ADDRESS,
followModuleData: [],
followNFTURI: MOCK_FOLLOW_NFT_URI,
})
).to.not.be.reverted;
// Then, whitelist a collect module
await expect(
lensHub.connect(governance).whitelistCollectModule(emptyCollectModule.address, true)
).to.not.be.reverted;
// Then, publish twice
const firstURI = 'first publication';
const secondURI = 'second publication';
await expect(
lensHub.post({
profileId: FIRST_PROFILE_ID,
contentURI: firstURI,
collectModule: emptyCollectModule.address,
collectModuleData: [],
referenceModule: ZERO_ADDRESS,
referenceModuleData: [],
})
).to.not.be.reverted;
await expect(
lensHub.post({
profileId: FIRST_PROFILE_ID,
contentURI: secondURI,
collectModule: emptyCollectModule.address,
collectModuleData: [],
referenceModule: ZERO_ADDRESS,
referenceModuleData: [],
})
).to.not.be.reverted;
// Then, deploy the data provider
const dataProvider = await new UIDataProvider__factory(deployer).deploy(lensHub.address);
// Lastly, validate the result from the data provider
const result = await dataProvider.getLatestData(FIRST_PROFILE_ID);
const pubStruct = result.publicationStruct;
const profileStruct = result.profileStruct;
expect(profileStruct.pubCount).to.eq(2);
expect(profileStruct.followModule).to.eq(ZERO_ADDRESS);
expect(profileStruct.followNFT).to.eq(ZERO_ADDRESS);
expect(profileStruct.handle).to.eq(MOCK_PROFILE_HANDLE);
expect(profileStruct.imageURI).to.eq(MOCK_PROFILE_URI);
expect(profileStruct.followNFTURI).to.eq(MOCK_FOLLOW_NFT_URI);
expect(pubStruct.profileIdPointed).to.eq(0);
expect(pubStruct.pubIdPointed).to.eq(0);
expect(pubStruct.contentURI).to.eq(secondURI);
expect(pubStruct.referenceModule).to.eq(ZERO_ADDRESS);
expect(pubStruct.collectModule).to.eq(emptyCollectModule.address);
expect(pubStruct.collectNFT).to.eq(ZERO_ADDRESS);
});
});
});