diff --git a/contracts/main/voice/src/contract.rs b/contracts/main/voice/src/contract.rs index ea90146..15996fb 100644 --- a/contracts/main/voice/src/contract.rs +++ b/contracts/main/voice/src/contract.rs @@ -41,6 +41,9 @@ pub fn instantiate( if contract_addr_len == 0 { return Err(ContractError::ContractAddrLenCantBeZero); } + if contract_addr_len > 32 { + return Err(ContractError::ContractAddrLenCantBeGreaterThan32); + } PROXY_CODE_ID.save(deps.storage, &msg.proxy_code_id.u64())?; BLOCK_MAX_GAS.save(deps.storage, &msg.block_max_gas.u64())?; @@ -222,6 +225,9 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result 32 { + return Err(ContractError::ContractAddrLenCantBeGreaterThan32); + } // update the proxy code ID, block max gas, and contract addr len PROXY_CODE_ID.save(deps.storage, &proxy_code_id.u64())?; diff --git a/contracts/main/voice/src/error.rs b/contracts/main/voice/src/error.rs index 6e65290..920501a 100644 --- a/contracts/main/voice/src/error.rs +++ b/contracts/main/voice/src/error.rs @@ -27,4 +27,7 @@ pub enum ContractError { #[error("Contract address length can't be zero")] ContractAddrLenCantBeZero, + + #[error("Contract address length can't be greater than 32")] + ContractAddrLenCantBeGreaterThan32, } diff --git a/contracts/main/voice/src/suite_tests/suite.rs b/contracts/main/voice/src/suite_tests/suite.rs index c899d7f..f311d55 100644 --- a/contracts/main/voice/src/suite_tests/suite.rs +++ b/contracts/main/voice/src/suite_tests/suite.rs @@ -73,6 +73,11 @@ impl SuiteBuilder { self.instantiate.proxy_code_id = code_id; self } + + pub fn with_contract_addr_len(mut self, len: Option) -> Self { + self.instantiate.contract_addr_len = len; + self + } } impl Suite { diff --git a/contracts/main/voice/src/suite_tests/tests.rs b/contracts/main/voice/src/suite_tests/tests.rs index df2e276..68d9e95 100644 --- a/contracts/main/voice/src/suite_tests/tests.rs +++ b/contracts/main/voice/src/suite_tests/tests.rs @@ -79,6 +79,22 @@ fn test_gas_validation() { .build(); } +#[test] +#[should_panic] +fn test_contract_addr_len_min_validation() { + SuiteBuilder::default() + .with_contract_addr_len(Some(0)) + .build(); +} + +#[test] +#[should_panic] +fn test_contract_addr_len_max_validation() { + SuiteBuilder::default() + .with_contract_addr_len(Some(33)) + .build(); +} + #[test] fn test_migrate_validation() { let mut suite = SuiteBuilder::default().build(); @@ -98,4 +114,20 @@ fn test_migrate_validation() { .unwrap(); assert_eq!(err, ContractError::GasLimitsMismatch); + + let err = suite + .update(Addr::unchecked(CREATOR_ADDR), 1, 110_000, 0) + .unwrap_err() + .downcast::() + .unwrap(); + + assert_eq!(err, ContractError::ContractAddrLenCantBeZero); + + let err = suite + .update(Addr::unchecked(CREATOR_ADDR), 1, 110_000, 33) + .unwrap_err() + .downcast::() + .unwrap(); + + assert_eq!(err, ContractError::ContractAddrLenCantBeGreaterThan32); }