Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pre_validate #109

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ overflow-checks = true
anyhow = "1.0.86"
cosmwasm-std = { version = "2.1.3" }
cosmwasm-schema = "2.1.3"
cosmwasm-crypto = "2.1.3"
cw-denom = { package = "cw-denom", git = "https://github.com/DA0-DA0/dao-contracts", branch = "cw-std-2" }
cw-ownable = "2.0.0"
cw-utils = "2.0.0"
Expand Down
1 change: 0 additions & 1 deletion local-interchaintest/examples/manager_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ fn main() -> Result<(), Box<dyn Error>> {
&authorization_addr,
format!("update_library_{}", library_1.get_library_id()).as_str(),
);

contract_execute(
test_ctx
.get_request_builder()
Expand Down
109 changes: 109 additions & 0 deletions local-interchaintest/examples/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
use std::error::Error;

use local_interchaintest::utils::{
manager::{setup_manager, use_manager_init, SPLITTER_NAME},
LOGS_FILE_PATH, NEUTRON_CONFIG_FILE, VALENCE_ARTIFACTS_PATH,
};
use localic_utils::{
ConfigChainBuilder, TestContextBuilder, GAIA_CHAIN_NAME, LOCAL_IC_API_URL,
NEUTRON_CHAIN_ADMIN_ADDR, NEUTRON_CHAIN_NAME,
};
use valence_authorization_utils::{
authorization_message::{Message, MessageDetails, MessageType, ParamRestriction},
builders::{AtomicFunctionBuilder, AtomicSubroutineBuilder, AuthorizationBuilder},
};
use valence_library_utils::denoms::UncheckedDenom;
use valence_program_manager::{
account::{AccountInfo, AccountType},
library::{LibraryConfig, LibraryInfo},
program_config_builder::ProgramConfigBuilder,
};
use valence_splitter_library::msg::{UncheckedSplitAmount, UncheckedSplitConfig};

fn main() -> Result<(), Box<dyn Error>> {
env_logger::init();

let mut test_ctx = TestContextBuilder::default()
.with_unwrap_raw_logs(true)
.with_api_url(LOCAL_IC_API_URL)
.with_artifacts_dir(VALENCE_ARTIFACTS_PATH)
.with_chain(ConfigChainBuilder::default_neutron().build()?)
.with_log_file_path(LOGS_FILE_PATH)
.build()?;

setup_manager(
&mut test_ctx,
NEUTRON_CONFIG_FILE,
vec![GAIA_CHAIN_NAME],
vec![SPLITTER_NAME],
)?;

let mut builder = ProgramConfigBuilder::new(NEUTRON_CHAIN_ADMIN_ADDR.to_string());
let neutron_domain =
valence_program_manager::domain::Domain::CosmosCosmwasm(NEUTRON_CHAIN_NAME.to_string());

let account_1 = builder.add_account(AccountInfo::new(
"test_1".to_string(),
&neutron_domain,
AccountType::default(),
));
let account_2 = builder.add_account(AccountInfo::new(
"test_2".to_string(),
&neutron_domain,
AccountType::default(),
));

let library_config = valence_splitter_library::msg::LibraryConfig {
input_addr: account_1.clone(),
splits: vec![UncheckedSplitConfig {
denom: UncheckedDenom::Native("test".to_string()),
account: account_2.clone(),
amount: UncheckedSplitAmount::FixedAmount(1000_u128.into()),
}],
};

let library_1 = builder.add_library(LibraryInfo::new(
"test_splitter".to_string(),
&neutron_domain,
LibraryConfig::ValenceSplitterLibrary(library_config.clone()),
));

builder.add_link(&library_1, vec![&account_1], vec![&account_2]);

let action_label = "swap";
builder.add_authorization(
AuthorizationBuilder::new()
.with_label(action_label)
.with_subroutine(
AtomicSubroutineBuilder::new()
.with_function(
AtomicFunctionBuilder::new()
.with_contract_address(library_1.clone())
.with_message_details(MessageDetails {
message_type: MessageType::CosmwasmExecuteMsg,
message: Message {
name: "process_function".to_string(),
params_restrictions: Some(vec![
ParamRestriction::MustBeIncluded(vec![
"process_function".to_string(),
"split".to_string(),
]),
]),
},
})
.build(),
)
.build(),
)
.build(),
);

let mut program_config = builder.build();
let mut program_config2 = program_config.clone();

use_manager_init(&mut program_config)?;

use_manager_init(&mut program_config2)?;

Ok(())
}
12 changes: 6 additions & 6 deletions packages/valence-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub fn manager_impl_library_configs(_attr: TokenStream, input: TokenStream) -> T
let mut update_msg_matches = Vec::new();
let mut replace_config_matches = Vec::new();
let mut get_instantiate_msg_matches = Vec::new();
let mut per_validate_matches = Vec::new();
let mut pre_validate_matches = Vec::new();
let mut get_account_ids_matches = Vec::new();

for variant in variants {
Expand All @@ -181,7 +181,7 @@ pub fn manager_impl_library_configs(_attr: TokenStream, input: TokenStream) -> T
get_instantiate_msg_matches.push(quote! {
#enum_ident::None => return Err(LibraryError::NoLibraryConfig)
});
per_validate_matches.push(quote! {
pre_validate_matches.push(quote! {
#enum_ident::None => Err(LibraryError::NoLibraryConfig)
});
get_account_ids_matches.push(quote! {
Expand Down Expand Up @@ -238,8 +238,8 @@ pub fn manager_impl_library_configs(_attr: TokenStream, input: TokenStream) -> T
})
});

// Add per_validate_config match
per_validate_matches.push(quote! {
// Add pre_validate_config match
pre_validate_matches.push(quote! {
#enum_ident::#variant_ident(config) => {
config.pre_validate(api)?;
Ok(())
Expand Down Expand Up @@ -310,9 +310,9 @@ pub fn manager_impl_library_configs(_attr: TokenStream, input: TokenStream) -> T
.map_err(LibraryError::SerdeJsonError)
}

pub fn per_validate_config(&self, api: &dyn cosmwasm_std::Api) -> LibraryResult<()> {
pub fn pre_validate_config(&self, api: &dyn cosmwasm_std::Api) -> LibraryResult<()> {
match self {
#(#per_validate_matches,)*
#(#pre_validate_matches,)*
}
}

Expand Down
30 changes: 17 additions & 13 deletions program-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ repository = { workspace = true }
[dependencies]
cosmwasm-std = { workspace = true }
cosmwasm-schema = { workspace = true }
cosmwasm-crypto = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
thiserror = { workspace = true }
anyhow = { workspace = true }
cw-ownable = { workspace = true }
env_logger = { workspace = true }
log = { workspace = true }
rand_core = "0.6.4"

valence-library-utils = { workspace = true }
valence-macros = { workspace = true }
Expand All @@ -25,19 +27,21 @@ valence-processor-utils = { workspace = true }
valence-program-registry-utils = { workspace = true }
valence-library-base = { workspace = true }

valence-splitter-library = { workspace = true }
valence-reverse-splitter-library = { workspace = true }
valence-astroport-lper = { workspace = true }
valence-astroport-withdrawer = { workspace = true }
valence-account-utils = { workspace = true }
valence-authorization = { workspace = true }
valence-processor = { workspace = true }
valence-program-registry = { workspace = true }
valence-forwarder-library = { workspace = true }
valence-osmosis-gamm-lper = { workspace = true }
valence-osmosis-gamm-withdrawer = { workspace = true }
valence-osmosis-cl-lper = { workspace = true }
valence-osmosis-cl-withdrawer = { workspace = true }
valence-splitter-library = { workspace = true }
valence-reverse-splitter-library = { workspace = true }
valence-astroport-lper = { workspace = true }
valence-astroport-withdrawer = { workspace = true }
valence-account-utils = { workspace = true }
valence-authorization = { workspace = true }
valence-processor = { workspace = true }
valence-program-registry = { workspace = true }
valence-forwarder-library = { workspace = true }
valence-osmosis-gamm-lper = { workspace = true }
valence-osmosis-gamm-withdrawer = { workspace = true }
valence-osmosis-cl-lper = { workspace = true }
valence-osmosis-cl-withdrawer = { workspace = true }
valence-generic-ibc-transfer-library = { workspace = true }
valence-neutron-ibc-transfer-library = { workspace = true }

tokio = { workspace = true }
aho-corasick = "1.1"
Expand Down
Loading
Loading