Skip to content

Commit

Permalink
Merge pull request #9 from HerodotusDev/better-test
Browse files Browse the repository at this point in the history
Better test
  • Loading branch information
rkdud007 authored May 9, 2024
2 parents 25840ca + ff89996 commit c14877b
Show file tree
Hide file tree
Showing 103 changed files with 444 additions and 107 deletions.
8 changes: 3 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ workspace = false
description = "Reset all setup and compiled files to their initial state."
script = '''
echo "Removing the setup and compiled files..."
rm -rf ./compiled_cairo/hdp.json
rm -rf ./hdp-cairo
rm -rf venv
rm -rf tools
'''
Expand Down
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# HDP Test

This repository contains all the fixture support from HDP.

- Input Generation : [HDP](https://github.com/HerodotusDev/hdp)
- Cairo Program : [HDP-Cairo](https://github.com/HerodotusDev/hdp-cairo)

# Fixtures

This guide provides detailed instructions for running integration tests using the Makefile in the HDP project. These examples demonstrate how to process requests and integrate them with the Cairo Program. Before starting, ensure you have the `RPC_URL` and `CHAIN_ID` set in your `.env` file, as the scripts utilize configuration from environment variables.

## Setup and Test Execution

Follow these steps to set up and run integration tests:

1. **Setup Cairo Environment:**
Sets up the virtual environment required for testing, including Cairo VM.

```bash
cargo make cairo-setup
```

2. **Run Integration Test**:
Verify that you are in the correct environment to run `cairo-run`. This step executes all provided [fixtures](./fixtures) input files against the compiled Cairo program.
```bash
cargo make integration-test
```

### Fast Setup and Test Execution

If want to run full flow in one command, try:

```bash
cargo make run-full-flow
```

And if want to reset all the setup and compiled files to back the initial state, try:

```bash
cargo make reset-setup
```

### Generate New Fixture

Simply run:
_wip: currently there are some issues for a supported query that match with randomized values, be might require comment out/in to handle the cases_

```
cargo run
```
76 changes: 76 additions & 0 deletions fixture_fail/0/error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Generating tx input file...
Computing avg of TX.CHAIN_ID from block 35 to block 76 with step 9, input file path: ./fixtures/transactions/chain_id/0/input.json, output file path: ./fixtures/transactions/chain_id/0/output.json
2024-05-09T06:54:52.157548Z INFO hdp_provider::evm: Successfully fetched MMR data from indexer
2024-05-09T06:54:52.157619Z INFO hdp_provider::evm: Time taken (fetch from Indexer): 5.911153542s
cairo pie file path: ./fixtures/transactions/chain_id/0/cairo.pie
/Users/piapark/Documents/GitHub/hdp-cairo/src/decoders/transaction_decoder.cairo:387:9: Error at pc=0:7729:
An ASSERT_EQ instruction failed: 0 != 1.
assert 1 = 0;
^****\*\*\*****^
Cairo traceback (most recent call last):
./src/hdp.cairo:51:5: (pc=0:10979)
./src/hdp.cairo:279:5: (pc=0:11178)
/Users/piapark/Documents/GitHub/hdp-cairo/src/tasks/computational.cairo:99:46: (pc=0:10251)
let (data_points, data_points_len) = Datalake.fetch_data_points(tasks[index]);
^******************\*\*******************^
/Users/piapark/Documents/GitHub/hdp-cairo/src/datalakes/datalake.cairo:83:34: (pc=0:8391)
let (res, res_len) = fetch_txs_in_block_data_points(tx_in_block_datalake);
^************************\*\*************************^
/Users/piapark/Documents/GitHub/hdp-cairo/src/datalakes/txs_in_block_datalake.cairo:89:31: (pc=0:8147)
let data_points_len = fetch_tx_data_points(
^********\*\*\*********^
/Users/piapark/Documents/GitHub/hdp-cairo/src/datalakes/txs_in_block_datalake.cairo:140:12: (pc=0:8272)
return fetch_tx_data_points(
^********\*\*\*********^
/Users/piapark/Documents/GitHub/hdp-cairo/src/datalakes/txs_in_block_datalake.cairo:140:12: (pc=0:8272)
return fetch_tx_data_points(
^********\*\*\*********^
/Users/piapark/Documents/GitHub/hdp-cairo/src/datalakes/txs_in_block_datalake.cairo:140:12: (pc=0:8272)
return fetch_tx_data_points(
^********\*\*\*********^
/Users/piapark/Documents/GitHub/hdp-cairo/src/datalakes/txs_in_block_datalake.cairo:140:12: (pc=0:8272)
return fetch_tx_data_points(
^********\*\*\*********^
/Users/piapark/Documents/GitHub/hdp-cairo/src/datalakes/txs_in_block_datalake.cairo:138:21: (pc=0:8242)
let datapoint = TransactionDecoder.get_field(tx, datalake.sampled_property);
^****************************\*****************************^
/Users/piapark/Documents/GitHub/hdp-cairo/src/decoders/transaction_decoder.cairo:72:21: (pc=0:7613)
let index = TxTypeFieldMap.get_field_index(tx.type, field);
^********************\*\*\*\*********************^
/Users/piapark/Documents/GitHub/hdp-cairo/src/decoders/transaction_decoder.cairo:328:20: (pc=0:7632)
return get_legacy_tx_field_index(field);
^**************\*\***************^
Cairo program ran successfully
Generating tx input file...
Computing count of TX.CHAIN_ID from block 3 to block 53 with step 9, input file path: ./fixtures/transactions/chain_id/1/input.json, output file path: ./fixtures/transactions/chain_id/1/output.json
2024-05-09T06:55:03.701330Z INFO hdp_provider::evm: Successfully fetched MMR data from indexer
2024-05-09T06:55:03.701434Z INFO hdp_provider::evm: Time taken (fetch from Indexer): 3.631315208s
cairo pie file path: ./fixtures/transactions/chain_id/1/cairo.pie
/Users/piapark/Documents/GitHub/hdp-cairo/src/decoders/transaction_decoder.cairo:387:9: Error at pc=0:7729:
An ASSERT_EQ instruction failed: 0 != 1.
assert 1 = 0;
^****\*\*\*****^
Cairo traceback (most recent call last):
./src/hdp.cairo:51:5: (pc=0:10979)
./src/hdp.cairo:279:5: (pc=0:11178)
/Users/piapark/Documents/GitHub/hdp-cairo/src/tasks/computational.cairo:99:46: (pc=0:10251)
let (data_points, data_points_len) = Datalake.fetch_data_points(tasks[index]);
^******************\*\*******************^
/Users/piapark/Documents/GitHub/hdp-cairo/src/datalakes/datalake.cairo:83:34: (pc=0:8391)
let (res, res_len) = fetch_txs_in_block_data_points(tx_in_block_datalake);
^************************\*\*************************^
/Users/piapark/Documents/GitHub/hdp-cairo/src/datalakes/txs_in_block_datalake.cairo:89:31: (pc=0:8147)
let data_points_len = fetch_tx_data_points(
^********\*\*\*********^
/Users/piapark/Documents/GitHub/hdp-cairo/src/datalakes/txs_in_block_datalake.cairo:140:12: (pc=0:8272)
return fetch_tx_data_points(
^********\*\*\*********^
/Users/piapark/Documents/GitHub/hdp-cairo/src/datalakes/txs_in_block_datalake.cairo:138:21: (pc=0:8242)
let datapoint = TransactionDecoder.get_field(tx, datalake.sampled_property);
^****************************\*****************************^
/Users/piapark/Documents/GitHub/hdp-cairo/src/decoders/transaction_decoder.cairo:72:21: (pc=0:7613)
let index = TxTypeFieldMap.get_field_index(tx.type, field);
^********************\*\*\*\*********************^
/Users/piapark/Documents/GitHub/hdp-cairo/src/decoders/transaction_decoder.cairo:328:20: (pc=0:7632)
return get_legacy_tx_field_index(field);
^**************\*\***************^
1 change: 1 addition & 0 deletions fixture_fail/0/input.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions fixture_fail/0/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Tasks [ComputationalTask { aggregate_fn_id: AVG, aggregate_fn_ctx: None }]
, Datalakes [Transactions(TransactionsInBlockDatalake { target_block: 5291354, start_index: 35, end_index: 76, increment: 9, included_types: IncludedTypes { inner: [1, 1, 1, 1] }, sampled_property: Transactions(ChainId) })]
59 changes: 59 additions & 0 deletions fixture_fail/1/error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
enerating tx input file...
Computing max of TX.R from block 27 to block 67 with step 3, input file path: ./fixtures/transactions/r/0/input.json, output file path: ./fixtures/transactions/r/0/output.json
2024-05-09T06:52:16.472435Z INFO hdp_provider::evm: Successfully fetched MMR data from indexer
2024-05-09T06:52:16.472504Z INFO hdp_provider::evm: Time taken (fetch from Indexer): 5.608959792s
cairo pie file path: ./fixtures/transactions/r/0/cairo.pie
Cairo program ran successfully
Generating tx input file...
Computing avg of TX.R from block 24 to block 40 with step 2, input file path: ./fixtures/transactions/r/1/input.json, output file path: ./fixtures/transactions/r/1/output.json
2024-05-09T06:52:30.705802Z INFO hdp_provider::evm: Successfully fetched MMR data from indexer
2024-05-09T06:52:30.705842Z INFO hdp_provider::evm: Time taken (fetch from Indexer): 3.848353042s
thread 'main' panicked at /Users/piapark/.cargo/git/checkouts/hdp-92c209099cc03759/8eeb5e0/crates/core/src/aggregate_fn/integer.rs:17:10:
called `Option::unwrap()` on a `None` value
stack backtrace:
0: rust_begin_unwind
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/panicking.rs:647:5
1: core::panicking::panic_fmt
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/panicking.rs:72:14
2: core::panicking::panic
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/panicking.rs:144:5
3: core::option::unwrap_failed
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/option.rs:1978:5
4: core::option::Option<T>::unwrap
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/option.rs:931:21
5: hdp_core::aggregate_fn::integer::average
at /Users/piapark/.cargo/git/checkouts/hdp-92c209099cc03759/8eeb5e0/crates/core/src/aggregate_fn/integer.rs:14:15
6: hdp_core::aggregate_fn::AggregationFunction::operation
at /Users/piapark/.cargo/git/checkouts/hdp-92c209099cc03759/8eeb5e0/crates/core/src/aggregate_fn/mod.rs:127:41
7: hdp_core::evaluator::evaluator::{{closure}}
at /Users/piapark/.cargo/git/checkouts/hdp-92c209099cc03759/8eeb5e0/crates/core/src/evaluator/mod.rs:265:22
8: generate::Generator::generate_tx_input_file::{{closure}}
at ./src/main.rs:302:22
9: generate::main::{{closure}}
at ./src/main.rs:84:14
10: tokio::runtime::park::CachedParkThread::block_on::{{closure}}
at /Users/piapark/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/park.rs:281:63
11: tokio::runtime::coop::with_budget
at /Users/piapark/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/coop.rs:107:5
12: tokio::runtime::coop::budget
at /Users/piapark/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/coop.rs:73:5
13: tokio::runtime::park::CachedParkThread::block_on
at /Users/piapark/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/park.rs:281:31
14: tokio::runtime::context::blocking::BlockingRegionGuard::block_on
at /Users/piapark/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/context/blocking.rs:66:9
15: tokio::runtime::scheduler::multi_thread::MultiThread::block_on::{{closure}}
at /Users/piapark/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/scheduler/multi_thread/mod.rs:87:13
16: tokio::runtime::context::runtime::enter_runtime
at /Users/piapark/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/context/runtime.rs:65:16
17: tokio::runtime::scheduler::multi_thread::MultiThread::block_on
at /Users/piapark/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/scheduler/multi_thread/mod.rs:86:9
18: tokio::runtime::runtime::Runtime::block_on
at /Users/piapark/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/runtime.rs:351:45
19: generate::main
at ./src/main.rs:62:5
20: core::ops::function::FnOnce::call_once
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

- The terminal process "cargo 'run', '--package', 'generate', '--bin', 'generate'" terminated with exit code: 101.
- Terminal will be reused by tasks, press any key to close it.
2 changes: 2 additions & 0 deletions fixture_fail/1/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Tasks [ComputationalTask { aggregate_fn_id: AVG, aggregate_fn_ctx: None }]
, Datalakes [Transactions(TransactionsInBlockDatalake { target_block: 5214489, start_index: 24, end_index: 40, increment: 2, included_types: IncludedTypes { inner: [1, 1, 1, 1] }, sampled_property: Transactions(R) })]
12 changes: 12 additions & 0 deletions fixture_fail/2/error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Generating tx input file...
Computing max of TX.CHAIN_ID from block 49 to block 79 with step 4, input file path: ./fixtures/transactions/chain_id/0/input.json, output file path: ./fixtures/transactions/chain_id/0/output.json
2024-05-09T06:56:07.451599Z INFO hdp_provider::evm: Successfully fetched MMR data from indexer
2024-05-09T06:56:07.451876Z INFO hdp_provider::evm: Time taken (fetch from Indexer): 4.851167958s
cairo pie file path: ./fixtures/transactions/chain_id/0/cairo.pie
Cairo program ran successfully
Generating tx input file...
Computing max of TX.CHAIN_ID from block 2 to block 26 with step 9, input file path: ./fixtures/transactions/chain_id/1/input.json, output file path: ./fixtures/transactions/chain_id/1/output.json
2024-05-09T06:56:22.659416Z INFO hdp_provider::evm: Successfully fetched MMR data from indexer
2024-05-09T06:56:22.659513Z INFO hdp_provider::evm: Time taken (fetch from Indexer): 3.834585708s
thread 'main' panicked at src/main.rs:303:22:
called `Result::unwrap()` on an `Err` value: No values found
2 changes: 2 additions & 0 deletions fixture_fail/2/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Tasks [ComputationalTask { aggregate_fn_id: MAX, aggregate_fn_ctx: None }]
, Datalakes [Transactions(TransactionsInBlockDatalake { target_block: 5335233, start_index: 2, end_index: 26, increment: 9, included_types: IncludedTypes { inner: [0, 1, 1, 1] }, sampled_property: Transactions(ChainId) })]
3 changes: 3 additions & 0 deletions fixture_fail/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Fixture Failure

Stack up the failed cases as TODOs
1 change: 0 additions & 1 deletion fixtures/TX/0/input.json

This file was deleted.

Loading

0 comments on commit c14877b

Please sign in to comment.