Skip to content

Commit

Permalink
add basic adminmodule support & tokenfactory update params prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
quasisamurai committed Nov 12, 2024
1 parent 9b6380e commit 3419a27
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 29 deletions.
25 changes: 25 additions & 0 deletions packages/neutron-test-tube/src/module/adminmodule.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use neutron_std::types::cosmos::adminmodule::adminmodule::{MsgSubmitProposal, MsgSubmitProposalResponse};

use test_tube_ntrn::{fn_execute};
use test_tube_ntrn::module::Module;
use test_tube_ntrn::runner::Runner;

pub struct Adminmodule<'a, R: Runner<'a>> {
runner: &'a R,
}

impl<'a, R: Runner<'a>> Module<'a, R> for Adminmodule<'a, R> {
fn new(runner: &'a R) -> Self {
Self { runner }
}
}

impl<'a, R> Adminmodule<'a, R>
where
R: Runner<'a>,
{
fn_execute! {
pub submit_proposal: MsgSubmitProposal ["/cosmos.adminmodule.adminmodule.MsgSubmitProposal"] => MsgSubmitProposalResponse
}

}
2 changes: 2 additions & 0 deletions packages/neutron-test-tube/src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod marketmap;
mod oracle;
mod tokenfactory;
mod wasm;
mod adminmodule;

pub use test_tube_ntrn::macros;
pub use test_tube_ntrn::module::Module;
Expand All @@ -17,3 +18,4 @@ pub use marketmap::Marketmap;
pub use oracle::Oracle;
pub use tokenfactory::TokenFactory;
pub use wasm::Wasm;
pub use adminmodule::Adminmodule;
75 changes: 46 additions & 29 deletions packages/neutron-test-tube/src/module/tokenfactory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use neutron_std::types::osmosis::tokenfactory::v1beta1::{
MsgSetDenomMetadataResponse, MsgUpdateParams, MsgUpdateParamsResponse,
QueryDenomAuthorityMetadataRequest, QueryDenomAuthorityMetadataResponse,
QueryDenomsFromCreatorRequest, QueryDenomsFromCreatorResponse, QueryParamsRequest,
QueryParamsResponse,
QueryParamsResponse
};

use test_tube_ntrn::module::Module;
Expand Down Expand Up @@ -66,14 +66,15 @@ where
mod tests {
use cosmos_sdk_proto::cosmos::bank::v1beta1::QueryBalanceRequest;
use cosmwasm_std::{coins, Coin, Uint128};
use neutron_std::types::osmosis::tokenfactory::v1beta1::{
MsgBurn, MsgCreateDenom, MsgMint, MsgUpdateParams, QueryDenomsFromCreatorRequest,
};
// use neutron_sdk::proto_types::osmosis::tokenfactory::Params as TokenFactoryParams;
use neutron_std::shim::Any;
use neutron_std::types::cosmos::adminmodule::adminmodule::MsgSubmitProposal;
use neutron_std::types::osmosis::tokenfactory::v1beta1::{MsgBurn, MsgCreateDenom, MsgMint, MsgUpdateParams, QueryDenomsFromCreatorRequest};
use neutron_std::types::osmosis::tokenfactory::Params;
use prost::Message;

use test_tube_ntrn::Module;

use crate::{Account, Bank, NeutronTestApp, TokenFactory};
use crate::{Account, Adminmodule, Bank, NeutronTestApp, TokenFactory};

#[test]
fn tokenfactory_integration() {
Expand Down Expand Up @@ -171,27 +172,43 @@ mod tests {
assert_eq!(coin.denom, balance.denom);
}

// #[test]
// fn test_set_bank_hook() {
// let app = NeutronTestApp::default();
// let tf = TokenFactory::new(&app);
//
// let admin = app
// .init_account(&coins(1_000_000_000_000u128, "untrn"), true)
// .unwrap();
// let adminmodule_addr = "neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z";
// tf.update_params(
// MsgUpdateParams {
// authority: adminmodule_addr.to_string(),
// params: Some(TokenFactoryParams {
// denom_creation_fee: vec![],
// denom_creation_gas_consume: 0,
// fee_collector_address: "".to_string(),
// whitelisted_hooks: vec![],
// }),
// },
// &admin,
// )
// .unwrap();
// }
#[test]
fn test_set_bank_hook() {
let app = NeutronTestApp::default();
let adm = Adminmodule::new(&app);

// we creating an addr which could send proposals directly
let admin = app
.init_account(&coins(1_000_000_000_000u128, "untrn"), true)
.unwrap();
// address of admin moudulele. it is an authority for all modules
let adminmodule_addr = "neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z";

// tokenfactory update params messaage
let tfmsg = MsgUpdateParams {
authority: adminmodule_addr.to_string(),
params: Some(Params {
// set proper params & hooks below
denom_creation_fee: vec![],
denom_creation_gas_consume: Some(0),
fee_collector_address: "".to_string(),
whitelisted_hooks: vec![],
}),
};

// encode it to Any
let tfmsg_any = Any {
type_url: "/osmosis.tokenfactory.v1beta1.MsgUpdateParams".to_string(),
value: tfmsg.encode_to_vec(),
};

// submit as a proposal
let msg = MsgSubmitProposal{messages: vec![tfmsg_any], proposer: admin.address()};

adm.submit_proposal(
msg,
&admin,
)
.unwrap();
}
}

0 comments on commit 3419a27

Please sign in to comment.