Skip to content

Commit

Permalink
use new created-at-time per canister if none specified
Browse files Browse the repository at this point in the history
  • Loading branch information
sesi200 committed Dec 22, 2023
1 parent 975aa28 commit c9cacfd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
5 changes: 3 additions & 2 deletions e2e/tests-dfx/cycles-ledger.bash
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,9 @@ current_time_nanoseconds() {
assert_command deploy_cycles_ledger
CYCLES_LEDGER_ID=$(dfx canister id cycles-ledger)
echo "Cycles ledger deployed at id $CYCLES_LEDGER_ID"
assert_command dfx deploy cycles-depositor --argument "(record {ledger_id = principal \"$(dfx canister id cycles-ledger)\"})" --with-cycles 10000000000000
assert_command dfx deploy cycles-depositor --argument "(record {ledger_id = principal \"$(dfx canister id cycles-ledger)\"})"
echo "Cycles depositor deployed at id $(dfx canister id cycles-depositor)"
assert_command dfx ledger fabricate-cycles --canister cycles-depositor --t 9999

assert_command dfx deploy

Expand Down Expand Up @@ -499,5 +500,5 @@ current_time_nanoseconds() {
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_eq "999600000000 cycles."
assert_eq "9399600000000 cycles."
}
11 changes: 1 addition & 10 deletions src/dfx/src/commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use slog::info;
use std::collections::BTreeMap;
use std::path::PathBuf;
use std::str::FromStr;
use std::time::{SystemTime, UNIX_EPOCH};
use tokio::runtime::Runtime;
use url::Host::Domain;
use url::Url;
Expand Down Expand Up @@ -175,14 +174,6 @@ pub fn exec(env: &dyn Environment, opts: DeployOpts) -> DfxResult {

let call_sender = CallSender::from(&opts.wallet)
.map_err(|e| anyhow!("Failed to determine call sender: {}", e))?;
let created_at_time = opts.created_at_time.or_else(|| {
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_nanos() as u64;
info!(env.get_logger(), "created-at-time is {now}.");
Some(now)
});

runtime.block_on(fetch_root_key_if_needed(&env))?;

Expand All @@ -194,7 +185,7 @@ pub fn exec(env: &dyn Environment, opts: DeployOpts) -> DfxResult {
&deploy_mode,
opts.upgrade_unchanged,
with_cycles,
created_at_time,
opts.created_at_time,
opts.specified_id,
&call_sender,
opts.from_subaccount,
Expand Down
1 change: 1 addition & 0 deletions src/dfx/src/lib/operations/canister/create_canister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub async fn create_canister(
create_with_cycles_ledger(
env,
agent,
canister_name,
with_cycles,
from_subaccount,
settings,
Expand Down
6 changes: 5 additions & 1 deletion src/dfx/src/lib/operations/cycles_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ pub async fn send(
pub async fn create_with_cycles_ledger(
env: &dyn Environment,
agent: &Agent,
canister_name: &str,
with_cycles: Option<u128>,
from_subaccount: Option<Subaccount>,
settings: DfxCanisterSettings,
Expand Down Expand Up @@ -259,7 +260,10 @@ pub async fn create_with_cycles_ledger(
.duration_since(UNIX_EPOCH)
.unwrap()
.as_nanos() as u64;
info!(env.get_logger(), "created-at-time is {now}.");
info!(
env.get_logger(),
"created-at-time for canister {canister_name} is {now}."
);
Some(now)
});

Expand Down

0 comments on commit c9cacfd

Please sign in to comment.