ic-mops 0.45.3 → 1.0.0-pre.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/.eslintrc.json +0 -0
  2. package/.gitignore +0 -0
  3. package/CHANGELOG.md +15 -0
  4. package/README.md +1 -1
  5. package/api/actors.ts +25 -17
  6. package/api/downloadPackageFiles.ts +0 -0
  7. package/api/getHighestVersion.ts +0 -0
  8. package/api/index.ts +0 -0
  9. package/api/network.ts +0 -0
  10. package/api/resolveVersion.ts +0 -0
  11. package/cache.ts +20 -8
  12. package/cli.ts +28 -27
  13. package/commands/add.ts +4 -0
  14. package/commands/bench/bench-canister.mo +34 -8
  15. package/commands/bench/user-bench.mo +0 -0
  16. package/commands/bench-replica.ts +11 -6
  17. package/commands/bench.ts +31 -5
  18. package/commands/bump.ts +0 -0
  19. package/commands/docs.ts +0 -0
  20. package/commands/outdated.ts +0 -0
  21. package/commands/publish.ts +1 -1
  22. package/commands/replica.ts +237 -0
  23. package/commands/search.ts +0 -0
  24. package/commands/sources.ts +2 -3
  25. package/commands/sync.ts +0 -0
  26. package/commands/template.ts +0 -0
  27. package/commands/test/mmf1.ts +5 -5
  28. package/commands/test/reporters/compact-reporter.ts +2 -1
  29. package/commands/test/reporters/files-reporter.ts +3 -2
  30. package/commands/test/reporters/reporter.ts +2 -1
  31. package/commands/test/reporters/silent-reporter.ts +2 -1
  32. package/commands/test/reporters/verbose-reporter.ts +14 -4
  33. package/commands/test/test.ts +213 -74
  34. package/commands/test/utils.ts +0 -0
  35. package/commands/toolchain/moc.ts +0 -0
  36. package/commands/toolchain/pocket-ic.ts +0 -0
  37. package/commands/toolchain/toolchain-utils.ts +0 -0
  38. package/commands/toolchain/wasmtime.ts +0 -0
  39. package/commands/transfer-ownership.ts +0 -0
  40. package/commands/update.ts +0 -0
  41. package/commands/user.ts +71 -1
  42. package/declarations/bench/bench.did +8 -4
  43. package/declarations/bench/bench.did.d.ts +4 -0
  44. package/declarations/bench/bench.did.js +4 -0
  45. package/declarations/storage/index.d.ts +0 -0
  46. package/declarations/storage/index.js +0 -0
  47. package/declarations/storage/storage.did +0 -0
  48. package/declarations/storage/storage.did.d.ts +0 -0
  49. package/declarations/storage/storage.did.js +0 -0
  50. package/dist/api/actors.js +19 -13
  51. package/dist/cache.js +17 -8
  52. package/dist/cli.d.ts +1 -0
  53. package/dist/cli.js +24 -27
  54. package/dist/commands/add.js +3 -0
  55. package/dist/commands/bench/bench-canister.mo +34 -8
  56. package/dist/commands/bench/user-bench.mo +0 -0
  57. package/dist/commands/bench-replica.d.ts +2 -1
  58. package/dist/commands/bench-replica.js +10 -6
  59. package/dist/commands/bench.js +29 -5
  60. package/dist/commands/publish.js +1 -1
  61. package/dist/commands/replica.d.ts +59 -0
  62. package/dist/commands/replica.js +193 -0
  63. package/dist/commands/sources.d.ts +2 -2
  64. package/dist/commands/sources.js +2 -3
  65. package/dist/commands/test/mmf1.d.ts +2 -2
  66. package/dist/commands/test/mmf1.js +4 -4
  67. package/dist/commands/test/reporters/compact-reporter.d.ts +2 -1
  68. package/dist/commands/test/reporters/compact-reporter.js +1 -1
  69. package/dist/commands/test/reporters/files-reporter.d.ts +2 -1
  70. package/dist/commands/test/reporters/files-reporter.js +2 -2
  71. package/dist/commands/test/reporters/reporter.d.ts +2 -1
  72. package/dist/commands/test/reporters/silent-reporter.d.ts +2 -1
  73. package/dist/commands/test/reporters/silent-reporter.js +1 -1
  74. package/dist/commands/test/reporters/verbose-reporter.d.ts +3 -1
  75. package/dist/commands/test/reporters/verbose-reporter.js +12 -4
  76. package/dist/commands/test/test.d.ts +10 -8
  77. package/dist/commands/test/test.js +170 -71
  78. package/dist/commands/user.d.ts +6 -0
  79. package/dist/commands/user.js +59 -1
  80. package/dist/declarations/bench/bench.did +8 -4
  81. package/dist/declarations/bench/bench.did.d.ts +4 -0
  82. package/dist/declarations/bench/bench.did.js +4 -0
  83. package/dist/declarations/storage/index.d.ts +0 -0
  84. package/dist/declarations/storage/index.js +0 -0
  85. package/dist/declarations/storage/storage.did +0 -0
  86. package/dist/declarations/storage/storage.did.d.ts +0 -0
  87. package/dist/declarations/storage/storage.did.js +0 -0
  88. package/dist/mops.d.ts +1 -1
  89. package/dist/mops.js +4 -28
  90. package/dist/package.json +4 -3
  91. package/dist/resolve-packages.d.ts +2 -2
  92. package/dist/resolve-packages.js +29 -7
  93. package/dist/templates/README.md +0 -0
  94. package/dist/templates/licenses/Apache-2.0 +0 -0
  95. package/dist/templates/licenses/Apache-2.0-NOTICE +0 -0
  96. package/dist/templates/licenses/MIT +0 -0
  97. package/dist/templates/mops-publish.yml +0 -0
  98. package/dist/templates/mops-test.yml +0 -0
  99. package/dist/templates/src/lib.mo +0 -0
  100. package/dist/templates/test/lib.test.mo +0 -0
  101. package/dist/types.d.ts +1 -0
  102. package/global.d.ts +0 -0
  103. package/helpers/get-dfx-version.ts +0 -0
  104. package/helpers/get-moc-path.ts +0 -0
  105. package/helpers/get-moc-version.ts +0 -0
  106. package/mops.ts +4 -31
  107. package/package.json +4 -3
  108. package/parallel.ts +0 -0
  109. package/resolve-packages.ts +39 -8
  110. package/templates/README.md +0 -0
  111. package/templates/licenses/Apache-2.0 +0 -0
  112. package/templates/licenses/Apache-2.0-NOTICE +0 -0
  113. package/templates/licenses/MIT +0 -0
  114. package/templates/mops-publish.yml +0 -0
  115. package/templates/mops-test.yml +0 -0
  116. package/templates/src/lib.mo +0 -0
  117. package/templates/test/lib.test.mo +0 -0
  118. package/types.ts +3 -1
  119. package/.DS_Store +0 -0
  120. package/bundle/bench/bench-canister.mo +0 -87
  121. package/bundle/bench/user-bench.mo +0 -14
  122. package/bundle/bin/moc-wrapper.sh +0 -40
  123. package/bundle/bin/mops.js +0 -3
  124. package/bundle/cli.js +0 -163
  125. package/bundle/cli.tgz +0 -0
  126. package/bundle/declarations/bench/bench.did +0 -26
  127. package/bundle/declarations/bench/bench.did.d.ts +0 -29
  128. package/bundle/declarations/bench/bench.did.js +0 -26
  129. package/bundle/declarations/bench/index.d.ts +0 -50
  130. package/bundle/declarations/bench/index.js +0 -40
  131. package/bundle/declarations/main/index.d.ts +0 -50
  132. package/bundle/declarations/main/index.js +0 -40
  133. package/bundle/declarations/main/main.did +0 -438
  134. package/bundle/declarations/main/main.did.d.ts +0 -360
  135. package/bundle/declarations/main/main.did.js +0 -412
  136. package/bundle/declarations/storage/index.d.ts +0 -50
  137. package/bundle/declarations/storage/index.js +0 -30
  138. package/bundle/declarations/storage/storage.did +0 -46
  139. package/bundle/declarations/storage/storage.did.d.ts +0 -40
  140. package/bundle/declarations/storage/storage.did.js +0 -38
  141. package/bundle/package.json +0 -31
  142. package/bundle/templates/README.md +0 -13
  143. package/bundle/templates/licenses/Apache-2.0 +0 -202
  144. package/bundle/templates/licenses/Apache-2.0-NOTICE +0 -13
  145. package/bundle/templates/licenses/MIT +0 -21
  146. package/bundle/templates/mops-publish.yml +0 -17
  147. package/bundle/templates/mops-test.yml +0 -22
  148. package/bundle/templates/src/lib.mo +0 -15
  149. package/bundle/templates/test/lib.test.mo +0 -4
  150. package/commands/import-identity.ts +0 -62
  151. package/commands/whoami.ts +0 -12
package/dist/cli.js CHANGED
@@ -1,14 +1,11 @@
1
1
  import process from 'node:process';
2
2
  import fs from 'node:fs';
3
3
  import { Command, Argument, Option } from 'commander';
4
- import chalk from 'chalk';
5
4
  import { init } from './commands/init.js';
6
5
  import { publish } from './commands/publish.js';
7
- import { importPem } from './commands/import-identity.js';
8
6
  import { sources } from './commands/sources.js';
9
7
  import { checkApiCompatibility, setNetwork, apiVersion, checkConfigFile, getNetworkFile, version } from './mops.js';
10
8
  import { getNetwork } from './api/network.js';
11
- import { whoami } from './commands/whoami.js';
12
9
  import { installAll } from './commands/install/install-all.js';
13
10
  import { search } from './commands/search.js';
14
11
  import { add } from './commands/add.js';
@@ -16,7 +13,7 @@ import { cacheSize, cleanCache, show } from './cache.js';
16
13
  import { test } from './commands/test/test.js';
17
14
  import { template } from './commands/template.js';
18
15
  import { remove } from './commands/remove.js';
19
- import { getUserProp, setUserProp } from './commands/user.js';
16
+ import { importPem, getPrincipal, getUserProp, setUserProp } from './commands/user.js';
20
17
  import { bump } from './commands/bump.js';
21
18
  import { sync } from './commands/sync.js';
22
19
  import { outdated } from './commands/outdated.js';
@@ -25,6 +22,7 @@ import { bench } from './commands/bench.js';
25
22
  import { transferOwnership } from './commands/transfer-ownership.js';
26
23
  import { toolchain } from './commands/toolchain/index.js';
27
24
  import * as self from './commands/self.js';
25
+ import { resolvePackages } from './resolve-packages.js';
28
26
  let networkFile = getNetworkFile();
29
27
  if (fs.existsSync(networkFile)) {
30
28
  globalThis.MOPS_NETWORK = fs.readFileSync(networkFile).toString() || 'ic';
@@ -71,12 +69,12 @@ program
71
69
  });
72
70
  // install
73
71
  program
74
- .command('install [pkg]')
72
+ .command('install')
75
73
  .alias('i')
76
74
  .description('Install all dependencies specified in mops.toml')
77
75
  .option('--verbose')
78
76
  .addOption(new Option('--lock <action>', 'Lockfile action').choices(['check', 'update', 'ignore']))
79
- .action(async (pkg, options) => {
77
+ .action(async (options) => {
80
78
  if (!checkConfigFile()) {
81
79
  process.exit(1);
82
80
  }
@@ -85,17 +83,12 @@ program
85
83
  return;
86
84
  }
87
85
  await toolchain.ensureToolchainInited({ strict: false });
88
- if (pkg) {
89
- // @deprecated
90
- console.log(chalk.yellow('Consider using the \'mops add\' command to install a specific package.'));
91
- await add(pkg, options);
92
- }
93
- else {
94
- let ok = await installAll(options);
95
- await toolchain.installAll(options);
96
- if (!ok) {
97
- process.exit(1);
98
- }
86
+ let ok = await installAll(options);
87
+ await toolchain.installAll(options);
88
+ // check conflicts
89
+ await resolvePackages({ conflicts: 'warning' });
90
+ if (!ok) {
91
+ process.exit(1);
99
92
  }
100
93
  });
101
94
  // publish
@@ -132,21 +125,22 @@ program
132
125
  .action(async () => {
133
126
  console.log(getNetwork());
134
127
  });
135
- // import-identity
128
+ // user import
136
129
  program
137
- .command('import-identity <data>')
130
+ .command('mops user import <data>')
138
131
  .description('Import .pem file data to use as identity')
139
132
  .addOption(new Option('--no-encrypt', 'Do not ask for a password to encrypt identity'))
140
133
  .action(async (data, options) => {
141
134
  await importPem(data, options);
142
- await whoami();
135
+ await getPrincipal();
143
136
  });
144
137
  // sources
145
138
  program
146
139
  .command('sources')
147
140
  .description('for dfx packtool')
148
141
  .option('--no-install', 'Do not install dependencies before running sources')
149
- .option('--verbose')
142
+ .addOption(new Option('--conflicts <action>', 'What to do with dependency version conflicts').choices(['ignore', 'warning', 'error']).default('warning'))
143
+ .option('--verbose', 'Show more information') // for backcompat
150
144
  .action(async (options) => {
151
145
  if (!checkConfigFile()) {
152
146
  process.exit(1);
@@ -158,12 +152,12 @@ program
158
152
  let sourcesArr = await sources(options);
159
153
  console.log(sourcesArr.join('\n'));
160
154
  });
161
- // whoami
155
+ // get-principal
162
156
  program
163
- .command('whoami')
157
+ .command('get-principal')
164
158
  .description('Print your principal')
165
159
  .action(async () => {
166
- await whoami();
160
+ await getPrincipal();
167
161
  });
168
162
  // search
169
163
  program
@@ -194,10 +188,12 @@ program
194
188
  program
195
189
  .command('test [filter]')
196
190
  .description('Run tests')
197
- .addOption(new Option('-r, --reporter <reporter>', 'Test reporter').choices(['verbose', 'compact', 'files', 'silent']).default('verbose'))
198
- .addOption(new Option('--mode <mode>', 'Test mode').choices(['interpreter', 'wasi']).default('interpreter'))
191
+ .addOption(new Option('-r, --reporter <reporter>', 'Test reporter').choices(['verbose', 'compact', 'files', 'silent']))
192
+ .addOption(new Option('--mode <mode>', 'Test mode').choices(['interpreter', 'wasi', 'replica']).default('interpreter'))
193
+ .addOption(new Option('--replica <replica>', 'Which replica to use to run tests in replica mode').choices(['dfx', 'pocket-ic']))
199
194
  .option('-w, --watch', 'Enable watch mode')
200
195
  .action(async (filter, options) => {
196
+ checkConfigFile(true);
201
197
  await installAll({ silent: true, lock: 'ignore' });
202
198
  await test(filter, options);
203
199
  });
@@ -205,13 +201,14 @@ program
205
201
  program
206
202
  .command('bench [filter]')
207
203
  .description('Run benchmarks')
208
- .addOption(new Option('--replica <replica>', 'Which replica to use to run benchmarks').choices(['dfx', 'pocket-ic']).default('dfx'))
204
+ .addOption(new Option('--replica <replica>', 'Which replica to use to run benchmarks').choices(['dfx', 'pocket-ic']))
209
205
  .addOption(new Option('--gc <gc>', 'Garbage collector').choices(['copying', 'compacting', 'generational', 'incremental']).default('copying'))
210
206
  .addOption(new Option('--save', 'Save benchmark results to .bench/<filename>.json'))
211
207
  .addOption(new Option('--compare', 'Run benchmark and compare results with .bench/<filename>.json'))
212
208
  // .addOption(new Option('--force-gc', 'Force GC'))
213
209
  .addOption(new Option('--verbose', 'Show more information'))
214
210
  .action(async (filter, options) => {
211
+ checkConfigFile(true);
215
212
  await installAll({ silent: true, lock: 'ignore' });
216
213
  await bench(filter, options);
217
214
  });
@@ -10,6 +10,7 @@ import { checkIntegrity } from '../integrity.js';
10
10
  import { checkRequirements } from '../check-requirements.js';
11
11
  import { syncLocalCache } from './install/sync-local-cache.js';
12
12
  import { notifyInstalls } from '../notify-installs.js';
13
+ import { resolvePackages } from '../resolve-packages.js';
13
14
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
14
15
  export async function add(name, { verbose = false, dev = false, lock } = {}, asName) {
15
16
  if (!checkConfigFile()) {
@@ -104,4 +105,6 @@ export async function add(name, { verbose = false, dev = false, lock } = {}, asN
104
105
  logUpdate.clear();
105
106
  await checkRequirements({ verbose });
106
107
  console.log(chalk.green('Package installed ') + `${pkgDetails.name} = "${pkgDetails.repo || pkgDetails.path || pkgDetails.version}"`);
108
+ // check conflicts
109
+ await resolvePackages({ conflicts: 'warning' });
107
110
  }
@@ -2,17 +2,35 @@ import Nat64 "mo:base/Nat64";
2
2
  import Nat "mo:base/Nat";
3
3
  import Debug "mo:base/Debug";
4
4
  import ExperimentalInternetComputer "mo:base/ExperimentalInternetComputer";
5
+ import ExperimentalStableMemory "mo:base/ExperimentalStableMemory";
6
+ import Int64 "mo:base/Int64";
7
+ import Region "mo:base/Region";
5
8
  import Prim "mo:prim";
6
9
  import Bench "mo:bench";
7
10
 
8
11
  import UserBench "./user-bench"; // file path will be replaced with the *.bench.mo file path
9
12
 
10
13
  actor class() {
14
+ type BenchResult = {
15
+ instructions : Int;
16
+ rts_mutator_instructions : Int;
17
+ stable_memory_size : Int;
18
+ rts_stable_memory_size : Int;
19
+ rts_logical_stable_memory_size : Int;
20
+ rts_collector_instructions : Int;
21
+ rts_heap_size : Int;
22
+ rts_memory_size : Int;
23
+ rts_total_allocation : Int;
24
+ rts_reclaimed : Int;
25
+ };
26
+
11
27
  var benchOpt : ?Bench.Bench = null;
12
28
 
13
29
  public func init() : async Bench.BenchSchema {
14
30
  let bench = UserBench.init();
15
31
  benchOpt := ?bench;
32
+ // ignore ExperimentalStableMemory.grow(1);
33
+ ignore Region.grow(Region.new(), 1);
16
34
  bench.getSchema();
17
35
  };
18
36
 
@@ -21,29 +39,37 @@ actor class() {
21
39
  bench.getSchema();
22
40
  };
23
41
 
24
- func _getStats() : Bench.BenchResult {
42
+ func _getStats() : BenchResult {
25
43
  {
26
44
  instructions = 0;
27
45
  rts_heap_size = Prim.rts_heap_size();
46
+ stable_memory_size = Int64.toInt(Int64.fromNat64(ExperimentalStableMemory.size())) * 65536;
47
+ rts_stable_memory_size = Prim.rts_stable_memory_size();
48
+ rts_logical_stable_memory_size = Prim.rts_logical_stable_memory_size();
28
49
  rts_memory_size = Prim.rts_memory_size();
29
50
  rts_total_allocation = Prim.rts_total_allocation();
51
+ rts_reclaimed = Prim.rts_reclaimed();
30
52
  rts_mutator_instructions = Prim.rts_mutator_instructions();
31
53
  rts_collector_instructions = Prim.rts_collector_instructions();
32
54
  }
33
55
  };
34
56
 
35
- func _diffStats(before : Bench.BenchResult, after : Bench.BenchResult) : Bench.BenchResult {
57
+ func _diffStats(before : BenchResult, after : BenchResult) : BenchResult {
36
58
  {
37
59
  instructions = after.instructions - before.instructions;
38
60
  rts_heap_size = after.rts_heap_size - before.rts_heap_size;
61
+ stable_memory_size = after.stable_memory_size - before.stable_memory_size;
62
+ rts_stable_memory_size = after.rts_stable_memory_size - before.rts_stable_memory_size;
63
+ rts_logical_stable_memory_size = after.rts_logical_stable_memory_size - before.rts_logical_stable_memory_size;
39
64
  rts_memory_size = after.rts_memory_size - before.rts_memory_size;
40
65
  rts_total_allocation = after.rts_total_allocation - before.rts_total_allocation;
66
+ rts_reclaimed = after.rts_reclaimed - before.rts_reclaimed;
41
67
  rts_mutator_instructions = after.rts_mutator_instructions - before.rts_mutator_instructions;
42
68
  rts_collector_instructions = after.rts_collector_instructions - before.rts_collector_instructions;
43
69
  }
44
70
  };
45
71
 
46
- func _runCell(rowIndex : Nat, colIndex : Nat) : Bench.BenchResult {
72
+ func _runCell(rowIndex : Nat, colIndex : Nat) : BenchResult {
47
73
  let ?bench = benchOpt else Debug.trap("bench not initialized");
48
74
  let statsBefore = _getStats();
49
75
 
@@ -55,7 +81,7 @@ actor class() {
55
81
  _diffStats(statsBefore, { statsAfter with instructions });
56
82
  };
57
83
 
58
- func _runCellAwait(rowIndex : Nat, colIndex : Nat) : async Bench.BenchResult {
84
+ func _runCellAwait(rowIndex : Nat, colIndex : Nat) : async BenchResult {
59
85
  let ?bench = benchOpt else Debug.trap("bench not initialized");
60
86
  let statsBefore = _getStats();
61
87
 
@@ -69,19 +95,19 @@ actor class() {
69
95
  _diffStats(statsBefore, { statsAfter with instructions });
70
96
  };
71
97
 
72
- public query func getStats() : async Bench.BenchResult {
98
+ public query func getStats() : async BenchResult {
73
99
  _getStats();
74
100
  };
75
101
 
76
- public query func runCellQuery(rowIndex : Nat, colIndex : Nat) : async Bench.BenchResult {
102
+ public query func runCellQuery(rowIndex : Nat, colIndex : Nat) : async BenchResult {
77
103
  _runCell(rowIndex, colIndex);
78
104
  };
79
105
 
80
- public func runCellUpdate(rowIndex : Nat, colIndex : Nat) : async Bench.BenchResult {
106
+ public func runCellUpdate(rowIndex : Nat, colIndex : Nat) : async BenchResult {
81
107
  _runCell(rowIndex, colIndex);
82
108
  };
83
109
 
84
- public func runCellUpdateAwait(rowIndex : Nat, colIndex : Nat) : async Bench.BenchResult {
110
+ public func runCellUpdateAwait(rowIndex : Nat, colIndex : Nat) : async BenchResult {
85
111
  await _runCellAwait(rowIndex, colIndex);
86
112
  };
87
113
  };
File without changes
@@ -1,4 +1,4 @@
1
- import { PocketIc } from 'pic-ic';
1
+ import { PocketIc, PocketIcServer } from 'pic-ic';
2
2
  export declare class BenchReplica {
3
3
  type: 'dfx' | 'pocket-ic';
4
4
  verbose: boolean;
@@ -7,6 +7,7 @@ export declare class BenchReplica {
7
7
  canisterId: string;
8
8
  actor: any;
9
9
  }>;
10
+ pocketIcServer?: PocketIcServer;
10
11
  pocketIc?: PocketIc;
11
12
  constructor(type: 'dfx' | 'pocket-ic', verbose?: boolean);
12
13
  start({ silent }?: {
@@ -3,7 +3,7 @@ import { execSync } from 'node:child_process';
3
3
  import path from 'node:path';
4
4
  import fs from 'node:fs';
5
5
  import { execaCommand } from 'execa';
6
- import { PocketIc } from 'pic-ic';
6
+ import { PocketIc, PocketIcServer } from 'pic-ic';
7
7
  import { getRootDir, readConfig } from '../mops.js';
8
8
  import { createActor, idlFactory } from '../declarations/bench/index.js';
9
9
  import { toolchain } from './toolchain/index.js';
@@ -25,11 +25,14 @@ export class BenchReplica {
25
25
  else {
26
26
  let pocketIcBin = await toolchain.bin('pocket-ic');
27
27
  let config = readConfig();
28
- if (config.toolchain?.['pocket-ic'] !== '1.0.0') {
29
- console.error('Currently only pocket-ic 1.0.0 is supported');
28
+ if (config.toolchain?.['pocket-ic'] !== '4.0.0') {
29
+ console.error('Current Mops CLI only supports pocket-ic 4.0.0');
30
30
  process.exit(1);
31
31
  }
32
- this.pocketIc = await PocketIc.create(pocketIcBin);
32
+ this.pocketIcServer = await PocketIcServer.start({
33
+ binPath: pocketIcBin,
34
+ });
35
+ this.pocketIc = await PocketIc.create(this.pocketIcServer.getUrl());
33
36
  }
34
37
  }
35
38
  async stop() {
@@ -37,8 +40,9 @@ export class BenchReplica {
37
40
  let dir = path.join(getRootDir(), '.mops/.bench');
38
41
  execSync('dfx stop' + (this.verbose ? '' : ' -qqqq'), { cwd: dir, stdio: ['pipe', this.verbose ? 'inherit' : 'ignore', 'pipe'] });
39
42
  }
40
- else if (this.pocketIc) {
43
+ else if (this.pocketIc && this.pocketIcServer) {
41
44
  await this.pocketIc.tearDown();
45
+ await this.pocketIcServer.stop();
42
46
  }
43
47
  }
44
48
  async deploy(name, wasm, cwd = process.cwd()) {
@@ -53,7 +57,7 @@ export class BenchReplica {
53
57
  this.canisters[name] = { cwd, canisterId, actor };
54
58
  }
55
59
  else if (this.pocketIc) {
56
- let { canisterId, actor } = await this.pocketIc.setupCanister(idlFactory, wasm);
60
+ let { canisterId, actor } = await this.pocketIc.setupCanister({ idlFactory, wasm });
57
61
  this.canisters[name] = {
58
62
  cwd,
59
63
  canisterId: canisterId.toText(),
@@ -16,6 +16,7 @@ import { getDfxVersion } from '../helpers/get-dfx-version.js';
16
16
  import { getMocPath } from '../helpers/get-moc-path.js';
17
17
  import { sources } from './sources.js';
18
18
  import { BenchReplica } from './bench-replica.js';
19
+ import { filesize } from 'filesize';
19
20
  let ignore = [
20
21
  '**/node_modules/**',
21
22
  '**/.mops/**',
@@ -27,8 +28,9 @@ let globConfig = {
27
28
  ignore: ignore,
28
29
  };
29
30
  export async function bench(filter = '', optionsArg = {}) {
31
+ let config = readConfig();
30
32
  let defaultOptions = {
31
- replica: 'dfx',
33
+ replica: config.toolchain?.['pocket-ic'] ? 'pocket-ic' : 'dfx',
32
34
  replicaVersion: '',
33
35
  compiler: 'moc',
34
36
  compilerVersion: getMocVersion(),
@@ -44,7 +46,6 @@ export async function bench(filter = '', optionsArg = {}) {
44
46
  options.replicaVersion = getDfxVersion();
45
47
  }
46
48
  else if (options.replica == 'pocket-ic') {
47
- let config = readConfig();
48
49
  options.replicaVersion = config.toolchain?.['pocket-ic'] || '';
49
50
  }
50
51
  options.verbose && console.log(options);
@@ -68,7 +69,7 @@ export async function bench(filter = '', optionsArg = {}) {
68
69
  }
69
70
  files.sort();
70
71
  let benchDir = `${getRootDir()}/.mops/.bench/`;
71
- fs.rmSync(benchDir, { recursive: true, force: true });
72
+ // fs.rmSync(benchDir, {recursive: true, force: true});
72
73
  fs.mkdirSync(benchDir, { recursive: true });
73
74
  if (!options.silent) {
74
75
  console.log('Benchmark files:');
@@ -110,7 +111,7 @@ export async function bench(filter = '', optionsArg = {}) {
110
111
  });
111
112
  options.silent || console.log('Stopping replica...');
112
113
  await replica.stop();
113
- fs.rmSync(benchDir, { recursive: true, force: true });
114
+ // fs.rmSync(benchDir, {recursive: true, force: true});
114
115
  return benchResults;
115
116
  }
116
117
  function getMocArgs(options) {
@@ -171,9 +172,14 @@ async function runBenchFile(file, options, replica) {
171
172
  let results = new Map();
172
173
  let instructionsCells = Array.from({ length: schema.rows.length }, () => []);
173
174
  let heapCells = Array.from({ length: schema.rows.length }, () => []);
175
+ let logicalStableMemoryCells = Array.from({ length: schema.rows.length }, () => []);
176
+ let reclaimedCells = Array.from({ length: schema.rows.length }, () => []);
174
177
  let formatNumber = (n) => {
175
178
  return n.toLocaleString('en-US').replaceAll(',', '_');
176
179
  };
180
+ let formatSize = (n) => {
181
+ return filesize(n, { standard: 'iec', round: 2 });
182
+ };
177
183
  let getTable = (prop) => {
178
184
  let resArr = [['', ...schema.cols]];
179
185
  for (let [_rowIndex, row] of schema.rows.entries()) {
@@ -197,7 +203,17 @@ async function runBenchFile(file, options, replica) {
197
203
  }
198
204
  }
199
205
  // add to table
200
- curRow.push(formatNumber(res[prop]) + diff);
206
+ let value = '';
207
+ if (prop == 'rts_logical_stable_memory_size') {
208
+ value = formatSize(res[prop] * 65536n);
209
+ }
210
+ else if (prop === 'rts_heap_size' || prop == 'rts_reclaimed') {
211
+ value = formatSize(res[prop]);
212
+ }
213
+ else {
214
+ value = formatNumber(res[prop]);
215
+ }
216
+ curRow.push(value + diff);
201
217
  }
202
218
  else {
203
219
  curRow.push('');
@@ -216,6 +232,8 @@ async function runBenchFile(file, options, replica) {
216
232
  ${schema.description ? '\n' + chalk.gray(schema.description) : ''}
217
233
  \n\n${chalk.blue('Instructions')}\n\n${getTable('instructions')}
218
234
  \n\n${chalk.blue('Heap')}\n\n${getTable('rts_heap_size')}
235
+ \n\n${chalk.blue('Stable Memory')}\n\n${getTable('rts_logical_stable_memory_size')}
236
+ \n\n${chalk.blue('Garbage Collection')}\n\n${getTable('rts_reclaimed')}
219
237
  `);
220
238
  };
221
239
  if (!process.env.CI && !options.silent) {
@@ -230,6 +248,10 @@ async function runBenchFile(file, options, replica) {
230
248
  instructionsCells[rowIndex][colIndex] = res.instructions;
231
249
  // @ts-ignore
232
250
  heapCells[rowIndex][colIndex] = res.rts_heap_size;
251
+ // @ts-ignore
252
+ logicalStableMemoryCells[rowIndex][colIndex] = res.rts_logical_stable_memory_size;
253
+ // @ts-ignore
254
+ reclaimedCells[rowIndex][colIndex] = res.rts_reclaimed;
233
255
  if (!process.env.CI && !options.silent) {
234
256
  printResults();
235
257
  }
@@ -277,6 +299,8 @@ async function runBenchFile(file, options, replica) {
277
299
  metrics: [
278
300
  ['instructions', instructionsCells],
279
301
  ['rts_heap_size', heapCells],
302
+ ['rts_logical_stable_memory_size', logicalStableMemoryCells],
303
+ ['rts_reclaimed', reclaimedCells],
280
304
  ],
281
305
  };
282
306
  }
@@ -242,7 +242,7 @@ export async function publish(options = {}) {
242
242
  let reporter = new SilentReporter;
243
243
  if (options.test) {
244
244
  console.log('Running tests...');
245
- await testWithReporter(reporter);
245
+ await testWithReporter(reporter, '', 'interpreter', config.toolchain?.['pocket-ic'] ? 'pocket-ic' : 'dfx');
246
246
  if (reporter.failed > 0) {
247
247
  console.log(chalk.red('Error: ') + 'tests failed');
248
248
  process.exit(1);
@@ -0,0 +1,59 @@
1
+ import { ChildProcessWithoutNullStreams } from 'node:child_process';
2
+ import { PassThrough } from 'node:stream';
3
+ import { IDL } from '@dfinity/candid';
4
+ import { PocketIc, PocketIcServer } from 'pic-ic';
5
+ type StartOptions = {
6
+ type?: 'dfx' | 'pocket-ic';
7
+ dir?: string;
8
+ verbose?: boolean;
9
+ silent?: boolean;
10
+ };
11
+ export declare class Replica {
12
+ type: 'dfx' | 'pocket-ic';
13
+ verbose: boolean;
14
+ canisters: Record<string, {
15
+ cwd: string;
16
+ canisterId: string;
17
+ actor: any;
18
+ stream: PassThrough;
19
+ }>;
20
+ pocketIcServer?: PocketIcServer;
21
+ pocketIc?: PocketIc;
22
+ dfxProcess?: ChildProcessWithoutNullStreams;
23
+ dir: string;
24
+ ttl: number;
25
+ start({ type, dir, verbose, silent }?: StartOptions): Promise<void>;
26
+ _attachCanisterLogHandler(proc: ChildProcessWithoutNullStreams): void;
27
+ stop(sigint?: boolean): Promise<void>;
28
+ deploy(name: string, wasm: string, idlFactory: IDL.InterfaceFactory, cwd?: string): Promise<{
29
+ cwd: string;
30
+ canisterId: string;
31
+ actor: any;
32
+ stream: PassThrough;
33
+ }>;
34
+ getActor(name: string): unknown;
35
+ getCanister(name: string): {
36
+ cwd: string;
37
+ canisterId: string;
38
+ actor: any;
39
+ stream: PassThrough;
40
+ } | undefined;
41
+ getCanisterId(name: string): string;
42
+ getCanisterStream(canisterId: string): PassThrough | null;
43
+ dfxJson(canisterName: string, wasmPath?: string, didPath?: string): {
44
+ version: number;
45
+ canisters: Record<string, any>;
46
+ defaults: {
47
+ build: {
48
+ packtool: string;
49
+ };
50
+ };
51
+ networks: {
52
+ local: {
53
+ type: string;
54
+ bind: string;
55
+ };
56
+ };
57
+ };
58
+ }
59
+ export {};