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 issues in runner tests #4962

Merged
merged 4 commits into from
Nov 1, 2023
Merged
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 tests/runner-tests/api-version/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dataSources:
abi: Contract
mapping:
kind: ethereum/events
apiVersion: 0.0.8
apiVersion: 0.0.7
language: wasm/assemblyscript
abis:
- name: Contract
Expand Down
5 changes: 3 additions & 2 deletions tests/runner-tests/data-source-revert/grafted.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ features:
schema:
file: ./schema.graphql
graft:
# Must match the id from building `subgraph.yaml`
base: QmR3TAJuimii5huAswW7uqSzJfsR4GmAxwfawK2DwF3YFh
# This can be overwritten by `updateAndDeploy.js`.
# Please commit this file when this happens.
base: QmcAL39QSKZvRssr2ToCJrav7XK9ggajxvBR7M1NNUCqdh
block: 3
dataSources:
- kind: ethereum/contract
Expand Down
2 changes: 1 addition & 1 deletion tests/runner-tests/data-source-revert/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"scripts": {
"codegen": "graph codegen --skip-migrations",
"deploy:test": "graph deploy test/data-source-revert --version-label v0.0.1 --ipfs $IPFS_URI --node $GRAPH_NODE_ADMIN_URI",
"deploy:test-grafted": "graph deploy test/data-source-revert-grafted grafted.yaml --version-label v0.0.1 --ipfs $IPFS_URI --node $GRAPH_NODE_ADMIN_URI"
"deploy:test-grafted": "node updateAndDeploy.js"
},
"devDependencies": {
"@graphprotocol/graph-cli": "0.60.0",
Expand Down
17 changes: 17 additions & 0 deletions tests/runner-tests/data-source-revert/updateAndDeploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// This takes a Qm.. hash as a CLI input, which is the graft base.

const fs = require('fs');
const { execSync } = require('child_process');

const graftBase = process.argv[2];

const yamlPath = './grafted.yaml';
let yamlContent = fs.readFileSync(yamlPath, 'utf-8');
yamlContent = yamlContent.replace(/base: .+/, `base: ${graftBase}`);
fs.writeFileSync(yamlPath, yamlContent);
console.log("bafuzz")

// Assuming you have your IPFS_URI and GRAPH_NODE_ADMIN_URI exported as environment variables.
execSync('graph deploy test/data-source-revert-grafted grafted.yaml --version-label v0.0.1 --ipfs $IPFS_URI --node $GRAPH_NODE_ADMIN_URI', {
stdio: 'inherit'
});
72 changes: 54 additions & 18 deletions tests/tests/runner_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use graph::ipfs_client::IpfsClient;
use graph::object;
use graph::prelude::ethabi::ethereum_types::H256;
use graph::prelude::{
CheapClone, DeploymentHash, SubgraphAssignmentProvider, SubgraphName, SubgraphStore,
hex, CheapClone, DeploymentHash, SubgraphAssignmentProvider, SubgraphName, SubgraphStore,
};
use graph_tests::fixture::ethereum::{
chain, empty_block, generate_empty_blocks_for_range, genesis, push_test_log,
Expand Down Expand Up @@ -69,6 +69,31 @@ impl RunnerTestRecipe {
}
}

fn assert_eq_ignore_backtrace(err: &SubgraphError, expected: &SubgraphError) {
let equal = {
if err.subgraph_id != expected.subgraph_id
|| err.block_ptr != expected.block_ptr
|| err.handler != expected.handler
|| err.deterministic != expected.deterministic
{
false;
}

// Ignore any WASM backtrace in the error message
let split_err: Vec<&str> = err.message.split("\\twasm backtrace:").collect();
let split_expected: Vec<&str> = expected.message.split("\\twasm backtrace:").collect();

split_err.get(0) == split_expected.get(0)
};

if !equal {
// Will fail
let mut err_no_trace = err.clone();
err_no_trace.message = expected.message.split("\\twasm backtrace:").collect();
assert_eq!(&err_no_trace, expected);
}
}

#[tokio::test]
async fn data_source_revert() -> anyhow::Result<()> {
let RunnerTestRecipe {
Expand Down Expand Up @@ -104,9 +129,12 @@ async fn data_source_revert() -> anyhow::Result<()> {

// Test grafted version
let subgraph_name = SubgraphName::new("data-source-revert-grafted").unwrap();
let hash =
build_subgraph_with_yarn_cmd("./runner-tests/data-source-revert", "deploy:test-grafted")
.await;
let hash = build_subgraph_with_yarn_cmd_and_arg(
"./runner-tests/data-source-revert",
"deploy:test-grafted",
Some(&hash),
)
.await;
let graft_block = Some(test_ptr(3));
let ctx = fixture::setup(
subgraph_name.clone(),
Expand Down Expand Up @@ -230,15 +258,15 @@ async fn api_version_0_0_8() {
let ctx = fixture::setup(subgraph_name.clone(), &hash, &stores, &chain, None, None).await;
let stop_block = blocks.last().unwrap().block.ptr();
let err = ctx.start_and_sync_to_error(stop_block.clone()).await;
let message = "transaction 0000000000000000000000000000000000000000000000000000000000000000: Attempted to set undefined fields [invalid_field] for the entity type `TestResult`. Make sure those fields are defined in the schema.\twasm backtrace:\t 0: 0x2ebc - <unknown>!src/mapping/handleTestEvent\t in handler `handleTestEvent` at block #1 (0000000000000000000000000000000000000000000000000000000000000001)".to_string();
let message = "transaction 0000000000000000000000000000000000000000000000000000000000000000: Attempted to set undefined fields [invalid_field] for the entity type `TestResult`. Make sure those fields are defined in the schema.".to_string();
let expected_err = SubgraphError {
subgraph_id: ctx.deployment.hash.clone(),
message,
block_ptr: Some(stop_block),
handler: None,
deterministic: true,
};
assert_eq!(err, expected_err);
assert_eq_ignore_backtrace(&err, &expected_err);
}

#[tokio::test]
Expand Down Expand Up @@ -519,15 +547,16 @@ async fn file_data_sources() {
let stop_block = test_ptr(7);
let err = ctx.start_and_sync_to_error(stop_block.clone()).await;
let message = "entity type `IpfsFile1` is not on the 'entities' list for data source `File2`. \
Hint: Add `IpfsFile1` to the 'entities' list, which currently is: `IpfsFile`.\twasm backtrace:\t 0: 0x3737 - <unknown>!src/mapping/handleFile1\t in handler `handleFile1` at block #7 ()".to_string();
Hint: Add `IpfsFile1` to the 'entities' list, which currently is: `IpfsFile`."
.to_string();
let expected_err = SubgraphError {
subgraph_id: ctx.deployment.hash.clone(),
message,
block_ptr: Some(stop_block),
handler: None,
deterministic: false,
};
assert_eq!(err, expected_err);
assert_eq_ignore_backtrace(&err, &expected_err);

// Unfail the subgraph to test a conflict between an onchain and offchain entity
{
Expand Down Expand Up @@ -783,11 +812,8 @@ async fn template_static_filters_false_positives() {
// POI table. If this fails it's likely that either the bug was re-introduced or there is
// a change in the POI infrastructure. Or the subgraph id changed.
assert_eq!(
poi.unwrap(),
[
253, 249, 50, 171, 127, 117, 77, 13, 79, 132, 88, 246, 223, 214, 225, 39, 112, 19, 73,
97, 193, 132, 103, 19, 191, 5, 28, 14, 232, 137, 76, 9
],
hex::encode(poi.unwrap()),
"c72af01a19a4e35a35778821a354b7a781062a9320ac8796ea65b115cb9844bf"
);
}

Expand Down Expand Up @@ -1053,6 +1079,14 @@ async fn build_subgraph(dir: &str, deploy_cmd: Option<&str>) -> DeploymentHash {
}

async fn build_subgraph_with_yarn_cmd(dir: &str, yarn_cmd: &str) -> DeploymentHash {
build_subgraph_with_yarn_cmd_and_arg(dir, yarn_cmd, None).await
}

async fn build_subgraph_with_yarn_cmd_and_arg(
dir: &str,
yarn_cmd: &str,
arg: Option<&str>,
) -> DeploymentHash {
// Test that IPFS is up.
IpfsClient::localhost()
.test()
Expand All @@ -1072,22 +1106,24 @@ async fn build_subgraph_with_yarn_cmd(dir: &str, yarn_cmd: &str) -> DeploymentHa
// Run codegen.
run_cmd(Command::new("yarn").arg("codegen").current_dir(dir));

let mut args = vec![yarn_cmd];
args.extend(arg);

// Run `deploy` for the side effect of uploading to IPFS, the graph node url
// is fake and the actual deploy call is meant to fail.
let deploy_output = run_cmd(
Command::new("yarn")
.arg(yarn_cmd)
.args(&args)
.env("IPFS_URI", "http://127.0.0.1:5001")
.env("GRAPH_NODE_ADMIN_URI", "http://localhost:0")
.current_dir(dir),
);

// Hack to extract deployment id from `graph deploy` output.
const ID_PREFIX: &str = "Build completed: ";
let mut line = deploy_output
.lines()
.find(|line| line.contains(ID_PREFIX))
.expect("found no matching line");
let Some(mut line) = deploy_output.lines().find(|line| line.contains(ID_PREFIX)) else {
panic!("No deployment id found, graph deploy probably had an error")
};
if !line.starts_with(ID_PREFIX) {
line = &line[5..line.len() - 5]; // workaround for colored output
}
Expand Down
Loading