Skip to content

Commit

Permalink
Merge pull request #1791 from multiversx/fix-esdt-system-chain-sim
Browse files Browse the repository at this point in the history
chain sim - fix TXs to ESDTSystemSCAddress
  • Loading branch information
BiancaIalangi authored Oct 2, 2024
2 parents c158030 + af928ec commit 999a67e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
7 changes: 6 additions & 1 deletion contracts/examples/adder/interact/src/basic_interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ impl AdderInteract {
)
.await;

interactor.proxy.generate_blocks(1).await.unwrap();
// generate blocks until ESDTSystemSCAddress is enabled
interactor
.proxy
.generate_blocks_until_epoch(1)
.await
.unwrap();

Self {
interactor,
Expand Down
33 changes: 29 additions & 4 deletions sdk/core/src/gateway/gateway_chain_simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ use anyhow::{anyhow, Error};
use serde::{Deserialize, Serialize};

const SEND_USER_FUNDS_ENDPOINT: &str = "transaction/send-user-funds";
const GENERATE_BLOCKS_FUNDS_ENDPOINT: &str = "simulator/generate-blocks";
const GENERATE_BLOCKS_ENDPOINT: &str = "simulator/generate-blocks";
const GENERATE_BLOCKS_UNTIL_TX_PROCESSED_ENDPOINT: &str =
"simulator/generate-blocks-until-transaction-processed";
const GENERATE_BLOCKS_UNTIL_EPOCH_REACHED_ENDPOINT: &str =
"simulator/generate-blocks-until-epoch-reached";

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GenerateBlocksResponse {
Expand Down Expand Up @@ -45,9 +47,32 @@ impl GatewayProxy {
return Ok(String::from("no-simulator"));
}

let url_gen_blocks: String =
format!("{}/{}", GENERATE_BLOCKS_FUNDS_ENDPOINT, number_blocks);
let endpoint_blocks = self.get_endpoint(&url_gen_blocks);
let uri_gen_blocks: String = format!("{}/{}", GENERATE_BLOCKS_ENDPOINT, number_blocks);
let endpoint_blocks = self.get_endpoint(&uri_gen_blocks);
let resp = self
.client
.post(endpoint_blocks)
.send()
.await?
.json::<GenerateBlocksResponse>()
.await?;

match resp.code.as_str() {
"successful" => Ok(resp.code),
_ => Err(anyhow!("{}", resp.error)),
}
}

pub async fn generate_blocks_until_epoch(&self, epoch_number: u64) -> Result<String, Error> {
if !self.chain_simulator {
return Ok(String::from("no-simulator"));
}

let uri_gen_blocks_until_reached_epoch: String = format!(
"{}/{}",
GENERATE_BLOCKS_UNTIL_EPOCH_REACHED_ENDPOINT, epoch_number
);
let endpoint_blocks = self.get_endpoint(&uri_gen_blocks_until_reached_epoch);
let resp = self
.client
.post(endpoint_blocks)
Expand Down
3 changes: 3 additions & 0 deletions tools/interactor-system-func-calls/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# chain_type = 'simulator'
# gateway_uri = 'http://localhost:8085'

chain_type = 'real'
gateway_uri = 'https://devnet-gateway.multiversx.com'
7 changes: 7 additions & 0 deletions tools/interactor-system-func-calls/src/system_sc_interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ impl SysFuncCallsInteract {

let wallet_address = interactor.register_wallet(test_wallets::alice()).await;

// generate blocks until ESDTSystemSCAddress is enabled
interactor
.proxy
.generate_blocks_until_epoch(1)
.await
.unwrap();

Self {
interactor,
wallet_address: wallet_address.into(),
Expand Down

0 comments on commit 999a67e

Please sign in to comment.