Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
breathx committed Dec 4, 2024
1 parent bc6b05a commit 32116ec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 31 deletions.
19 changes: 5 additions & 14 deletions ethexe/cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ pub struct UploadCodeArgs {
#[derive(Clone, Debug, Deserialize, Parser)]
pub struct CreateProgramArgs {
code_id: String,
init_payload: String,
value: u128,
}

// TODO (breathx): support message sending here.

impl ExtraCommands {
pub async fn run(&self, config: &config::Config) -> anyhow::Result<()> {
let signer = ethexe_signer::Signer::new(config.key_path.clone())?;
Expand Down Expand Up @@ -288,15 +288,8 @@ impl ExtraCommands {
.code_id
.parse()
.map_err(|err| anyhow!("failed to parse code id: {err}"))?;

let salt = rand::random();
let init_payload = if let Some(init_payload) =
create_program_args.init_payload.strip_prefix("0x")
{
hex::decode(init_payload)?
} else {
create_program_args.init_payload.clone().into_bytes()
};
let value = create_program_args.value;

let Some((sender_address, ethexe_ethereum)) =
maybe_sender_address.zip(maybe_ethereum)
Expand All @@ -308,13 +301,11 @@ impl ExtraCommands {

let router = ethexe_ethereum.router();

let (tx, actor_id) = router
.create_program(code_id, salt, init_payload, value)
.await?;
let (tx, actor_id) = router.create_program(code_id, salt).await?;

println!("Completed in transaction {tx:?}");
println!(
"Waiting for state update of program {}...",
"Program address on Ethereum {}",
actor_id.to_address_lossy()
);

Expand Down
22 changes: 18 additions & 4 deletions ethexe/cli/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -986,25 +986,39 @@ mod utils {
Ok(WaitForUploadCode { listener, code_id })
}

// TODO (breathx): split it into different functions WITHIN THE PR.
pub async fn create_program(
&self,
code_id: CodeId,
payload: &[u8],
value: u128,
) -> Result<WaitForProgramCreation> {
const EXECUTABLE_BALANCE: u128 = 500_000_000_000_000;

log::info!(
"📗 Create program, code_id {code_id}, payload len {}",
payload.len()
);

let listener = self.events_publisher().subscribe().await;

let (_, program_id) = self
.ethereum
.router()
.create_program(code_id, H256::random(), payload, value)
let router = self.ethereum.router();

let (_, program_id) = router.create_program(code_id, H256::random()).await?;

let program_address = program_id.to_address_lossy().0.into();

router
.wvara()
.approve(program_address, value + EXECUTABLE_BALANCE)
.await?;

let mirror = self.ethereum.mirror(program_address.into_array().into());

mirror.executable_balance_top_up(EXECUTABLE_BALANCE).await?;

mirror.send_message(payload, value).await?;

Ok(WaitForProgramCreation {
listener,
program_id,
Expand Down
17 changes: 4 additions & 13 deletions ethexe/ethereum/src/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,10 @@ impl Router {
Err(anyhow!("Failed to define if code is validated"))
}

pub async fn create_program(
&self,
code_id: CodeId,
salt: H256,
payload: impl AsRef<[u8]>,
value: u128,
) -> Result<(H256, ActorId)> {
let builder = self.instance.createProgram(
code_id.into_bytes().into(),
salt.to_fixed_bytes().into(),
payload.as_ref().to_vec().into(),
value,
);
pub async fn create_program(&self, code_id: CodeId, salt: H256) -> Result<(H256, ActorId)> {
let builder = self
.instance
.createProgram(code_id.into_bytes().into(), salt.to_fixed_bytes().into());
let receipt = builder.send().await?.try_get_receipt().await?;

let tx_hash = (*receipt.transaction_hash).into();
Expand Down

0 comments on commit 32116ec

Please sign in to comment.