Skip to content

Commit 06a9f6c

Browse files
committed
test: add unit test to ensure only contract admin can deploy all contracts
1 parent 78ce1d6 commit 06a9f6c

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

apps/smart-contracts/contracts/deployer/src/deployer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ impl DeployerContract {
201201
/// 4. Transfer token-sale admin to params.token_sale_admin via `set_admin`
202202
/// 5. Deploy vault-contract pointing to the participation-token
203203
pub fn deploy_all(env: Env, signer: Address, params: DeployAllParams) -> DeployedContracts {
204+
let admin: Address = env.storage().instance().get(&DataKey::Admin).unwrap();
205+
if signer != admin {
206+
panic!("Signer must be the contract admin");
207+
}
204208
signer.require_auth();
205209

206210
let participation_token_wasm: BytesN<32> = env

apps/smart-contracts/contracts/deployer/src/test.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,45 @@ fn test_deploy_all() {
149149
assert_ne!(result.token_sale, result.vault_contract);
150150
}
151151

152+
#[test]
153+
#[should_panic(expected = "Signer must be the contract admin")]
154+
fn test_deploy_all_rejects_non_admin_signer() {
155+
let env = Env::default();
156+
env.mock_all_auths();
157+
158+
let admin = Address::generate(&env);
159+
let non_admin = Address::generate(&env);
160+
let escrow_contract = Address::generate(&env);
161+
let vault_admin = Address::generate(&env);
162+
let token_sale_admin = Address::generate(&env);
163+
let usdc = Address::generate(&env);
164+
let deployer = setup_deployer(&env, &admin);
165+
166+
let token_sale_salt = BytesN::from_array(&env, &[10u8; 32]);
167+
let participation_salt = BytesN::from_array(&env, &[11u8; 32]);
168+
let vault_salt = BytesN::from_array(&env, &[12u8; 32]);
169+
170+
deployer.deploy_all(
171+
&non_admin,
172+
&DeployAllParams {
173+
participation_salt,
174+
token_sale_salt,
175+
vault_salt,
176+
token_name: String::from_str(&env, "CampaignToken"),
177+
token_symbol: String::from_str(&env, "CAMP"),
178+
decimal: 7u32,
179+
escrow_contract,
180+
vault_admin,
181+
vault_enabled: true,
182+
roi_percentage: 5i128,
183+
usdc,
184+
token_sale_admin,
185+
hard_cap: 1_000_000i128,
186+
max_per_investor: 10_000i128,
187+
}
188+
);
189+
}
190+
152191
#[test]
153192
fn test_update_wasm() {
154193
let env = Env::default();

0 commit comments

Comments
 (0)