Skip to content

Commit

Permalink
Adds the context behaviour to MarketplaceAccessFacet.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesduncombe committed Feb 5, 2024
1 parent f09a5d2 commit a01a741
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
24 changes: 19 additions & 5 deletions contracts/marketplace/MarketplaceAccessFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pragma solidity 0.8.10;
import "../lib/LibAddressSet.sol";
import "../lib/LibPaginate.sol";
import "../common/AHasMembers.sol";
import "../common/AHasForwarder.sol";
import "../common/AHasContext.sol";
import "../issuer/IssuerTopFacet.sol";
import "../interfaces/ICustomErrors.sol";
import "../interfaces/IHasActiveMembers.sol";
Expand All @@ -15,9 +17,21 @@ import "./MarketplaceAutomatonsFacet.sol";
* @title The Marketplace Smart Contract.
* @notice The Marketplace Access facet is in charge of keeping track of marketplace members.
*/
contract MarketplaceAccessFacet is AMarketplaceFacet, AHasMembers, IHasActiveMembers {
contract MarketplaceAccessFacet is AMarketplaceFacet, AHasMembers, AHasContext, IHasActiveMembers {
using LibAddressSet for LibAddressSet.Data;

/// AHasContext implementation.

// TODO: Could _isTrustedForwarder actually have it's default implementation point to
// IHasForwarder(address(this)).isTrustedForwarder(forwarder) or similar?
function _isTrustedForwarder(address forwarder) internal view override(AHasContext) returns (bool) {
return AHasForwarder(address(this)).isTrustedForwarder(forwarder);
}

function _msgSender() internal view override(AHasMembers, AHasContext) returns (address) {
return AHasContext._msgSender();
}

/// AHasMembers implementation.

function isMembersManager(address who) internal view override(AHasMembers) returns (bool) {
Expand Down Expand Up @@ -56,25 +70,25 @@ contract MarketplaceAccessFacet is AMarketplaceFacet, AHasMembers, IHasActiveMem
*/
function memberAddedToFast(address member) external {
// Verify that the given address is in fact a registered FAST contract.
if (!IssuerTopFacet(LibMarketplace.data().issuer).isFastRegistered(msg.sender)) {
if (!IssuerTopFacet(LibMarketplace.data().issuer).isFastRegistered(_msgSender())) {
revert ICustomErrors.RequiresFastContractCaller();
}
// Keep track of the member's FAST membership.
// TODO: We don't throw until we've fixed the `marketplace.fastMemberships`.
LibMarketplaceAccess.data().fastMemberships[member].add(msg.sender, true);
LibMarketplaceAccess.data().fastMemberships[member].add(_msgSender(), true);
}

/**
* @notice Callback from FAST contracts allowing the Marketplace contract to keep track of FAST memberships.
* @param member The member for which a FAST membership has been removed.
*/
function memberRemovedFromFast(address member) external {
if (!IssuerTopFacet(LibMarketplace.data().issuer).isFastRegistered(msg.sender)) {
if (!IssuerTopFacet(LibMarketplace.data().issuer).isFastRegistered(_msgSender())) {
revert ICustomErrors.RequiresFastContractCaller();
}
// Remove the tracked membership.
// TODO: We don't throw until we've fixed the `marketplace.fastMemberships`.
LibMarketplaceAccess.data().fastMemberships[member].remove(msg.sender, true);
LibMarketplaceAccess.data().fastMemberships[member].remove(_msgSender(), true);
}

/// IHasActiveMembers implementation.
Expand Down
20 changes: 17 additions & 3 deletions test/marketplace/MarketplaceAccessFacet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Issuer,
Marketplace,
} from "../../typechain/hardhat-diamond-abi/HardhatDiamondABI.sol";
import { IForwarder } from "../../typechain";
chai.use(solidity);
chai.use(smock.matchers);

Expand All @@ -24,11 +25,13 @@ describe("MarketplaceAccessFacet", () => {
alice: SignerWithAddress,
bob: SignerWithAddress,
rob: SignerWithAddress,
john: SignerWithAddress;
john: SignerWithAddress,
trustedForwarder: SignerWithAddress;

let issuer: FakeContract<Issuer>,
fast: FakeContract<Fast>,
marketplace: Marketplace,
forwarder: FakeContract<IForwarder>,
access: MarketplaceAccessFacet,
issuerMemberAccess: MarketplaceAccessFacet;

Expand All @@ -50,10 +53,11 @@ describe("MarketplaceAccessFacet", () => {

before(async () => {
// Keep track of a few signers.
[deployer, issuerMember, alice, bob, rob, john] = await ethers.getSigners();
// Mock Issuer and Fast contracts.
[deployer, issuerMember, alice, bob, rob, john, trustedForwarder] = await ethers.getSigners();
// Mock Issuer, Fast and IForwarder contracts.
issuer = await smock.fake("Issuer");
fast = await smock.fake("Fast");
forwarder = await smock.fake("IForwarder");
});

beforeEach(async () => {
Expand All @@ -79,6 +83,16 @@ describe("MarketplaceAccessFacet", () => {
resetFastMock();
});

describe("AHasContext implementation", () => {
describe("_isTrustedForwarder()", () => {
it("is implemented");
});

describe("_msgSender()", () => {
it("is implemented");
});
});

describe("IHasMembers", () => {
describe("isMember", () => {
beforeEach(async () => {
Expand Down

0 comments on commit a01a741

Please sign in to comment.