|
3 | 3 | #![allow(dead_code)]
|
4 | 4 |
|
5 | 5 | use crate::{
|
6 |
| - msg::{ExecuteMsg, InitialBalance, InstantiateMsg, NewTokenInfo, QueryMsg, TokenInfo}, |
| 6 | + abc::{ |
| 7 | + ClosedConfig, CommonsPhaseConfig, CurveType, HatchConfig, MinMax, OpenConfig, ReserveToken, |
| 8 | + SupplyToken, |
| 9 | + }, |
| 10 | + msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}, |
7 | 11 | ContractError,
|
8 | 12 | };
|
9 | 13 |
|
10 |
| -use cosmwasm_std::{Coin, Uint128}; |
| 14 | +use cosmwasm_std::{Coin, Decimal, Uint128}; |
11 | 15 | use cw_tokenfactory_issuer::msg::{DenomResponse, DenomUnit};
|
12 | 16 | use cw_utils::Duration;
|
13 |
| -use dao_interface::voting::{IsActiveResponse, VotingPowerAtHeightResponse}; |
14 |
| -use dao_testing::test_tube::{cw_abc::CwAbc, cw_tokenfactory_issuer::TokenfactoryIssuer}; |
15 |
| -use dao_voting::threshold::ActiveThreshold; |
16 |
| -use osmosis_std::types::{ |
17 |
| - cosmos::bank::v1beta1::QueryAllBalancesRequest, cosmwasm::wasm::v1::MsgExecuteContractResponse, |
18 |
| -}; |
| 17 | +use dao_testing::test_tube::cw_tokenfactory_issuer::TokenfactoryIssuer; |
19 | 18 | use osmosis_test_tube::{
|
| 19 | + osmosis_std::types::cosmos::bank::v1beta1::QueryAllBalancesRequest, |
| 20 | + osmosis_std::types::cosmwasm::wasm::v1::{ |
| 21 | + MsgExecuteContractResponse, MsgMigrateContract, MsgMigrateContractResponse, |
| 22 | + }, |
20 | 23 | Account, Bank, Module, OsmosisTestApp, RunnerError, RunnerExecuteResult, RunnerResult,
|
21 | 24 | SigningAccount, Wasm,
|
22 | 25 | };
|
23 | 26 | use serde::de::DeserializeOwned;
|
| 27 | +use std::fmt::Debug; |
24 | 28 | use std::path::PathBuf;
|
25 | 29 |
|
26 | 30 | pub const DENOM: &str = "ucat";
|
27 | 31 | pub const JUNO: &str = "ujuno";
|
28 | 32 |
|
29 | 33 | pub struct TestEnv<'a> {
|
30 | 34 | pub app: &'a OsmosisTestApp,
|
31 |
| - pub abc: TfDaoVotingContract<'a>, |
| 35 | + pub abc: CwAbc<'a>, |
32 | 36 | pub tf_issuer: TokenfactoryIssuer<'a>,
|
33 | 37 | pub accounts: Vec<SigningAccount>,
|
34 | 38 | }
|
@@ -105,17 +109,46 @@ impl TestEnvBuilder {
|
105 | 109 | .init_accounts(&[Coin::new(1000000000000000u128, "uosmo")], 10)
|
106 | 110 | .unwrap();
|
107 | 111 |
|
108 |
| - let initial_balances: Vec<InitialBalance> = accounts |
109 |
| - .iter() |
110 |
| - .map(|acc| InitialBalance { |
111 |
| - address: acc.address(), |
112 |
| - amount: Uint128::new(100), |
113 |
| - }) |
114 |
| - .collect(); |
115 |
| - |
116 | 112 | let issuer_id = TokenfactoryIssuer::upload(app, &accounts[0]).unwrap();
|
117 | 113 |
|
118 |
| - let abc = CwAbc::deploy(app, &InstantiateMsg {}, &accounts[0]).unwrap(); |
| 114 | + let abc = CwAbc::deploy( |
| 115 | + app, |
| 116 | + &InstantiateMsg { |
| 117 | + token_issuer_code_id: issuer_id, |
| 118 | + supply: SupplyToken { |
| 119 | + subdenom: DENOM.to_string(), |
| 120 | + metadata: None, |
| 121 | + decimals: 6, |
| 122 | + }, |
| 123 | + reserve: ReserveToken { |
| 124 | + denom: JUNO.to_string(), |
| 125 | + decimals: 6, |
| 126 | + }, |
| 127 | + phase_config: CommonsPhaseConfig { |
| 128 | + hatch: HatchConfig { |
| 129 | + initial_raise: MinMax { |
| 130 | + min: Uint128::one(), |
| 131 | + max: Uint128::from(1000000u128), |
| 132 | + }, |
| 133 | + initial_price: Uint128::one(), |
| 134 | + initial_allocation_ratio: Decimal::percent(10u64), |
| 135 | + exit_tax: Decimal::zero(), |
| 136 | + }, |
| 137 | + open: OpenConfig { |
| 138 | + allocation_percentage: Decimal::percent(10u64), |
| 139 | + exit_tax: Decimal::percent(10u64), |
| 140 | + }, |
| 141 | + closed: ClosedConfig {}, |
| 142 | + }, |
| 143 | + hatcher_allowlist: None, |
| 144 | + curve_type: CurveType::Constant { |
| 145 | + value: Uint128::one(), |
| 146 | + scale: 1, |
| 147 | + }, |
| 148 | + }, |
| 149 | + &accounts[0], |
| 150 | + ) |
| 151 | + .unwrap(); |
119 | 152 |
|
120 | 153 | let issuer_addr = CwAbc::query(&abc, &QueryMsg::TokenContract {}).unwrap();
|
121 | 154 |
|
@@ -193,3 +226,169 @@ pub fn assert_contract_err(expected: ContractError, actual: RunnerError) {
|
193 | 226 | _ => panic!("unexpected error, expect execute error but got: {}", actual),
|
194 | 227 | };
|
195 | 228 | }
|
| 229 | + |
| 230 | +#[derive(Debug)] |
| 231 | +pub struct CwAbc<'a> { |
| 232 | + pub app: &'a OsmosisTestApp, |
| 233 | + pub code_id: u64, |
| 234 | + pub contract_addr: String, |
| 235 | +} |
| 236 | + |
| 237 | +impl<'a> CwAbc<'a> { |
| 238 | + pub fn deploy( |
| 239 | + app: &'a OsmosisTestApp, |
| 240 | + instantiate_msg: &InstantiateMsg, |
| 241 | + signer: &SigningAccount, |
| 242 | + ) -> Result<Self, RunnerError> { |
| 243 | + let wasm = Wasm::new(app); |
| 244 | + let token_creation_fee = Coin::new(10000000, "uosmo"); |
| 245 | + |
| 246 | + let code_id = wasm |
| 247 | + .store_code(&Self::get_wasm_byte_code(), None, signer)? |
| 248 | + .data |
| 249 | + .code_id; |
| 250 | + |
| 251 | + let contract_addr = wasm |
| 252 | + .instantiate( |
| 253 | + code_id, |
| 254 | + &instantiate_msg, |
| 255 | + Some(&signer.address()), |
| 256 | + None, |
| 257 | + &[token_creation_fee], |
| 258 | + signer, |
| 259 | + )? |
| 260 | + .data |
| 261 | + .address; |
| 262 | + |
| 263 | + Ok(Self { |
| 264 | + app, |
| 265 | + code_id, |
| 266 | + contract_addr, |
| 267 | + }) |
| 268 | + } |
| 269 | + |
| 270 | + pub fn new_with_values( |
| 271 | + app: &'a OsmosisTestApp, |
| 272 | + code_id: u64, |
| 273 | + contract_addr: String, |
| 274 | + ) -> Result<Self, RunnerError> { |
| 275 | + Ok(Self { |
| 276 | + app, |
| 277 | + code_id, |
| 278 | + contract_addr, |
| 279 | + }) |
| 280 | + } |
| 281 | + |
| 282 | + /// uploads contract and returns a code ID |
| 283 | + pub fn upload(app: &OsmosisTestApp, signer: &SigningAccount) -> Result<u64, RunnerError> { |
| 284 | + let wasm = Wasm::new(app); |
| 285 | + |
| 286 | + let code_id = wasm |
| 287 | + .store_code(&Self::get_wasm_byte_code(), None, signer)? |
| 288 | + .data |
| 289 | + .code_id; |
| 290 | + |
| 291 | + Ok(code_id) |
| 292 | + } |
| 293 | + |
| 294 | + pub fn instantiate( |
| 295 | + app: &'a OsmosisTestApp, |
| 296 | + code_id: u64, |
| 297 | + instantiate_msg: &InstantiateMsg, |
| 298 | + signer: &SigningAccount, |
| 299 | + ) -> Result<Self, RunnerError> { |
| 300 | + let wasm = Wasm::new(app); |
| 301 | + let contract_addr = wasm |
| 302 | + .instantiate( |
| 303 | + code_id, |
| 304 | + &instantiate_msg, |
| 305 | + Some(&signer.address()), |
| 306 | + None, |
| 307 | + &[], |
| 308 | + signer, |
| 309 | + )? |
| 310 | + .data |
| 311 | + .address; |
| 312 | + |
| 313 | + Ok(Self { |
| 314 | + app, |
| 315 | + code_id, |
| 316 | + contract_addr, |
| 317 | + }) |
| 318 | + } |
| 319 | + |
| 320 | + // executes |
| 321 | + pub fn execute( |
| 322 | + &self, |
| 323 | + execute_msg: &ExecuteMsg, |
| 324 | + funds: &[Coin], |
| 325 | + signer: &SigningAccount, |
| 326 | + ) -> RunnerExecuteResult<MsgExecuteContractResponse> { |
| 327 | + let wasm = Wasm::new(self.app); |
| 328 | + wasm.execute(&self.contract_addr, execute_msg, funds, signer) |
| 329 | + } |
| 330 | + |
| 331 | + // queries |
| 332 | + pub fn query<T>(&self, query_msg: &QueryMsg) -> Result<T, RunnerError> |
| 333 | + where |
| 334 | + T: DeserializeOwned, |
| 335 | + { |
| 336 | + let wasm = Wasm::new(self.app); |
| 337 | + wasm.query(&self.contract_addr, query_msg) |
| 338 | + } |
| 339 | + |
| 340 | + // pub fn migrate( |
| 341 | + // &self, |
| 342 | + // testdata: &str, |
| 343 | + // signer: &SigningAccount, |
| 344 | + // ) -> RunnerExecuteResult<MsgMigrateContractResponse> { |
| 345 | + // let wasm = Wasm::new(self.app); |
| 346 | + // let manifest_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); |
| 347 | + // let wasm_byte_code = |
| 348 | + // std::fs::read(manifest_path.join("tests").join("testdata").join(testdata)).unwrap(); |
| 349 | + |
| 350 | + // let code_id = wasm.store_code(&wasm_byte_code, None, signer)?.data.code_id; |
| 351 | + // self.app.execute( |
| 352 | + // MsgMigrateContract { |
| 353 | + // sender: signer.address(), |
| 354 | + // contract: self.contract_addr.clone(), |
| 355 | + // code_id, |
| 356 | + // msg: serde_json::to_vec(&MigrateMsg {}).unwrap(), |
| 357 | + // }, |
| 358 | + // "/cosmwasm.wasm.v1.MsgMigrateContract", |
| 359 | + // signer, |
| 360 | + // ) |
| 361 | + // } |
| 362 | + |
| 363 | + fn get_wasm_byte_code() -> Vec<u8> { |
| 364 | + let manifest_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); |
| 365 | + let byte_code = std::fs::read( |
| 366 | + manifest_path |
| 367 | + .join("..") |
| 368 | + .join("..") |
| 369 | + .join("artifacts") |
| 370 | + .join("cw_tokenfactory_issuer.wasm"), |
| 371 | + ); |
| 372 | + match byte_code { |
| 373 | + Ok(byte_code) => byte_code, |
| 374 | + // On arm processors, the above path is not found, so we try the following path |
| 375 | + Err(_) => std::fs::read( |
| 376 | + manifest_path |
| 377 | + .join("..") |
| 378 | + .join("..") |
| 379 | + .join("artifacts") |
| 380 | + .join("cw_tokenfactory_issuer-aarch64.wasm"), |
| 381 | + ) |
| 382 | + .unwrap(), |
| 383 | + } |
| 384 | + } |
| 385 | + |
| 386 | + pub fn execute_error(err: ContractError) -> RunnerError { |
| 387 | + RunnerError::ExecuteError { |
| 388 | + msg: format!( |
| 389 | + "failed to execute message; message index: 0: {}: execute wasm contract failed", |
| 390 | + err |
| 391 | + ), |
| 392 | + } |
| 393 | + } |
| 394 | +} |
0 commit comments