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

update limit for number of creator dao tokens per user #461

Merged
merged 3 commits into from
Nov 14, 2024
Merged
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
27 changes: 15 additions & 12 deletions src/canister/individual_user_template/src/api/cdao/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,17 @@ use ic_nns_governance::pb::v1::{
SettleNeuronsFundParticipationRequest, SettleNeuronsFundParticipationResponse,
};
use shared_utils::{
canister_specific::individual_user_template::{
consts::CDAO_TOKEN_LIMIT,
types::{
cdao::{AirdropInfo, DeployedCdaoCanisters},
error::CdaoDeployError,
session::SessionType,
},
canister_specific::individual_user_template::types::{
cdao::{AirdropInfo, DeployedCdaoCanisters},
error::CdaoDeployError,
session::SessionType,
},
common::types::known_principal::KnownPrincipalType,
constant::{
NNS_LEDGER_CANISTER_ID, SNS_TOKEN_ARCHIVE_MODULE_HASH, SNS_TOKEN_GOVERNANCE_MODULE_HASH,
SNS_TOKEN_INDEX_MODULE_HASH, SNS_TOKEN_LEDGER_MODULE_HASH, SNS_TOKEN_ROOT_MODULE_HASH,
SNS_TOKEN_SWAP_MODULE_HASH, USER_SNS_CANISTER_INITIAL_CYCLES,
MAX_LIMIT_FOR_CREATOR_DAO_SNS_TOKEN, NNS_LEDGER_CANISTER_ID, SNS_TOKEN_ARCHIVE_MODULE_HASH,
SNS_TOKEN_GOVERNANCE_MODULE_HASH, SNS_TOKEN_INDEX_MODULE_HASH,
SNS_TOKEN_LEDGER_MODULE_HASH, SNS_TOKEN_ROOT_MODULE_HASH, SNS_TOKEN_SWAP_MODULE_HASH,
USER_SNS_CANISTER_INITIAL_CYCLES,
},
};

Expand Down Expand Up @@ -113,11 +111,16 @@ async fn deploy_cdao_sns(
let (registered, limit_hit) = CANISTER_DATA.with(|cdata| {
let cdata = cdata.borrow();
let registered = matches!(cdata.session_type, Some(SessionType::RegisteredSession));
(registered, cdata.cdao_canisters.len() == CDAO_TOKEN_LIMIT)
(
registered,
cdata.cdao_canisters.len() >= MAX_LIMIT_FOR_CREATOR_DAO_SNS_TOKEN,
)
});

if limit_hit {
return Err(CdaoDeployError::TokenLimit(CDAO_TOKEN_LIMIT));
return Err(CdaoDeployError::TokenLimit(
MAX_LIMIT_FOR_CREATOR_DAO_SNS_TOKEN,
));
}

// Alloting 0.5T more to the user canister to be on safer side while deploying canisters
Expand Down
154 changes: 4 additions & 150 deletions src/lib/integration_tests/tests/creator_dao/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pub mod test_number_of_creator_tokens;
pub mod types;
pub mod utils;

use ic_ledger_types::Memo;
use ic_sns_governance::pb::v1::governance::Version;
Expand All @@ -24,6 +26,7 @@ use shared_utils::constant::{
use std::time::{Duration, UNIX_EPOCH};
use std::{collections::HashMap, fmt::Debug, str::FromStr, time::SystemTime, vec};
use test_utils::setup::test_constants::get_mock_user_bob_principal_id;
use utils::setup_sns_w_canister_for_creator_dao;

use candid::{encode_args, CandidType, Decode, Encode, Nat, Principal};
use ic_base_types::PrincipalId;
Expand Down Expand Up @@ -186,158 +189,9 @@ fn creator_dao_tests() {
.unwrap();

let alice_initial_cycle_balance = pocket_ic.cycle_balance(alice_canister_id);

let sns_wasm_w_canister_wasm = include_bytes!("../../../../../wasms/sns-wasm-canister.wasm");
let sns_wasm_w_canister_id = Principal::from_text(SNS_WASM_W_PRINCIPAL_ID).unwrap();

let _ = pocket_ic.create_canister_with_id(
Some(super_admin),
None,
Principal::from_text(SNS_WASM_W_PRINCIPAL_ID).unwrap(),
);

let sns_wasm_canister_init_payload = SnsWasmCanisterInitPayload {
sns_subnet_ids: vec![],
access_controls_enabled: false,
allowed_principals: vec![],
};

pocket_ic.install_canister(
sns_wasm_w_canister_id,
sns_wasm_w_canister_wasm.to_vec(),
Encode!(&sns_wasm_canister_init_payload).unwrap(),
Some(super_admin),
);

let res = pocket_ic
.update_call(
sns_wasm_w_canister_id,
super_admin,
"add_wasm",
candid::encode_one(add_wasm(
include_bytes!("../../../../../wasms/root.wasm.gz"),
1,
))
.unwrap(),
)
.map(|res| {
let response: AddWasmResultRecord = match res {
WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(),
_ => panic!("\n🛑 get requester principals canister id failed\n"),
};
response
})
.unwrap();
ic_cdk::println!("🧪 Result: {:?}", res);

let res = pocket_ic
.update_call(
sns_wasm_w_canister_id,
super_admin,
"add_wasm",
candid::encode_one(add_wasm(
include_bytes!("../../../../../wasms/governance.wasm.gz"),
2,
))
.unwrap(),
)
.map(|res| {
let response: AddWasmResultRecord = match res {
WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(),
_ => panic!("\n🛑 get requester principals canister id failed\n"),
};
response
})
.unwrap();
ic_cdk::println!("🧪 Result: {:?}", res);

let res = pocket_ic
.update_call(
sns_wasm_w_canister_id,
super_admin,
"add_wasm",
candid::encode_one(add_wasm(
include_bytes!("../../../../../wasms/ledger.wasm.gz"),
3,
))
.unwrap(),
)
.map(|res| {
let response: AddWasmResultRecord = match res {
WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(),
_ => panic!("\n🛑 get requester principals canister id failed\n"),
};
response
})
.unwrap();
ic_cdk::println!("🧪 Result: {:?}", res);

let res = pocket_ic
.update_call(
sns_wasm_w_canister_id,
super_admin,
"add_wasm",
candid::encode_one(add_wasm(
include_bytes!("../../../../../wasms/swap.wasm.gz"),
4,
))
.unwrap(),
)
.map(|res| {
let response: AddWasmResultRecord = match res {
WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(),
_ => panic!("\n🛑 get requester principals canister id failed\n"),
};
response
})
.unwrap();
ic_cdk::println!("🧪 Result: {:?}", res);

let res = pocket_ic
.update_call(
sns_wasm_w_canister_id,
super_admin,
"add_wasm",
candid::encode_one(add_wasm(
include_bytes!("../../../../../wasms/archive.wasm.gz"),
5,
))
.unwrap(),
)
.map(|res| {
let response: AddWasmResultRecord = match res {
WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(),
_ => panic!("\n🛑 get requester principals canister id failed\n"),
};
response
})
.unwrap();
ic_cdk::println!("🧪 Result: {:?}", res);

let res = pocket_ic
.update_call(
sns_wasm_w_canister_id,
super_admin,
"add_wasm",
candid::encode_one(add_wasm(
include_bytes!("../../../../../wasms/index.wasm.gz"),
6,
))
.unwrap(),
)
.map(|res| {
let response: AddWasmResultRecord = match res {
WasmResult::Reply(payload) => candid::decode_one(&payload).unwrap(),
_ => panic!("\n🛑 get requester principals canister id failed\n"),
};
response
})
.unwrap();
ic_cdk::println!("🧪 Result: {:?}", res);

for _ in 0..50 {
pocket_ic.tick();
}
setup_sns_w_canister_for_creator_dao(&pocket_ic, super_admin);

let res = pocket_ic
.update_call(
Expand Down
Loading