Skip to content

Commit 29e2eb0

Browse files
committed
modified tokenfactory msg validation according to the new types
1 parent 3f5318d commit 29e2eb0

File tree

6 files changed

+79
-14
lines changed

6 files changed

+79
-14
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contracts/dao/neutron-chain-manager/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ serde = { version = "1.0.175", default-features = false, features = ["derive"] }
2929
serde_with = { version = "3.7.0", features = ["json"] }
3030
thiserror = { version = "1.0" }
3131

32-
neutron-std = { git = "https://github.com/neutron-org/neutron-std.git", branch = "main" }
32+
neutron-std = { git = "https://github.com/neutron-org/neutron-std.git", rev = "434d24d568a6f6ccb5db6bcf0729b715a1104b5e" }
3333
neutron-sdk = "0.11.0"
3434
serde-json-wasm = "1.0.1"
3535
prost = "0.9.0"

contracts/dao/neutron-chain-manager/src/contract.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,13 @@ fn check_tokenfactory_update_msg_params(
350350
return Err(ContractError::Unauthorized {});
351351
}
352352

353+
if tokenfactory_params.track_before_send_gas_limit
354+
!= msg_update_params.track_before_send_gas_limit
355+
&& !tokenfactory_update_param_permission.track_before_send_gas_limit
356+
{
357+
return Err(ContractError::Unauthorized {});
358+
}
359+
353360
Ok(())
354361
}
355362

contracts/dao/neutron-chain-manager/src/msg.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ impl Strategy {
141141
denom_creation_gas_consume: true,
142142
fee_collector_address: true,
143143
whitelisted_hooks: true,
144+
track_before_send_gas_limit: true,
144145
}),
145146
Strategy::AllowOnly(permissions) => {
146147
match permissions.get(&PermissionType::UpdateTokenfactoryParamsPermission) {
@@ -355,6 +356,7 @@ pub struct TokenfactoryUpdateParamsPermission {
355356
pub denom_creation_gas_consume: bool,
356357
pub fee_collector_address: bool,
357358
pub whitelisted_hooks: bool,
359+
pub track_before_send_gas_limit: bool,
358360
}
359361

360362
#[cw_serde]

contracts/dao/neutron-chain-manager/src/testing/mock_querier.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ impl WasmMockQuerier {
6868
denom_creation_gas_consume: None,
6969
fee_collector_address: "test_addr".to_string(),
7070
whitelisted_hooks: vec![],
71+
track_before_send_gas_limit: 123456,
7172
}),
7273
}
7374
.to_proto_bytes();

contracts/dao/neutron-chain-manager/src/testing/tests.rs

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ pub fn test_execute_execute_message_update_params_tokenfactory_authorized() {
465465
admin_proposal: AdminProposal::ProposalExecuteMessage(ProposalExecuteMessage {
466466
message: r#"{"@type":"/osmosis.tokenfactory.v1beta1.MsgUpdateParams",
467467
"authority":"neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z",
468-
"params": {"denom_creation_fee": [{"denom": "untrn", "amount": "100"}], "denom_creation_gas_consume": "100", "fee_collector_address": "neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z", "whitelisted_hooks": [{"code_id": "1", "denom_creator": "neutron1yw4xvtc43me9scqfr2jr2gzvcxd3a9y4eq7gaukreugw2yd2f8ts8g30fq"}]}}"#
468+
"params": {"denom_creation_fee": [{"denom": "untrn", "amount": "100"}], "denom_creation_gas_consume": "100", "fee_collector_address": "neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z", "whitelisted_hooks": [{"code_id": "1", "denom_creator": "neutron1yw4xvtc43me9scqfr2jr2gzvcxd3a9y4eq7gaukreugw2yd2f8ts8g30fq"}],"track_before_send_gas_limit":10000}}"#
469469
.to_string(),
470470
}),
471471
});
@@ -495,6 +495,7 @@ pub fn test_execute_execute_message_update_params_tokenfactory_authorized() {
495495
denom_creation_gas_consume: true,
496496
fee_collector_address: true,
497497
whitelisted_hooks: true,
498+
track_before_send_gas_limit: true,
498499
},
499500
)]),
500501
)
@@ -511,7 +512,7 @@ pub fn test_execute_execute_message_update_params_tokenfactory_unauthorized_deno
511512
admin_proposal: AdminProposal::ProposalExecuteMessage(ProposalExecuteMessage {
512513
message: r#"{"@type":"/osmosis.tokenfactory.v1beta1.MsgUpdateParams",
513514
"authority":"neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z",
514-
"params": {"denom_creation_fee": [{"denom": "untrn", "amount": "100"}], "denom_creation_gas_consume": "100", "fee_collector_address": "neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z", "whitelisted_hooks": [{"code_id": "1", "denom_creator": "neutron1yw4xvtc43me9scqfr2jr2gzvcxd3a9y4eq7gaukreugw2yd2f8ts8g30fq"}]}}"#
515+
"params": {"denom_creation_fee": [{"denom": "untrn", "amount": "100"}], "denom_creation_gas_consume": "100", "fee_collector_address": "neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z", "whitelisted_hooks": [{"code_id": "1", "denom_creator": "neutron1yw4xvtc43me9scqfr2jr2gzvcxd3a9y4eq7gaukreugw2yd2f8ts8g30fq"}],"track_before_send_gas_limit":10000}}"#
515516
.to_string(),
516517
}),
517518
});
@@ -541,6 +542,7 @@ pub fn test_execute_execute_message_update_params_tokenfactory_unauthorized_deno
541542
denom_creation_gas_consume: true,
542543
fee_collector_address: true,
543544
whitelisted_hooks: true,
545+
track_before_send_gas_limit: true,
544546
},
545547
)]),
546548
)
@@ -560,7 +562,7 @@ pub fn test_execute_execute_message_update_params_tokenfactory_unauthorized_deno
560562
admin_proposal: AdminProposal::ProposalExecuteMessage(ProposalExecuteMessage {
561563
message: r#"{"@type":"/osmosis.tokenfactory.v1beta1.MsgUpdateParams",
562564
"authority":"neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z",
563-
"params": {"denom_creation_fee": [{"denom": "untrn", "amount": "100"}], "denom_creation_gas_consume": "100", "fee_collector_address": "neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z", "whitelisted_hooks": [{"code_id": "1", "denom_creator": "neutron1yw4xvtc43me9scqfr2jr2gzvcxd3a9y4eq7gaukreugw2yd2f8ts8g30fq"}]}}"#
565+
"params": {"denom_creation_fee": [{"denom": "untrn", "amount": "100"}], "denom_creation_gas_consume": "100", "fee_collector_address": "neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z", "whitelisted_hooks": [{"code_id": "1", "denom_creator": "neutron1yw4xvtc43me9scqfr2jr2gzvcxd3a9y4eq7gaukreugw2yd2f8ts8g30fq"}],"track_before_send_gas_limit":10000}}"#
564566
.to_string(),
565567
}),
566568
});
@@ -590,6 +592,7 @@ pub fn test_execute_execute_message_update_params_tokenfactory_unauthorized_deno
590592
denom_creation_gas_consume: false,
591593
fee_collector_address: true,
592594
whitelisted_hooks: true,
595+
track_before_send_gas_limit: true,
593596
},
594597
)]),
595598
)
@@ -609,7 +612,7 @@ pub fn test_execute_execute_message_update_params_tokenfactory_unauthorized_fee_
609612
admin_proposal: AdminProposal::ProposalExecuteMessage(ProposalExecuteMessage {
610613
message: r#"{"@type":"/osmosis.tokenfactory.v1beta1.MsgUpdateParams",
611614
"authority":"neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z",
612-
"params": {"denom_creation_fee": [{"denom": "untrn", "amount": "100"}], "denom_creation_gas_consume": "100", "fee_collector_address": "neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z", "whitelisted_hooks": [{"code_id": "1", "denom_creator": "neutron1yw4xvtc43me9scqfr2jr2gzvcxd3a9y4eq7gaukreugw2yd2f8ts8g30fq"}]}}"#
615+
"params": {"denom_creation_fee": [{"denom": "untrn", "amount": "100"}], "denom_creation_gas_consume": "100", "fee_collector_address": "neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z", "whitelisted_hooks": [{"code_id": "1", "denom_creator": "neutron1yw4xvtc43me9scqfr2jr2gzvcxd3a9y4eq7gaukreugw2yd2f8ts8g30fq"}],"track_before_send_gas_limit":10000}}"#
613616
.to_string(),
614617
}),
615618
});
@@ -639,6 +642,7 @@ pub fn test_execute_execute_message_update_params_tokenfactory_unauthorized_fee_
639642
denom_creation_gas_consume: true,
640643
fee_collector_address: false,
641644
whitelisted_hooks: true,
645+
track_before_send_gas_limit: true,
642646
},
643647
)]),
644648
)
@@ -657,7 +661,7 @@ pub fn test_execute_execute_message_update_params_tokenfactory_unauthorized_whit
657661
admin_proposal: AdminProposal::ProposalExecuteMessage(ProposalExecuteMessage {
658662
message: r#"{"@type":"/osmosis.tokenfactory.v1beta1.MsgUpdateParams",
659663
"authority":"neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z",
660-
"params": {"denom_creation_fee": [{"denom": "untrn", "amount": "100"}], "denom_creation_gas_consume": "100", "fee_collector_address": "neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z", "whitelisted_hooks": [{"code_id": "1", "denom_creator": "neutron1yw4xvtc43me9scqfr2jr2gzvcxd3a9y4eq7gaukreugw2yd2f8ts8g30fq"}]}}"#
664+
"params": {"denom_creation_fee": [{"denom": "untrn", "amount": "100"}], "denom_creation_gas_consume": "100", "fee_collector_address": "neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z", "whitelisted_hooks": [{"code_id": "1", "denom_creator": "neutron1yw4xvtc43me9scqfr2jr2gzvcxd3a9y4eq7gaukreugw2yd2f8ts8g30fq"}],"track_before_send_gas_limit":10000}}"#
661665
.to_string(),
662666
}),
663667
});
@@ -687,6 +691,57 @@ pub fn test_execute_execute_message_update_params_tokenfactory_unauthorized_whit
687691
denom_creation_gas_consume: true,
688692
fee_collector_address: true,
689693
whitelisted_hooks: false,
694+
track_before_send_gas_limit: true,
695+
},
696+
)]),
697+
)
698+
.unwrap();
699+
700+
let info = message_info(&Addr::unchecked("addr1"), &[]);
701+
let err = execute_execute_messages(deps.as_mut(), info.clone(), vec![msg]).unwrap_err();
702+
assert_eq!(err, Unauthorized {});
703+
}
704+
705+
/// Checks that you can't change the track_before_send_gas_limit if you don't have the permission to do so
706+
/// (new style parameter changes).
707+
#[test]
708+
pub fn test_execute_execute_message_update_params_tokenfactory_unauthorized_track_before_send_gas_limit(
709+
) {
710+
let msg = CosmosMsg::Custom(NeutronMsg::SubmitAdminProposal {
711+
admin_proposal: AdminProposal::ProposalExecuteMessage(ProposalExecuteMessage {
712+
message: r#"{"@type":"/osmosis.tokenfactory.v1beta1.MsgUpdateParams",
713+
"authority":"neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z",
714+
"params": {"denom_creation_fee": [{"denom": "untrn", "amount": "100"}], "denom_creation_gas_consume": "100", "fee_collector_address": "neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z", "whitelisted_hooks": [{"code_id": "1", "denom_creator": "neutron1yw4xvtc43me9scqfr2jr2gzvcxd3a9y4eq7gaukreugw2yd2f8ts8g30fq"}],"track_before_send_gas_limit":10000}}"#
715+
.to_string(),
716+
}),
717+
});
718+
719+
let mut deps = mock_dependencies();
720+
let env = mock_env();
721+
let info = message_info(&Addr::unchecked("neutron_dao_address"), &[]);
722+
723+
instantiate(
724+
deps.as_mut(),
725+
env.clone(),
726+
info.clone(),
727+
InstantiateMsg {
728+
initial_strategy_address: Addr::unchecked("neutron_dao_address".to_string()),
729+
},
730+
)
731+
.unwrap();
732+
733+
let info = message_info(&Addr::unchecked("neutron_dao_address"), &[]);
734+
execute_add_strategy(
735+
deps.as_mut(),
736+
info.clone(),
737+
Addr::unchecked("addr1".to_string()),
738+
StrategyMsg::AllowOnly(vec![UpdateTokenfactoryParamsPermission(
739+
TokenfactoryUpdateParamsPermission {
740+
denom_creation_fee: true,
741+
denom_creation_gas_consume: true,
742+
fee_collector_address: true,
743+
whitelisted_hooks: true,
744+
track_before_send_gas_limit: false,
690745
},
691746
)]),
692747
)

0 commit comments

Comments
 (0)