@clarigen/test 0.3.4 → 1.0.0-next.11

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.
package/dist/test.esm.js DELETED
@@ -1,1633 +0,0 @@
1
- import { deserializeCV, ClarityType, responseOkCV, responseErrorCV } from '@stacks/transactions';
2
- import { err, ok } from 'neverthrow';
3
- import { cvToValue, parseToCV, cvToString, getContractNameFromPath, getContractIdentifier } from '@clarigen/core';
4
- import { getDefaultBinaryFilePath, getTempFilePath, NativeClarityBinProvider, hasStdErr } from '@clarigen/native-bin';
5
- import { join } from 'path';
6
-
7
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
8
- try {
9
- var info = gen[key](arg);
10
- var value = info.value;
11
- } catch (error) {
12
- reject(error);
13
- return;
14
- }
15
-
16
- if (info.done) {
17
- resolve(value);
18
- } else {
19
- Promise.resolve(value).then(_next, _throw);
20
- }
21
- }
22
-
23
- function _asyncToGenerator(fn) {
24
- return function () {
25
- var self = this,
26
- args = arguments;
27
- return new Promise(function (resolve, reject) {
28
- var gen = fn.apply(self, args);
29
-
30
- function _next(value) {
31
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
32
- }
33
-
34
- function _throw(err) {
35
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
36
- }
37
-
38
- _next(undefined);
39
- });
40
- };
41
- }
42
-
43
- function createCommonjsModule(fn, module) {
44
- return module = { exports: {} }, fn(module, module.exports), module.exports;
45
- }
46
-
47
- var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
48
- /**
49
- * Copyright (c) 2014-present, Facebook, Inc.
50
- *
51
- * This source code is licensed under the MIT license found in the
52
- * LICENSE file in the root directory of this source tree.
53
- */
54
- var runtime = function (exports) {
55
-
56
- var Op = Object.prototype;
57
- var hasOwn = Op.hasOwnProperty;
58
- var undefined$1; // More compressible than void 0.
59
-
60
- var $Symbol = typeof Symbol === "function" ? Symbol : {};
61
- var iteratorSymbol = $Symbol.iterator || "@@iterator";
62
- var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
63
- var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
64
-
65
- function define(obj, key, value) {
66
- Object.defineProperty(obj, key, {
67
- value: value,
68
- enumerable: true,
69
- configurable: true,
70
- writable: true
71
- });
72
- return obj[key];
73
- }
74
-
75
- try {
76
- // IE 8 has a broken Object.defineProperty that only works on DOM objects.
77
- define({}, "");
78
- } catch (err) {
79
- define = function define(obj, key, value) {
80
- return obj[key] = value;
81
- };
82
- }
83
-
84
- function wrap(innerFn, outerFn, self, tryLocsList) {
85
- // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
86
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
87
- var generator = Object.create(protoGenerator.prototype);
88
- var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
89
- // .throw, and .return methods.
90
-
91
- generator._invoke = makeInvokeMethod(innerFn, self, context);
92
- return generator;
93
- }
94
-
95
- exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
96
- // record like context.tryEntries[i].completion. This interface could
97
- // have been (and was previously) designed to take a closure to be
98
- // invoked without arguments, but in all the cases we care about we
99
- // already have an existing method we want to call, so there's no need
100
- // to create a new function object. We can even get away with assuming
101
- // the method takes exactly one argument, since that happens to be true
102
- // in every case, so we don't have to touch the arguments object. The
103
- // only additional allocation required is the completion record, which
104
- // has a stable shape and so hopefully should be cheap to allocate.
105
-
106
- function tryCatch(fn, obj, arg) {
107
- try {
108
- return {
109
- type: "normal",
110
- arg: fn.call(obj, arg)
111
- };
112
- } catch (err) {
113
- return {
114
- type: "throw",
115
- arg: err
116
- };
117
- }
118
- }
119
-
120
- var GenStateSuspendedStart = "suspendedStart";
121
- var GenStateSuspendedYield = "suspendedYield";
122
- var GenStateExecuting = "executing";
123
- var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
124
- // breaking out of the dispatch switch statement.
125
-
126
- var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
127
- // .constructor.prototype properties for functions that return Generator
128
- // objects. For full spec compliance, you may wish to configure your
129
- // minifier not to mangle the names of these two functions.
130
-
131
- function Generator() {}
132
-
133
- function GeneratorFunction() {}
134
-
135
- function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
136
- // don't natively support it.
137
-
138
-
139
- var IteratorPrototype = {};
140
-
141
- IteratorPrototype[iteratorSymbol] = function () {
142
- return this;
143
- };
144
-
145
- var getProto = Object.getPrototypeOf;
146
- var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
147
-
148
- if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
149
- // This environment has a native %IteratorPrototype%; use it instead
150
- // of the polyfill.
151
- IteratorPrototype = NativeIteratorPrototype;
152
- }
153
-
154
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
155
- GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
156
- GeneratorFunctionPrototype.constructor = GeneratorFunction;
157
- GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
158
- // Iterator interface in terms of a single ._invoke method.
159
-
160
- function defineIteratorMethods(prototype) {
161
- ["next", "throw", "return"].forEach(function (method) {
162
- define(prototype, method, function (arg) {
163
- return this._invoke(method, arg);
164
- });
165
- });
166
- }
167
-
168
- exports.isGeneratorFunction = function (genFun) {
169
- var ctor = typeof genFun === "function" && genFun.constructor;
170
- return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
171
- // do is to check its .name property.
172
- (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
173
- };
174
-
175
- exports.mark = function (genFun) {
176
- if (Object.setPrototypeOf) {
177
- Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
178
- } else {
179
- genFun.__proto__ = GeneratorFunctionPrototype;
180
- define(genFun, toStringTagSymbol, "GeneratorFunction");
181
- }
182
-
183
- genFun.prototype = Object.create(Gp);
184
- return genFun;
185
- }; // Within the body of any async function, `await x` is transformed to
186
- // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
187
- // `hasOwn.call(value, "__await")` to determine if the yielded value is
188
- // meant to be awaited.
189
-
190
-
191
- exports.awrap = function (arg) {
192
- return {
193
- __await: arg
194
- };
195
- };
196
-
197
- function AsyncIterator(generator, PromiseImpl) {
198
- function invoke(method, arg, resolve, reject) {
199
- var record = tryCatch(generator[method], generator, arg);
200
-
201
- if (record.type === "throw") {
202
- reject(record.arg);
203
- } else {
204
- var result = record.arg;
205
- var value = result.value;
206
-
207
- if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
208
- return PromiseImpl.resolve(value.__await).then(function (value) {
209
- invoke("next", value, resolve, reject);
210
- }, function (err) {
211
- invoke("throw", err, resolve, reject);
212
- });
213
- }
214
-
215
- return PromiseImpl.resolve(value).then(function (unwrapped) {
216
- // When a yielded Promise is resolved, its final value becomes
217
- // the .value of the Promise<{value,done}> result for the
218
- // current iteration.
219
- result.value = unwrapped;
220
- resolve(result);
221
- }, function (error) {
222
- // If a rejected Promise was yielded, throw the rejection back
223
- // into the async generator function so it can be handled there.
224
- return invoke("throw", error, resolve, reject);
225
- });
226
- }
227
- }
228
-
229
- var previousPromise;
230
-
231
- function enqueue(method, arg) {
232
- function callInvokeWithMethodAndArg() {
233
- return new PromiseImpl(function (resolve, reject) {
234
- invoke(method, arg, resolve, reject);
235
- });
236
- }
237
-
238
- return previousPromise = // If enqueue has been called before, then we want to wait until
239
- // all previous Promises have been resolved before calling invoke,
240
- // so that results are always delivered in the correct order. If
241
- // enqueue has not been called before, then it is important to
242
- // call invoke immediately, without waiting on a callback to fire,
243
- // so that the async generator function has the opportunity to do
244
- // any necessary setup in a predictable way. This predictability
245
- // is why the Promise constructor synchronously invokes its
246
- // executor callback, and why async functions synchronously
247
- // execute code before the first await. Since we implement simple
248
- // async functions in terms of async generators, it is especially
249
- // important to get this right, even though it requires care.
250
- previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
251
- // invocations of the iterator.
252
- callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
253
- } // Define the unified helper method that is used to implement .next,
254
- // .throw, and .return (see defineIteratorMethods).
255
-
256
-
257
- this._invoke = enqueue;
258
- }
259
-
260
- defineIteratorMethods(AsyncIterator.prototype);
261
-
262
- AsyncIterator.prototype[asyncIteratorSymbol] = function () {
263
- return this;
264
- };
265
-
266
- exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
267
- // AsyncIterator objects; they just return a Promise for the value of
268
- // the final result produced by the iterator.
269
-
270
- exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
271
- if (PromiseImpl === void 0) PromiseImpl = Promise;
272
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
273
- return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
274
- : iter.next().then(function (result) {
275
- return result.done ? result.value : iter.next();
276
- });
277
- };
278
-
279
- function makeInvokeMethod(innerFn, self, context) {
280
- var state = GenStateSuspendedStart;
281
- return function invoke(method, arg) {
282
- if (state === GenStateExecuting) {
283
- throw new Error("Generator is already running");
284
- }
285
-
286
- if (state === GenStateCompleted) {
287
- if (method === "throw") {
288
- throw arg;
289
- } // Be forgiving, per 25.3.3.3.3 of the spec:
290
- // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
291
-
292
-
293
- return doneResult();
294
- }
295
-
296
- context.method = method;
297
- context.arg = arg;
298
-
299
- while (true) {
300
- var delegate = context.delegate;
301
-
302
- if (delegate) {
303
- var delegateResult = maybeInvokeDelegate(delegate, context);
304
-
305
- if (delegateResult) {
306
- if (delegateResult === ContinueSentinel) continue;
307
- return delegateResult;
308
- }
309
- }
310
-
311
- if (context.method === "next") {
312
- // Setting context._sent for legacy support of Babel's
313
- // function.sent implementation.
314
- context.sent = context._sent = context.arg;
315
- } else if (context.method === "throw") {
316
- if (state === GenStateSuspendedStart) {
317
- state = GenStateCompleted;
318
- throw context.arg;
319
- }
320
-
321
- context.dispatchException(context.arg);
322
- } else if (context.method === "return") {
323
- context.abrupt("return", context.arg);
324
- }
325
-
326
- state = GenStateExecuting;
327
- var record = tryCatch(innerFn, self, context);
328
-
329
- if (record.type === "normal") {
330
- // If an exception is thrown from innerFn, we leave state ===
331
- // GenStateExecuting and loop back for another invocation.
332
- state = context.done ? GenStateCompleted : GenStateSuspendedYield;
333
-
334
- if (record.arg === ContinueSentinel) {
335
- continue;
336
- }
337
-
338
- return {
339
- value: record.arg,
340
- done: context.done
341
- };
342
- } else if (record.type === "throw") {
343
- state = GenStateCompleted; // Dispatch the exception by looping back around to the
344
- // context.dispatchException(context.arg) call above.
345
-
346
- context.method = "throw";
347
- context.arg = record.arg;
348
- }
349
- }
350
- };
351
- } // Call delegate.iterator[context.method](context.arg) and handle the
352
- // result, either by returning a { value, done } result from the
353
- // delegate iterator, or by modifying context.method and context.arg,
354
- // setting context.delegate to null, and returning the ContinueSentinel.
355
-
356
-
357
- function maybeInvokeDelegate(delegate, context) {
358
- var method = delegate.iterator[context.method];
359
-
360
- if (method === undefined$1) {
361
- // A .throw or .return when the delegate iterator has no .throw
362
- // method always terminates the yield* loop.
363
- context.delegate = null;
364
-
365
- if (context.method === "throw") {
366
- // Note: ["return"] must be used for ES3 parsing compatibility.
367
- if (delegate.iterator["return"]) {
368
- // If the delegate iterator has a return method, give it a
369
- // chance to clean up.
370
- context.method = "return";
371
- context.arg = undefined$1;
372
- maybeInvokeDelegate(delegate, context);
373
-
374
- if (context.method === "throw") {
375
- // If maybeInvokeDelegate(context) changed context.method from
376
- // "return" to "throw", let that override the TypeError below.
377
- return ContinueSentinel;
378
- }
379
- }
380
-
381
- context.method = "throw";
382
- context.arg = new TypeError("The iterator does not provide a 'throw' method");
383
- }
384
-
385
- return ContinueSentinel;
386
- }
387
-
388
- var record = tryCatch(method, delegate.iterator, context.arg);
389
-
390
- if (record.type === "throw") {
391
- context.method = "throw";
392
- context.arg = record.arg;
393
- context.delegate = null;
394
- return ContinueSentinel;
395
- }
396
-
397
- var info = record.arg;
398
-
399
- if (!info) {
400
- context.method = "throw";
401
- context.arg = new TypeError("iterator result is not an object");
402
- context.delegate = null;
403
- return ContinueSentinel;
404
- }
405
-
406
- if (info.done) {
407
- // Assign the result of the finished delegate to the temporary
408
- // variable specified by delegate.resultName (see delegateYield).
409
- context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
410
-
411
- context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
412
- // exception, let the outer generator proceed normally. If
413
- // context.method was "next", forget context.arg since it has been
414
- // "consumed" by the delegate iterator. If context.method was
415
- // "return", allow the original .return call to continue in the
416
- // outer generator.
417
-
418
- if (context.method !== "return") {
419
- context.method = "next";
420
- context.arg = undefined$1;
421
- }
422
- } else {
423
- // Re-yield the result returned by the delegate method.
424
- return info;
425
- } // The delegate iterator is finished, so forget it and continue with
426
- // the outer generator.
427
-
428
-
429
- context.delegate = null;
430
- return ContinueSentinel;
431
- } // Define Generator.prototype.{next,throw,return} in terms of the
432
- // unified ._invoke helper method.
433
-
434
-
435
- defineIteratorMethods(Gp);
436
- define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
437
- // @@iterator function is called on it. Some browsers' implementations of the
438
- // iterator prototype chain incorrectly implement this, causing the Generator
439
- // object to not be returned from this call. This ensures that doesn't happen.
440
- // See https://github.com/facebook/regenerator/issues/274 for more details.
441
-
442
- Gp[iteratorSymbol] = function () {
443
- return this;
444
- };
445
-
446
- Gp.toString = function () {
447
- return "[object Generator]";
448
- };
449
-
450
- function pushTryEntry(locs) {
451
- var entry = {
452
- tryLoc: locs[0]
453
- };
454
-
455
- if (1 in locs) {
456
- entry.catchLoc = locs[1];
457
- }
458
-
459
- if (2 in locs) {
460
- entry.finallyLoc = locs[2];
461
- entry.afterLoc = locs[3];
462
- }
463
-
464
- this.tryEntries.push(entry);
465
- }
466
-
467
- function resetTryEntry(entry) {
468
- var record = entry.completion || {};
469
- record.type = "normal";
470
- delete record.arg;
471
- entry.completion = record;
472
- }
473
-
474
- function Context(tryLocsList) {
475
- // The root entry object (effectively a try statement without a catch
476
- // or a finally block) gives us a place to store values thrown from
477
- // locations where there is no enclosing try statement.
478
- this.tryEntries = [{
479
- tryLoc: "root"
480
- }];
481
- tryLocsList.forEach(pushTryEntry, this);
482
- this.reset(true);
483
- }
484
-
485
- exports.keys = function (object) {
486
- var keys = [];
487
-
488
- for (var key in object) {
489
- keys.push(key);
490
- }
491
-
492
- keys.reverse(); // Rather than returning an object with a next method, we keep
493
- // things simple and return the next function itself.
494
-
495
- return function next() {
496
- while (keys.length) {
497
- var key = keys.pop();
498
-
499
- if (key in object) {
500
- next.value = key;
501
- next.done = false;
502
- return next;
503
- }
504
- } // To avoid creating an additional object, we just hang the .value
505
- // and .done properties off the next function object itself. This
506
- // also ensures that the minifier will not anonymize the function.
507
-
508
-
509
- next.done = true;
510
- return next;
511
- };
512
- };
513
-
514
- function values(iterable) {
515
- if (iterable) {
516
- var iteratorMethod = iterable[iteratorSymbol];
517
-
518
- if (iteratorMethod) {
519
- return iteratorMethod.call(iterable);
520
- }
521
-
522
- if (typeof iterable.next === "function") {
523
- return iterable;
524
- }
525
-
526
- if (!isNaN(iterable.length)) {
527
- var i = -1,
528
- next = function next() {
529
- while (++i < iterable.length) {
530
- if (hasOwn.call(iterable, i)) {
531
- next.value = iterable[i];
532
- next.done = false;
533
- return next;
534
- }
535
- }
536
-
537
- next.value = undefined$1;
538
- next.done = true;
539
- return next;
540
- };
541
-
542
- return next.next = next;
543
- }
544
- } // Return an iterator with no values.
545
-
546
-
547
- return {
548
- next: doneResult
549
- };
550
- }
551
-
552
- exports.values = values;
553
-
554
- function doneResult() {
555
- return {
556
- value: undefined$1,
557
- done: true
558
- };
559
- }
560
-
561
- Context.prototype = {
562
- constructor: Context,
563
- reset: function reset(skipTempReset) {
564
- this.prev = 0;
565
- this.next = 0; // Resetting context._sent for legacy support of Babel's
566
- // function.sent implementation.
567
-
568
- this.sent = this._sent = undefined$1;
569
- this.done = false;
570
- this.delegate = null;
571
- this.method = "next";
572
- this.arg = undefined$1;
573
- this.tryEntries.forEach(resetTryEntry);
574
-
575
- if (!skipTempReset) {
576
- for (var name in this) {
577
- // Not sure about the optimal order of these conditions:
578
- if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
579
- this[name] = undefined$1;
580
- }
581
- }
582
- }
583
- },
584
- stop: function stop() {
585
- this.done = true;
586
- var rootEntry = this.tryEntries[0];
587
- var rootRecord = rootEntry.completion;
588
-
589
- if (rootRecord.type === "throw") {
590
- throw rootRecord.arg;
591
- }
592
-
593
- return this.rval;
594
- },
595
- dispatchException: function dispatchException(exception) {
596
- if (this.done) {
597
- throw exception;
598
- }
599
-
600
- var context = this;
601
-
602
- function handle(loc, caught) {
603
- record.type = "throw";
604
- record.arg = exception;
605
- context.next = loc;
606
-
607
- if (caught) {
608
- // If the dispatched exception was caught by a catch block,
609
- // then let that catch block handle the exception normally.
610
- context.method = "next";
611
- context.arg = undefined$1;
612
- }
613
-
614
- return !!caught;
615
- }
616
-
617
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
618
- var entry = this.tryEntries[i];
619
- var record = entry.completion;
620
-
621
- if (entry.tryLoc === "root") {
622
- // Exception thrown outside of any try block that could handle
623
- // it, so set the completion value of the entire function to
624
- // throw the exception.
625
- return handle("end");
626
- }
627
-
628
- if (entry.tryLoc <= this.prev) {
629
- var hasCatch = hasOwn.call(entry, "catchLoc");
630
- var hasFinally = hasOwn.call(entry, "finallyLoc");
631
-
632
- if (hasCatch && hasFinally) {
633
- if (this.prev < entry.catchLoc) {
634
- return handle(entry.catchLoc, true);
635
- } else if (this.prev < entry.finallyLoc) {
636
- return handle(entry.finallyLoc);
637
- }
638
- } else if (hasCatch) {
639
- if (this.prev < entry.catchLoc) {
640
- return handle(entry.catchLoc, true);
641
- }
642
- } else if (hasFinally) {
643
- if (this.prev < entry.finallyLoc) {
644
- return handle(entry.finallyLoc);
645
- }
646
- } else {
647
- throw new Error("try statement without catch or finally");
648
- }
649
- }
650
- }
651
- },
652
- abrupt: function abrupt(type, arg) {
653
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
654
- var entry = this.tryEntries[i];
655
-
656
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
657
- var finallyEntry = entry;
658
- break;
659
- }
660
- }
661
-
662
- if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
663
- // Ignore the finally entry if control is not jumping to a
664
- // location outside the try/catch block.
665
- finallyEntry = null;
666
- }
667
-
668
- var record = finallyEntry ? finallyEntry.completion : {};
669
- record.type = type;
670
- record.arg = arg;
671
-
672
- if (finallyEntry) {
673
- this.method = "next";
674
- this.next = finallyEntry.finallyLoc;
675
- return ContinueSentinel;
676
- }
677
-
678
- return this.complete(record);
679
- },
680
- complete: function complete(record, afterLoc) {
681
- if (record.type === "throw") {
682
- throw record.arg;
683
- }
684
-
685
- if (record.type === "break" || record.type === "continue") {
686
- this.next = record.arg;
687
- } else if (record.type === "return") {
688
- this.rval = this.arg = record.arg;
689
- this.method = "return";
690
- this.next = "end";
691
- } else if (record.type === "normal" && afterLoc) {
692
- this.next = afterLoc;
693
- }
694
-
695
- return ContinueSentinel;
696
- },
697
- finish: function finish(finallyLoc) {
698
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
699
- var entry = this.tryEntries[i];
700
-
701
- if (entry.finallyLoc === finallyLoc) {
702
- this.complete(entry.completion, entry.afterLoc);
703
- resetTryEntry(entry);
704
- return ContinueSentinel;
705
- }
706
- }
707
- },
708
- "catch": function _catch(tryLoc) {
709
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
710
- var entry = this.tryEntries[i];
711
-
712
- if (entry.tryLoc === tryLoc) {
713
- var record = entry.completion;
714
-
715
- if (record.type === "throw") {
716
- var thrown = record.arg;
717
- resetTryEntry(entry);
718
- }
719
-
720
- return thrown;
721
- }
722
- } // The context.catch method must only be called with a location
723
- // argument that corresponds to a known catch block.
724
-
725
-
726
- throw new Error("illegal catch attempt");
727
- },
728
- delegateYield: function delegateYield(iterable, resultName, nextLoc) {
729
- this.delegate = {
730
- iterator: values(iterable),
731
- resultName: resultName,
732
- nextLoc: nextLoc
733
- };
734
-
735
- if (this.method === "next") {
736
- // Deliberately forget the last sent value so that we don't
737
- // accidentally pass it on to the delegate.
738
- this.arg = undefined$1;
739
- }
740
-
741
- return ContinueSentinel;
742
- }
743
- }; // Regardless of whether this script is executing as a CommonJS module
744
- // or not, return the runtime object so that we can declare the variable
745
- // regeneratorRuntime in the outer scope, which allows this module to be
746
- // injected easily by `bin/regenerator --include-runtime script.js`.
747
-
748
- return exports;
749
- }( // If this script is executing as a CommonJS module, use module.exports
750
- // as the regeneratorRuntime namespace. Otherwise create a new empty
751
- // object. Either way, the resulting object will be used to initialize
752
- // the regeneratorRuntime variable at the top of this file.
753
- module.exports );
754
-
755
- try {
756
- regeneratorRuntime = runtime;
757
- } catch (accidentalStrictMode) {
758
- // This module should not be running in strict mode, so the above
759
- // assignment should always work unless something is misconfigured. Just
760
- // in case runtime.js accidentally runs in strict mode, we can escape
761
- // strict mode using a global Function call. This could conceivably fail
762
- // if a Content Security Policy forbids using Function, but in that case
763
- // the proper solution is to fix the accidental strict mode problem. If
764
- // you've misconfigured your bundler to force strict mode and applied a
765
- // CSP to forbid Function, and you're not willing to fix either of those
766
- // problems, please detail your unique predicament in a GitHub issue.
767
- Function("r", "regeneratorRuntime = r")(runtime);
768
- }
769
- });
770
-
771
- var executeJson = /*#__PURE__*/function () {
772
- var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref) {
773
- var contractAddress, senderAddress, functionName, provider, _ref$args, args, result, response;
774
-
775
- return runtime_1.wrap(function _callee$(_context) {
776
- while (1) {
777
- switch (_context.prev = _context.next) {
778
- case 0:
779
- contractAddress = _ref.contractAddress, senderAddress = _ref.senderAddress, functionName = _ref.functionName, provider = _ref.provider, _ref$args = _ref.args, args = _ref$args === void 0 ? [] : _ref$args;
780
- _context.next = 3;
781
- return provider.runCommand(['execute', '--costs', '--assets', provider.dbFilePath, contractAddress, functionName, senderAddress].concat(args));
782
-
783
- case 3:
784
- result = _context.sent;
785
-
786
- if (process.env.PRINT_CLARIGEN_STDERR && result.stderr) {
787
- console.log(result.stderr);
788
- }
789
-
790
- response = JSON.parse(result.stdout);
791
-
792
- if (!(response && 'error' in response)) {
793
- _context.next = 8;
794
- break;
795
- }
796
-
797
- throw new Error("Transaction error: " + JSON.stringify(response.error, null, 2));
798
-
799
- case 8:
800
- if (!(result.exitCode !== 0)) {
801
- _context.next = 10;
802
- break;
803
- }
804
-
805
- throw new Error("Execution error: " + result.stderr);
806
-
807
- case 10:
808
- return _context.abrupt("return", response);
809
-
810
- case 11:
811
- case "end":
812
- return _context.stop();
813
- }
814
- }
815
- }, _callee);
816
- }));
817
-
818
- return function executeJson(_x) {
819
- return _ref2.apply(this, arguments);
820
- };
821
- }();
822
- var evalJson = /*#__PURE__*/function () {
823
- var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref3) {
824
- var contractAddress, functionName, provider, _ref3$args, args, evalCode, receipt, response;
825
-
826
- return runtime_1.wrap(function _callee2$(_context2) {
827
- while (1) {
828
- switch (_context2.prev = _context2.next) {
829
- case 0:
830
- contractAddress = _ref3.contractAddress, functionName = _ref3.functionName, provider = _ref3.provider, _ref3$args = _ref3.args, args = _ref3$args === void 0 ? [] : _ref3$args;
831
- evalCode = "(" + functionName + " " + args.join(' ') + ")";
832
- _context2.next = 4;
833
- return provider.runCommand(['eval_at_chaintip', '--costs', contractAddress, provider.dbFilePath], {
834
- stdin: evalCode
835
- });
836
-
837
- case 4:
838
- receipt = _context2.sent;
839
-
840
- if (process.env.PRINT_CLARIGEN_STDERR && receipt.stderr) {
841
- console.log(receipt.stderr);
842
- }
843
-
844
- response = JSON.parse(receipt.stdout);
845
-
846
- if (response.success) {
847
- _context2.next = 9;
848
- break;
849
- }
850
-
851
- throw new Error(JSON.stringify(response.error, null, 2));
852
-
853
- case 9:
854
- return _context2.abrupt("return", response);
855
-
856
- case 10:
857
- case "end":
858
- return _context2.stop();
859
- }
860
- }
861
- }, _callee2);
862
- }));
863
-
864
- return function evalJson(_x2) {
865
- return _ref4.apply(this, arguments);
866
- };
867
- }();
868
- function getAllocations(allocations) {
869
- if (!allocations) return [];
870
-
871
- if ('deployer' in allocations) {
872
- return Object.values(allocations).map(function (a) {
873
- return {
874
- amount: a.balance,
875
- principal: a.address
876
- };
877
- });
878
- } else if (Array.isArray(allocations)) {
879
- return allocations;
880
- }
881
-
882
- return [];
883
- }
884
-
885
- function bigintReplacer(key, value) {
886
- if (typeof value === 'bigint') return value + "n";
887
- return value;
888
- }
889
-
890
- function stringifyAllocations(allocations) {
891
- var json = JSON.stringify(allocations, bigintReplacer);
892
- return json.replace(/"(-?\d+)n"/g, function (_, a) {
893
- return a;
894
- });
895
- }
896
-
897
- var createClarityBin = /*#__PURE__*/function () {
898
- var _ref5 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(_temp) {
899
- var _ref6, allocations, _ref6$testnet, testnet, binFile, dbFileName, _allocations, provider, args;
900
-
901
- return runtime_1.wrap(function _callee3$(_context3) {
902
- while (1) {
903
- switch (_context3.prev = _context3.next) {
904
- case 0:
905
- _ref6 = _temp === void 0 ? {} : _temp, allocations = _ref6.allocations, _ref6$testnet = _ref6.testnet, testnet = _ref6$testnet === void 0 ? true : _ref6$testnet;
906
- binFile = getDefaultBinaryFilePath();
907
- dbFileName = getTempFilePath();
908
- _allocations = getAllocations(allocations);
909
- provider = new NativeClarityBinProvider(dbFileName, binFile);
910
- args = ['initialize', '-', dbFileName];
911
- if (testnet) args.push('--testnet');
912
- _context3.next = 9;
913
- return provider.runCommand(args, {
914
- stdin: stringifyAllocations(_allocations)
915
- });
916
-
917
- case 9:
918
- return _context3.abrupt("return", provider);
919
-
920
- case 10:
921
- case "end":
922
- return _context3.stop();
923
- }
924
- }
925
- }, _callee3);
926
- }));
927
-
928
- return function createClarityBin(_x3) {
929
- return _ref5.apply(this, arguments);
930
- };
931
- }();
932
- function getDefaultClarityBin(_x4) {
933
- return _getDefaultClarityBin.apply(this, arguments);
934
- }
935
-
936
- function _getDefaultClarityBin() {
937
- _getDefaultClarityBin = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(clarityBinOrAccounts) {
938
- var clarityBin;
939
- return runtime_1.wrap(function _callee4$(_context4) {
940
- while (1) {
941
- switch (_context4.prev = _context4.next) {
942
- case 0:
943
- if (clarityBinOrAccounts) {
944
- _context4.next = 6;
945
- break;
946
- }
947
-
948
- _context4.next = 3;
949
- return createClarityBin();
950
-
951
- case 3:
952
- clarityBin = _context4.sent;
953
- _context4.next = 17;
954
- break;
955
-
956
- case 6:
957
- if (!('deployer' in clarityBinOrAccounts)) {
958
- _context4.next = 12;
959
- break;
960
- }
961
-
962
- _context4.next = 9;
963
- return createClarityBin({
964
- allocations: clarityBinOrAccounts
965
- });
966
-
967
- case 9:
968
- clarityBin = _context4.sent;
969
- _context4.next = 17;
970
- break;
971
-
972
- case 12:
973
- if (!(clarityBinOrAccounts instanceof NativeClarityBinProvider)) {
974
- _context4.next = 16;
975
- break;
976
- }
977
-
978
- clarityBin = clarityBinOrAccounts;
979
- _context4.next = 17;
980
- break;
981
-
982
- case 16:
983
- throw new Error('Should never get here');
984
-
985
- case 17:
986
- return _context4.abrupt("return", clarityBin);
987
-
988
- case 18:
989
- case "end":
990
- return _context4.stop();
991
- }
992
- }
993
- }, _callee4);
994
- }));
995
- return _getDefaultClarityBin.apply(this, arguments);
996
- }
997
-
998
- function deployContract(_x5) {
999
- return _deployContract.apply(this, arguments);
1000
- }
1001
-
1002
- function _deployContract() {
1003
- _deployContract = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(_ref7) {
1004
- var contractIdentifier, contractFilePath, provider, receipt, output, initialization, _initialization$split, error, trace, startLine, matcher, matches;
1005
-
1006
- return runtime_1.wrap(function _callee5$(_context5) {
1007
- while (1) {
1008
- switch (_context5.prev = _context5.next) {
1009
- case 0:
1010
- contractIdentifier = _ref7.contractIdentifier, contractFilePath = _ref7.contractFilePath, provider = _ref7.provider;
1011
- _context5.next = 3;
1012
- return provider.runCommand(['launch', contractIdentifier, contractFilePath, provider.dbFilePath, '--costs', '--assets']);
1013
-
1014
- case 3:
1015
- receipt = _context5.sent;
1016
-
1017
- if (!hasStdErr(receipt.stderr)) {
1018
- _context5.next = 6;
1019
- break;
1020
- }
1021
-
1022
- throw new Error("Error on " + contractFilePath + ":\n " + receipt.stderr + "\n ");
1023
-
1024
- case 6:
1025
- output = JSON.parse(receipt.stdout);
1026
-
1027
- if (!output.error) {
1028
- _context5.next = 17;
1029
- break;
1030
- }
1031
-
1032
- initialization = output.error.initialization;
1033
-
1034
- if (!(initialization != null && initialization.includes('\nNear:\n'))) {
1035
- _context5.next = 16;
1036
- break;
1037
- }
1038
-
1039
- _initialization$split = initialization.split('\nNear:\n'), error = _initialization$split[0], trace = _initialization$split[1];
1040
- startLine = '';
1041
- matcher = /start_line: (\d+),/;
1042
- matches = matcher.exec(trace);
1043
- if (matches) startLine = matches[1];
1044
- throw new Error("Error on " + contractFilePath + ":\n " + error + "\n " + (startLine ? "Near line " + startLine : '') + "\n Raw trace:\n " + trace + "\n ");
1045
-
1046
- case 16:
1047
- throw new Error("Error on " + contractFilePath + ":\n " + JSON.stringify(output.error, null, 2) + "\n ");
1048
-
1049
- case 17:
1050
- case "end":
1051
- return _context5.stop();
1052
- }
1053
- }
1054
- }, _callee5);
1055
- }));
1056
- return _deployContract.apply(this, arguments);
1057
- }
1058
-
1059
- var UTIL_CONTRACT_ID = 'ST000000000000000000002AMW42H.clarigen-test-utils';
1060
- function deployUtilContract(_x) {
1061
- return _deployUtilContract.apply(this, arguments);
1062
- }
1063
-
1064
- function _deployUtilContract() {
1065
- _deployUtilContract = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(clarityBin) {
1066
- var contractFilePath;
1067
- return runtime_1.wrap(function _callee$(_context) {
1068
- while (1) {
1069
- switch (_context.prev = _context.next) {
1070
- case 0:
1071
- contractFilePath = join(__dirname, '..', '..', 'contracts', 'test-utils.clar');
1072
-
1073
- if (__dirname.includes('dist')) {
1074
- contractFilePath = join(__dirname, '..', 'contracts', 'test-utils.clar');
1075
- }
1076
-
1077
- _context.next = 4;
1078
- return deployContract({
1079
- contractIdentifier: UTIL_CONTRACT_ID,
1080
- provider: clarityBin,
1081
- contractFilePath: contractFilePath
1082
- });
1083
-
1084
- case 4:
1085
- case "end":
1086
- return _context.stop();
1087
- }
1088
- }
1089
- }, _callee);
1090
- }));
1091
- return _deployUtilContract.apply(this, arguments);
1092
- }
1093
-
1094
- function getBlockHeight(_x2) {
1095
- return _getBlockHeight.apply(this, arguments);
1096
- }
1097
-
1098
- function _getBlockHeight() {
1099
- _getBlockHeight = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(provider) {
1100
- var _yield$evalJson, output_serialized, outputCV, blockHeight;
1101
-
1102
- return runtime_1.wrap(function _callee2$(_context2) {
1103
- while (1) {
1104
- switch (_context2.prev = _context2.next) {
1105
- case 0:
1106
- _context2.next = 2;
1107
- return evalJson({
1108
- contractAddress: UTIL_CONTRACT_ID,
1109
- functionName: 'get-block-height',
1110
- args: [],
1111
- provider: provider
1112
- });
1113
-
1114
- case 2:
1115
- _yield$evalJson = _context2.sent;
1116
- output_serialized = _yield$evalJson.output_serialized;
1117
- outputCV = deserializeCV(Buffer.from(output_serialized, 'hex'));
1118
- blockHeight = cvToValue(outputCV);
1119
- return _context2.abrupt("return", blockHeight);
1120
-
1121
- case 7:
1122
- case "end":
1123
- return _context2.stop();
1124
- }
1125
- }
1126
- }, _callee2);
1127
- }));
1128
- return _getBlockHeight.apply(this, arguments);
1129
- }
1130
-
1131
- function mineBlock(_x3) {
1132
- return _mineBlock.apply(this, arguments);
1133
- }
1134
-
1135
- function _mineBlock() {
1136
- _mineBlock = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(provider) {
1137
- return runtime_1.wrap(function _callee3$(_context3) {
1138
- while (1) {
1139
- switch (_context3.prev = _context3.next) {
1140
- case 0:
1141
- _context3.next = 2;
1142
- return executeJson({
1143
- contractAddress: UTIL_CONTRACT_ID,
1144
- functionName: 'mine-block',
1145
- args: [],
1146
- provider: provider,
1147
- senderAddress: 'ST000000000000000000002AMW42H'
1148
- });
1149
-
1150
- case 2:
1151
- case "end":
1152
- return _context3.stop();
1153
- }
1154
- }
1155
- }, _callee3);
1156
- }));
1157
- return _mineBlock.apply(this, arguments);
1158
- }
1159
-
1160
- function mineBlocks(_x4, _x5) {
1161
- return _mineBlocks.apply(this, arguments);
1162
- }
1163
-
1164
- function _mineBlocks() {
1165
- _mineBlocks = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(blocks, provider) {
1166
- var index;
1167
- return runtime_1.wrap(function _callee4$(_context4) {
1168
- while (1) {
1169
- switch (_context4.prev = _context4.next) {
1170
- case 0:
1171
- index = 0;
1172
-
1173
- case 1:
1174
- if (!(index < blocks)) {
1175
- _context4.next = 7;
1176
- break;
1177
- }
1178
-
1179
- _context4.next = 4;
1180
- return mineBlock(provider);
1181
-
1182
- case 4:
1183
- index++;
1184
- _context4.next = 1;
1185
- break;
1186
-
1187
- case 7:
1188
- case "end":
1189
- return _context4.stop();
1190
- }
1191
- }
1192
- }, _callee4);
1193
- }));
1194
- return _mineBlocks.apply(this, arguments);
1195
- }
1196
-
1197
- function getStxBalance(_x6, _x7) {
1198
- return _getStxBalance.apply(this, arguments);
1199
- }
1200
-
1201
- function _getStxBalance() {
1202
- _getStxBalance = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(provider, account) {
1203
- var _yield$evalJson2, output_serialized, outputCV, balance;
1204
-
1205
- return runtime_1.wrap(function _callee5$(_context5) {
1206
- while (1) {
1207
- switch (_context5.prev = _context5.next) {
1208
- case 0:
1209
- _context5.next = 2;
1210
- return evalJson({
1211
- contractAddress: UTIL_CONTRACT_ID,
1212
- functionName: 'get-stx-balance',
1213
- args: ["'" + account],
1214
- provider: provider
1215
- });
1216
-
1217
- case 2:
1218
- _yield$evalJson2 = _context5.sent;
1219
- output_serialized = _yield$evalJson2.output_serialized;
1220
- outputCV = deserializeCV(Buffer.from(output_serialized, 'hex'));
1221
- balance = cvToValue(outputCV);
1222
- return _context5.abrupt("return", balance);
1223
-
1224
- case 7:
1225
- case "end":
1226
- return _context5.stop();
1227
- }
1228
- }
1229
- }, _callee5);
1230
- }));
1231
- return _getStxBalance.apply(this, arguments);
1232
- }
1233
-
1234
- function tx(_x, _x2) {
1235
- return _tx2.apply(this, arguments);
1236
- }
1237
-
1238
- function _tx2() {
1239
- _tx2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(tx, sender) {
1240
- var receipt, result;
1241
- return runtime_1.wrap(function _callee$(_context) {
1242
- while (1) {
1243
- switch (_context.prev = _context.next) {
1244
- case 0:
1245
- _context.next = 2;
1246
- return tx.submit({
1247
- sender: sender
1248
- });
1249
-
1250
- case 2:
1251
- receipt = _context.sent;
1252
- _context.next = 5;
1253
- return receipt.getResult();
1254
-
1255
- case 5:
1256
- result = _context.sent;
1257
- return _context.abrupt("return", result);
1258
-
1259
- case 7:
1260
- case "end":
1261
- return _context.stop();
1262
- }
1263
- }
1264
- }, _callee);
1265
- }));
1266
- return _tx2.apply(this, arguments);
1267
- }
1268
-
1269
- function txOk(_x3, _x4) {
1270
- return _txOk.apply(this, arguments);
1271
- }
1272
-
1273
- function _txOk() {
1274
- _txOk = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_tx, sender) {
1275
- var result;
1276
- return runtime_1.wrap(function _callee2$(_context2) {
1277
- while (1) {
1278
- switch (_context2.prev = _context2.next) {
1279
- case 0:
1280
- _context2.next = 2;
1281
- return tx(_tx, sender);
1282
-
1283
- case 2:
1284
- result = _context2.sent;
1285
-
1286
- if (result.isOk) {
1287
- _context2.next = 5;
1288
- break;
1289
- }
1290
-
1291
- throw new Error("Expected transaction ok, got error: " + result.value);
1292
-
1293
- case 5:
1294
- return _context2.abrupt("return", result);
1295
-
1296
- case 6:
1297
- case "end":
1298
- return _context2.stop();
1299
- }
1300
- }
1301
- }, _callee2);
1302
- }));
1303
- return _txOk.apply(this, arguments);
1304
- }
1305
-
1306
- function txErr(_x5, _x6) {
1307
- return _txErr.apply(this, arguments);
1308
- }
1309
-
1310
- function _txErr() {
1311
- _txErr = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(_tx, sender) {
1312
- var result;
1313
- return runtime_1.wrap(function _callee3$(_context3) {
1314
- while (1) {
1315
- switch (_context3.prev = _context3.next) {
1316
- case 0:
1317
- _context3.next = 2;
1318
- return tx(_tx, sender);
1319
-
1320
- case 2:
1321
- result = _context3.sent;
1322
-
1323
- if (!result.isOk) {
1324
- _context3.next = 5;
1325
- break;
1326
- }
1327
-
1328
- throw new Error("Expected transaction error, got ok: " + result.value);
1329
-
1330
- case 5:
1331
- return _context3.abrupt("return", result);
1332
-
1333
- case 6:
1334
- case "end":
1335
- return _context3.stop();
1336
- }
1337
- }
1338
- }, _callee3);
1339
- }));
1340
- return _txErr.apply(this, arguments);
1341
- }
1342
-
1343
- var TestProvider = /*#__PURE__*/function () {
1344
- function TestProvider(clarityBin, contractIdentifier, contractFile) {
1345
- this.clarityBin = clarityBin;
1346
- this.contractIdentifier = contractIdentifier;
1347
- this.contractFile = contractFile;
1348
- }
1349
-
1350
- TestProvider.create = /*#__PURE__*/function () {
1351
- var _create = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref) {
1352
- var clarityBin, contractFilePath, contractIdentifier;
1353
- return runtime_1.wrap(function _callee$(_context) {
1354
- while (1) {
1355
- switch (_context.prev = _context.next) {
1356
- case 0:
1357
- clarityBin = _ref.clarityBin, contractFilePath = _ref.contractFilePath, contractIdentifier = _ref.contractIdentifier;
1358
- _context.next = 3;
1359
- return deployContract({
1360
- contractIdentifier: contractIdentifier,
1361
- contractFilePath: contractFilePath,
1362
- provider: clarityBin
1363
- });
1364
-
1365
- case 3:
1366
- return _context.abrupt("return", new this(clarityBin, contractIdentifier, contractFilePath));
1367
-
1368
- case 4:
1369
- case "end":
1370
- return _context.stop();
1371
- }
1372
- }
1373
- }, _callee, this);
1374
- }));
1375
-
1376
- function create(_x) {
1377
- return _create.apply(this, arguments);
1378
- }
1379
-
1380
- return create;
1381
- }();
1382
-
1383
- TestProvider.fromContract = /*#__PURE__*/function () {
1384
- var _fromContract = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref2) {
1385
- var contract, clarityBin, address, contractName, provider;
1386
- return runtime_1.wrap(function _callee2$(_context2) {
1387
- while (1) {
1388
- switch (_context2.prev = _context2.next) {
1389
- case 0:
1390
- contract = _ref2.contract, clarityBin = _ref2.clarityBin;
1391
- address = contract.address;
1392
-
1393
- if (address) {
1394
- _context2.next = 4;
1395
- break;
1396
- }
1397
-
1398
- throw new Error('TestProvider must have an address');
1399
-
1400
- case 4:
1401
- contractName = contract.name || getContractNameFromPath(contract.contractFile);
1402
- _context2.next = 7;
1403
- return this.create({
1404
- clarityBin: clarityBin,
1405
- contractFilePath: contract.contractFile,
1406
- contractIdentifier: address + "." + contractName
1407
- });
1408
-
1409
- case 7:
1410
- provider = _context2.sent;
1411
- return _context2.abrupt("return", contract.contract(provider));
1412
-
1413
- case 9:
1414
- case "end":
1415
- return _context2.stop();
1416
- }
1417
- }
1418
- }, _callee2, this);
1419
- }));
1420
-
1421
- function fromContract(_x2) {
1422
- return _fromContract.apply(this, arguments);
1423
- }
1424
-
1425
- return fromContract;
1426
- }();
1427
-
1428
- TestProvider.fromContracts = /*#__PURE__*/function () {
1429
- var _fromContracts = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(contracts, clarityBinOrAccounts) {
1430
- var clarityBin, instances, k, contract, instance;
1431
- return runtime_1.wrap(function _callee3$(_context3) {
1432
- while (1) {
1433
- switch (_context3.prev = _context3.next) {
1434
- case 0:
1435
- _context3.next = 2;
1436
- return getDefaultClarityBin(clarityBinOrAccounts);
1437
-
1438
- case 2:
1439
- clarityBin = _context3.sent;
1440
- instances = {};
1441
- _context3.next = 6;
1442
- return deployUtilContract(clarityBin);
1443
-
1444
- case 6:
1445
- _context3.t0 = runtime_1.keys(contracts);
1446
-
1447
- case 7:
1448
- if ((_context3.t1 = _context3.t0()).done) {
1449
- _context3.next = 16;
1450
- break;
1451
- }
1452
-
1453
- k = _context3.t1.value;
1454
- contract = contracts[k];
1455
- _context3.next = 12;
1456
- return this.fromContract({
1457
- contract: contract,
1458
- clarityBin: clarityBin
1459
- });
1460
-
1461
- case 12:
1462
- instance = _context3.sent;
1463
- instances[k] = {
1464
- identifier: getContractIdentifier(contract),
1465
- contract: instance
1466
- };
1467
- _context3.next = 7;
1468
- break;
1469
-
1470
- case 16:
1471
- return _context3.abrupt("return", instances);
1472
-
1473
- case 17:
1474
- case "end":
1475
- return _context3.stop();
1476
- }
1477
- }
1478
- }, _callee3, this);
1479
- }));
1480
-
1481
- function fromContracts(_x3, _x4) {
1482
- return _fromContracts.apply(this, arguments);
1483
- }
1484
-
1485
- return fromContracts;
1486
- }();
1487
-
1488
- var _proto = TestProvider.prototype;
1489
-
1490
- _proto.callReadOnly = /*#__PURE__*/function () {
1491
- var _callReadOnly = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(func, args) {
1492
- var argsFormatted, result, resultCV, value;
1493
- return runtime_1.wrap(function _callee4$(_context4) {
1494
- while (1) {
1495
- switch (_context4.prev = _context4.next) {
1496
- case 0:
1497
- argsFormatted = this.formatArguments(func, args);
1498
- _context4.next = 3;
1499
- return evalJson({
1500
- contractAddress: this.contractIdentifier,
1501
- functionName: func.name,
1502
- args: argsFormatted,
1503
- provider: this.clarityBin
1504
- });
1505
-
1506
- case 3:
1507
- result = _context4.sent;
1508
- resultCV = deserializeCV(Buffer.from(result.output_serialized, 'hex'));
1509
- value = cvToValue(resultCV);
1510
- _context4.t0 = resultCV.type;
1511
- _context4.next = _context4.t0 === ClarityType.ResponseOk ? 9 : _context4.t0 === ClarityType.ResponseErr ? 10 : 11;
1512
- break;
1513
-
1514
- case 9:
1515
- return _context4.abrupt("return", ok(value));
1516
-
1517
- case 10:
1518
- return _context4.abrupt("return", err(value));
1519
-
1520
- case 11:
1521
- return _context4.abrupt("return", value);
1522
-
1523
- case 12:
1524
- case "end":
1525
- return _context4.stop();
1526
- }
1527
- }
1528
- }, _callee4, this);
1529
- }));
1530
-
1531
- function callReadOnly(_x5, _x6) {
1532
- return _callReadOnly.apply(this, arguments);
1533
- }
1534
-
1535
- return callReadOnly;
1536
- }();
1537
-
1538
- _proto.callPublic = function callPublic(func, args) {
1539
- var _this = this;
1540
-
1541
- var argsFormatted = this.formatArguments(func, args);
1542
-
1543
- var submit = /*#__PURE__*/function () {
1544
- var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(options) {
1545
- var receipt, getResult;
1546
- return runtime_1.wrap(function _callee5$(_context5) {
1547
- while (1) {
1548
- switch (_context5.prev = _context5.next) {
1549
- case 0:
1550
- if ('sender' in options) {
1551
- _context5.next = 2;
1552
- break;
1553
- }
1554
-
1555
- throw new Error('Passing `sender` is required.');
1556
-
1557
- case 2:
1558
- _context5.next = 4;
1559
- return executeJson({
1560
- provider: _this.clarityBin,
1561
- contractAddress: _this.contractIdentifier,
1562
- senderAddress: options.sender,
1563
- functionName: func.name,
1564
- args: argsFormatted
1565
- });
1566
-
1567
- case 4:
1568
- receipt = _context5.sent;
1569
-
1570
- getResult = function getResult() {
1571
- var resultCV = deserializeCV(Buffer.from(receipt.output_serialized, 'hex'));
1572
- var result = cvToValue(resultCV);
1573
-
1574
- if (receipt.success) {
1575
- return Promise.resolve({
1576
- isOk: true,
1577
- response: responseOkCV(resultCV),
1578
- value: result,
1579
- events: receipt.events,
1580
- costs: receipt.costs,
1581
- assets: receipt.assets
1582
- });
1583
- } else {
1584
- return Promise.resolve({
1585
- isOk: false,
1586
- response: responseErrorCV(resultCV),
1587
- value: result,
1588
- costs: receipt.costs
1589
- });
1590
- }
1591
- };
1592
-
1593
- return _context5.abrupt("return", {
1594
- getResult: getResult
1595
- });
1596
-
1597
- case 7:
1598
- case "end":
1599
- return _context5.stop();
1600
- }
1601
- }
1602
- }, _callee5);
1603
- }));
1604
-
1605
- return function submit(_x7) {
1606
- return _ref3.apply(this, arguments);
1607
- };
1608
- }();
1609
-
1610
- return {
1611
- submit: submit
1612
- };
1613
- };
1614
-
1615
- _proto.formatArguments = function formatArguments(func, args) {
1616
- return args.map(function (arg, index) {
1617
- var type = func.args[index].type;
1618
-
1619
- if (type === 'trait_reference') {
1620
- return "'" + arg;
1621
- }
1622
-
1623
- var argCV = parseToCV(arg, type);
1624
- var cvString = cvToString(argCV);
1625
- return cvString;
1626
- });
1627
- };
1628
-
1629
- return TestProvider;
1630
- }();
1631
-
1632
- export { TestProvider, createClarityBin, evalJson, executeJson, getBlockHeight, getStxBalance, mineBlocks, tx, txErr, txOk };
1633
- //# sourceMappingURL=test.esm.js.map