Skip to content

Commit

Permalink
Add tests and update operator assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
BCLeFevre committed Jun 12, 2022
1 parent e9badfb commit 9215fde
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 2 deletions.
15 changes: 14 additions & 1 deletion contracts/zones/DeployerGlobalPausable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,20 @@ contract DeployerGlobalPausable is GlobalPausableEventsAndErrors {
);
pauserAddress = pauserToAssign;

// Emit the event
// Emit the epvent
emit PauserUpdated(pauserAddress);
}

/**
* @notice Assigns the given address with the ability to operate the
* give zone.
*
* @param _globalPausableAddress Zone Address to assign operator role.
* @param operatorToAssign Address to assign role.
*/
function assignOperatorOfZone(address _globalPausableAddress, address operatorToAssign) external {
require(msg.sender == deployerOwner, "Can only be set by the deployer");
GlobalPausable gp = GlobalPausable(_globalPausableAddress);
gp.assignOperator(operatorToAssign);
}
}
2 changes: 1 addition & 1 deletion contracts/zones/GlobalPausable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ contract GlobalPausable is GlobalPausableEventsAndErrors, ZoneInterface {
*
* @param operatorToAssign Address to assign role.
*/
function assignOperator(address operatorToAssign) public {
function assignOperator(address operatorToAssign) external {
require(msg.sender == deployer, "Can only be set by the deployer");
require(
operatorToAssign != address(0),
Expand Down
125 changes: 125 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,34 @@ describe(`Consideration (version: ${VERSION}) — initial test suite`, function
);
});

it("Assign pauser and self destruct the zone", async () => {
// deploy GPD
const GPDeployer = await ethers.getContractFactory(
"DeployerGlobalPausable",
owner
);
const gpDeployer = await GPDeployer.deploy(
owner.address,
ethers.utils.formatBytes32String("0")
);

// deploy GP
const zoneAddr = await createZone(gpDeployer);

// Try to nuke the zone before being assigned pauser
await expect(
gpDeployer.connect(buyer).killSwitch(zoneAddr)
).to.be.revertedWith("InvalidPauser");

// owner assigns the pauser of the zone
await whileImpersonating(owner.address, provider, async () => {
gpDeployer.assignPauser(buyer.address);
});

// Now as pauser, nuke the zone
await gpDeployer.connect(buyer).killSwitch(zoneAddr);
});

it("Revert on an order with a global pausable zone if zone has been self destructed", async () => {
// deploy GPD
const GPDeployer = await ethers.getContractFactory(
Expand Down Expand Up @@ -744,6 +772,103 @@ describe(`Consideration (version: ${VERSION}) — initial test suite`, function
);
});

it.only("Operator of zone can cancel restricted orders.", async () => {
// deploy GPD
const GPDeployer = await ethers.getContractFactory(
"DeployerGlobalPausable",
owner
);
const gpDeployer = await GPDeployer.deploy(
owner.address,
ethers.utils.formatBytes32String("0")
);

// deploy GlobalPausable
const zoneAddress = await createZone(gpDeployer);

// Attach to GlobalPausable zone
const gpZoneContract = await ethers.getContractFactory(
"GlobalPausable",
owner
);

// Attach to zone
const gpZone = await gpZoneContract.attach(zoneAddress);

const nftId = await mintAndApprove721(
seller,
marketplaceContract.address
);

const offer = [getTestItem721(nftId)];

const consideration = [
getItemETH(parseEther("10"), parseEther("10"), seller.address),
getItemETH(parseEther("1"), parseEther("1"), owner.address),
];

const { orderComponents } = await createOrder(
seller,
{ address: zoneAddress },
offer,
consideration,
2 // FULL_RESTRICTED, zone can execute or cancel
);

// Non operator address should not be allowed to operate the zone
await expect(
gpZone
.connect(seller)
.cancelOrder(marketplaceContract.address, [orderComponents])
).to.be.revertedWith("InvalidOperator");

// Approve operator
await gpDeployer
.connect(owner)
.assignOperatorOfZone(zoneAddress, seller.address);

// Now allowed to operate the zone
await gpZone
.connect(seller)
.cancelOrder(marketplaceContract.address, [orderComponents]);
});

it.only("Reverts trying to assign operator as non-deployer", async () => {
// deploy GPD
const GPDeployer = await ethers.getContractFactory(
"DeployerGlobalPausable",
owner
);
const gpDeployer = await GPDeployer.deploy(
owner.address,
ethers.utils.formatBytes32String("0")
);

// deploy GlobalPausable
const zoneAddress = await createZone(gpDeployer);

// Attach to GlobalPausable zone
const gpZoneContract = await ethers.getContractFactory(
"GlobalPausable",
owner
);

// Attach to zone
const gpZone = await gpZoneContract.attach(zoneAddress);

// Try to approve operator without permission
await expect(
gpDeployer
.connect(seller)
.assignOperatorOfZone(zoneAddress, seller.address)
).to.be.revertedWith("Can only be set by the deployer");

// Try to approve operator directly without permission
await expect(
gpZone.connect(seller).assignOperator(seller.address)
).to.be.revertedWith("Can only be set by the deployer");
});

it("Reverts if non-Zone tries to cancel restricted orders.", async () => {
// deploy GPD
const GPDeployer = await ethers.getContractFactory(
Expand Down

0 comments on commit 9215fde

Please sign in to comment.