Skip to content

Commit

Permalink
Merge pull request #21 from timewave-computer/dowlandaiello/enhanceme…
Browse files Browse the repository at this point in the history
…nt-instantiate2flags

Add Custom Flag Support for Instantiate2
  • Loading branch information
dowlandaiello authored Aug 17, 2024
2 parents 7908bd3 + 0f0ed2f commit a00b840
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
21 changes: 14 additions & 7 deletions examples/neutron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const ARTIFACTS_DIR: &str = "contracts";
const ACC_0_ADDR: &str = "neutron1hj5fveer5cjtn4wd6wstzugjfdxzl0xpznmsky";
const LOCAL_CODE_ID_CACHE_PATH: &str = "code_id_cache.json";

const TEST_TOKEN_1_NAME: &str = "bruhtoken3";
const TEST_TOKEN_2_NAME: &str = "amoguscoin3";

/// Demonstrates using localic-utils for neutron.
fn main() -> Result<(), Box<dyn Error>> {
env_logger::init();
Expand All @@ -30,14 +33,14 @@ fn main() -> Result<(), Box<dyn Error>> {

// Create a token in the tokenfactory
ctx.build_tx_create_tokenfactory_token()
.with_subdenom("bruhtoken")
.with_subdenom(TEST_TOKEN_1_NAME)
.send()?;
ctx.build_tx_create_tokenfactory_token()
.with_subdenom("amoguscoin")
.with_subdenom(TEST_TOKEN_2_NAME)
.send()?;

let bruhtoken = ctx.get_tokenfactory_denom(ACC_0_ADDR, "bruhtoken");
let amoguscoin = ctx.get_tokenfactory_denom(ACC_0_ADDR, "amoguscoin");
let bruhtoken = ctx.get_tokenfactory_denom(ACC_0_ADDR, TEST_TOKEN_1_NAME);
let amoguscoin = ctx.get_tokenfactory_denom(ACC_0_ADDR, TEST_TOKEN_2_NAME);

// Deploy valence auctions
ctx.build_tx_create_auctions_manager()
Expand Down Expand Up @@ -78,10 +81,13 @@ fn main() -> Result<(), Box<dyn Error>> {
.with_amount_offer_asset(10000)
.send()?;

ctx.get_auction(("untrn", ctx.get_tokenfactory_denom(ACC_0_ADDR, "bruhtoken")))?;
ctx.get_auction((
"untrn",
ctx.get_tokenfactory_denom(ACC_0_ADDR, "amoguscoin"),
ctx.get_tokenfactory_denom(ACC_0_ADDR, TEST_TOKEN_1_NAME),
))?;
ctx.get_auction((
"untrn",
ctx.get_tokenfactory_denom(ACC_0_ADDR, TEST_TOKEN_2_NAME),
))?;

ctx.build_tx_create_token_registry()
Expand All @@ -101,7 +107,7 @@ fn main() -> Result<(), Box<dyn Error>> {

let pool = ctx.get_astroport_pool(
"untrn",
ctx.get_tokenfactory_denom(ACC_0_ADDR, "amoguscoin"),
ctx.get_tokenfactory_denom(ACC_0_ADDR, TEST_TOKEN_2_NAME),
)?;

assert!(pool
Expand Down Expand Up @@ -148,6 +154,7 @@ fn main() -> Result<(), Box<dyn Error>> {
}))
.with_salt_hex_encoded(hex::encode("examplesalt").as_str())
.with_label("test_contract")
.with_flags("--gas 10000000")
.send()
.unwrap();

Expand Down
16 changes: 14 additions & 2 deletions src/utils/setup/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub struct Instantiate2TxBuilder<'a> {
// Assume the user performs hex encoding
salt: Option<&'a str>,
fix_msg: Option<bool>,
flags: Option<&'a str>,

test_ctx: &'a mut TestContext,
}

Expand Down Expand Up @@ -77,6 +79,12 @@ impl<'a> Instantiate2TxBuilder<'a> {
self
}

pub fn with_flags(&mut self, flags: &'a str) -> &mut Self {
self.flags = Some(flags);

self
}

/// Sends the built instantiate 2 tx.
pub fn send(&mut self) -> Result<(), Error> {
self.test_ctx.tx_instantiate2(
Expand All @@ -89,6 +97,7 @@ impl<'a> Instantiate2TxBuilder<'a> {
self.funds.as_ref(),
self.salt.as_ref().expect("missing builder param salt"),
self.fix_msg,
self.flags,
)
}
}
Expand All @@ -105,6 +114,7 @@ impl TestContext {
funds: None,
salt: None,
fix_msg: None,
flags: None,
test_ctx: self,
}
}
Expand All @@ -120,6 +130,7 @@ impl TestContext {
funds: Option<&Coin>,
salt: &str,
fix_msg: Option<bool>,
flags: Option<&str>,
) -> Result<(), Error> {
let chain = self.get_chain(chain_name);

Expand All @@ -133,10 +144,11 @@ impl TestContext {
let fix_msg_part = fix_msg
.map(|fix_msg| format!("--fix_msg {fix_msg} "))
.unwrap_or_default();
let flags_part = flags.map(|flags| format!(" {flags}")).unwrap_or_default();

let receipt = chain.rb.tx(
&format!("tx wasm instantiate2 {code_id} {msg} {salt} --label {label} {admin_part}{amt_part}{fix_msg_part}--from {key}"),
false,
&format!("tx wasm instantiate2 {code_id} {msg} {salt} --label {label} {admin_part}{amt_part}{fix_msg_part}--from {key}{flags_part}"),
true,
)?;

self.guard_tx_errors(
Expand Down

0 comments on commit a00b840

Please sign in to comment.