Skip to content

Commit 169ed5b

Browse files
committed
update multiple subgraph datasources integration test
1 parent c81369a commit 169ed5b

File tree

7 files changed

+27
-48
lines changed

7 files changed

+27
-48
lines changed

tests/integration-tests/multiple-subgraph-datasources/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ type AggregatedData @entity {
22
id: ID!
33
sourceA: String
44
sourceB: String
5+
first: String!
56
}

tests/integration-tests/multiple-subgraph-datasources/src/mapping.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
import { dataSource, EntityTrigger } from '@graphprotocol/graph-ts'
1+
import { dataSource, EntityTrigger, log } from '@graphprotocol/graph-ts'
22
import { AggregatedData } from '../generated/schema'
3-
import { SourceAData } from '../generated/subgraph-QmU35YwAsv59gJxhejp3qqUrSFMaoBXuskNLX7wJHNUzyA'
4-
import { SourceBData } from '../generated/subgraph-QmXjHeC7j5iWF49oEngV3tqFrHvb4NhkFpAdJYVJ1SFPNk'
3+
import { SourceAData } from '../generated/subgraph-QmcYeEnoRzLgrwwW1StY7wTAGSS8Qt5G78RYAHHyLJWYBy'
4+
import { SourceBData } from '../generated/subgraph-QmetPUZD9SNGjdpkgefBGe8uWEcLYxggVaixkYKd22AKr6'
55

66
export function handleSourceAData(data: EntityTrigger<SourceAData>): void {
7-
let aggregated = AggregatedData.load('1')
7+
let aggregated = AggregatedData.load(data.data.id)
88
if (!aggregated) {
9-
aggregated = new AggregatedData('1')
9+
aggregated = new AggregatedData(data.data.id)
1010
aggregated.sourceA = data.data.data
11+
aggregated.first = 'sourceA'
1112
} else {
1213
aggregated.sourceA = data.data.data
1314
}
1415
aggregated.save()
1516
}
1617

1718
export function handleSourceBData(data: EntityTrigger<SourceBData>): void {
18-
let aggregated = AggregatedData.load('1')
19+
let aggregated = AggregatedData.load(data.data.id)
1920
if (!aggregated) {
20-
aggregated = new AggregatedData('1')
21+
aggregated = new AggregatedData(data.data.id)
2122
aggregated.sourceB = data.data.data
23+
aggregated.first = 'sourceB'
2224
} else {
2325
aggregated.sourceB = data.data.data
2426
}

tests/integration-tests/multiple-subgraph-datasources/subgraph.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dataSources:
66
name: SourceA
77
network: test
88
source:
9-
address: 'QmU35YwAsv59gJxhejp3qqUrSFMaoBXuskNLX7wJHNUzyA'
9+
address: 'QmcYeEnoRzLgrwwW1StY7wTAGSS8Qt5G78RYAHHyLJWYBy'
1010
startBlock: 0
1111
mapping:
1212
apiVersion: 0.0.7
@@ -22,7 +22,7 @@ dataSources:
2222
name: SourceB
2323
network: test
2424
source:
25-
address: 'QmXjHeC7j5iWF49oEngV3tqFrHvb4NhkFpAdJYVJ1SFPNk'
25+
address: 'QmetPUZD9SNGjdpkgefBGe8uWEcLYxggVaixkYKd22AKr6'
2626
startBlock: 0
2727
mapping:
2828
apiVersion: 0.0.7
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
type SourceAData @entity {
22
id: ID!
33
data: String!
4-
timestamp: BigInt!
4+
blockNumber: BigInt!
55
}

tests/integration-tests/source-subgraph-a/src/mapping.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { ethereum } from '@graphprotocol/graph-ts'
22
import { SourceAData } from '../generated/schema'
33

44
export function handleBlock(block: ethereum.Block): void {
5-
let entity = new SourceAData('1')
5+
let entity = new SourceAData(block.number.toString())
66
entity.data = 'from source A'
7-
entity.timestamp = block.timestamp
7+
entity.blockNumber = block.number
88
entity.save()
99
}

tests/integration-tests/source-subgraph-b/src/mapping.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ethereum } from '@graphprotocol/graph-ts'
22
import { SourceBData } from '../generated/schema'
33

44
export function handleBlock(block: ethereum.Block): void {
5-
let entity = new SourceBData('1')
5+
let entity = new SourceBData(block.number.toString())
66
entity.data = 'from source B'
77
entity.blockNumber = block.number
88
entity.save()

tests/tests/integration_tests.rs

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,9 @@ impl TestCase {
103103
where
104104
T: Future<Output = Result<(), anyhow::Error>> + Send + 'static,
105105
{
106-
fn force_boxed<T>(f: fn(TestContext) -> T) -> TestFn
107-
where
108-
T: Future<Output = Result<(), anyhow::Error>> + Send + 'static,
109-
{
110-
Box::new(move |ctx| Box::pin(f(ctx)))
111-
}
112-
113106
Self {
114107
name: name.to_string(),
115-
test: force_boxed(test),
108+
test: Box::new(move |ctx| Box::pin(test(ctx))),
116109
source_subgraph: None,
117110
}
118111
}
@@ -125,18 +118,9 @@ impl TestCase {
125118
where
126119
T: Future<Output = Result<(), anyhow::Error>> + Send + 'static,
127120
{
128-
fn force_boxed<T>(f: fn(TestContext) -> T) -> TestFn
129-
where
130-
T: Future<Output = Result<(), anyhow::Error>> + Send + 'static,
131-
{
132-
Box::new(move |ctx| Box::pin(f(ctx)))
133-
}
134-
135-
Self {
136-
name: name.to_string(),
137-
test: force_boxed(test),
138-
source_subgraph: Some(source_subgraph.to_string()),
139-
}
121+
let mut test_case = Self::new(name, test);
122+
test_case.source_subgraph = Some(source_subgraph.to_string());
123+
test_case
140124
}
141125

142126
fn new_with_multiple_source_subgraphs<T>(
@@ -147,18 +131,9 @@ impl TestCase {
147131
where
148132
T: Future<Output = Result<(), anyhow::Error>> + Send + 'static,
149133
{
150-
fn force_boxed<T>(f: fn(TestContext) -> T) -> TestFn
151-
where
152-
T: Future<Output = Result<(), anyhow::Error>> + Send + 'static,
153-
{
154-
Box::new(move |ctx| Box::pin(f(ctx)))
155-
}
156-
157-
Self {
158-
name: name.to_string(),
159-
test: force_boxed(test),
160-
source_subgraph: Some(source_subgraphs.join(",")),
161-
}
134+
let mut test_case = Self::new(name, test);
135+
test_case.source_subgraph = Some(source_subgraphs.join(","));
136+
test_case
162137
}
163138

164139
async fn deploy_and_wait(
@@ -966,17 +941,18 @@ async fn test_multiple_subgraph_datasources(ctx: TestContext) -> anyhow::Result<
966941
let exp = json!({
967942
"aggregatedDatas": [
968943
{
969-
"id": "1",
944+
"id": "0",
970945
"sourceA": "from source A",
971946
"sourceB": "from source B",
972-
}
947+
"first": "sourceA"
948+
},
973949
]
974950
});
975951

976952
query_succeeds(
977953
"should aggregate data from multiple sources",
978954
&subgraph,
979-
"{ aggregatedDatas(first: 1) { id sourceA sourceB } }",
955+
"{ aggregatedDatas(first: 1) { id sourceA sourceB first } }",
980956
exp,
981957
)
982958
.await?;

0 commit comments

Comments
 (0)