Skip to content

Commit

Permalink
Merge branch 'feat/unified' into crypto-kitties-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Apr 4, 2024
2 parents a9c5925 + da5c23e commit 9505b94
Show file tree
Hide file tree
Showing 96 changed files with 2,024 additions and 1,036 deletions.
58 changes: 3 additions & 55 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,11 @@ permissions:
jobs:
contracts:
name: Contracts
uses: multiversx/mx-sc-actions/.github/workflows/contracts.yml@v3.0.0
uses: multiversx/mx-sc-actions/.github/workflows/contracts.yml@v3.1.0
with:
rust-toolchain: nightly-2023-12-11
path-to-sc-meta: framework/meta
mx-scenario-go-version: v2.1.0-alpha
coverage-args: --ignore-filename-regex='meta/src' --ignore-filename-regex='wasm-adapter' --ignore-filename-regex='benchmarks/' --ignore-filename-regex='tests/' --output ./coverage.md
secrets:
token: ${{ secrets.GITHUB_TOKEN }}

test_coverage:
name: Test Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly-2023-12-11

- name: Install prerequisites
run: |
rustup component add llvm-tools-preview
dirname $(find ~/.rustup -name llvm-cov) >> $GITHUB_PATH
echo $(dirname $(find ~/.rustup -name llvm-cov))
- name: Run tests and generate report
env:
RUSTFLAGS: ""
run: |
cargo run --bin sc-meta test-coverage \
--ignore-filename-regex='meta/src' \
--ignore-filename-regex='wasm-adapter' \
--ignore-filename-regex='benchmarks/' \
--ignore-filename-regex='tests/' \
--output ./coverage.md
- name: Upload the report
uses: actions/upload-artifact@v3
with:
name: coverage
path: coverage.md

- name: Find the comment containing the report
id: fc
uses: peter-evans/find-comment@v2
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: "Coverage Summary"

- name: Create or update the report comment
uses: peter-evans/create-or-update-comment@v2
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body-file: ./coverage.md
edit-mode: replace
token: ${{ secrets.GITHUB_TOKEN }}
16 changes: 16 additions & 0 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,7 @@ members = [
"contracts/feature-tests/rust-testing-framework-tester/meta",
"contracts/feature-tests/use-module",
"contracts/feature-tests/use-module/meta",
"contracts/feature-tests/exchange-features",
"contracts/feature-tests/exchange-features/meta",

]
2 changes: 1 addition & 1 deletion contracts/examples/adder/interact/config.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
gateway = 'https://testnet-gateway.multiversx.com'
gateway = 'https://devnet-gateway.multiversx.com'
44 changes: 18 additions & 26 deletions contracts/examples/adder/interact/src/basic_interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod basic_interact_cli;
mod basic_interact_config;
mod basic_interact_state;

use adder::{adder_proxy, ProxyTrait};
use adder::adder_proxy;
use basic_interact_config::Config;
use basic_interact_state::State;
use clap::Parser;
Expand All @@ -15,11 +15,11 @@ use multiversx_sc_snippets::{
mandos_system::ScenarioRunner,
num_bigint::BigUint,
scenario_format::interpret_trait::{InterpretableFrom, InterpreterContext},
scenario_model::{BytesValue, ScDeployStep, Scenario},
scenario_model::{BytesValue, Scenario},
standalone::retrieve_account_as_scenario_set_state,
test_wallets, ContractInfo, NumExpr, WithRawTxResponse,
},
tokio, Interactor, InteractorPrepareAsync, StepBuffer,
tokio, Interactor, InteractorPrepareAsync,
};

const INTERACTOR_SCENARIO_TRACE_PATH: &str = "interactor_trace.scen.json";
Expand Down Expand Up @@ -135,33 +135,25 @@ impl AdderInteract {
self.set_state().await;
println!("deploying {count} contracts...");

let mut steps = Vec::new();
let mut buffer = self.interactor.homogenous_call_buffer();
for _ in 0..*count {
let typed_sc_deploy = ScDeployStep::new()
.call(self.state.default_adder().init(0u32))
.from(&self.wallet_address)
.code(&self.adder_code)
.gas_limit("70,000,000");

steps.push(typed_sc_deploy);
buffer.push_tx(|tx| {
tx.from(&self.wallet_address)
.typed(adder_proxy::AdderProxy)
.init(0u32)
.code(&self.adder_code)
.gas(NumExpr("70,000,000"))
.returns(ReturnsNewAddress)
});
}

self.interactor
.multi_sc_exec(StepBuffer::from_sc_deploy_vec(&mut steps))
.await;
let results = buffer.run().await;
for result in results {
let new_address_bech32 = bech32::encode(&result.to_address());
println!("new address: {new_address_bech32}");

for step in steps.iter() {
// warning: multi deploy not yet fully supported
// only works with last deployed address
// will be addressed in future versions
let new_deployed_address = step.response().new_deployed_address.clone();
if let Some(new_address) = new_deployed_address {
let new_address_bech32 = bech32::encode(&new_address);
println!("new address: {new_address_bech32}");
} else {
println!("deploy failed");
return;
}
let new_address_expr = format!("bech32:{new_address_bech32}");
self.state.set_adder_address(&new_address_expr);
}
}

Expand Down
9 changes: 0 additions & 9 deletions contracts/examples/adder/interact/src/basic_interact_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ use std::{
path::Path,
};

/// Default adder address
const DEFAULT_ADDER_ADDRESS: &str =
"0x0000000000000000000000000000000000000000000000000000000000000000";

/// State file
const STATE_FILE: &str = "state.toml";

Expand Down Expand Up @@ -46,11 +42,6 @@ impl State {
.expect("no known adder contract, deploy first"),
)
}

/// Returns the adder contract with default address
pub fn default_adder(&self) -> AdderContract {
AdderContract::new(DEFAULT_ADDER_ADDRESS)
}
}

impl Drop for State {
Expand Down
49 changes: 18 additions & 31 deletions contracts/examples/multisig/interact/src/multisig_interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,13 @@ impl MultisigInteract {

let board = self.board();

let quorum = Config::load_config().quorum();
let new_address = self
.interactor
.tx()
.from(&self.wallet_address)
.typed(multisig_proxy::MultisigProxy)
.init(&Config::load_config().quorum(), board)
.init(quorum, board)
.code(&self.multisig_code)
.gas(NumExpr("100,000,000"))
.returns(ReturnsNewAddress)
Expand All @@ -189,40 +190,26 @@ impl MultisigInteract {
println!("deploying {count} contracts...");

let board = self.board();
let mut steps = Vec::new();
let quorum = Config::load_config().quorum();
let mut buffer = self.interactor.homogenous_call_buffer();
for _ in 0..*count {
let typed_sc_deploy = ScDeployStep::new()
.call(
self.state
.default_multisig()
.init(Config::load_config().quorum(), board.clone()),
)
.from(&self.wallet_address)
.code(&self.multisig_code)
.gas_limit("70,000,000");

steps.push(typed_sc_deploy);
buffer.push_tx(|tx| {
tx.from(&self.wallet_address)
.typed(multisig_proxy::MultisigProxy)
.init(quorum, board.clone())
.code(&self.multisig_code)
.gas(NumExpr("70,000,000"))
.returns(ReturnsNewAddress)
});
}

self.interactor
.multi_sc_exec(StepBuffer::from_sc_deploy_vec(&mut steps))
.await;
let results = buffer.run().await;
for result in results {
let new_address_bech32 = bech32::encode(&result.to_address());
println!("new address: {new_address_bech32}");

for step in steps.iter() {
// warning: multi deploy not yet fully supported
// only works with last deployed address
// will be addressed in future versions
let new_deployed_address = step.response().new_deployed_address.clone();
if let Some(new_address) = new_deployed_address {
let new_address_bech32 = bech32::encode(&new_address);
println!("new address: {new_address_bech32}");

let new_address_expr = format!("bech32:{new_address_bech32}");
self.state.set_multisig_address(&new_address_expr);
} else {
println!("deploy failed");
return;
}
let new_address_expr = format!("bech32:{new_address_bech32}");
self.state.set_multisig_address(&new_address_expr);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ use std::{
path::Path,
};

/// Default multisig address
const DEFAULT_MULTISIG_ADDRESS: &str =
"0x0000000000000000000000000000000000000000000000000000000000000000";

/// State file
const STATE_FILE: &str = "state.toml";

Expand Down Expand Up @@ -42,11 +38,6 @@ impl State {
pub fn multisig(&self) -> MultisigContract {
MultisigContract::new(self.multisig_address.clone().unwrap())
}

/// Returns the multisig contract with default address
pub fn default_multisig(&self) -> MultisigContract {
MultisigContract::new(DEFAULT_MULTISIG_ADDRESS)
}
}

impl Drop for State {
Expand Down
29 changes: 10 additions & 19 deletions contracts/examples/multisig/interact/src/multisig_interact_wegld.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
use std::time::Duration;

use multiversx_sc_scenario::{
multiversx_sc::types::{ContractCallBase, FunctionCall, ReturnsResult},
multiversx_sc::types::{FunctionCall, ManagedAddress, ReturnsResult},
NumExpr,
};
#[allow(unused_imports)]
use multiversx_sc_snippets::multiversx_sc::types::{
EsdtTokenPayment, MultiValueEncoded, TokenIdentifier,
};
use multiversx_sc_snippets::{
multiversx_sc::types::ContractCallNoPayment,
multiversx_sc_scenario::{
mandos_system::ScenarioRunner, scenario_format::interpret_trait::InterpretableFrom,
standalone::retrieve_account_as_scenario_set_state,
},
use multiversx_sc_snippets::multiversx_sc_scenario::{
mandos_system::ScenarioRunner, scenario_format::interpret_trait::InterpretableFrom,
standalone::retrieve_account_as_scenario_set_state,
};

use super::*;
Expand Down Expand Up @@ -85,16 +82,13 @@ impl MultisigInteract {
}

async fn propose_unwrap_egld(&mut self) -> usize {
let contract_call = ContractCallNoPayment::<StaticApi, ()>::new(
bech32::decode(WEGLD_SWAP_SC_BECH32).into(),
"unwrapEgld",
)
.with_esdt_transfer(EsdtTokenPayment::new(
let to = ManagedAddress::<StaticApi>::from(bech32::decode(WEGLD_SWAP_SC_BECH32));
let payment = EsdtTokenPayment::new(
TokenIdentifier::from(WEGLD_TOKEN_IDENTIFIER),
0u64,
UNWRAP_AMOUNT.into(),
))
.into_normalized();
);
let function_call = FunctionCall::new("unwrapEgld");

let action_id = self
.interactor
Expand All @@ -103,11 +97,8 @@ impl MultisigInteract {
.to(&self.state.multisig().to_address())
.gas(NumExpr("10,000,000"))
.typed(multisig_proxy::MultisigProxy)
.propose_async_call(
contract_call.basic.to,
0u64,
contract_call.basic.function_call,
)
.propose_async_call(to, 0u64, function_call)
.esdt(payment)
.returns(ReturnsResult)
.prepare_async()
.run()
Expand Down
15 changes: 8 additions & 7 deletions contracts/examples/multisig/src/multisig_perform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,14 @@ pub trait MultisigPerformModule:
&call_data.endpoint_name,
call_data.arguments.as_multi(),
);
self.send()
.contract_call::<()>(call_data.to, call_data.endpoint_name)
.with_egld_transfer(call_data.egld_amount)
.with_raw_arguments(call_data.arguments.into())
.async_call()
.with_callback(self.callbacks().perform_async_call_callback())
.call_and_exit()

self.tx()
.to(&call_data.to)
.raw_call(call_data.endpoint_name)
.arguments_raw(call_data.arguments.into())
.egld(call_data.egld_amount)
.callback(self.callbacks().perform_async_call_callback())
.async_call_and_exit();
},
Action::SCDeployFromSource {
amount,
Expand Down
9 changes: 5 additions & 4 deletions contracts/examples/seed-nft-minter/src/distribution_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ pub trait DistributionModule {
if payment_amount == 0 {
continue;
}
self.send()
.contract_call::<IgnoreValue>(distribution.address, distribution.endpoint)
.with_egld_or_single_esdt_transfer((token_id.clone(), token_nonce, payment_amount))
.with_gas_limit(distribution.gas_limit)
self.tx()
.to(&distribution.address)
.raw_call(distribution.endpoint)
.egld_or_single_esdt(token_id, token_nonce, &payment_amount)
.gas(distribution.gas_limit)
.transfer_execute();
}
}
Expand Down
Loading

0 comments on commit 9505b94

Please sign in to comment.