Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Felipe Forbeck <felipe.forbeck@gmail.com>
  • Loading branch information
fforbeck committed Mar 17, 2022
1 parent 1a6b44f commit be276de
Show file tree
Hide file tree
Showing 3 changed files with 256 additions and 20 deletions.
20 changes: 9 additions & 11 deletions contracts/adapters/ERC1155Adapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,14 @@ contract ERC1155AdapterContract is AdapterGuard {
uint256 nftTokenId,
uint256 amount
) external reentrancyGuard(dao) {
ERC1155TokenExtension erc1155 = ERC1155TokenExtension(
dao.getExtensionAddress(DaoHelper.ERC1155_EXT)
);
erc1155.internalTransfer(
dao,
DaoHelper.msgSender(dao, msg.sender),
toOwner,
nftAddr,
nftTokenId,
amount
);
ERC1155TokenExtension(dao.getExtensionAddress(DaoHelper.ERC1155_EXT))
.internalTransfer(
dao,
DaoHelper.msgSender(dao, msg.sender),
toOwner,
nftAddr,
nftTokenId,
amount
);
}
}
153 changes: 153 additions & 0 deletions test/extensions/erc1155.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const {
isMember,
onboardingNewMember,
encodeDaoInfo,
guildKickProposal,
} = require("../../utils/test-util");

const proposalCounter = proposalIdGenerator().generator;
Expand Down Expand Up @@ -649,6 +650,158 @@ describe("Extension - ERC1155", () => {
).to.be.revertedWith("ERC1155: ids and amounts length mismatch");
});

it("should not be possible to execute an internalTransfer if the nftOwner is in jail", async () => {
const jailedNftOwner = accounts[2];
const bank = this.extensions.bankExt;
const onboarding = this.adapters.onboarding;
const voting = this.adapters.voting;
const erc1155TestToken = this.testContracts.erc1155TestToken;
const guildkickContract = this.adapters.guildkick;
const erc1155TokenExtension = this.extensions.erc1155Ext;
const erc1155Adapter = this.adapters.erc1155Adapter;

//create a test 1155 token
const tokenId = 1,
tokenAmount = 10;
await erc1155TestToken.mint(jailedNftOwner, tokenId, tokenAmount, "0x0", {
from: daoOwner,
gasPrice: toBN("0"),
});

// transfer from nft owner to the extension to test out the internal transfer
await erc1155TestToken.safeTransferFrom(
jailedNftOwner,
erc1155TokenExtension.address,
tokenId,
tokenAmount,
[],
{
from: jailedNftOwner,
}
);

// Onboard the nftOwner as a member
await onboardingNewMember(
getProposalCounter(),
this.dao,
onboarding,
voting,
jailedNftOwner,
daoOwner,
unitPrice,
UNITS,
toBN("3")
);
expect(await isMember(bank, jailedNftOwner)).equal(true);

// Start a new kick proposal
let memberToKick = jailedNftOwner;
let kickProposalId = getProposalCounter();

await guildKickProposal(
this.dao,
guildkickContract,
memberToKick,
daoOwner,
kickProposalId
);

// Jailed member attempts to execute an internalTransfer, it should revert
await expect(
erc1155Adapter.internalTransfer(
this.dao.address,
jailedNftOwner,
erc1155TestToken.address,
tokenId,
tokenAmount,
{ from: jailedNftOwner }
)
).to.be.revertedWith("member is jailed");
});

it("should be possible to withdraw the NFT even if the nftOwner is in jail", async () => {
const jailedNftOwner = accounts[2];
const bank = this.extensions.bankExt;
const onboarding = this.adapters.onboarding;
const voting = this.adapters.voting;
const erc1155TestToken = this.testContracts.erc1155TestToken;
const guildkickContract = this.adapters.guildkick;
const erc1155TokenExtension = this.extensions.erc1155Ext;
const erc1155TestAdapter = this.adapters.erc1155TestAdapter;

//create a test 1155 token
const tokenId = 1,
tokenAmount = 10;
await erc1155TestToken.mint(jailedNftOwner, tokenId, tokenAmount, "0x0", {
from: daoOwner,
gasPrice: toBN("0"),
});

// transfer from nft owner to the extension to test out the internal transfer
await erc1155TestToken.safeTransferFrom(
jailedNftOwner,
erc1155TokenExtension.address,
tokenId,
tokenAmount,
[],
{
from: jailedNftOwner,
}
);

// Onboard the nftOwner as a member
await onboardingNewMember(
getProposalCounter(),
this.dao,
onboarding,
voting,
jailedNftOwner,
daoOwner,
unitPrice,
UNITS,
toBN("3")
);
expect(await isMember(bank, jailedNftOwner)).equal(true);

// Start a new kick proposal
let memberToKick = jailedNftOwner;
let kickProposalId = getProposalCounter();

await guildKickProposal(
this.dao,
guildkickContract,
memberToKick,
daoOwner,
kickProposalId
);

await erc1155TestAdapter.withdraw(
this.dao.address,
erc1155TestToken.address,
tokenId,
tokenAmount,
{ from: jailedNftOwner }
);

const balanceOfNftOwner = await erc1155TestToken.balanceOf(
jailedNftOwner,
tokenId
);
expect(balanceOfNftOwner.toString()).equal(tokenAmount.toString());

const balanceInExtension = await erc1155TokenExtension.getNFTIdAmount(
jailedNftOwner,
erc1155TestToken.address,
1
);
expect(balanceInExtension.toString()).equal("0");
// The nft was moved to the new owner account, so the GUILD should not be the NFT owner anymore
// The getNFTOwner must revert because there is no NFT asset for the GUILD owner at index 0
await expect(
erc1155TokenExtension.getNFTOwner(erc1155TestToken.address, 1, 0)
).to.be.reverted;
});

it("should not be possible to send ETH to the extension via receive function", async () => {
const extension = this.extensions.erc1155Ext;
await expect(
Expand Down
103 changes: 94 additions & 9 deletions test/extensions/erc721.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,25 @@ describe("Extension - ERC721", () => {
const voting = this.adapters.voting;
const guildkickContract = this.adapters.guildkick;

const pixelNFT = this.testContracts.pixelNFT;
const nftExtension = this.extensions.erc721Ext;
const erc721TestAdapter = this.adapters.erc721TestAdapter;

// Add an NFT directly into the ERC721 extension to test the internal transfer
await pixelNFT.mintPixel(jailedNftOwner, 1, 1, { from: daoOwner });
let pastEvents = await pixelNFT.getPastEvents();
let { tokenId } = pastEvents[1].returnValues;

await pixelNFT.methods["safeTransferFrom(address,address,uint256,bytes)"](
jailedNftOwner,
nftExtension.address,
tokenId,
encodeDaoInfo(this.dao.address),
{
from: jailedNftOwner,
}
);

await onboardingNewMember(
getProposalCounter(),
this.dao,
Expand All @@ -313,6 +332,15 @@ describe("Extension - ERC721", () => {
UNITS
);

// Move the NFT to the jailedNftOwner account before the Guild Kick starts
await erc721TestAdapter.internalTransfer(
this.dao.address,
jailedNftOwner,
pixelNFT.address,
tokenId,
{ from: daoOwner }
);

// Start a new kick proposal
let memberToKick = jailedNftOwner;
let kickProposalId = getProposalCounter();
Expand All @@ -325,6 +353,24 @@ describe("Extension - ERC721", () => {
kickProposalId
);

// Jailed member attempts to move the NFT again, but now it should not be possible
await expect(
erc721TestAdapter.internalTransfer(
this.dao.address,
daoOwner,
pixelNFT.address,
tokenId,
{ from: jailedNftOwner }
)
).to.be.revertedWith("member is jailed");
});

it("should be possible to withdraw the NFT even if the nftOwner is in jail", async () => {
const jailedNftOwner = accounts[2];
const onboarding = this.adapters.onboarding;
const voting = this.adapters.voting;
const guildkickContract = this.adapters.guildkick;

const pixelNFT = this.testContracts.pixelNFT;
const nftExtension = this.extensions.erc721Ext;
const erc721TestAdapter = this.adapters.erc721TestAdapter;
Expand All @@ -344,15 +390,54 @@ describe("Extension - ERC721", () => {
}
);

await expect(
erc721TestAdapter.internalTransfer(
this.dao.address,
daoOwner,
pixelNFT.address,
tokenId,
{ from: jailedNftOwner }
)
).to.be.revertedWith("member is jailed");
await onboardingNewMember(
getProposalCounter(),
this.dao,
onboarding,
voting,
jailedNftOwner,
daoOwner,
unitPrice,
UNITS
);

// Move the NFT to the jailedNftOwner account before the Guild Kick starts
await erc721TestAdapter.internalTransfer(
this.dao.address,
jailedNftOwner,
pixelNFT.address,
tokenId,
{ from: daoOwner }
);

// Start a new kick proposal
let memberToKick = jailedNftOwner;
let kickProposalId = getProposalCounter();

await guildKickProposal(
this.dao,
guildkickContract,
memberToKick,
daoOwner,
kickProposalId
);

await erc721TestAdapter.withdraw(
this.dao.address,
pixelNFT.address,
tokenId,
{ from: jailedNftOwner }
);

// After the withdraw the actual owner of the NFT is the jailedNftOwner address
expect(await pixelNFT.ownerOf(tokenId)).equal(jailedNftOwner);

// And the NFT metadata is not available in the extension anymore
await expect(nftExtension.getNFTAddress(0)).to.be.reverted;
await expect(nftExtension.getNFT(pixelNFT.address, 0)).to.be.reverted;
expect(
await nftExtension.getNFTOwner(pixelNFT.address, tokenId)
).to.be.equal(ZERO_ADDRESS);
});

it("should not be possible get an NFT in the collection if it is empty", async () => {
Expand Down

0 comments on commit be276de

Please sign in to comment.