Skip to content

Commit d221d3b

Browse files
committed
fixes structural traversal
adds ipfs reading / conversion tests rolls back pnpm to yarn deescalates sample key releases 1.3.1 Signed-off-by: Stefan Adolf <[email protected]>
1 parent c38ef8a commit d221d3b

File tree

6 files changed

+125
-10
lines changed

6 files changed

+125
-10
lines changed

deploy/inittest.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ $DC ps
1515
./setupLocal.sh -fx
1616

1717
cd subgraph
18-
pnpm codegen
19-
pnpm build:local
20-
pnpm create:local
18+
yarn codegen
19+
yarn build:local
20+
yarn create:local
2121
# that's a bad local config hack still required: the root's subgraph.yaml's network must be "mainnet" for foundry
2222
sed -i '' -e 's/network\: foundry/network\: mainnet/g' build/subgraph.yaml
2323
sed -i '' -e 's/network\: foundry/network\: mainnet/g' subgraph.yaml
24-
pnpm deploy:local -l v0.0.1
24+
yarn deploy:local -l v0.0.1
2525
sed -i '' -e 's/network\: mainnet/network\: foundry/g' subgraph.yaml
2626
cd ..
2727

subgraph/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ node_modules
22

33
build/
44
generated
5+
6+
tests/.bin
7+
.latest.json

subgraph/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"build:sepolia": "graph codegen && graph build --network sepolia",
99
"build:mainnet": "graph codegen && graph build --network mainnet",
1010
"deploy:local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 moleculeprotocol/ipnft-subgraph",
11-
"deploy:sepolia": "env-cmd -x -f ../.env graph deploy ip-nft-sepolia --version-label 1.3.1-dev.8 --node https://subgraphs.alchemy.com/api/subgraphs/deploy --ipfs https://ipfs.satsuma.xyz --deploy-key \\$SATSUMA_DEPLOY_KEY",
12-
"deploy:mainnet": "env-cmd -x -f ../.env graph deploy ip-nft-mainnet --version-label 1.3.0 --node https://subgraphs.alchemy.com/api/subgraphs/deploy --ipfs https://ipfs.satsuma.xyz --deploy-key \\$SATSUMA_DEPLOY_KEY",
11+
"deploy:sepolia": "env-cmd -x -f ../.env graph deploy ip-nft-sepolia --version-label 1.3.1 --node https://subgraphs.alchemy.com/api/subgraphs/deploy --ipfs https://ipfs.satsuma.xyz --deploy-key \\$SATSUMA_DEPLOY_KEY",
12+
"deploy:mainnet": "env-cmd -x -f ../.env graph deploy ip-nft-mainnet --version-label 1.3.1 --node https://subgraphs.alchemy.com/api/subgraphs/deploy --ipfs https://ipfs.satsuma.xyz --deploy-key \\$SATSUMA_DEPLOY_KEY",
1313
"create:local": "graph create --node http://localhost:8020/ moleculeprotocol/ipnft-subgraph",
1414
"remove:local": "graph remove --node http://localhost:8020/ moleculeprotocol/ipnft-subgraph",
1515
"test": "graph test"

subgraph/src/metadataMapping.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ export function handleMetadata(content: Bytes): void {
1616
ipnftMetadata.image = image.toString()
1717
ipnftMetadata.externalURL = externalURL.toString()
1818
ipnftMetadata.description = description.toString()
19-
19+
2020
ipnftMetadata.save()
2121
} else {
2222
log.info("[handlemetadata] name, image, description, external_url not found", [])
2323
}
24-
24+
2525
let _properties = value.get('properties')
2626
if (_properties) {
2727
let properties = _properties.toObject()
@@ -61,14 +61,15 @@ export function handleMetadata(content: Bytes): void {
6161
}
6262
}
6363

64-
let _funding_amount = properties.get('funding_amount')
64+
let _funding_amount = projectDetails.get('funding_amount')
65+
6566
if (_funding_amount) {
6667
let funding_amount = _funding_amount.toObject()
6768
let _fundingAmount_value = funding_amount.get('value')
6869
let _fundingAmount_decimals = funding_amount.get('decimals')
6970
let _fundingAmount_currency = funding_amount.get('currency')
7071
let _fundingAmount_currencyType = funding_amount.get('currency_type')
71-
72+
7273
if (_fundingAmount_value && _fundingAmount_decimals && _fundingAmount_currency && _fundingAmount_currencyType) {
7374
// on json metadata this can be a decimal value. I'm using a string to store as there's imo no f64 compatible decimal type on the schema scalar types
7475
// https://thegraph.com/docs/en/subgraphs/developing/creating/ql-schema/#built-in-scalar-types
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"schema_version": "0.0.1",
3+
"name": "Our awesome test IP-NFT",
4+
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua...",
5+
"image": "ipfs://bafkreih5d2453qzkprn35zm4gj5ff6ezroevnaaygxqlwcbqq2tg7ebbe4",
6+
"external_url": "https://testnet.mint.molecule.to/ipnft/76",
7+
"terms_signature": "0x1f030b9f1a91d74610cb296aa87f12b2207d2b336766fffad8c53b825f1bee7d30f3665076102fe635dd3664d564ae1e5e746794b58e8861feafacfa6767ea491b",
8+
"properties": {
9+
"type": "IP-NFT",
10+
"initial_symbol": "AWSOME",
11+
"agreements": [
12+
{
13+
"type": "Research Agreement",
14+
"url": "ipfs://bafkreigqttkfe2vsgddhy4ohf3qs3eyacdz2vwindo33y7jefox3377yqq",
15+
"mime_type": "application/pdf",
16+
"content_hash": "bagaaiera7ftqs3jmnoph3zgq67bgjrszlqtxkk5ygadgjvnihukrqioipndq",
17+
"encryption": {
18+
"protocol": "lit",
19+
"encrypted_sym_key": "abcdefedcba0123443210",
20+
"access_control_conditions": [
21+
{
22+
"conditionType": "evmContract",
23+
"contractAddress": "0x152B444e60C526fe4434C721561a077269FcF61a",
24+
"chain": "sepolia",
25+
"functionName": "canRead",
26+
"functionParams": [":userAddress", "76"],
27+
"functionAbi": {
28+
"inputs": [
29+
{
30+
"internalType": "address",
31+
"name": "reader",
32+
"type": "address"
33+
},
34+
{
35+
"internalType": "uint256",
36+
"name": "tokenId",
37+
"type": "uint256"
38+
}
39+
],
40+
"name": "canRead",
41+
"outputs": [
42+
{
43+
"internalType": "bool",
44+
"name": "",
45+
"type": "bool"
46+
}
47+
],
48+
"stateMutability": "view",
49+
"type": "function"
50+
},
51+
"returnValueTest": {
52+
"key": "",
53+
"comparator": "=",
54+
"value": "true"
55+
}
56+
}
57+
]
58+
}
59+
},
60+
{
61+
"type": "Assignment Agreement",
62+
"url": "ipfs://bafkreihzm4ew2ldltz66juhxyjsmmwk4e52sxobqazsnlkb5cumcdsd3i4",
63+
"mime_type": "application/pdf",
64+
"content_hash": "bagaaiera7ftqs3jmnoph3zgq67bgjrszlqtxkk5ygadgjvnihukrqioipndq"
65+
}
66+
],
67+
"project_details": {
68+
"industry": "Space Exploration",
69+
"organization": "NASA",
70+
"topic": "Wormholes",
71+
"funding_amount": {
72+
"value": 1234.5678,
73+
"decimals": 2,
74+
"currency": "USD",
75+
"currency_type": "ISO4217"
76+
},
77+
"research_lead": {
78+
"name": "Carl Sagan",
79+
"email": "[email protected]"
80+
}
81+
}
82+
}
83+
}

subgraph/tests/metadata.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { ipfs } from "@graphprotocol/graph-ts"
2+
import { assert, describe, mockIpfsFile, test } from 'matchstick-as/assembly/index'
3+
import { handleMetadata } from '../src/metadataMapping'
4+
5+
const IPNFT_METADATA = "IpnftMetadata"
6+
7+
describe('Metadata', () => {
8+
//https://thegraph.com/docs/en/subgraphs/developing/creating/unit-testing-framework/#mocking-ipfs-files-from-matchstick-041
9+
10+
test('reads ipnft metadata', () => {
11+
12+
mockIpfsFile('ipfsCatBaseIpnft', 'tests/fixtures/ipnft_1.json')
13+
14+
let rawData = ipfs.cat("ipfsCatBaseIpnft")
15+
if (!rawData) {
16+
throw new Error("Failed to fetch ipfs data")
17+
}
18+
19+
handleMetadata(rawData)
20+
assert.entityCount(IPNFT_METADATA, 1)
21+
assert.fieldEquals(IPNFT_METADATA, '', 'topic', 'Wormholes')
22+
assert.fieldEquals(IPNFT_METADATA, '', 'fundingAmount_value', '1234.5678')
23+
assert.fieldEquals(IPNFT_METADATA, '', 'fundingAmount_currency', 'USD')
24+
25+
//logStore()
26+
})
27+
})
28+

0 commit comments

Comments
 (0)