Skip to content

Commit

Permalink
Add xtask check gas cost definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
sydhds committed Oct 9, 2024
1 parent 0165395 commit 8751cb1
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,24 @@ jobs:
submodules: "recursive"
- uses: crate-ci/typos@master

misc:
if: github.ref != 'refs/heads/staging'
needs: sanity
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v4
with:
submodules: "recursive"
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.81.0
- uses: Swatinem/rust-cache@v2
with:
shared-key: "clippy"
save-if: ${{ github.ref_name == 'main' }}
- run: cargo xtask check_gas_cost_definitions

# Full cross-platform tests required to merge on main branch
full:
name: full
Expand Down
3 changes: 2 additions & 1 deletion Cargo.lock

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

3 changes: 3 additions & 0 deletions massa-xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ version = "2.3.0"
edition = "2021"

[dependencies]
# update_package_versions dependencies
massa_models = {workspace = true}
toml_edit = {workspace = true} # BOM UPGRADE Revert to "0.19.8" if problem
walkdir = {workspace = true}
# check_gas_costs dependencies
massa-sc-runtime = {workspace = true, features = ["gas_calibration"]}
47 changes: 47 additions & 0 deletions massa-xtask/src/check_gas_cost_definitions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use massa_sc_runtime::GasCosts;
use std::collections::HashSet;

pub(crate) fn check_gas_cost_definitions() -> Result<(), String> {
// Check gas cost definition between:
// massa-node/base_config/gas_costs/abi_gas_costs.json
// massa-sc-runtime GasCosts::default()

let gas_costs = GasCosts::default();
let gas_costs_abi_defined = gas_costs
.get_abi_costs()
.keys()
.cloned()
.collect::<HashSet<String>>();

let massa_node_gas_costs = GasCosts::new(
// SETTINGS.execution.abi_gas_costs_file.clone(),
// SETTINGS.execution.wasm_gas_costs_file.clone(),
"massa-node/base_config/gas_costs/abi_gas_costs.json".into(),
"massa-node/base_config/gas_costs/wasm_gas_costs.json".into(),
)
.expect("Failed to load gas costs");

let massa_node_gas_costs_abi_defined = massa_node_gas_costs
.get_abi_costs()
.keys()
.cloned()
.collect::<HashSet<String>>();

let mut found_diff = false;
let diff_1 = gas_costs_abi_defined.difference(&massa_node_gas_costs_abi_defined);
for x1 in diff_1 {
println!("Found in default() but not in json: {x1}");
found_diff = true;
}

let diff_2 = massa_node_gas_costs_abi_defined.difference(&gas_costs_abi_defined);
for x2 in diff_2 {
println!("Found in json but not in default(): {x2}");
}

if found_diff {
Err("Found gas costs definition differences".to_string())
} else {
Ok(())
}
}
4 changes: 4 additions & 0 deletions massa-xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
mod check_gas_cost_definitions;
mod update_package_versions;

use crate::check_gas_cost_definitions::check_gas_cost_definitions;
use crate::update_package_versions::update_package_versions;
use std::env;

Expand All @@ -10,6 +13,7 @@ fn main() {
match task.as_deref() {
// We can add more tasks here
Some("update_package_versions") => update_package_versions(),
Some("check_gas_cost_definitions") => check_gas_cost_definitions().unwrap(),
_ => panic!("Unknown task"),
}
}

0 comments on commit 8751cb1

Please sign in to comment.