Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Peckshield PVE004 #5

Merged
merged 1 commit into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions contracts/NestedAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ contract NestedAsset is ERC721Enumerable, Ownable {
return tokenId;
}

require(
_exists(_replicatedTokenId) && tokenId != _replicatedTokenId,
"NestedAsset::mint: Invalid replicated token ID"
);

uint256 originalTokenId = originalAsset[_replicatedTokenId];
originalAsset[tokenId] = originalTokenId != 0 ? originalTokenId : _replicatedTokenId;

Expand Down
10 changes: 10 additions & 0 deletions test/unit/NestedAsset.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { expect } from "chai";
import { ethers } from "hardhat";
import { NestedAsset, NestedAsset__factory } from "../../typechain";
import { BigNumber } from "ethers";

describe("NestedAsset", () => {
let NestedAsset: NestedAsset__factory, asset: NestedAsset;
Expand Down Expand Up @@ -55,6 +56,15 @@ describe("NestedAsset", () => {
expect(await asset.originalAsset(2)).to.equal(1);
expect(await asset.originalAsset(3)).to.equal(1);
});

it("should revert if replicate id doesnt exist", async () => {
await expect(asset.mint(alice.address, 1)).to.be.revertedWith(
"NestedAsset::mint: Invalid replicated token ID",
);
await expect(asset.mint(alice.address, 10)).to.be.revertedWith(
"NestedAsset::mint: Invalid replicated token ID",
);
});
});

it("should revert if the caller is not the factory", async () => {
Expand Down