@clarigen/test 0.3.2 → 1.0.0-next.3

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.
@@ -2,11 +2,13 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var transactions = require('@stacks/transactions');
6
- var neverthrow = require('neverthrow');
7
- var core = require('@clarigen/core');
8
5
  var nativeBin = require('@clarigen/native-bin');
6
+ var core = require('@clarigen/core');
7
+ var crypto = require('micro-stacks/crypto');
8
+ var transactions = require('micro-stacks/transactions');
9
+ var clarity = require('micro-stacks/clarity');
9
10
  var path = require('path');
11
+ var common = require('micro-stacks/common');
10
12
 
11
13
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
12
14
  try {
@@ -44,6 +46,24 @@ function _asyncToGenerator(fn) {
44
46
  };
45
47
  }
46
48
 
49
+ function _extends() {
50
+ _extends = Object.assign || function (target) {
51
+ for (var i = 1; i < arguments.length; i++) {
52
+ var source = arguments[i];
53
+
54
+ for (var key in source) {
55
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
56
+ target[key] = source[key];
57
+ }
58
+ }
59
+ }
60
+
61
+ return target;
62
+ };
63
+
64
+ return _extends.apply(this, arguments);
65
+ }
66
+
47
67
  function createCommonjsModule(fn, module) {
48
68
  return module = { exports: {} }, fn(module, module.exports), module.exports;
49
69
  }
@@ -809,7 +829,9 @@ var executeJson = /*#__PURE__*/function () {
809
829
  throw new Error("Execution error: " + result.stderr);
810
830
 
811
831
  case 10:
812
- return _context.abrupt("return", response);
832
+ return _context.abrupt("return", _extends({}, response, {
833
+ stderr: result.stderr
834
+ }));
813
835
 
814
836
  case 11:
815
837
  case "end":
@@ -823,22 +845,20 @@ var executeJson = /*#__PURE__*/function () {
823
845
  return _ref2.apply(this, arguments);
824
846
  };
825
847
  }();
826
- var evalJson = /*#__PURE__*/function () {
848
+ var evalRaw = /*#__PURE__*/function () {
827
849
  var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref3) {
828
- var contractAddress, functionName, provider, _ref3$args, args, evalCode, receipt, response;
829
-
850
+ var contractAddress, code, provider, receipt, response;
830
851
  return runtime_1.wrap(function _callee2$(_context2) {
831
852
  while (1) {
832
853
  switch (_context2.prev = _context2.next) {
833
854
  case 0:
834
- contractAddress = _ref3.contractAddress, functionName = _ref3.functionName, provider = _ref3.provider, _ref3$args = _ref3.args, args = _ref3$args === void 0 ? [] : _ref3$args;
835
- evalCode = "(" + functionName + " " + args.join(' ') + ")";
836
- _context2.next = 4;
855
+ contractAddress = _ref3.contractAddress, code = _ref3.code, provider = _ref3.provider;
856
+ _context2.next = 3;
837
857
  return provider.runCommand(['eval_at_chaintip', '--costs', contractAddress, provider.dbFilePath], {
838
- stdin: evalCode
858
+ stdin: code
839
859
  });
840
860
 
841
- case 4:
861
+ case 3:
842
862
  receipt = _context2.sent;
843
863
 
844
864
  if (process.env.PRINT_CLARIGEN_STDERR && receipt.stderr) {
@@ -848,16 +868,18 @@ var evalJson = /*#__PURE__*/function () {
848
868
  response = JSON.parse(receipt.stdout);
849
869
 
850
870
  if (response.success) {
851
- _context2.next = 9;
871
+ _context2.next = 8;
852
872
  break;
853
873
  }
854
874
 
855
875
  throw new Error(JSON.stringify(response.error, null, 2));
856
876
 
857
- case 9:
858
- return _context2.abrupt("return", response);
877
+ case 8:
878
+ return _context2.abrupt("return", _extends({}, response, {
879
+ stderr: receipt.stderr
880
+ }));
859
881
 
860
- case 10:
882
+ case 9:
861
883
  case "end":
862
884
  return _context2.stop();
863
885
  }
@@ -865,10 +887,23 @@ var evalJson = /*#__PURE__*/function () {
865
887
  }, _callee2);
866
888
  }));
867
889
 
868
- return function evalJson(_x2) {
890
+ return function evalRaw(_x2) {
869
891
  return _ref4.apply(this, arguments);
870
892
  };
871
893
  }();
894
+ var evalJson = function evalJson(_ref5) {
895
+ var contractAddress = _ref5.contractAddress,
896
+ functionName = _ref5.functionName,
897
+ provider = _ref5.provider,
898
+ _ref5$args = _ref5.args,
899
+ args = _ref5$args === void 0 ? [] : _ref5$args;
900
+ var code = "(" + functionName + " " + args.join(' ') + ")";
901
+ return evalRaw({
902
+ contractAddress: contractAddress,
903
+ provider: provider,
904
+ code: code
905
+ });
906
+ };
872
907
  function getAllocations(allocations) {
873
908
  if (!allocations) return [];
874
909
 
@@ -899,14 +934,14 @@ function stringifyAllocations(allocations) {
899
934
  }
900
935
 
901
936
  var createClarityBin = /*#__PURE__*/function () {
902
- var _ref5 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(_temp) {
903
- var _ref6, allocations, _ref6$testnet, testnet, binFile, dbFileName, _allocations, provider, args;
937
+ var _ref6 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(_temp) {
938
+ var _ref7, allocations, _ref7$testnet, testnet, binFile, dbFileName, _allocations, provider, args;
904
939
 
905
940
  return runtime_1.wrap(function _callee3$(_context3) {
906
941
  while (1) {
907
942
  switch (_context3.prev = _context3.next) {
908
943
  case 0:
909
- _ref6 = _temp === void 0 ? {} : _temp, allocations = _ref6.allocations, _ref6$testnet = _ref6.testnet, testnet = _ref6$testnet === void 0 ? true : _ref6$testnet;
944
+ _ref7 = _temp === void 0 ? {} : _temp, allocations = _ref7.allocations, _ref7$testnet = _ref7.testnet, testnet = _ref7$testnet === void 0 ? true : _ref7$testnet;
910
945
  binFile = nativeBin.getDefaultBinaryFilePath();
911
946
  dbFileName = nativeBin.getTempFilePath();
912
947
  _allocations = getAllocations(allocations);
@@ -930,88 +965,23 @@ var createClarityBin = /*#__PURE__*/function () {
930
965
  }));
931
966
 
932
967
  return function createClarityBin(_x3) {
933
- return _ref5.apply(this, arguments);
968
+ return _ref6.apply(this, arguments);
934
969
  };
935
970
  }();
936
- function getDefaultClarityBin(_x4) {
937
- return _getDefaultClarityBin.apply(this, arguments);
938
- }
939
-
940
- function _getDefaultClarityBin() {
941
- _getDefaultClarityBin = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(clarityBinOrAccounts) {
942
- var clarityBin;
943
- return runtime_1.wrap(function _callee4$(_context4) {
944
- while (1) {
945
- switch (_context4.prev = _context4.next) {
946
- case 0:
947
- if (clarityBinOrAccounts) {
948
- _context4.next = 6;
949
- break;
950
- }
951
-
952
- _context4.next = 3;
953
- return createClarityBin();
954
-
955
- case 3:
956
- clarityBin = _context4.sent;
957
- _context4.next = 17;
958
- break;
959
-
960
- case 6:
961
- if (!('deployer' in clarityBinOrAccounts)) {
962
- _context4.next = 12;
963
- break;
964
- }
965
-
966
- _context4.next = 9;
967
- return createClarityBin({
968
- allocations: clarityBinOrAccounts
969
- });
970
-
971
- case 9:
972
- clarityBin = _context4.sent;
973
- _context4.next = 17;
974
- break;
975
-
976
- case 12:
977
- if (!(clarityBinOrAccounts instanceof nativeBin.NativeClarityBinProvider)) {
978
- _context4.next = 16;
979
- break;
980
- }
981
-
982
- clarityBin = clarityBinOrAccounts;
983
- _context4.next = 17;
984
- break;
985
-
986
- case 16:
987
- throw new Error('Should never get here');
988
-
989
- case 17:
990
- return _context4.abrupt("return", clarityBin);
991
-
992
- case 18:
993
- case "end":
994
- return _context4.stop();
995
- }
996
- }
997
- }, _callee4);
998
- }));
999
- return _getDefaultClarityBin.apply(this, arguments);
1000
- }
1001
971
 
1002
972
  function deployContract(_x5) {
1003
973
  return _deployContract.apply(this, arguments);
1004
974
  }
1005
975
 
1006
976
  function _deployContract() {
1007
- _deployContract = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(_ref7) {
977
+ _deployContract = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(_ref8) {
1008
978
  var contractIdentifier, contractFilePath, provider, receipt, output, initialization, _initialization$split, error, trace, startLine, matcher, matches;
1009
979
 
1010
980
  return runtime_1.wrap(function _callee5$(_context5) {
1011
981
  while (1) {
1012
982
  switch (_context5.prev = _context5.next) {
1013
983
  case 0:
1014
- contractIdentifier = _ref7.contractIdentifier, contractFilePath = _ref7.contractFilePath, provider = _ref7.provider;
984
+ contractIdentifier = _ref8.contractIdentifier, contractFilePath = _ref8.contractFilePath, provider = _ref8.provider;
1015
985
  _context5.next = 3;
1016
986
  return provider.runCommand(['launch', contractIdentifier, contractFilePath, provider.dbFilePath, '--costs', '--assets']);
1017
987
 
@@ -1060,6 +1030,18 @@ function _deployContract() {
1060
1030
  return _deployContract.apply(this, arguments);
1061
1031
  }
1062
1032
 
1033
+ function getPrints(events) {
1034
+ var prints = [];
1035
+ events.forEach(function (e) {
1036
+ if (e.type === 'contract_event') {
1037
+ var hex = e.contract_event.raw_value;
1038
+ var cv = clarity.hexToCV(hex);
1039
+ prints.push(core.cvToValue(cv));
1040
+ }
1041
+ });
1042
+ return prints;
1043
+ }
1044
+
1063
1045
  var UTIL_CONTRACT_ID = 'ST000000000000000000002AMW42H.clarigen-test-utils';
1064
1046
  function deployUtilContract(_x) {
1065
1047
  return _deployUtilContract.apply(this, arguments);
@@ -1095,34 +1077,39 @@ function _deployUtilContract() {
1095
1077
  return _deployUtilContract.apply(this, arguments);
1096
1078
  }
1097
1079
 
1080
+ function getBin(provider) {
1081
+ return 'clarityBin' in provider ? provider.clarityBin : provider;
1082
+ }
1083
+
1098
1084
  function getBlockHeight(_x2) {
1099
1085
  return _getBlockHeight.apply(this, arguments);
1100
1086
  }
1101
1087
 
1102
1088
  function _getBlockHeight() {
1103
1089
  _getBlockHeight = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(provider) {
1104
- var _yield$evalJson, output_serialized, outputCV, blockHeight;
1090
+ var bin, _yield$evalJson, output_serialized, outputCV, blockHeight;
1105
1091
 
1106
1092
  return runtime_1.wrap(function _callee2$(_context2) {
1107
1093
  while (1) {
1108
1094
  switch (_context2.prev = _context2.next) {
1109
1095
  case 0:
1110
- _context2.next = 2;
1096
+ bin = getBin(provider);
1097
+ _context2.next = 3;
1111
1098
  return evalJson({
1112
1099
  contractAddress: UTIL_CONTRACT_ID,
1113
1100
  functionName: 'get-block-height',
1114
1101
  args: [],
1115
- provider: provider
1102
+ provider: bin
1116
1103
  });
1117
1104
 
1118
- case 2:
1105
+ case 3:
1119
1106
  _yield$evalJson = _context2.sent;
1120
1107
  output_serialized = _yield$evalJson.output_serialized;
1121
- outputCV = transactions.deserializeCV(Buffer.from(output_serialized, 'hex'));
1108
+ outputCV = clarity.hexToCV(output_serialized);
1122
1109
  blockHeight = core.cvToValue(outputCV);
1123
1110
  return _context2.abrupt("return", blockHeight);
1124
1111
 
1125
- case 7:
1112
+ case 8:
1126
1113
  case "end":
1127
1114
  return _context2.stop();
1128
1115
  }
@@ -1138,20 +1125,22 @@ function mineBlock(_x3) {
1138
1125
 
1139
1126
  function _mineBlock() {
1140
1127
  _mineBlock = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(provider) {
1128
+ var bin;
1141
1129
  return runtime_1.wrap(function _callee3$(_context3) {
1142
1130
  while (1) {
1143
1131
  switch (_context3.prev = _context3.next) {
1144
1132
  case 0:
1145
- _context3.next = 2;
1133
+ bin = getBin(provider);
1134
+ _context3.next = 3;
1146
1135
  return executeJson({
1147
1136
  contractAddress: UTIL_CONTRACT_ID,
1148
1137
  functionName: 'mine-block',
1149
1138
  args: [],
1150
- provider: provider,
1139
+ provider: bin,
1151
1140
  senderAddress: 'ST000000000000000000002AMW42H'
1152
1141
  });
1153
1142
 
1154
- case 2:
1143
+ case 3:
1155
1144
  case "end":
1156
1145
  return _context3.stop();
1157
1146
  }
@@ -1166,29 +1155,30 @@ function mineBlocks(_x4, _x5) {
1166
1155
  }
1167
1156
 
1168
1157
  function _mineBlocks() {
1169
- _mineBlocks = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(blocks, provider) {
1170
- var index;
1158
+ _mineBlocks = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(_blocks, provider) {
1159
+ var blocks, index;
1171
1160
  return runtime_1.wrap(function _callee4$(_context4) {
1172
1161
  while (1) {
1173
1162
  switch (_context4.prev = _context4.next) {
1174
1163
  case 0:
1164
+ blocks = common.intToBigInt(_blocks);
1175
1165
  index = 0;
1176
1166
 
1177
- case 1:
1167
+ case 2:
1178
1168
  if (!(index < blocks)) {
1179
- _context4.next = 7;
1169
+ _context4.next = 8;
1180
1170
  break;
1181
1171
  }
1182
1172
 
1183
- _context4.next = 4;
1173
+ _context4.next = 5;
1184
1174
  return mineBlock(provider);
1185
1175
 
1186
- case 4:
1176
+ case 5:
1187
1177
  index++;
1188
- _context4.next = 1;
1178
+ _context4.next = 2;
1189
1179
  break;
1190
1180
 
1191
- case 7:
1181
+ case 8:
1192
1182
  case "end":
1193
1183
  return _context4.stop();
1194
1184
  }
@@ -1204,28 +1194,29 @@ function getStxBalance(_x6, _x7) {
1204
1194
 
1205
1195
  function _getStxBalance() {
1206
1196
  _getStxBalance = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(provider, account) {
1207
- var _yield$evalJson2, output_serialized, outputCV, balance;
1197
+ var bin, _yield$evalJson2, output_serialized, outputCV, balance;
1208
1198
 
1209
1199
  return runtime_1.wrap(function _callee5$(_context5) {
1210
1200
  while (1) {
1211
1201
  switch (_context5.prev = _context5.next) {
1212
1202
  case 0:
1213
- _context5.next = 2;
1203
+ bin = getBin(provider);
1204
+ _context5.next = 3;
1214
1205
  return evalJson({
1215
1206
  contractAddress: UTIL_CONTRACT_ID,
1216
1207
  functionName: 'get-stx-balance',
1217
1208
  args: ["'" + account],
1218
- provider: provider
1209
+ provider: bin
1219
1210
  });
1220
1211
 
1221
- case 2:
1212
+ case 3:
1222
1213
  _yield$evalJson2 = _context5.sent;
1223
1214
  output_serialized = _yield$evalJson2.output_serialized;
1224
- outputCV = transactions.deserializeCV(Buffer.from(output_serialized, 'hex'));
1215
+ outputCV = clarity.hexToCV(output_serialized);
1225
1216
  balance = core.cvToValue(outputCV);
1226
1217
  return _context5.abrupt("return", balance);
1227
1218
 
1228
- case 7:
1219
+ case 8:
1229
1220
  case "end":
1230
1221
  return _context5.stop();
1231
1222
  }
@@ -1235,141 +1226,284 @@ function _getStxBalance() {
1235
1226
  return _getStxBalance.apply(this, arguments);
1236
1227
  }
1237
1228
 
1238
- function tx(_x, _x2) {
1239
- return _tx2.apply(this, arguments);
1229
+ function makeRandomAddress(version) {
1230
+ if (version === void 0) {
1231
+ version = crypto.StacksNetworkVersion.testnetP2PKH;
1232
+ }
1233
+
1234
+ var privateKey = transactions.makeRandomPrivKey();
1235
+ var publicKey = transactions.getPublicKeyFromStacksPrivateKey(privateKey);
1236
+ var address = crypto.publicKeyToStxAddress(publicKey.data, version);
1237
+ return address;
1238
+ }
1239
+
1240
+ function formatArguments(args) {
1241
+ return args.map(function (arg) {
1242
+ return core.cvToString(arg);
1243
+ });
1244
+ }
1245
+
1246
+ function getIdentifier(tx) {
1247
+ return tx.contractAddress + "." + tx.contractName;
1248
+ }
1249
+
1250
+ function getLogs(stderr) {
1251
+ if (stderr === '') return [];
1252
+ return stderr.split('\n').map(function (line) {
1253
+ return line.slice(62);
1254
+ });
1240
1255
  }
1241
1256
 
1242
- function _tx2() {
1243
- _tx2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(tx, sender) {
1244
- var receipt, result;
1257
+ function makeEvalResult(result) {
1258
+ var resultCV = clarity.hexToCV(result.output_serialized);
1259
+ var value = core.cvToValue(resultCV, true);
1260
+ return {
1261
+ value: value,
1262
+ clarityValue: resultCV,
1263
+ logs: getLogs(result.stderr),
1264
+ costs: result.costs
1265
+ };
1266
+ }
1267
+
1268
+ function ro(_x, _x2) {
1269
+ return _ro.apply(this, arguments);
1270
+ }
1271
+
1272
+ function _ro() {
1273
+ _ro = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(tx, bin) {
1274
+ var result;
1245
1275
  return runtime_1.wrap(function _callee$(_context) {
1246
1276
  while (1) {
1247
1277
  switch (_context.prev = _context.next) {
1248
1278
  case 0:
1249
1279
  _context.next = 2;
1250
- return tx.submit({
1251
- sender: sender
1280
+ return evalJson({
1281
+ functionName: tx["function"].name,
1282
+ args: formatArguments(tx.functionArgs),
1283
+ contractAddress: getIdentifier(tx),
1284
+ provider: bin
1252
1285
  });
1253
1286
 
1254
1287
  case 2:
1255
- receipt = _context.sent;
1256
- _context.next = 5;
1257
- return receipt.getResult();
1258
-
1259
- case 5:
1260
1288
  result = _context.sent;
1261
- return _context.abrupt("return", result);
1289
+ return _context.abrupt("return", makeEvalResult(result));
1262
1290
 
1263
- case 7:
1291
+ case 4:
1264
1292
  case "end":
1265
1293
  return _context.stop();
1266
1294
  }
1267
1295
  }
1268
1296
  }, _callee);
1269
1297
  }));
1270
- return _tx2.apply(this, arguments);
1298
+ return _ro.apply(this, arguments);
1271
1299
  }
1272
1300
 
1273
- function txOk(_x3, _x4) {
1274
- return _txOk.apply(this, arguments);
1301
+ function evalCode(_x3) {
1302
+ return _evalCode.apply(this, arguments);
1275
1303
  }
1276
1304
 
1277
- function _txOk() {
1278
- _txOk = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_tx, sender) {
1279
- var result;
1305
+ function _evalCode() {
1306
+ _evalCode = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref) {
1307
+ var contractAddress, code, bin, result;
1280
1308
  return runtime_1.wrap(function _callee2$(_context2) {
1281
1309
  while (1) {
1282
1310
  switch (_context2.prev = _context2.next) {
1283
1311
  case 0:
1284
- _context2.next = 2;
1285
- return tx(_tx, sender);
1312
+ contractAddress = _ref.contractAddress, code = _ref.code, bin = _ref.bin;
1313
+ _context2.next = 3;
1314
+ return evalRaw({
1315
+ contractAddress: contractAddress,
1316
+ code: code,
1317
+ provider: bin
1318
+ });
1286
1319
 
1287
- case 2:
1320
+ case 3:
1288
1321
  result = _context2.sent;
1289
-
1290
- if (result.isOk) {
1291
- _context2.next = 5;
1292
- break;
1293
- }
1294
-
1295
- throw new Error("Expected transaction ok, got error: " + result.value);
1322
+ return _context2.abrupt("return", makeEvalResult(result));
1296
1323
 
1297
1324
  case 5:
1298
- return _context2.abrupt("return", result);
1299
-
1300
- case 6:
1301
1325
  case "end":
1302
1326
  return _context2.stop();
1303
1327
  }
1304
1328
  }
1305
1329
  }, _callee2);
1306
1330
  }));
1307
- return _txOk.apply(this, arguments);
1331
+ return _evalCode.apply(this, arguments);
1308
1332
  }
1309
1333
 
1310
- function txErr(_x5, _x6) {
1311
- return _txErr.apply(this, arguments);
1334
+ function tx(_x4) {
1335
+ return _tx.apply(this, arguments);
1312
1336
  }
1313
1337
 
1314
- function _txErr() {
1315
- _txErr = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(_tx, sender) {
1316
- var result;
1338
+ function _tx() {
1339
+ _tx = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(_ref2) {
1340
+ var tx, senderAddress, bin, result, resultCV, value, baseReturn;
1317
1341
  return runtime_1.wrap(function _callee3$(_context3) {
1318
1342
  while (1) {
1319
1343
  switch (_context3.prev = _context3.next) {
1320
1344
  case 0:
1321
- _context3.next = 2;
1322
- return tx(_tx, sender);
1345
+ tx = _ref2.tx, senderAddress = _ref2.senderAddress, bin = _ref2.bin;
1346
+ _context3.next = 3;
1347
+ return executeJson({
1348
+ contractAddress: getIdentifier(tx),
1349
+ senderAddress: senderAddress,
1350
+ provider: bin,
1351
+ functionName: tx["function"].name,
1352
+ args: formatArguments(tx.functionArgs)
1353
+ });
1323
1354
 
1324
- case 2:
1355
+ case 3:
1325
1356
  result = _context3.sent;
1357
+ resultCV = clarity.hexToCV(result.output_serialized);
1358
+ value = core.cvToValue(resultCV);
1359
+ baseReturn = {
1360
+ value: value,
1361
+ logs: getLogs(result.stderr),
1362
+ costs: result.costs
1363
+ };
1326
1364
 
1327
- if (!result.isOk) {
1328
- _context3.next = 5;
1365
+ if (!result.success) {
1366
+ _context3.next = 9;
1329
1367
  break;
1330
1368
  }
1331
1369
 
1332
- throw new Error("Expected transaction error, got ok: " + result.value);
1370
+ return _context3.abrupt("return", _extends({}, baseReturn, {
1371
+ isOk: true,
1372
+ response: clarity.responseOkCV(resultCV),
1373
+ assets: result.assets,
1374
+ events: result.events,
1375
+ prints: getPrints(result.events)
1376
+ }));
1333
1377
 
1334
- case 5:
1335
- return _context3.abrupt("return", result);
1378
+ case 9:
1379
+ return _context3.abrupt("return", _extends({}, baseReturn, {
1380
+ isOk: false,
1381
+ response: clarity.responseErrorCV(resultCV)
1382
+ }));
1336
1383
 
1337
- case 6:
1384
+ case 10:
1338
1385
  case "end":
1339
1386
  return _context3.stop();
1340
1387
  }
1341
1388
  }
1342
1389
  }, _callee3);
1343
1390
  }));
1344
- return _txErr.apply(this, arguments);
1391
+ return _tx.apply(this, arguments);
1392
+ }
1393
+
1394
+ function mapGet(_x5) {
1395
+ return _mapGet.apply(this, arguments);
1396
+ }
1397
+
1398
+ function _mapGet() {
1399
+ _mapGet = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(_ref3) {
1400
+ var map, bin, code, result;
1401
+ return runtime_1.wrap(function _callee4$(_context4) {
1402
+ while (1) {
1403
+ switch (_context4.prev = _context4.next) {
1404
+ case 0:
1405
+ map = _ref3.map, bin = _ref3.bin;
1406
+ code = "(map-get? " + map.map.name + " " + core.cvToString(map.key) + ")";
1407
+ _context4.next = 4;
1408
+ return evalCode({
1409
+ contractAddress: getIdentifier(map),
1410
+ code: code,
1411
+ bin: bin
1412
+ });
1413
+
1414
+ case 4:
1415
+ result = _context4.sent;
1416
+ return _context4.abrupt("return", result.value);
1417
+
1418
+ case 6:
1419
+ case "end":
1420
+ return _context4.stop();
1421
+ }
1422
+ }
1423
+ }, _callee4);
1424
+ }));
1425
+ return _mapGet.apply(this, arguments);
1345
1426
  }
1346
1427
 
1347
1428
  var TestProvider = /*#__PURE__*/function () {
1348
- function TestProvider(clarityBin, contractIdentifier, contractFile) {
1429
+ function TestProvider(clarityBin) {
1349
1430
  this.clarityBin = clarityBin;
1350
- this.contractIdentifier = contractIdentifier;
1351
- this.contractFile = contractFile;
1352
1431
  }
1353
1432
 
1354
- TestProvider.create = /*#__PURE__*/function () {
1355
- var _create = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref) {
1356
- var clarityBin, contractFilePath, contractIdentifier;
1433
+ TestProvider.fromContracts = /*#__PURE__*/function () {
1434
+ var _fromContracts = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(contracts, options) {
1435
+ var clarityBin, instances, k, contract, identifier, instance, provider;
1357
1436
  return runtime_1.wrap(function _callee$(_context) {
1358
1437
  while (1) {
1359
1438
  switch (_context.prev = _context.next) {
1360
1439
  case 0:
1361
- clarityBin = _ref.clarityBin, contractFilePath = _ref.contractFilePath, contractIdentifier = _ref.contractIdentifier;
1362
- _context.next = 3;
1440
+ if (options === void 0) {
1441
+ options = {};
1442
+ }
1443
+
1444
+ _context.t0 = options.clarityBin;
1445
+
1446
+ if (_context.t0) {
1447
+ _context.next = 6;
1448
+ break;
1449
+ }
1450
+
1451
+ _context.next = 5;
1452
+ return nativeBin.createClarityBin();
1453
+
1454
+ case 5:
1455
+ _context.t0 = _context.sent;
1456
+
1457
+ case 6:
1458
+ clarityBin = _context.t0;
1459
+ instances = {};
1460
+ _context.next = 10;
1461
+ return deployUtilContract(clarityBin);
1462
+
1463
+ case 10:
1464
+ _context.t1 = runtime_1.keys(contracts);
1465
+
1466
+ case 11:
1467
+ if ((_context.t2 = _context.t1()).done) {
1468
+ _context.next = 22;
1469
+ break;
1470
+ }
1471
+
1472
+ k = _context.t2.value;
1473
+
1474
+ if (!Object.prototype.hasOwnProperty.call(contracts, k)) {
1475
+ _context.next = 20;
1476
+ break;
1477
+ }
1478
+
1479
+ contract = contracts[k];
1480
+ identifier = core.getContractIdentifier(contract);
1481
+ _context.next = 18;
1363
1482
  return deployContract({
1364
- contractIdentifier: contractIdentifier,
1365
- contractFilePath: contractFilePath,
1483
+ contractIdentifier: identifier,
1484
+ contractFilePath: contract.contractFile,
1366
1485
  provider: clarityBin
1367
1486
  });
1368
1487
 
1369
- case 3:
1370
- return _context.abrupt("return", new this(clarityBin, contractIdentifier, contractFilePath));
1488
+ case 18:
1489
+ instance = contract.contract(contract.address, contract.name);
1490
+ instances[k] = {
1491
+ identifier: core.getContractIdentifier(contract),
1492
+ contract: instance
1493
+ };
1371
1494
 
1372
- case 4:
1495
+ case 20:
1496
+ _context.next = 11;
1497
+ break;
1498
+
1499
+ case 22:
1500
+ provider = new this(clarityBin);
1501
+ return _context.abrupt("return", {
1502
+ deployed: instances,
1503
+ provider: provider
1504
+ });
1505
+
1506
+ case 24:
1373
1507
  case "end":
1374
1508
  return _context.stop();
1375
1509
  }
@@ -1377,44 +1511,34 @@ var TestProvider = /*#__PURE__*/function () {
1377
1511
  }, _callee, this);
1378
1512
  }));
1379
1513
 
1380
- function create(_x) {
1381
- return _create.apply(this, arguments);
1514
+ function fromContracts(_x, _x2) {
1515
+ return _fromContracts.apply(this, arguments);
1382
1516
  }
1383
1517
 
1384
- return create;
1518
+ return fromContracts;
1385
1519
  }();
1386
1520
 
1387
- TestProvider.fromContract = /*#__PURE__*/function () {
1388
- var _fromContract = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref2) {
1389
- var contract, clarityBin, address, contractName, provider;
1521
+ var _proto = TestProvider.prototype;
1522
+
1523
+ _proto.ro = function ro$1(tx) {
1524
+ return ro(tx, this.clarityBin);
1525
+ };
1526
+
1527
+ _proto.rov = /*#__PURE__*/function () {
1528
+ var _rov = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(tx) {
1529
+ var result;
1390
1530
  return runtime_1.wrap(function _callee2$(_context2) {
1391
1531
  while (1) {
1392
1532
  switch (_context2.prev = _context2.next) {
1393
1533
  case 0:
1394
- contract = _ref2.contract, clarityBin = _ref2.clarityBin;
1395
- address = contract.address;
1534
+ _context2.next = 2;
1535
+ return this.ro(tx);
1396
1536
 
1397
- if (address) {
1398
- _context2.next = 4;
1399
- break;
1400
- }
1401
-
1402
- throw new Error('TestProvider must have an address');
1537
+ case 2:
1538
+ result = _context2.sent;
1539
+ return _context2.abrupt("return", result.value);
1403
1540
 
1404
1541
  case 4:
1405
- contractName = contract.name || core.getContractNameFromPath(contract.contractFile);
1406
- _context2.next = 7;
1407
- return this.create({
1408
- clarityBin: clarityBin,
1409
- contractFilePath: contract.contractFile,
1410
- contractIdentifier: address + "." + contractName
1411
- });
1412
-
1413
- case 7:
1414
- provider = _context2.sent;
1415
- return _context2.abrupt("return", contract.contract(provider));
1416
-
1417
- case 9:
1418
1542
  case "end":
1419
1543
  return _context2.stop();
1420
1544
  }
@@ -1422,211 +1546,270 @@ var TestProvider = /*#__PURE__*/function () {
1422
1546
  }, _callee2, this);
1423
1547
  }));
1424
1548
 
1425
- function fromContract(_x2) {
1426
- return _fromContract.apply(this, arguments);
1549
+ function rov(_x3) {
1550
+ return _rov.apply(this, arguments);
1427
1551
  }
1428
1552
 
1429
- return fromContract;
1553
+ return rov;
1430
1554
  }();
1431
1555
 
1432
- TestProvider.fromContracts = /*#__PURE__*/function () {
1433
- var _fromContracts = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(contracts, clarityBinOrAccounts) {
1434
- var clarityBin, instances, k, contract, instance;
1556
+ _proto.roOk = /*#__PURE__*/function () {
1557
+ var _roOk = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(tx) {
1558
+ var result;
1435
1559
  return runtime_1.wrap(function _callee3$(_context3) {
1436
1560
  while (1) {
1437
1561
  switch (_context3.prev = _context3.next) {
1438
1562
  case 0:
1439
1563
  _context3.next = 2;
1440
- return getDefaultClarityBin(clarityBinOrAccounts);
1564
+ return this.ro(tx);
1441
1565
 
1442
1566
  case 2:
1443
- clarityBin = _context3.sent;
1444
- instances = {};
1445
- _context3.next = 6;
1446
- return deployUtilContract(clarityBin);
1567
+ result = _context3.sent;
1568
+ return _context3.abrupt("return", result.value.match(function (ok) {
1569
+ return _extends({}, result, {
1570
+ value: ok
1571
+ });
1572
+ }, function (err) {
1573
+ throw new Error("Expected OK, received error: " + err);
1574
+ }));
1447
1575
 
1448
- case 6:
1449
- _context3.t0 = runtime_1.keys(contracts);
1576
+ case 4:
1577
+ case "end":
1578
+ return _context3.stop();
1579
+ }
1580
+ }
1581
+ }, _callee3, this);
1582
+ }));
1450
1583
 
1451
- case 7:
1452
- if ((_context3.t1 = _context3.t0()).done) {
1453
- _context3.next = 16;
1454
- break;
1455
- }
1584
+ function roOk(_x4) {
1585
+ return _roOk.apply(this, arguments);
1586
+ }
1456
1587
 
1457
- k = _context3.t1.value;
1458
- contract = contracts[k];
1459
- _context3.next = 12;
1460
- return this.fromContract({
1461
- contract: contract,
1462
- clarityBin: clarityBin
1463
- });
1588
+ return roOk;
1589
+ }();
1464
1590
 
1465
- case 12:
1466
- instance = _context3.sent;
1467
- instances[k] = {
1468
- identifier: core.getContractIdentifier(contract),
1469
- contract: instance
1470
- };
1471
- _context3.next = 7;
1472
- break;
1591
+ _proto.roErr = /*#__PURE__*/function () {
1592
+ var _roErr = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(tx) {
1593
+ var result;
1594
+ return runtime_1.wrap(function _callee4$(_context4) {
1595
+ while (1) {
1596
+ switch (_context4.prev = _context4.next) {
1597
+ case 0:
1598
+ _context4.next = 2;
1599
+ return this.ro(tx);
1473
1600
 
1474
- case 16:
1475
- return _context3.abrupt("return", instances);
1601
+ case 2:
1602
+ result = _context4.sent;
1603
+ return _context4.abrupt("return", result.value.match(function (ok) {
1604
+ throw new Error("Expected err, received ok: " + ok);
1605
+ }, function (err) {
1606
+ return _extends({}, result, {
1607
+ value: err
1608
+ });
1609
+ }));
1476
1610
 
1477
- case 17:
1611
+ case 4:
1478
1612
  case "end":
1479
- return _context3.stop();
1613
+ return _context4.stop();
1480
1614
  }
1481
1615
  }
1482
- }, _callee3, this);
1616
+ }, _callee4, this);
1483
1617
  }));
1484
1618
 
1485
- function fromContracts(_x3, _x4) {
1486
- return _fromContracts.apply(this, arguments);
1619
+ function roErr(_x5) {
1620
+ return _roErr.apply(this, arguments);
1487
1621
  }
1488
1622
 
1489
- return fromContracts;
1623
+ return roErr;
1490
1624
  }();
1491
1625
 
1492
- var _proto = TestProvider.prototype;
1626
+ _proto.rovOk = /*#__PURE__*/function () {
1627
+ var _rovOk = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(tx) {
1628
+ return runtime_1.wrap(function _callee5$(_context5) {
1629
+ while (1) {
1630
+ switch (_context5.prev = _context5.next) {
1631
+ case 0:
1632
+ _context5.next = 2;
1633
+ return this.roOk(tx);
1493
1634
 
1494
- _proto.callReadOnly = /*#__PURE__*/function () {
1495
- var _callReadOnly = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(func, args) {
1496
- var argsFormatted, result, resultCV, value;
1497
- return runtime_1.wrap(function _callee4$(_context4) {
1635
+ case 2:
1636
+ return _context5.abrupt("return", _context5.sent.value);
1637
+
1638
+ case 3:
1639
+ case "end":
1640
+ return _context5.stop();
1641
+ }
1642
+ }
1643
+ }, _callee5, this);
1644
+ }));
1645
+
1646
+ function rovOk(_x6) {
1647
+ return _rovOk.apply(this, arguments);
1648
+ }
1649
+
1650
+ return rovOk;
1651
+ }();
1652
+
1653
+ _proto.rovErr = /*#__PURE__*/function () {
1654
+ var _rovErr = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(tx) {
1655
+ return runtime_1.wrap(function _callee6$(_context6) {
1498
1656
  while (1) {
1499
- switch (_context4.prev = _context4.next) {
1657
+ switch (_context6.prev = _context6.next) {
1500
1658
  case 0:
1501
- argsFormatted = this.formatArguments(func, args);
1502
- _context4.next = 3;
1503
- return evalJson({
1504
- contractAddress: this.contractIdentifier,
1505
- functionName: func.name,
1506
- args: argsFormatted,
1507
- provider: this.clarityBin
1508
- });
1659
+ _context6.next = 2;
1660
+ return this.roErr(tx);
1661
+
1662
+ case 2:
1663
+ return _context6.abrupt("return", _context6.sent.value);
1509
1664
 
1510
1665
  case 3:
1511
- result = _context4.sent;
1512
- resultCV = transactions.deserializeCV(Buffer.from(result.output_serialized, 'hex'));
1513
- value = core.cvToValue(resultCV);
1514
- _context4.t0 = resultCV.type;
1515
- _context4.next = _context4.t0 === transactions.ClarityType.ResponseOk ? 9 : _context4.t0 === transactions.ClarityType.ResponseErr ? 10 : 11;
1516
- break;
1666
+ case "end":
1667
+ return _context6.stop();
1668
+ }
1669
+ }
1670
+ }, _callee6, this);
1671
+ }));
1517
1672
 
1518
- case 9:
1519
- return _context4.abrupt("return", neverthrow.ok(value));
1673
+ function rovErr(_x7) {
1674
+ return _rovErr.apply(this, arguments);
1675
+ }
1520
1676
 
1521
- case 10:
1522
- return _context4.abrupt("return", neverthrow.err(value));
1677
+ return rovErr;
1678
+ }();
1523
1679
 
1524
- case 11:
1525
- return _context4.abrupt("return", value);
1680
+ _proto.tx = function tx$1(_tx2, senderAddress) {
1681
+ return tx({
1682
+ tx: _tx2,
1683
+ senderAddress: senderAddress,
1684
+ bin: this.clarityBin
1685
+ });
1686
+ };
1526
1687
 
1527
- case 12:
1688
+ _proto.txOk = /*#__PURE__*/function () {
1689
+ var _txOk = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(tx, senderAddress) {
1690
+ var result;
1691
+ return runtime_1.wrap(function _callee7$(_context7) {
1692
+ while (1) {
1693
+ switch (_context7.prev = _context7.next) {
1694
+ case 0:
1695
+ _context7.next = 2;
1696
+ return this.tx(tx, senderAddress);
1697
+
1698
+ case 2:
1699
+ result = _context7.sent;
1700
+
1701
+ if (result.isOk) {
1702
+ _context7.next = 5;
1703
+ break;
1704
+ }
1705
+
1706
+ throw new Error("Expected OK, received error: " + result.value);
1707
+
1708
+ case 5:
1709
+ return _context7.abrupt("return", result);
1710
+
1711
+ case 6:
1528
1712
  case "end":
1529
- return _context4.stop();
1713
+ return _context7.stop();
1530
1714
  }
1531
1715
  }
1532
- }, _callee4, this);
1716
+ }, _callee7, this);
1533
1717
  }));
1534
1718
 
1535
- function callReadOnly(_x5, _x6) {
1536
- return _callReadOnly.apply(this, arguments);
1719
+ function txOk(_x8, _x9) {
1720
+ return _txOk.apply(this, arguments);
1537
1721
  }
1538
1722
 
1539
- return callReadOnly;
1723
+ return txOk;
1540
1724
  }();
1541
1725
 
1542
- _proto.callPublic = function callPublic(func, args) {
1543
- var _this = this;
1544
-
1545
- var argsFormatted = this.formatArguments(func, args);
1546
-
1547
- var submit = /*#__PURE__*/function () {
1548
- var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(options) {
1549
- var receipt, getResult;
1550
- return runtime_1.wrap(function _callee5$(_context5) {
1551
- while (1) {
1552
- switch (_context5.prev = _context5.next) {
1553
- case 0:
1554
- if ('sender' in options) {
1555
- _context5.next = 2;
1556
- break;
1557
- }
1558
-
1559
- throw new Error('Passing `sender` is required.');
1560
-
1561
- case 2:
1562
- _context5.next = 4;
1563
- return executeJson({
1564
- provider: _this.clarityBin,
1565
- contractAddress: _this.contractIdentifier,
1566
- senderAddress: options.sender,
1567
- functionName: func.name,
1568
- args: argsFormatted
1569
- });
1726
+ _proto.txErr = /*#__PURE__*/function () {
1727
+ var _txErr = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(tx, senderAddress) {
1728
+ var result;
1729
+ return runtime_1.wrap(function _callee8$(_context8) {
1730
+ while (1) {
1731
+ switch (_context8.prev = _context8.next) {
1732
+ case 0:
1733
+ _context8.next = 2;
1734
+ return this.tx(tx, senderAddress);
1570
1735
 
1571
- case 4:
1572
- receipt = _context5.sent;
1573
-
1574
- getResult = function getResult() {
1575
- var resultCV = transactions.deserializeCV(Buffer.from(receipt.output_serialized, 'hex'));
1576
- var result = core.cvToValue(resultCV);
1577
-
1578
- if (receipt.success) {
1579
- return Promise.resolve({
1580
- isOk: true,
1581
- response: transactions.responseOkCV(resultCV),
1582
- value: result,
1583
- events: receipt.events,
1584
- costs: receipt.costs,
1585
- assets: receipt.assets
1586
- });
1587
- } else {
1588
- return Promise.resolve({
1589
- isOk: false,
1590
- response: transactions.responseErrorCV(resultCV),
1591
- value: result,
1592
- costs: receipt.costs
1593
- });
1594
- }
1595
- };
1596
-
1597
- return _context5.abrupt("return", {
1598
- getResult: getResult
1599
- });
1736
+ case 2:
1737
+ result = _context8.sent;
1600
1738
 
1601
- case 7:
1602
- case "end":
1603
- return _context5.stop();
1604
- }
1739
+ if (!result.isOk) {
1740
+ _context8.next = 5;
1741
+ break;
1742
+ }
1743
+
1744
+ throw new Error("Expected Err, received ok: " + result.value);
1745
+
1746
+ case 5:
1747
+ return _context8.abrupt("return", result);
1748
+
1749
+ case 6:
1750
+ case "end":
1751
+ return _context8.stop();
1605
1752
  }
1606
- }, _callee5);
1607
- }));
1753
+ }
1754
+ }, _callee8, this);
1755
+ }));
1608
1756
 
1609
- return function submit(_x7) {
1610
- return _ref3.apply(this, arguments);
1611
- };
1612
- }();
1757
+ function txErr(_x10, _x11) {
1758
+ return _txErr.apply(this, arguments);
1759
+ }
1613
1760
 
1614
- return {
1615
- submit: submit
1616
- };
1761
+ return txErr;
1762
+ }();
1763
+
1764
+ _proto.evalCode = function evalCode$1(code, contractAddress) {
1765
+ if (contractAddress === void 0) {
1766
+ contractAddress = UTIL_CONTRACT_ID;
1767
+ }
1768
+
1769
+ return evalCode({
1770
+ contractAddress: contractAddress,
1771
+ code: code,
1772
+ bin: this.clarityBin
1773
+ });
1617
1774
  };
1618
1775
 
1619
- _proto.formatArguments = function formatArguments(func, args) {
1620
- return args.map(function (arg, index) {
1621
- var type = func.args[index].type;
1776
+ _proto.eval = /*#__PURE__*/function () {
1777
+ var _eval2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(code, contractAddress) {
1778
+ var result;
1779
+ return runtime_1.wrap(function _callee9$(_context9) {
1780
+ while (1) {
1781
+ switch (_context9.prev = _context9.next) {
1782
+ case 0:
1783
+ if (contractAddress === void 0) {
1784
+ contractAddress = UTIL_CONTRACT_ID;
1785
+ }
1786
+
1787
+ _context9.next = 3;
1788
+ return this.evalCode(code, contractAddress);
1622
1789
 
1623
- if (type === 'trait_reference') {
1624
- return "'" + arg;
1625
- }
1790
+ case 3:
1791
+ result = _context9.sent;
1792
+ return _context9.abrupt("return", result.value);
1793
+
1794
+ case 5:
1795
+ case "end":
1796
+ return _context9.stop();
1797
+ }
1798
+ }
1799
+ }, _callee9, this);
1800
+ }));
1801
+
1802
+ function _eval(_x12, _x13) {
1803
+ return _eval2.apply(this, arguments);
1804
+ }
1805
+
1806
+ return _eval;
1807
+ }();
1626
1808
 
1627
- var argCV = core.parseToCV(arg, type);
1628
- var cvString = core.cvToString(argCV);
1629
- return cvString;
1809
+ _proto.mapGet = function mapGet$1(map) {
1810
+ return mapGet({
1811
+ map: map,
1812
+ bin: this.clarityBin
1630
1813
  });
1631
1814
  };
1632
1815
 
@@ -1639,8 +1822,6 @@ exports.evalJson = evalJson;
1639
1822
  exports.executeJson = executeJson;
1640
1823
  exports.getBlockHeight = getBlockHeight;
1641
1824
  exports.getStxBalance = getStxBalance;
1825
+ exports.makeRandomAddress = makeRandomAddress;
1642
1826
  exports.mineBlocks = mineBlocks;
1643
- exports.tx = tx;
1644
- exports.txErr = txErr;
1645
- exports.txOk = txOk;
1646
1827
  //# sourceMappingURL=test.cjs.development.js.map