Skip to content

Commit

Permalink
fix/audit-16
Browse files Browse the repository at this point in the history
  • Loading branch information
whalelephant committed Dec 13, 2023
1 parent 66f47e9 commit 3e0b48f
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 25 deletions.
2 changes: 1 addition & 1 deletion contracts/core
Submodule core updated from 6edab6 to 90ebee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use vectis_wallet::{
registry_management_trait::sv as registry_management_trait,
wallet_plugin_trait::sv as wallet_plugin_trait,
},
types::plugin::{PluginListResponse, PluginWithVersionResponse},
types::plugin::{PluginListResponse, PluginPermission, PluginWithVersionResponse},
};

use crate::{
Expand Down Expand Up @@ -49,10 +49,14 @@ fn can_query_plugin_by_addr() {

let wallet = Contract::from_addr(&app, wallet_addr.to_string());
let plugins: PluginListResponse = wallet
.query(&wallet_plugin_trait::QueryMsg::Plugins {})
.query(&wallet_plugin_trait::QueryMsg::Plugins {
ty: PluginPermission::PostTxHook,
start_after: None,
limit: None,
})
.unwrap();

let post_tx_addr = plugins.post_tx_hooks[0].clone().0;
let post_tx_addr = plugins.plugins[0].clone().0;

let registry = Contract::from_addr(&app, suite.plugin_registry);

Expand Down
8 changes: 6 additions & 2 deletions packages/vectis-tests/src/test_tube/wallet_plugin/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ fn can_migrate_plugin() {

let wallet = Contract::from_addr(&app, wallet_addr.to_string());
let plugins: PluginListResponse = wallet
.query(&wallet_plugin_trait::sv::QueryMsg::Plugins {})
.query(&wallet_plugin_trait::sv::QueryMsg::Plugins {
ty: PluginPermission::PreTxCheck,
start_after: None,
limit: None,
})
.unwrap();

let mut new_code_data =
Expand All @@ -74,7 +78,7 @@ fn can_migrate_plugin() {
contract_addr: wallet_addr.to_string(),
msg: to_binary(&wallet_plugin_trait::sv::ExecMsg::update_plugins(vec![
PluginMigrateParams {
plugin_addr: plugins.pre_tx[0].clone().0,
plugin_addr: plugins.plugins[0].clone().0,
plugin_permission: PluginPermission::PreTxCheck,
target_src: PluginSource::VectisRegistry(
suite.test_contracts.pre_tx.2,
Expand Down
13 changes: 10 additions & 3 deletions packages/vectis-tests/src/test_tube/wallet_plugin/plugin_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ use osmosis_test_tube::{Bank, OsmosisTestApp};
use serial_test::serial;
use test_tube::module::Module;
use test_vectis_plugin_exec::contract::sv::ExecMsg;
use vectis_wallet::{interface::wallet_plugin_trait, types::plugin::PluginListResponse};
use vectis_wallet::{
interface::wallet_plugin_trait,
types::plugin::{PluginListResponse, PluginPermission},
};

// This uses the code from contracts/test-contracts/
// It will return false if msg contains bankmsg
Expand Down Expand Up @@ -46,10 +49,14 @@ fn plugin_exec_works() {

let wallet = Contract::from_addr(&app, wallet_addr.to_string());
let plugins: PluginListResponse = wallet
.query(&wallet_plugin_trait::sv::QueryMsg::Plugins {})
.query(&wallet_plugin_trait::sv::QueryMsg::Plugins {
ty: PluginPermission::Exec,
start_after: None,
limit: None,
})
.unwrap();

let exec_addr = plugins.exec[0].clone().0;
let exec_addr = plugins.plugins[0].clone().0;
let exec_contract = Contract::from_addr(&app, exec_addr);

// check wallet balance before plugin exec
Expand Down
13 changes: 10 additions & 3 deletions packages/vectis-tests/src/test_tube/wallet_plugin/post_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use osmosis_test_tube::OsmosisTestApp;
use serial_test::serial;

use test_vectis_post_tx_exec::contract::sv::QueryMsg as PostTxQueryMsg;
use vectis_wallet::{interface::wallet_plugin_trait, types::plugin::PluginListResponse};
use vectis_wallet::{
interface::wallet_plugin_trait,
types::plugin::{PluginListResponse, PluginPermission},
};

use crate::{
constants::*,
Expand Down Expand Up @@ -47,10 +50,14 @@ fn post_tx_executes() {

let wallet = Contract::from_addr(&app, wallet_addr.to_string());
let plugins: PluginListResponse = wallet
.query(&wallet_plugin_trait::sv::QueryMsg::Plugins {})
.query(&wallet_plugin_trait::sv::QueryMsg::Plugins {
ty: PluginPermission::PostTxHook,
start_after: None,
limit: None,
})
.unwrap();

let post_tx_addr = plugins.post_tx_hooks[0].clone().0;
let post_tx_addr = plugins.plugins[0].clone().0;
let post_tx_contract = Contract::from_addr(&app, post_tx_addr);

// initially counter is untouched
Expand Down
22 changes: 17 additions & 5 deletions packages/vectis-tests/src/test_tube/wallet_plugin/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,19 @@ fn remove_installed_plugin_successfully() {
assert_eq!(sub.plugin_installed.len(), 1);

let wallet = Contract::from_addr(&app, wallet_addr.to_string());
let info: PluginListResponse = wallet.query(&WalletPluginQueryMsg::Plugins {}).unwrap();
assert_eq!(info.pre_tx.len(), 1);
let info: PluginListResponse = wallet
.query(&WalletPluginQueryMsg::Plugins {
ty: PluginPermission::PreTxCheck,
start_after: None,
limit: None,
})
.unwrap();
assert_eq!(info.plugins.len(), 1);

// Remove plugin
let remove_plugin_msg = RegistryServiceTraitExecMsg::ProxyRemovePlugins {
addr: info
.pre_tx
.plugins
.iter()
.map(|(addr, _)| addr.to_string())
.collect(),
Expand All @@ -114,8 +120,14 @@ fn remove_installed_plugin_successfully() {
.unwrap();

// Check wallet and registry that this was removed
let info: PluginListResponse = wallet.query(&WalletPluginQueryMsg::Plugins {}).unwrap();
assert_eq!(info.pre_tx.len(), 0);
let info: PluginListResponse = wallet
.query(&WalletPluginQueryMsg::Plugins {
ty: PluginPermission::PreTxCheck,
start_after: None,
limit: None,
})
.unwrap();
assert_eq!(info.plugins.len(), 0);

let sub_result: Option<Subscriber> = registry
.query(&registry_service_trait::sv::QueryMsg::SubsciptionDetails {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use vectis_wallet::{
registry_service_trait::sv::RegistryServiceTraitExecMsg,
wallet_plugin_trait::sv::QueryMsg as WalletPluginQueryMsg,
},
types::plugin::PluginListResponse,
types::plugin::{PluginListResponse, PluginPermission},
};

use crate::{
Expand Down Expand Up @@ -69,10 +69,16 @@ fn auth_tx_without_plugin_can_bypass_and_remove_plugin() {

// Can remove plugin
let wallet = Contract::from_addr(&app, wallet_addr.to_string());
let info: PluginListResponse = wallet.query(&WalletPluginQueryMsg::Plugins {}).unwrap();
let info: PluginListResponse = wallet
.query(&WalletPluginQueryMsg::Plugins {
ty: PluginPermission::PreTxCheck,
start_after: None,
limit: None,
})
.unwrap();
let remove_plugin_msg = RegistryServiceTraitExecMsg::ProxyRemovePlugins {
addr: info
.pre_tx
.plugins
.iter()
.map(|(addr, _)| addr.to_string())
.collect(),
Expand Down
12 changes: 10 additions & 2 deletions packages/vectis/src/interface/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ pub mod wallet_trait {
}

pub mod wallet_plugin_trait {
use crate::types::plugin::{PluginInstallParams, PluginListResponse, PluginMigrateParams};
use crate::types::plugin::{
PluginInstallParams, PluginListResponse, PluginMigrateParams, PluginPermission,
};

use super::*;

Expand All @@ -76,7 +78,13 @@ pub mod wallet_plugin_trait {

/// Returns all installed plugins by types
#[msg(query)]
fn plugins(&self, ctx: QueryCtx) -> Result<PluginListResponse, StdError>;
fn plugins(
&self,
ctx: QueryCtx,
ty: PluginPermission,
start_after: Option<String>,
limit: Option<u32>,
) -> Result<PluginListResponse, StdError>;

#[msg(exec)]
fn plugin_execute(
Expand Down
5 changes: 2 additions & 3 deletions packages/vectis/src/types/plugin/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use super::types::*;

#[cw_serde]
pub struct PluginListResponse {
pub exec: Vec<(String, PluginInfo)>,
pub pre_tx: Vec<(String, PluginInfo)>,
pub post_tx_hooks: Vec<(String, PluginInfo)>,
pub ty: PluginPermission,
pub plugins: Vec<(String, PluginInfo)>,
}

#[cw_serde]
Expand Down

0 comments on commit 3e0b48f

Please sign in to comment.