ant-node 0.10.1

Pure quantum-proof network node for the Autonomi decentralized network
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
//! Auto-upgrade system with ML-DSA signature verification.
//!
//! This module handles:
//! - Polling GitHub releases for new versions
//! - Verifying ML-DSA-65 signatures on binaries
//! - Replacing the running binary with rollback support
//! - Staged rollout to prevent mass network restarts
//! - Auto-apply: download, extract, verify, replace, restart

mod apply;
mod binary_cache;
mod cache_dir;
mod monitor;
mod release_cache;
mod rollout;
mod signature;

pub use apply::{AutoApplyUpgrader, RESTART_EXIT_CODE};
pub use binary_cache::BinaryCache;
pub use cache_dir::upgrade_cache_dir;
pub use monitor::{find_platform_asset, version_from_tag, Asset, GitHubRelease, UpgradeMonitor};
pub use release_cache::ReleaseCache;
pub use rollout::StagedRollout;
pub use signature::{
    verify_binary_signature, verify_binary_signature_with_key, verify_from_file,
    verify_from_file_with_key, PUBLIC_KEY_SIZE, SIGNATURE_SIZE, SIGNING_CONTEXT,
};

use crate::error::{Error, Result};
use crate::logging::{debug, info, warn};
use semver::Version;
use std::fs;
use std::path::Path;

/// Maximum allowed upgrade binary size (200 MiB).
///
/// This is a sanity limit to prevent memory exhaustion during ML-DSA verification,
/// which requires loading the full binary into RAM.
const MAX_BINARY_SIZE_BYTES: usize = 200 * 1024 * 1024;

/// Information about an available upgrade.
#[derive(Debug, Clone)]
pub struct UpgradeInfo {
    /// The new version.
    pub version: Version,
    /// Download URL for the binary.
    pub download_url: String,
    /// Signature URL.
    pub signature_url: String,
    /// Release notes.
    pub release_notes: String,
}

/// Result of an upgrade operation.
#[derive(Debug)]
pub enum UpgradeResult {
    /// Upgrade was successful and the process should exit to complete the restart.
    Success {
        /// The new version.
        version: Version,
        /// Exit code to use when terminating the process.
        /// The caller should trigger graceful shutdown, then exit with this code.
        exit_code: i32,
    },
    /// Upgrade failed, rolled back.
    RolledBack {
        /// Error that caused the rollback.
        reason: String,
    },
    /// No upgrade available.
    NoUpgrade,
}

/// Upgrade orchestrator with rollback support.
///
/// Handles the complete upgrade lifecycle:
/// 1. Validate upgrade (prevent downgrade)
/// 2. Download new binary and signature
/// 3. Verify ML-DSA-65 signature
/// 4. Create backup of current binary
/// 5. Atomic replacement
/// 6. Rollback on failure
pub struct Upgrader {
    /// Current running version.
    current_version: Version,
    /// HTTP client for downloads.
    client: reqwest::Client,
}

impl Upgrader {
    /// Create a new upgrader with the current package version.
    #[must_use]
    pub fn new() -> Self {
        let current_version =
            Version::parse(env!("CARGO_PKG_VERSION")).unwrap_or_else(|_| Version::new(0, 0, 0));

        Self {
            current_version,
            client: reqwest::Client::new(),
        }
    }

    /// Create an upgrader with a custom version (for testing).
    #[cfg(test)]
    #[must_use]
    pub fn with_version(version: Version) -> Self {
        Self {
            current_version: version,
            client: reqwest::Client::new(),
        }
    }

    /// Get the current version.
    #[must_use]
    pub fn current_version(&self) -> &Version {
        &self.current_version
    }

    /// Validate that the upgrade is allowed (prevents downgrade).
    ///
    /// # Errors
    ///
    /// Returns an error if the target version is older than or equal to current.
    pub fn validate_upgrade(&self, info: &UpgradeInfo) -> Result<()> {
        if info.version <= self.current_version {
            return Err(Error::Upgrade(format!(
                "Cannot downgrade from {} to {}",
                self.current_version, info.version
            )));
        }
        Ok(())
    }

    /// Create a backup of the current binary.
    ///
    /// # Arguments
    ///
    /// * `current` - Path to the current binary
    /// * `rollback_dir` - Directory to store the backup
    ///
    /// # Errors
    ///
    /// Returns an error if the backup cannot be created.
    pub fn create_backup(&self, current: &Path, rollback_dir: &Path) -> Result<()> {
        let filename = current
            .file_name()
            .ok_or_else(|| Error::Upgrade("Invalid binary path".to_string()))?;

        let backup_path = rollback_dir.join(format!("{}.backup", filename.to_string_lossy()));

        debug!("Creating backup at: {}", backup_path.display());
        fs::copy(current, &backup_path)?;
        Ok(())
    }

    /// Restore binary from backup.
    ///
    /// # Arguments
    ///
    /// * `current` - Path to restore to
    /// * `rollback_dir` - Directory containing the backup
    ///
    /// # Errors
    ///
    /// Returns an error if the backup cannot be restored.
    pub fn restore_from_backup(&self, current: &Path, rollback_dir: &Path) -> Result<()> {
        let filename = current
            .file_name()
            .ok_or_else(|| Error::Upgrade("Invalid binary path".to_string()))?;

        let backup_path = rollback_dir.join(format!("{}.backup", filename.to_string_lossy()));

        if !backup_path.exists() {
            return Err(Error::Upgrade("No backup found for rollback".to_string()));
        }

        info!("Restoring from backup: {}", backup_path.display());
        fs::copy(&backup_path, current)?;
        Ok(())
    }

    /// Atomically replace the binary (rename on POSIX).
    ///
    /// Preserves file permissions from the original binary.
    ///
    /// # Arguments
    ///
    /// * `new_binary` - Path to the new binary
    /// * `target` - Path to replace
    ///
    /// # Errors
    ///
    /// Returns an error if the replacement fails.
    pub fn atomic_replace(&self, new_binary: &Path, target: &Path) -> Result<()> {
        // Preserve original permissions on Unix
        #[cfg(unix)]
        {
            if let Ok(meta) = fs::metadata(target) {
                let perms = meta.permissions();
                fs::set_permissions(new_binary, perms)?;
            }
        }

        // Atomic rename
        fs::rename(new_binary, target)?;
        debug!("Atomic replacement complete");
        Ok(())
    }

    /// Download a file to the specified path.
    ///
    /// # Errors
    ///
    /// Returns an error if the download fails.
    async fn download(&self, url: &str, dest: &Path) -> Result<()> {
        debug!("Downloading: {}", url);

        let response = self
            .client
            .get(url)
            .send()
            .await
            .map_err(|e| Error::Network(format!("Download failed: {e}")))?;

        if !response.status().is_success() {
            return Err(Error::Network(format!(
                "Download returned status: {}",
                response.status()
            )));
        }

        let bytes = response
            .bytes()
            .await
            .map_err(|e| Error::Network(format!("Failed to read response: {e}")))?;

        Self::enforce_max_binary_size(bytes.len())?;

        fs::write(dest, &bytes)?;
        debug!("Downloaded {} bytes to {}", bytes.len(), dest.display());
        Ok(())
    }

    /// Ensure the downloaded binary is within a sane size limit.
    fn enforce_max_binary_size(len: usize) -> Result<()> {
        if len > MAX_BINARY_SIZE_BYTES {
            return Err(Error::Upgrade(format!(
                "Downloaded binary too large: {len} bytes (max {MAX_BINARY_SIZE_BYTES})"
            )));
        }
        Ok(())
    }

    /// Create a temp directory for upgrades in the same directory as the target binary.
    ///
    /// Ensures `fs::rename` is atomic by keeping source/target on the same filesystem.
    fn create_tempdir_in_target_dir(current_binary: &Path) -> Result<tempfile::TempDir> {
        let target_dir = current_binary
            .parent()
            .ok_or_else(|| Error::Upgrade("Current binary has no parent directory".to_string()))?;

        tempfile::Builder::new()
            .prefix("ant-upgrade-")
            .tempdir_in(target_dir)
            .map_err(|e| Error::Upgrade(format!("Failed to create temp dir: {e}")))
    }

    /// Perform upgrade with rollback support.
    ///
    /// This is the main upgrade entry point. It:
    /// 1. Validates the upgrade (prevents downgrade)
    /// 2. Creates a backup of the current binary
    /// 3. Downloads the new binary and signature
    /// 4. Verifies the ML-DSA-65 signature
    /// 5. Atomically replaces the binary
    /// 6. Rolls back on any failure
    ///
    /// # Arguments
    ///
    /// * `info` - Information about the upgrade to perform
    /// * `current_binary` - Path to the currently running binary
    /// * `rollback_dir` - Directory to store backup for rollback
    ///
    /// # Errors
    ///
    /// Returns an error only if both the upgrade AND rollback fail (critical).
    pub async fn perform_upgrade(
        &self,
        info: &UpgradeInfo,
        current_binary: &Path,
        rollback_dir: &Path,
    ) -> Result<UpgradeResult> {
        // Auto-upgrade on Windows is not supported yet due to running-binary locks.
        // We fail closed with an explicit reason rather than attempting a broken replace.
        if !Self::auto_upgrade_supported() {
            warn!(
                "Auto-upgrade is not supported on this platform; refusing upgrade to {}",
                info.version
            );
            return Ok(UpgradeResult::RolledBack {
                reason: "Auto-upgrade not supported on this platform".to_string(),
            });
        }

        // 1. Validate upgrade
        self.validate_upgrade(info)?;

        // 2. Create backup
        self.create_backup(current_binary, rollback_dir)?;

        // 3. Download new binary and signature to temp directory
        let temp_dir = Self::create_tempdir_in_target_dir(current_binary)?;
        let new_binary = temp_dir.path().join("new_binary");
        let sig_path = temp_dir.path().join("signature");

        if let Err(e) = self.download(&info.download_url, &new_binary).await {
            warn!("Download failed: {e}");
            return Ok(UpgradeResult::RolledBack {
                reason: format!("Download failed: {e}"),
            });
        }

        if let Err(e) = self.download(&info.signature_url, &sig_path).await {
            warn!("Signature download failed: {e}");
            return Ok(UpgradeResult::RolledBack {
                reason: format!("Signature download failed: {e}"),
            });
        }

        // 4. Verify signature
        if let Err(e) = signature::verify_from_file(&new_binary, &sig_path) {
            warn!("Signature verification failed: {e}");
            return Ok(UpgradeResult::RolledBack {
                reason: format!("Signature verification failed: {e}"),
            });
        }

        // 5. Atomic replacement
        if let Err(e) = self.atomic_replace(&new_binary, current_binary) {
            warn!("Replacement failed, rolling back: {e}");
            if let Err(restore_err) = self.restore_from_backup(current_binary, rollback_dir) {
                return Err(Error::Upgrade(format!(
                    "Critical: replacement failed ({e}) AND rollback failed ({restore_err})"
                )));
            }
            return Ok(UpgradeResult::RolledBack {
                reason: format!("Replacement failed: {e}"),
            });
        }

        info!("Successfully upgraded to version {}", info.version);
        Ok(UpgradeResult::Success {
            version: info.version.clone(),
            exit_code: 0,
        })
    }

    /// Whether the current platform supports in-place auto-upgrade.
    ///
    /// Supported on Unix (via `exec()`) and Windows (via `self-replace` crate).
    const fn auto_upgrade_supported() -> bool {
        true
    }
}

impl Default for Upgrader {
    fn default() -> Self {
        Self::new()
    }
}

/// Legacy function for backward compatibility.
///
/// # Errors
///
/// Returns an error if the upgrade fails and rollback is not possible.
pub async fn perform_upgrade(
    info: &UpgradeInfo,
    current_binary: &Path,
    rollback_dir: &Path,
) -> Result<UpgradeResult> {
    Upgrader::new()
        .perform_upgrade(info, current_binary, rollback_dir)
        .await
}

#[cfg(test)]
#[allow(
    clippy::unwrap_used,
    clippy::expect_used,
    clippy::doc_markdown,
    clippy::cast_possible_truncation,
    clippy::cast_sign_loss,
    clippy::case_sensitive_file_extension_comparisons
)]
mod tests {
    use super::*;
    use tempfile::TempDir;

    /// Test 1: Backup creation
    #[test]
    fn test_backup_created() {
        let temp = TempDir::new().unwrap();
        let current = temp.path().join("current");
        let rollback_dir = temp.path().join("rollback");
        fs::create_dir(&rollback_dir).unwrap();

        let original_content = b"old binary content";
        fs::write(&current, original_content).unwrap();

        let upgrader = Upgrader::new();
        upgrader.create_backup(&current, &rollback_dir).unwrap();

        let backup_path = rollback_dir.join("current.backup");
        assert!(backup_path.exists(), "Backup file should exist");
        assert_eq!(
            fs::read(&backup_path).unwrap(),
            original_content,
            "Backup content should match"
        );
    }

    /// Test 2: Restore from backup
    #[test]
    fn test_restore_from_backup() {
        let temp = TempDir::new().unwrap();
        let current = temp.path().join("binary");
        let rollback_dir = temp.path().join("rollback");
        fs::create_dir(&rollback_dir).unwrap();

        let original = b"original content";
        fs::write(&current, original).unwrap();

        let upgrader = Upgrader::new();
        upgrader.create_backup(&current, &rollback_dir).unwrap();

        // Simulate corruption
        fs::write(&current, b"corrupted content").unwrap();

        // Restore
        upgrader
            .restore_from_backup(&current, &rollback_dir)
            .unwrap();

        assert_eq!(fs::read(&current).unwrap(), original);
    }

    /// Test 3: Atomic replacement
    #[test]
    fn test_atomic_replacement() {
        let temp = TempDir::new().unwrap();
        let current = temp.path().join("binary");
        let new_binary = temp.path().join("new_binary");

        fs::write(&current, b"old").unwrap();
        fs::write(&new_binary, b"new").unwrap();

        let upgrader = Upgrader::new();
        upgrader.atomic_replace(&new_binary, &current).unwrap();

        assert_eq!(fs::read(&current).unwrap(), b"new");
        assert!(!new_binary.exists(), "Source should be moved, not copied");
    }

    /// Test 4: Downgrade prevention
    #[test]
    fn test_downgrade_prevention() {
        let current_version = Version::new(1, 1, 0);
        let older_version = Version::new(1, 0, 0);

        let upgrader = Upgrader::with_version(current_version);

        let info = UpgradeInfo {
            version: older_version,
            download_url: "test".to_string(),
            signature_url: "test.sig".to_string(),
            release_notes: "Old".to_string(),
        };

        let result = upgrader.validate_upgrade(&info);
        assert!(result.is_err());
        let err_msg = result.unwrap_err().to_string();
        assert!(
            err_msg.contains("downgrade") || err_msg.contains("Cannot"),
            "Error should mention downgrade prevention: {err_msg}"
        );
    }

    /// Test 5: Same version prevention
    #[test]
    fn test_same_version_prevention() {
        let version = Version::new(1, 0, 0);
        let upgrader = Upgrader::with_version(version.clone());

        let info = UpgradeInfo {
            version,
            download_url: "test".to_string(),
            signature_url: "test.sig".to_string(),
            release_notes: "Same".to_string(),
        };

        let result = upgrader.validate_upgrade(&info);
        assert!(result.is_err(), "Same version should be rejected");
    }

    /// Test 6: Upgrade validation passes for newer version
    #[test]
    fn test_upgrade_validation_passes() {
        let upgrader = Upgrader::with_version(Version::new(1, 0, 0));

        let info = UpgradeInfo {
            version: Version::new(1, 1, 0),
            download_url: "test".to_string(),
            signature_url: "test.sig".to_string(),
            release_notes: "New".to_string(),
        };

        let result = upgrader.validate_upgrade(&info);
        assert!(result.is_ok(), "Newer version should be accepted");
    }

    /// Test 7: Restore fails without backup
    #[test]
    fn test_restore_fails_without_backup() {
        let temp = TempDir::new().unwrap();
        let current = temp.path().join("binary");
        let rollback_dir = temp.path().join("rollback");
        fs::create_dir(&rollback_dir).unwrap();

        fs::write(&current, b"content").unwrap();

        let upgrader = Upgrader::new();
        let result = upgrader.restore_from_backup(&current, &rollback_dir);

        assert!(result.is_err());
        assert!(result.unwrap_err().to_string().contains("No backup"));
    }

    /// Test 8: Permissions preserved on Unix
    #[cfg(unix)]
    #[test]
    fn test_permissions_preserved() {
        use std::os::unix::fs::PermissionsExt;

        let temp = TempDir::new().unwrap();
        let current = temp.path().join("binary");
        let new_binary = temp.path().join("new");

        fs::write(&current, b"old").unwrap();
        fs::write(&new_binary, b"new").unwrap();

        // Set executable permissions on original
        let mut perms = fs::metadata(&current).unwrap().permissions();
        perms.set_mode(0o755);
        fs::set_permissions(&current, perms).unwrap();

        let upgrader = Upgrader::new();
        upgrader.atomic_replace(&new_binary, &current).unwrap();

        let new_perms = fs::metadata(&current).unwrap().permissions();
        assert_eq!(
            new_perms.mode() & 0o777,
            0o755,
            "Permissions should be preserved"
        );
    }

    /// Test 9: Current version getter
    #[test]
    fn test_current_version_getter() {
        let version = Version::new(2, 3, 4);
        let upgrader = Upgrader::with_version(version.clone());
        assert_eq!(*upgrader.current_version(), version);
    }

    /// Test 10: Default implementation
    #[test]
    fn test_default_impl() {
        let upgrader = Upgrader::default();
        // Should not panic and should have a valid version
        assert!(!upgrader.current_version().to_string().is_empty());
    }

    /// Test 11: Backup with special characters in filename
    #[test]
    fn test_backup_special_filename() {
        let temp = TempDir::new().unwrap();
        let current = temp.path().join("ant-node-v1.0.0");
        let rollback_dir = temp.path().join("rollback");
        fs::create_dir(&rollback_dir).unwrap();

        fs::write(&current, b"content").unwrap();

        let upgrader = Upgrader::new();
        let result = upgrader.create_backup(&current, &rollback_dir);
        assert!(result.is_ok());

        let backup_path = rollback_dir.join("ant-node-v1.0.0.backup");
        assert!(backup_path.exists());
    }

    /// Test 12: UpgradeInfo construction
    #[test]
    fn test_upgrade_info() {
        let info = UpgradeInfo {
            version: Version::new(1, 2, 3),
            download_url: "https://example.com/binary".to_string(),
            signature_url: "https://example.com/binary.sig".to_string(),
            release_notes: "Bug fixes and improvements".to_string(),
        };

        assert_eq!(info.version, Version::new(1, 2, 3));
        assert!(info.download_url.contains("example.com"));
        assert!(info.signature_url.ends_with(".sig"));
    }

    /// Test 13: UpgradeResult variants
    #[test]
    fn test_upgrade_result_variants() {
        let success = UpgradeResult::Success {
            version: Version::new(1, 0, 0),
            exit_code: 0,
        };
        assert!(matches!(success, UpgradeResult::Success { .. }));

        let rolled_back = UpgradeResult::RolledBack {
            reason: "Test failure".to_string(),
        };
        assert!(matches!(rolled_back, UpgradeResult::RolledBack { .. }));

        let no_upgrade = UpgradeResult::NoUpgrade;
        assert!(matches!(no_upgrade, UpgradeResult::NoUpgrade));
    }

    /// Test 14: Large file backup
    #[test]
    fn test_large_file_backup() {
        let temp = TempDir::new().unwrap();
        let current = temp.path().join("large_binary");
        let rollback_dir = temp.path().join("rollback");
        fs::create_dir(&rollback_dir).unwrap();

        // Create 1MB file
        let large_content: Vec<u8> = (0..1_000_000).map(|i| (i % 256) as u8).collect();
        fs::write(&current, &large_content).unwrap();

        let upgrader = Upgrader::new();
        upgrader.create_backup(&current, &rollback_dir).unwrap();

        let backup_path = rollback_dir.join("large_binary.backup");
        assert_eq!(fs::read(&backup_path).unwrap(), large_content);
    }

    /// Test 15: Backup directory doesn't exist
    #[test]
    fn test_backup_nonexistent_rollback_dir() {
        let temp = TempDir::new().unwrap();
        let current = temp.path().join("binary");
        let rollback_dir = temp.path().join("nonexistent");

        fs::write(&current, b"content").unwrap();

        let upgrader = Upgrader::new();
        let result = upgrader.create_backup(&current, &rollback_dir);

        assert!(result.is_err(), "Should fail if rollback dir doesn't exist");
    }

    /// Test 16: Tempdir for upgrades is created in target directory.
    #[test]
    fn test_tempdir_in_target_dir() {
        let temp = TempDir::new().unwrap();
        let current = temp.path().join("binary");
        fs::write(&current, b"content").unwrap();

        let tempdir = Upgrader::create_tempdir_in_target_dir(&current).unwrap();

        assert_eq!(
            tempdir.path().parent().unwrap(),
            temp.path(),
            "Upgrade tempdir should be in same dir as target"
        );
    }

    /// Test 17: Enforce max binary size rejects huge downloads.
    #[test]
    fn test_enforce_max_binary_size_rejects_large() {
        let too_large = MAX_BINARY_SIZE_BYTES + 1;
        let result = Upgrader::enforce_max_binary_size(too_large);
        assert!(result.is_err());
    }

    /// Test 18: Enforce max binary size accepts reasonable downloads.
    #[test]
    fn test_enforce_max_binary_size_accepts_small() {
        let result = Upgrader::enforce_max_binary_size(1024);
        assert!(result.is_ok());
    }

    #[test]
    fn test_auto_upgrade_supported_on_all_platforms() {
        assert!(Upgrader::auto_upgrade_supported());
    }
}