Skip to content

Commit 0b1623a

Browse files
committed
test: try to reproduce addresse string corruption
1 parent d0ae5cb commit 0b1623a

File tree

6 files changed

+122
-0
lines changed

6 files changed

+122
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[
2+
{
3+
"inputs": [],
4+
"stateMutability": "nonpayable",
5+
"type": "constructor"
6+
},
7+
{
8+
"anonymous": false,
9+
"inputs": [
10+
{
11+
"indexed": false,
12+
"internalType": "uint16",
13+
"name": "x",
14+
"type": "uint16"
15+
}
16+
],
17+
"name": "Trigger",
18+
"type": "event"
19+
},
20+
{
21+
"inputs": [
22+
{
23+
"internalType": "uint16",
24+
"name": "x",
25+
"type": "uint16"
26+
}
27+
],
28+
"name": "emitTrigger",
29+
"outputs": [],
30+
"stateMutability": "nonpayable",
31+
"type": "function"
32+
}
33+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "address-corruption",
3+
"version": "0.0.0",
4+
"private": true,
5+
"scripts": {
6+
"codegen": "graph codegen --skip-migrations",
7+
"deploy:test": "graph deploy test/address-corruption --version-label v0.0.1 --ipfs $IPFS_URI --node $GRAPH_NODE_ADMIN_URI"
8+
},
9+
"devDependencies": {
10+
"@graphprotocol/graph-cli": "0.69.0",
11+
"@graphprotocol/graph-ts": "0.34.0"
12+
}
13+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type AddressTest @entity {
2+
id: ID!
3+
originalString: String!
4+
parsedAddress: Bytes
5+
testType: String!
6+
errorMessage: String
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Address, log } from '@graphprotocol/graph-ts'
2+
import { Trigger } from "../generated/Contract/Contract"
3+
4+
export function handleTrigger(_: Trigger): void {
5+
log.info("ADDRESS CORRUPTION TEST - ADDRESS: {}", ["0x3b44b2a187a7b3824131f8db5a74194d0a42fc15"])
6+
log.info("ADDRESS CORRUPTION TEST - LENGTH: {}", ["0x3b44b2a187a7b3824131f8db5a74194d0a42fc15".length.toString()])
7+
8+
// This call should fail with: "Failed to convert string to Address/H160: '': Invalid input length"
9+
let address = Address.fromString("0x3b44b2a187a7b3824131f8db5a74194d0a42fc15")
10+
11+
// If we reach here, the bug is not reproduced
12+
log.info("ADDRESS CORRUPTION TEST - ALL GOOD: {}", [address.toHexString()])
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
specVersion: 0.0.4
2+
schema:
3+
file: ./schema.graphql
4+
dataSources:
5+
- kind: ethereum/contract
6+
name: Contract
7+
network: test
8+
source:
9+
address: "@SimpleContract@"
10+
abi: Contract
11+
mapping:
12+
kind: ethereum/events
13+
apiVersion: 0.0.6
14+
language: wasm/assemblyscript
15+
abis:
16+
- name: Contract
17+
file: ./abis/Contract.abi
18+
entities:
19+
- AddressTest
20+
eventHandlers:
21+
- event: Trigger(uint16)
22+
handler: handleTrigger
23+
file: ./src/mapping.ts

tests/tests/integration_tests.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,38 @@ async fn wait_for_blockchain_block(block_number: i32) -> bool {
10861086
false
10871087
}
10881088

1089+
async fn test_address_corruption(ctx: TestContext) -> anyhow::Result<()> {
1090+
let subgraph = ctx.subgraph;
1091+
assert!(subgraph.healthy);
1092+
1093+
// Read the graph-node.log file to analyze the actual log output
1094+
let log_path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
1095+
.join("integration-tests")
1096+
.join("graph-node.log");
1097+
let log_content = std::fs::read_to_string(&log_path)
1098+
.with_context(|| format!("Failed to read log file: {}", log_path.display()))?;
1099+
1100+
// Ensure our test actually ran with the specific problematic address
1101+
assert!(
1102+
log_content.contains("ADDRESS CORRUPTION TEST - ADDRESS: 0x3b44b2a187a7b3824131f8db5a74194d0a42fc15"),
1103+
"Address corruption test mapping did not execute - no test logs found for the problematic address"
1104+
);
1105+
1106+
// Assert that the test completed successfully with the parsed address (bug is not reproduced)
1107+
assert!(
1108+
log_content.contains("ADDRESS CORRUPTION TEST - ALL GOOD: 0x3b44b2a187a7b3824131f8db5a74194d0a42fc15"),
1109+
"Address corruption test should complete successfully with parsed address - bug should not be reproduced in current codebase"
1110+
);
1111+
1112+
// Assert that the bug error is not present
1113+
assert!(
1114+
!log_content.contains("Failed to convert string to Address/H160: ''"),
1115+
"String corruption bug should not be present - Address.fromString() should work correctly"
1116+
);
1117+
1118+
Ok(())
1119+
}
1120+
10891121
/// The main test entrypoint.
10901122
#[tokio::test]
10911123
async fn integration_tests() -> anyhow::Result<()> {
@@ -1094,6 +1126,7 @@ async fn integration_tests() -> anyhow::Result<()> {
10941126
let cases = vec![
10951127
TestCase::new("reverted-calls", test_reverted_calls_are_indexed),
10961128
TestCase::new("host-exports", test_host_exports),
1129+
TestCase::new("address-corruption", test_address_corruption),
10971130
TestCase::new("non-fatal-errors", test_non_fatal_errors),
10981131
TestCase::new("overloaded-functions", test_overloaded_functions),
10991132
TestCase::new("poi-for-failed-subgraph", test_poi_for_failed_subgraph),

0 commit comments

Comments
 (0)