Skip to content

Commit

Permalink
use hard-coded cycles ledger canister id
Browse files Browse the repository at this point in the history
  • Loading branch information
sesi200 committed Jan 9, 2024
1 parent 5e2c9f5 commit 280868e
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 43 deletions.
30 changes: 15 additions & 15 deletions e2e/tests-dfx/cycles-ledger.bash
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ add_cycles_ledger_canisters_to_project() {
}

deploy_cycles_ledger() {
assert_command dfx deploy cycles-ledger --specified-id "um5iw-rqaaa-aaaaq-qaaba-cai"
assert_command dfx deploy cycles-ledger --specified-id "um5iw-rqaaa-aaaaq-qaaba-cai" --argument '(variant { Init = record { max_transactions_per_request = 100; index_id = null; } })'
assert_command dfx deploy cycles-depositor --argument "(record {ledger_id = principal \"$(dfx canister id cycles-ledger)\"})" --with-cycles 10000000000000 --specified-id "ul4oc-4iaaa-aaaaq-qaabq-cai"
}

Expand Down Expand Up @@ -446,58 +446,58 @@ current_time_nanoseconds() {
dfx identity use alice
export DFX_DISABLE_AUTO_WALLET=1
t=$(current_time_nanoseconds)
assert_command dfx canister create e2e_project_backend --with-cycles 1T --created-at-time "$t" --cycles-ledger-canister-id "$CYCLES_LEDGER_ID"
assert_command dfx canister create e2e_project_backend --with-cycles 1T --created-at-time "$t"
assert_command dfx canister id e2e_project_backend
E2E_PROJECT_BACKEND_CANISTER_ID=$(dfx canister id e2e_project_backend)
assert_command dfx cycles balance --cycles-ledger-canister-id "$CYCLES_LEDGER_ID" --precise
assert_command dfx cycles balance --precise
assert_eq "12399900000000 cycles."
# forget about canister. If --created-at-time is a valid idempotency key we should end up with the same canister id
rm .dfx/local/canister_ids.json
assert_command dfx canister create e2e_project_backend --with-cycles 1T --created-at-time "$t" --cycles-ledger-canister-id "$CYCLES_LEDGER_ID"
assert_command dfx canister create e2e_project_backend --with-cycles 1T --created-at-time "$t"
assert_command dfx canister id e2e_project_backend
assert_contains "$E2E_PROJECT_BACKEND_CANISTER_ID"
assert_command dfx cycles balance --cycles-ledger-canister-id "$CYCLES_LEDGER_ID" --precise
assert_command dfx cycles balance --precise
assert_eq "12399900000000 cycles."
dfx canister stop e2e_project_backend
dfx canister delete e2e_project_backend

assert_command dfx canister create e2e_project_backend --with-cycles 0.5T --from-subaccount "$ALICE_SUBACCT1" --cycles-ledger-canister-id "$CYCLES_LEDGER_ID"
assert_command dfx canister create e2e_project_backend --with-cycles 0.5T --from-subaccount "$ALICE_SUBACCT1"
assert_command dfx canister id e2e_project_backend
assert_command dfx cycles balance --cycles-ledger-canister-id "$CYCLES_LEDGER_ID" --subaccount "$ALICE_SUBACCT1" --precise
assert_command dfx cycles balance --subaccount "$ALICE_SUBACCT1" --precise
assert_eq "2099900000000 cycles."

# reset deployment status
rm -r .dfx

# using dfx deploy
t=$(current_time_nanoseconds)
assert_command dfx deploy e2e_project_backend --with-cycles 1T --created-at-time "$t" --cycles-ledger-canister-id "$CYCLES_LEDGER_ID"
assert_command dfx deploy e2e_project_backend --with-cycles 1T --created-at-time "$t"
assert_command dfx canister id e2e_project_backend
E2E_PROJECT_BACKEND_CANISTER_ID=$(dfx canister id e2e_project_backend)
assert_command dfx cycles balance --cycles-ledger-canister-id "$CYCLES_LEDGER_ID" --precise
assert_command dfx cycles balance --precise
assert_eq "11399800000000 cycles."
# reset and forget about canister. If --created-at-time is a valid idempotency key we should end up with the same canister id
dfx canister uninstall-code e2e_project_backend
rm .dfx/local/canister_ids.json
assert_command dfx deploy e2e_project_backend --with-cycles 1T --created-at-time "$t" --cycles-ledger-canister-id "$CYCLES_LEDGER_ID" -vv
assert_command dfx deploy e2e_project_backend --with-cycles 1T --created-at-time "$t" -vv
assert_command dfx canister id e2e_project_backend
assert_contains "$E2E_PROJECT_BACKEND_CANISTER_ID"
assert_command dfx cycles balance --cycles-ledger-canister-id "$CYCLES_LEDGER_ID" --precise
assert_command dfx cycles balance --precise
assert_eq "11399800000000 cycles."
dfx canister stop e2e_project_backend
dfx canister delete e2e_project_backend

assert_command dfx deploy e2e_project_backend --with-cycles 0.5T --from-subaccount "$ALICE_SUBACCT1" --cycles-ledger-canister-id "$CYCLES_LEDGER_ID"
assert_command dfx deploy e2e_project_backend --with-cycles 0.5T --from-subaccount "$ALICE_SUBACCT1"
assert_command dfx canister id e2e_project_backend
assert_command dfx cycles balance --cycles-ledger-canister-id "$CYCLES_LEDGER_ID" --subaccount "$ALICE_SUBACCT1" --precise
assert_command dfx cycles balance --subaccount "$ALICE_SUBACCT1" --precise
assert_eq "1599800000000 cycles."
dfx canister stop e2e_project_backend
dfx canister delete e2e_project_backend

assert_command dfx deploy --with-cycles 1T --cycles-ledger-canister-id "$CYCLES_LEDGER_ID"
assert_command dfx deploy --with-cycles 1T
assert_command dfx canister id e2e_project_backend
assert_command dfx canister id e2e_project_frontend
assert_not_contains "$(dfx canister id e2e_project_backend)"
assert_command dfx cycles balance --cycles-ledger-canister-id "$CYCLES_LEDGER_ID" --precise
assert_command dfx cycles balance --precise
assert_eq "9399600000000 cycles."
}
4 changes: 0 additions & 4 deletions e2e/utils/cycles-ledger.bash
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,3 @@ install_cycles_ledger_canisters() {
download_cycles_ledger_canisters
cp "$(downloaded_cycles_ledger_canisters_dir)"/* .
}

deploy_cycles_ledger() {
dfx deploy cycles-ledger --argument '(variant { Init = record { max_transactions_per_request = 100; index_id = null; } })'
}
8 changes: 0 additions & 8 deletions src/dfx/src/commands/canister/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ pub struct CanisterCreateOpts {
//TODO(SDK-1331): unhide
#[arg(long, value_parser = icrc_subaccount_parser, hide = true)]
from_subaccount: Option<Subaccount>,

/// Canister ID of the cycles ledger canister.
/// If not specified, the default cycles ledger canister ID will be used.
// todo: remove this. See https://dfinity.atlassian.net/browse/SDK-1262
#[arg(long, hide = true)]
cycles_ledger_canister_id: Option<CanisterId>,
}

pub async fn exec(
Expand Down Expand Up @@ -225,7 +219,6 @@ pub async fn exec(
reserved_cycles_limit,
},
opts.created_at_time,
opts.cycles_ledger_canister_id,
)
.await?;
Ok(())
Expand Down Expand Up @@ -296,7 +289,6 @@ pub async fn exec(
reserved_cycles_limit,
},
opts.created_at_time,
opts.cycles_ledger_canister_id,
)
.await?;
}
Expand Down
7 changes: 0 additions & 7 deletions src/dfx/src/commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,6 @@ pub struct DeployOpts {
//TODO(SDK-1331): unhide
#[arg(long, value_parser = icrc_subaccount_parser, hide = true)]
from_subaccount: Option<Subaccount>,

/// Canister ID of the cycles ledger canister.
/// If not specified, the default cycles ledger canister ID will be used.
// todo: remove this. See https://dfinity.atlassian.net/browse/SDK-1262
#[arg(long, hide = true)]
cycles_ledger_canister_id: Option<Principal>,
}

pub fn exec(env: &dyn Environment, opts: DeployOpts) -> DfxResult {
Expand Down Expand Up @@ -193,7 +187,6 @@ pub fn exec(env: &dyn Environment, opts: DeployOpts) -> DfxResult {
opts.yes,
env_file,
opts.no_asset_upgrade,
opts.cycles_ledger_canister_id,
))?;

if matches!(deploy_mode, NormalDeploy | ForceReinstallSingleCanister(_)) {
Expand Down
3 changes: 0 additions & 3 deletions src/dfx/src/lib/operations/canister/create_canister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub async fn create_canister(
from_subaccount: Option<Subaccount>,
settings: DfxCanisterSettings,
created_at_time: Option<u64>,
cycles_ledger_canister_id: Option<Principal>,
) -> DfxResult {
let log = env.get_logger();
info!(log, "Creating canister {}...", canister_name);
Expand Down Expand Up @@ -84,7 +83,6 @@ pub async fn create_canister(
let auto_wallet_disabled = std::env::var("DFX_DISABLE_AUTO_WALLET").is_ok();
let ic_network = env.get_network_descriptor().is_ic;
if CYCLES_LEDGER_ENABLED && (ic_network || auto_wallet_disabled) {
let Some(cycles_ledger_canister_id) = cycles_ledger_canister_id else { bail!("Must specify cycles ledger canister id")};
create_with_cycles_ledger(
env,
agent,
Expand All @@ -93,7 +91,6 @@ pub async fn create_canister(
from_subaccount,
settings,
created_at_time,
cycles_ledger_canister_id,
)
.await
} else {
Expand Down
4 changes: 0 additions & 4 deletions src/dfx/src/lib/operations/canister/deploy_canisters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ pub async fn deploy_canisters(
skip_consent: bool,
env_file: Option<PathBuf>,
no_asset_upgrade: bool,
cycles_ledger_canister_id: Option<Principal>,
) -> DfxResult {
let log = env.get_logger();

Expand Down Expand Up @@ -144,7 +143,6 @@ pub async fn deploy_canisters(
from_subaccount,
created_at_time,
&config,
cycles_ledger_canister_id,
)
.await?;
} else {
Expand Down Expand Up @@ -217,7 +215,6 @@ async fn register_canisters(
from_subaccount: Option<Subaccount>,
created_at_time: Option<u64>,
config: &Config,
cycles_ledger_canister_id: Option<Principal>,
) -> DfxResult {
let canisters_to_create = canister_names
.iter()
Expand Down Expand Up @@ -282,7 +279,6 @@ async fn register_canisters(
reserved_cycles_limit,
},
created_at_time,
cycles_ledger_canister_id,
)
.await?;
}
Expand Down
3 changes: 1 addition & 2 deletions src/dfx/src/lib/operations/cycles_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ pub async fn create_with_cycles_ledger(
from_subaccount: Option<Subaccount>,
settings: DfxCanisterSettings,
created_at_time: Option<u64>,
cycles_ledger_canister_id: Principal,
) -> DfxResult<Principal> {
#[derive(CandidType, Clone, Debug)]
// TODO(FI-1022): Import types from cycles ledger crate once available
Expand Down Expand Up @@ -268,7 +267,7 @@ pub async fn create_with_cycles_ledger(

let result = loop {
match agent
.update(&cycles_ledger_canister_id, CREATE_CANISTER_METHOD)
.update(&CYCLES_LEDGER_CANISTER_ID, CREATE_CANISTER_METHOD)
.with_arg(
Encode!(&CreateCanisterArgs {
from_subaccount,
Expand Down

0 comments on commit 280868e

Please sign in to comment.