Skip to content

Commit

Permalink
fix: ensure subgraphNFT handles metadata with leading zeros correctly
Browse files Browse the repository at this point in the history
Closes: #576
Signed-off-by: Tomás Migone <tomas@edgeandnode.com>
  • Loading branch information
tmigone committed May 24, 2022
1 parent 6e9b7f1 commit 5e1db55
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
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
32 changes: 32 additions & 0 deletions test/gns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,8 @@ describe('GNS', () => {
})

it('without token descriptor', async function () {
newSubgraph0.subgraphMetadata =
'0x00fae00cac62e26a062ca75eb35392df730f5e6c84aa36aa7d199b4bd713f73a'
const subgraph0 = await publishNewSubgraph(me, newSubgraph0)

const subgraphNFTAddress = await gns.subgraphNFT()
Expand All @@ -1039,6 +1041,14 @@ describe('GNS', () => {
const tokenURI = await subgraphNFT.connect(me.signer).tokenURI(subgraph0.id)

const sub = new SubgraphDeploymentID(newSubgraph0.subgraphMetadata)
console.log('test 1')

console.log(subgraph0)

console.log(sub.bytes32)
console.log(sub)
console.log(tokenURI)

expect(sub.bytes32).eq(tokenURI)
})

Expand All @@ -1065,7 +1075,29 @@ describe('GNS', () => {
await subgraphNFT.connect(governor.signer).setTokenDescriptor(AddressZero)
await subgraphNFT.connect(governor.signer).setBaseURI('ipfs://')
const tokenURI = await subgraphNFT.connect(me.signer).tokenURI(subgraph0.id)
console.log('test 2')

console.log(tokenURI)
console.log(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)
})
})
})

0 comments on commit 5e1db55

Please sign in to comment.