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

fix: ensure subgraphNFT handles metadata with leading zeros correctly #577

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion contracts/discovery/SubgraphNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ contract SubgraphNFT is Governed, ERC721, ISubgraphNFT {
// Default token URI
uint256 metadata = uint256(_subgraphMetadataHashes[_tokenId]);

string memory _subgraphURI = metadata > 0 ? HexStrings.toString(metadata) : "";
string memory _subgraphURI = metadata > 0 ? HexStrings.toHexString(metadata, 32) : "";
string memory base = baseURI();

// If there is no base URI, return the token URI.
Expand Down
17 changes: 17 additions & 0 deletions test/gns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1067,5 +1067,22 @@ describe('GNS', () => {
const tokenURI = await subgraphNFT.connect(me.signer).tokenURI(subgraph0.id)
expect('ipfs://' + subgraph0.id).eq(tokenURI)
})

it('without token descriptor and metadata with leading zeros', async function () {
const newSubgraph = buildSubgraph()
newSubgraph.subgraphMetadata = `0x00${newSubgraph.subgraphMetadata.slice(4)}`

const subgraph0 = await publishNewSubgraph(me, newSubgraph)

const subgraphNFTAddress = await gns.subgraphNFT()
const subgraphNFT = getContractAt('SubgraphNFT', subgraphNFTAddress) as SubgraphNFT
await subgraphNFT.connect(governor.signer).setTokenDescriptor(AddressZero)
await subgraphNFT.connect(governor.signer).setBaseURI('ipfs://')
const tokenURI = await subgraphNFT.connect(me.signer).tokenURI(subgraph0.id)

const sub = new SubgraphDeploymentID(newSubgraph.subgraphMetadata)

expect('ipfs://' + sub.bytes32).eq(tokenURI)
})
})
})