-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sort of get test-tube tests working for custom factory
- Loading branch information
Jake Hartnell
committed
Sep 13, 2023
1 parent
7b5e097
commit 32d86ee
Showing
7 changed files
with
250 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
packages/dao-testing/src/test_tube/dao_test_custom_factory.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
use cosmwasm_std::Coin; | ||
use dao_test_custom_factory::{ | ||
msg::{ExecuteMsg, InstantiateMsg, QueryMsg}, | ||
ContractError, | ||
}; | ||
use osmosis_test_tube::{ | ||
osmosis_std::types::cosmwasm::wasm::v1::MsgExecuteContractResponse, Account, Module, | ||
OsmosisTestApp, RunnerError, RunnerExecuteResult, SigningAccount, Wasm, | ||
}; | ||
use serde::de::DeserializeOwned; | ||
use std::fmt::Debug; | ||
use std::path::PathBuf; | ||
|
||
#[derive(Debug)] | ||
pub struct CustomFactoryContract<'a> { | ||
pub app: &'a OsmosisTestApp, | ||
pub code_id: u64, | ||
pub contract_addr: String, | ||
} | ||
|
||
impl<'a> CustomFactoryContract<'a> { | ||
pub fn new( | ||
app: &'a OsmosisTestApp, | ||
instantiate_msg: &InstantiateMsg, | ||
signer: &SigningAccount, | ||
) -> Result<Self, RunnerError> { | ||
let wasm = Wasm::new(app); | ||
let token_creation_fee = Coin::new(10000000, "uosmo"); | ||
|
||
let code_id = wasm | ||
.store_code(&Self::get_wasm_byte_code(), None, signer)? | ||
.data | ||
.code_id; | ||
|
||
let contract_addr = wasm | ||
.instantiate( | ||
code_id, | ||
&instantiate_msg, | ||
Some(&signer.address()), | ||
None, | ||
&[token_creation_fee], | ||
signer, | ||
)? | ||
.data | ||
.address; | ||
|
||
Ok(Self { | ||
app, | ||
code_id, | ||
contract_addr, | ||
}) | ||
} | ||
|
||
pub fn new_with_values( | ||
app: &'a OsmosisTestApp, | ||
code_id: u64, | ||
contract_addr: String, | ||
) -> Result<Self, RunnerError> { | ||
Ok(Self { | ||
app, | ||
code_id, | ||
contract_addr, | ||
}) | ||
} | ||
|
||
/// uploads contract and returns a code ID | ||
pub fn upload(app: &OsmosisTestApp, signer: &SigningAccount) -> Result<u64, RunnerError> { | ||
let wasm = Wasm::new(app); | ||
|
||
let code_id = wasm | ||
.store_code(&Self::get_wasm_byte_code(), None, signer)? | ||
.data | ||
.code_id; | ||
|
||
Ok(code_id) | ||
} | ||
|
||
// executes | ||
pub fn execute( | ||
&self, | ||
execute_msg: &ExecuteMsg, | ||
funds: &[Coin], | ||
signer: &SigningAccount, | ||
) -> RunnerExecuteResult<MsgExecuteContractResponse> { | ||
let wasm = Wasm::new(self.app); | ||
wasm.execute(&self.contract_addr, execute_msg, funds, signer) | ||
} | ||
|
||
// queries | ||
pub fn query<T>(&self, query_msg: &QueryMsg) -> Result<T, RunnerError> | ||
where | ||
T: DeserializeOwned, | ||
{ | ||
let wasm = Wasm::new(self.app); | ||
wasm.query(&self.contract_addr, query_msg) | ||
} | ||
|
||
fn get_wasm_byte_code() -> Vec<u8> { | ||
let manifest_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
let byte_code = std::fs::read( | ||
manifest_path | ||
.join("..") | ||
.join("..") | ||
.join("artifacts") | ||
.join("dao_test_custom_factory.wasm"), | ||
); | ||
match byte_code { | ||
Ok(byte_code) => byte_code, | ||
// On arm processors, the above path is not found, so we try the following path | ||
Err(_) => std::fs::read( | ||
manifest_path | ||
.join("..") | ||
.join("..") | ||
.join("artifacts") | ||
.join("dao_test_custom_factory-aarch64.wasm"), | ||
) | ||
.unwrap(), | ||
} | ||
} | ||
|
||
pub fn execute_error(err: ContractError) -> RunnerError { | ||
RunnerError::ExecuteError { | ||
msg: format!( | ||
"failed to execute message; message index: 0: {}: execute wasm contract failed", | ||
err | ||
), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters