|
1 | 1 | use std::collections::HashMap;
|
2 | 2 | use std::num::NonZeroU32;
|
| 3 | +use std::str::FromStr; |
3 | 4 | use std::sync::Arc;
|
4 | 5 | use std::time::Duration;
|
5 | 6 |
|
6 | 7 | use graph::blockchain::DataSource;
|
| 8 | +use graph::data::store::scalar::Bytes; |
7 | 9 | use graph::data::store::Value;
|
8 | 10 | use graph::data::subgraph::schema::SubgraphError;
|
9 | 11 | use graph::data::subgraph::{SPEC_VERSION_0_0_4, SPEC_VERSION_0_0_7, SPEC_VERSION_0_0_8};
|
10 | 12 | use graph::data_source::offchain::OffchainDataSourceKind;
|
11 | 13 | use graph::data_source::DataSourceTemplate;
|
12 | 14 | use graph::entity;
|
13 | 15 | use graph::prelude::{
|
14 |
| - anyhow, async_trait, serde_yaml, tokio, DeploymentHash, Link, Logger, SubgraphManifest, |
15 |
| - SubgraphManifestValidationError, SubgraphStore, UnvalidatedSubgraphManifest, |
| 16 | + anyhow, async_trait, serde_yaml, tokio, BigDecimal, BigInt, DeploymentHash, Link, Logger, |
| 17 | + SubgraphManifest, SubgraphManifestValidationError, SubgraphStore, UnvalidatedSubgraphManifest, |
16 | 18 | };
|
17 | 19 | use graph::{
|
18 | 20 | blockchain::NodeCapabilities as _,
|
@@ -387,10 +389,34 @@ dataSources:
|
387 | 389 | name: Factory
|
388 | 390 | network: mainnet
|
389 | 391 | context:
|
390 |
| - foo: |
| 392 | + bool_example: |
| 393 | + type: Bool |
| 394 | + data: true |
| 395 | + int8_example: |
| 396 | + type: Int8 |
| 397 | + data: 64 |
| 398 | + big_decimal_example: |
| 399 | + type: BigDecimal |
| 400 | + data: 10.99 |
| 401 | + bytes_example: |
| 402 | + type: Bytes |
| 403 | + data: \"0x68656c6c6f\" |
| 404 | + list_example: |
| 405 | + type: List |
| 406 | + data: |
| 407 | + - type: Int |
| 408 | + data: 1 |
| 409 | + - type: Int |
| 410 | + data: 2 |
| 411 | + - type: Int |
| 412 | + data: 3 |
| 413 | + big_int_example: |
| 414 | + type: BigInt |
| 415 | + data: \"1000000000000000000000000\" |
| 416 | + string_example: |
391 | 417 | type: String
|
392 |
| - data: bar |
393 |
| - qux: |
| 418 | + data: \"bar\" |
| 419 | + int_example: |
394 | 420 | type: Int
|
395 | 421 | data: 42
|
396 | 422 | source:
|
@@ -427,9 +453,42 @@ specVersion: 0.0.8
|
427 | 453 | let context = data_source.context.as_ref().clone().unwrap();
|
428 | 454 | let sorted = context.sorted();
|
429 | 455 |
|
430 |
| - assert_eq!(sorted.len(), 2); |
431 |
| - assert_eq!(sorted[0], ("foo".into(), Value::String("bar".into()))); |
432 |
| - assert_eq!(sorted[1], ("qux".into(), Value::Int(42))); |
| 456 | + assert_eq!(sorted.len(), 8); |
| 457 | + assert_eq!( |
| 458 | + sorted[0], |
| 459 | + ( |
| 460 | + "big_decimal_example".into(), |
| 461 | + Value::BigDecimal(BigDecimal::from(10.99)) |
| 462 | + ) |
| 463 | + ); |
| 464 | + assert_eq!( |
| 465 | + sorted[1], |
| 466 | + ( |
| 467 | + "big_int_example".into(), |
| 468 | + Value::BigInt(BigInt::from_str("1000000000000000000000000").unwrap()) |
| 469 | + ) |
| 470 | + ); |
| 471 | + assert_eq!(sorted[2], ("bool_example".into(), Value::Bool(true))); |
| 472 | + assert_eq!( |
| 473 | + sorted[3], |
| 474 | + ( |
| 475 | + "bytes_example".into(), |
| 476 | + Value::Bytes(Bytes::from_str("0x68656c6c6f").unwrap()) |
| 477 | + ) |
| 478 | + ); |
| 479 | + assert_eq!(sorted[4], ("int8_example".into(), Value::Int8(64))); |
| 480 | + assert_eq!(sorted[5], ("int_example".into(), Value::Int(42))); |
| 481 | + assert_eq!( |
| 482 | + sorted[6], |
| 483 | + ( |
| 484 | + "list_example".into(), |
| 485 | + Value::List(vec![Value::Int(1), Value::Int(2), Value::Int(3)]) |
| 486 | + ) |
| 487 | + ); |
| 488 | + assert_eq!( |
| 489 | + sorted[7], |
| 490 | + ("string_example".into(), Value::String("bar".into())) |
| 491 | + ); |
433 | 492 | }
|
434 | 493 |
|
435 | 494 | #[tokio::test]
|
|
0 commit comments