Skip to content

Commit

Permalink
sc-meta compare feature and github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaicalinluca committed May 20, 2024
1 parent ed42bb3 commit 1bc1b02
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 3 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/proxy-compare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

on:
push:
branches:
- master
pull_request:

jobs:
proxy_compare:
name: Proxy compare - newly generated vs present in file tree
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
default: true
toolchain: stable
target: wasm32-unknown-unknown

- name: Install prerequisites
run: |
cargo install wasm-opt
cargo install --path framework/meta
sc-meta install mx-scenario-go --tag v2.0.0
which wasm-opt
which mx-scenario-go
mx-scenario-go --version
- name: Run proxy compare
run: |
cd framework/meta
cargo run compare
5 changes: 2 additions & 3 deletions contracts/examples/adder/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

// Init: 1
// Upgrade: 1
// Endpoints: 2
// Endpoints: 1
// Async Callback (empty): 1
// Total number of exported functions: 5
// Total number of exported functions: 4

#![no_std]

Expand All @@ -21,7 +21,6 @@ multiversx_sc_wasm_adapter::endpoints! {
init => init
upgrade => upgrade
getSum => sum
add => add
)
}

Expand Down
8 changes: 8 additions & 0 deletions framework/meta/src/cli_args/cli_args_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ pub enum ContractCliAction {
about = "Generates a proxy, based on the contract ABI."
)]
GenerateProxies,
#[command(
name = "compare",
about = "Compares a newly generated proxy with the proxies already on disk."
)]
Compare
}

impl CliArgsToRaw for ContractCliAction {
Expand Down Expand Up @@ -106,6 +111,9 @@ impl CliArgsToRaw for ContractCliAction {
ContractCliAction::GenerateProxies => {
raw.push("proxy".to_string());
},
ContractCliAction::Compare => {
raw.push("compare".to_string());
},
}
raw
}
Expand Down
1 change: 1 addition & 0 deletions framework/meta/src/cmd/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub fn cli_main<AbiObj: ContractAbiProvider>() {
meta_config_opt.generate_proxy()
},
ContractCliAction::GenerateProxies => meta_config_opt.generate_proxy(),
ContractCliAction::Compare => meta_config_opt.compare_proxy(),
}
}

Expand Down
30 changes: 30 additions & 0 deletions framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use colored::Colorize;
use std::fs;

use multiversx_sc::abi::ContractAbi;

use crate::cmd::contract::sc_config::ProxyConfigSerde;
Expand All @@ -14,6 +17,33 @@ impl MetaConfig {
write_proxy_with_explicit_path(&proxy_config, self);
}
}

pub fn compare_proxy(&mut self) {
for proxy_config in self.sc_config.proxy_configs.clone() {
compare_proxy_explicit_path(&proxy_config, self);
}
}
}

fn compare_proxy_explicit_path(proxy_config: &ProxyConfigSerde, meta_config: &MetaConfig) {
let contract_abi = extract_contract_abi(proxy_config, meta_config);
let mut temp = create_file("temp");
let mut proxy_generator =
ProxyGenerator::new(meta_config, &mut temp, proxy_config, contract_abi);
proxy_generator.write_proxy_to_file();

let existent_proxy_path = format!("../{}", proxy_config.path);
let temp_path = "../temp";

let existent_proxy = fs::read_to_string(existent_proxy_path).unwrap();
let temp = fs::read_to_string(temp_path).unwrap();

if existent_proxy != temp {
fs::remove_file(temp_path).unwrap();
panic!("{}", format!("Contract has been modified and proxies have not been updated. Regenerate proxies to avoid inconsistencies.").red());

Check warning on line 43 in framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs#L43

warning: useless use of `format!` --> framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs:43:22 | 43 | ...("{}", format!("Contract has been modified and proxies have not been updated. Regenerate proxies to avoid inconsistencies.").red()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"Contract has been modified and proxies have not been updated. Regenerate proxies to avoid inconsistencies.".to_string()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format = note: `#[warn(clippy::useless_format)]` on by default
Raw output
framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs:43:22:w:warning: useless use of `format!`
  --> framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs:43:22
   |
43 | ...("{}", format!("Contract has been modified and proxies have not been updated. Regenerate proxies to avoid inconsistencies.").red());
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"Contract has been modified and proxies have not been updated. Regenerate proxies to avoid inconsistencies.".to_string()`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format
   = note: `#[warn(clippy::useless_format)]` on by default


__END__

Check warning on line 43 in framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs#L43

warning: useless use of `format!` --> framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs:43:22 | 43 | ...("{}", format!("Contract has been modified and proxies have not been updated. Regenerate proxies to avoid inconsistencies.").red()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"Contract has been modified and proxies have not been updated. Regenerate proxies to avoid inconsistencies.".to_string()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format = note: `#[warn(clippy::useless_format)]` on by default
Raw output
framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs:43:22:w:warning: useless use of `format!`
  --> framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs:43:22
   |
43 | ...("{}", format!("Contract has been modified and proxies have not been updated. Regenerate proxies to avoid inconsistencies.").red());
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"Contract has been modified and proxies have not been updated. Regenerate proxies to avoid inconsistencies.".to_string()`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format
   = note: `#[warn(clippy::useless_format)]` on by default


__END__
}

fs::remove_file(temp_path).unwrap();
}

fn write_proxy_with_explicit_path(proxy_config: &ProxyConfigSerde, meta_config: &MetaConfig) {
Expand Down

0 comments on commit 1bc1b02

Please sign in to comment.