Skip to content

Commit

Permalink
fix: surrender status for accepted tokens (Open-Attestation#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
superical committed Mar 2, 2022
1 parent 1b14383 commit e589f53
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion contracts/TradeTrustERC721Base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ abstract contract TradeTrustERC721Base is MinterRole, TitleEscrowCloner, IERC721

function isSurrendered(uint256 tokenId) public view returns (bool) {
if (_exists(tokenId)) {
return ownerOf(tokenId) == address(this) && _surrenderedOwners[tokenId] != address(0);
address owner = ownerOf(tokenId);
return (owner == address(this) && _surrenderedOwners[tokenId] != address(0)) || owner == BURN_ADDRESS;
}
return false;
}
Expand Down
49 changes: 49 additions & 0 deletions test/TradeTrustERC721.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,4 +527,53 @@ describe("TradeTrustERC721 (TS Migration)", async () => {
});
});
});

describe("Check is token surrendered status", () => {
let tokenId: string;
let titleEscrowContract: TitleEscrowCloneable;

beforeEach(async () => {
tokenId = faker.datatype.hexaDecimal(64);

await tradeTrustERC721Mock
.connect(users.carrier)
.mintTitle(users.beneficiary.address, users.beneficiary.address, tokenId);

const TitleEscrow = await ethers.getContractFactory("TitleEscrowCloneable");
const titleEscrowAddr = await tradeTrustERC721Mock.ownerOf(tokenId);
titleEscrowContract = TitleEscrow.attach(titleEscrowAddr) as TitleEscrowCloneable;
});

it("should return false for an unsurrendered token", async () => {
const res = await tradeTrustERC721Mock.isSurrendered(tokenId);

expect(res).to.be.false;
});

it("should return true for a surrendered token", async () => {
await titleEscrowContract.connect(users.beneficiary).surrender();

const res = await tradeTrustERC721Mock.isSurrendered(tokenId);

expect(res).to.be.true;
});

it("should return true for an accepted token", async () => {
await titleEscrowContract.connect(users.beneficiary).surrender();
await tradeTrustERC721Mock.destroyToken(tokenId);

const res = await tradeTrustERC721Mock.isSurrendered(tokenId);

expect(res).to.be.true;
});

it("should return false for a restored token", async () => {
await titleEscrowContract.connect(users.beneficiary).surrender();
await tradeTrustERC721Mock.restoreTitle(tokenId);

const res = await tradeTrustERC721Mock.isSurrendered(tokenId);

expect(res).to.be.false;
});
});
});

0 comments on commit e589f53

Please sign in to comment.