Skip to content

Commit

Permalink
Merge branch 'pr/264'
Browse files Browse the repository at this point in the history
  • Loading branch information
cinnabarhorse committed Aug 5, 2024
2 parents fe18868 + 9aea316 commit 3d78452
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 10 deletions.
2 changes: 1 addition & 1 deletion contracts/Aavegotchi/facets/ItemsRolesRegistryFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ contract ItemsRolesRegistryFacet is Modifiers, IERC7589, ERC1155Holder {
LibItems.removeFromOwner(_from, _tokenId, _tokenAmount);
LibItems.addToOwner(_to, _tokenId, _tokenAmount);
IEventHandlerFacet(_tokenAddress).emitTransferSingleEvent(LibMeta.msgSender(), _from, _to, _tokenId, _tokenAmount);
LibERC1155Marketplace.updateERC1155Listing(address(this), _tokenId, _to);
LibERC1155Marketplace.updateERC1155Listing(address(this), _tokenId, _from);
}

/**
Expand Down
34 changes: 34 additions & 0 deletions scripts/itemsRolesRegistry/upgradeRolesRegistryBaazarDelist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ethers, run } from "hardhat";
import {
DeployUpgradeTaskArgs,
FacetsAndAddSelectors,
convertFacetAndSelectorsToString,
} from "../../tasks/deployUpgrade";


const aavegotchiDiamondAddress = "0x86935F11C86623deC8a25696E1C19a8659CbF95d";
const owner = "0x01F010a5e001fe9d6940758EA5e8c777885E351e";

export async function upgradeRolesRegistryBaazarDelist() {

const facets: FacetsAndAddSelectors[] = [
{
facetName: "contracts/Aavegotchi/facets/ItemsRolesRegistryFacet.sol:ItemsRolesRegistryFacet",
addSelectors: [],
removeSelectors: [],
}
];

//@ts-ignore
const joined = convertFacetAndSelectorsToString(facets);
const args: DeployUpgradeTaskArgs = {
diamondOwner: owner,
diamondAddress: aavegotchiDiamondAddress,
facetsAndAddSelectors: joined,
useLedger: false,
useMultisig: false,
freshDeployment: false,
};

await run("deployUpgrade", args);
}
105 changes: 105 additions & 0 deletions test/ItemsRolesRegistryFacet/RolesRegistryUnlistedBazaarTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* global describe it before ethers network */
/* eslint prefer-const: "off" */

//@ts-ignore
import { ethers, network } from "hardhat";
import chai from "chai";
import { ERC1155MarketplaceFacet, MarketplaceGetterFacet } from "../../typechain";
import { Contract } from "ethers";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import {
aavegotchiDiamondAddress,
buildCommitment,
} from "./helpers";
import {
aavegotchiDiamondAddressMatic
} from "../../helpers/constants";
import { impersonate } from "../../scripts/helperFunctions";
import { RolesRegistryUnlistedBazaarTest } from "./deployTest";

const { expect } = chai;

describe("ItemsRolesRegistryFacet", async () => {
let ItemsRolesRegistryFacet: Contract;
let grantor: SignerWithAddress;
let erc1155MarketWithItemSeller: ERC1155MarketplaceFacet;
let marketplaceGetter: MarketplaceGetterFacet;
const erc1155Id = 37; // Should be erc1155/item
const test1155Quantity = 3;
const diamondAddress = aavegotchiDiamondAddressMatic;
const itemOwnerAddress = "0x983b36872ae1bbC40dD0A99c3ed98429FEa0EbD4"; // Should be Item owner
const listingId = 368953;

let snapshot: any;
before(async () => {
const signers = await ethers.getSigners();
grantor = signers[0];

await RolesRegistryUnlistedBazaarTest();

const erc1155MarketplaceFacet = (await ethers.getContractAt(
"ERC1155MarketplaceFacet",
diamondAddress
)) as ERC1155MarketplaceFacet;

erc1155MarketWithItemSeller = await impersonate(
itemOwnerAddress,
erc1155MarketplaceFacet,
ethers,
network
);

marketplaceGetter = (await ethers.getContractAt(
"MarketplaceGetterFacet",
diamondAddress
)) as MarketplaceGetterFacet;


snapshot = await ethers.provider.send("evm_snapshot", []);

// -------------------------//--------------------
// Roles Registry

ItemsRolesRegistryFacet = await ethers.getContractAt(
"ItemsRolesRegistryFacet",
aavegotchiDiamondAddress,
);

ItemsRolesRegistryFacet = await impersonate(
itemOwnerAddress,
ItemsRolesRegistryFacet,
ethers,
network
);

// Ensure itemOwnerAddress has sufficient balance
await network.provider.request({
method: "hardhat_setBalance",
params: [itemOwnerAddress, "0x1000000000000000000"], // Set balance to 1 ETH
});
});

describe('commitTokens', async () => {
after(async function () {
await ethers.provider.send("evm_revert", [snapshot]);
});
it("Should delist ERC1155 From Bazaar when CommitTokens was called from Roles Registry", async function () {

const commitment = buildCommitment({grantor: grantor.address})

const listingBefore = await marketplaceGetter.getERC1155Listing(listingId);
expect(listingBefore.quantity).to.equal(3);

await
ItemsRolesRegistryFacet.commitTokens(
itemOwnerAddress,
commitment.tokenAddress,
erc1155Id,
test1155Quantity,
)

const listingAfter = await marketplaceGetter.getERC1155Listing(listingId);
expect(listingAfter.quantity).to.equal(0);
});
})
});
46 changes: 37 additions & 9 deletions test/ItemsRolesRegistryFacet/deployTest.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { diamondOwner } from "../../scripts/helperFunctions";
import {
DeployUpgradeTaskArgs,
FacetsAndAddSelectors,
convertFacetAndSelectorsToString,
} from "../../tasks/deployUpgrade";
import { InitItemsRolesRegistryFacet__factory, OwnershipFacet } from "../../typechain";
import { InitItemsRolesRegistryFacetInterface } from "../../typechain/InitItemsRolesRegistryFacet";
import { aavegotchiDiamondAddress, diamondUpgrader } from "./helpers";
import { aavegotchiDiamondAddress, diamondUpgrader , } from "./helpers";
import { ethers, run } from "hardhat";
const owner = "0x01F010a5e001fe9d6940758EA5e8c777885E351e";

export async function deployItemsRolesRegistryFacet() {



const facets: FacetsAndAddSelectors[] = [
{
facetName:
Expand Down Expand Up @@ -47,7 +53,7 @@ export async function deployItemsRolesRegistryFacet() {
const joined = convertFacetAndSelectorsToString(facets);

const args: DeployUpgradeTaskArgs = {
diamondUpgrader: diamondUpgrader,
diamondOwner: owner,
diamondAddress: aavegotchiDiamondAddress,
facetsAndAddSelectors: joined,
useLedger: false,
Expand All @@ -57,6 +63,8 @@ export async function deployItemsRolesRegistryFacet() {
initCalldata: payload,
};



await run("deployUpgrade", args);

await removeInitItemsRolesRegistryFacet();
Expand All @@ -75,9 +83,8 @@ async function removeInitItemsRolesRegistryFacet() {
];

const joined = convertFacetAndSelectorsToString(facets);

const args: DeployUpgradeTaskArgs = {
diamondUpgrader: diamondUpgrader,
diamondOwner: owner,
diamondAddress: aavegotchiDiamondAddress,
facetsAndAddSelectors: joined,
useLedger: false,
Expand Down Expand Up @@ -110,9 +117,8 @@ export async function upgradeItemsFacet() {
];

const joined = convertFacetAndSelectorsToString(facets);

const args: DeployUpgradeTaskArgs = {
diamondUpgrader: diamondUpgrader,
diamondOwner: owner,
diamondAddress: aavegotchiDiamondAddress,
facetsAndAddSelectors: joined,
useLedger: false,
Expand All @@ -139,9 +145,8 @@ export async function upgradeItemsRolesRegistryFacet() {

//@ts-ignore
const joined = convertFacetAndSelectorsToString(facets);

const args: DeployUpgradeTaskArgs = {
diamondUpgrader: diamondUpgrader,
diamondOwner: owner,
diamondAddress: aavegotchiDiamondAddress,
facetsAndAddSelectors: joined,
useLedger: false,
Expand All @@ -163,9 +168,32 @@ export async function upgradeItemsFacetOnly() {

//@ts-ignore
const joined = convertFacetAndSelectorsToString(facets);
const args: DeployUpgradeTaskArgs = {
diamondOwner: owner,
diamondAddress: aavegotchiDiamondAddress,
facetsAndAddSelectors: joined,
useLedger: false,
useMultisig: false,
freshDeployment: false,
};

await run("deployUpgrade", args);
}

export async function RolesRegistryUnlistedBazaarTest() {

const facets: FacetsAndAddSelectors[] = [
{
facetName: "contracts/Aavegotchi/facets/ItemsRolesRegistryFacet.sol:ItemsRolesRegistryFacet",
addSelectors: [],
removeSelectors: [],
},
];

//@ts-ignore
const joined = convertFacetAndSelectorsToString(facets);
const args: DeployUpgradeTaskArgs = {
diamondUpgrader: diamondUpgrader,
diamondOwner: owner,
diamondAddress: aavegotchiDiamondAddress,
facetsAndAddSelectors: joined,
useLedger: false,
Expand Down

0 comments on commit 3d78452

Please sign in to comment.