Skip to content

Commit

Permalink
Merge pull request #3806 from anoma/bat/validate-nam-masp-params
Browse files Browse the repository at this point in the history
Validate genesis NAM MaspParams
  • Loading branch information
mergify[bot] authored Sep 12, 2024
2 parents d32e856 + ea5404a commit b0b41dc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- When calling init chain, we now verify that the native token alias has masp
parameters set. ([\#3806](https://github.com/anoma/namada/pull/3806))
25 changes: 25 additions & 0 deletions crates/node/src/shell/init_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ enum Panic {
"Config for token '{0}' with configured balance not found in genesis"
)]
MissingTokenConfig(String),
#[error("The MASP parameters for the native token is missing")]
MissingMaspParams,
#[error("Failed to read wasm {0} with reason: {1}")]
ReadingWasm(String, String),
}
Expand Down Expand Up @@ -446,13 +448,17 @@ where
/// Init genesis token accounts
fn init_token_accounts(&mut self, genesis: &genesis::chain::Finalized) {
let mut token_map = BTreeMap::new();
let native_alias = &genesis.parameters.parameters.native_token;
for (alias, token) in &genesis.tokens.token {
tracing::debug!("Initializing token {alias}");

let FinalizedTokenConfig {
address,
config: TokenConfig { denom, masp_params },
} = token;
if alias == native_alias && masp_params.is_none() {
self.register_err(Panic::MissingMaspParams);
}
// associate a token with its denomination.
write_denom(&mut self.state, address, *denom).unwrap();
namada_sdk::token::write_params(
Expand Down Expand Up @@ -1211,4 +1217,23 @@ mod test {
)];
assert_eq!(expected, initializer.warnings);
}

#[test]
fn test_dry_run_native_token_masp_params() {
let (mut shell, _x, _y, _z) = TestShell::new_at_height(0);
shell.wasm_dir = PathBuf::new();
let mut genesis = genesis::make_dev_genesis(1, &shell.base_dir);
let mut initializer = InitChainValidation::new(&mut shell, true);
genesis
.tokens
.token
.get_mut(&genesis.parameters.parameters.native_token)
.expect("Test failed")
.config
.masp_params = None;
initializer.init_token_accounts(&genesis);
let [panic]: [Panic; 1] =
initializer.panics.clone().try_into().expect("Test failed");
assert_eq!(panic, Panic::MissingMaspParams);
}
}

0 comments on commit b0b41dc

Please sign in to comment.