@clarigen/test 0.3.3 → 1.0.0-next.10

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,14 @@ function _deployContract() {
1060
1030
  return _deployContract.apply(this, arguments);
1061
1031
  }
1062
1032
 
1033
+ function getPrints(events) {
1034
+ return core.filterEvents(events, core.CoreNodeEventType.ContractEvent).map(function (e) {
1035
+ var hex = e.contract_event.raw_value;
1036
+ var cv = clarity.hexToCV(hex);
1037
+ return core.cvToValue(cv);
1038
+ });
1039
+ }
1040
+
1063
1041
  var UTIL_CONTRACT_ID = 'ST000000000000000000002AMW42H.clarigen-test-utils';
1064
1042
  function deployUtilContract(_x) {
1065
1043
  return _deployUtilContract.apply(this, arguments);
@@ -1095,34 +1073,39 @@ function _deployUtilContract() {
1095
1073
  return _deployUtilContract.apply(this, arguments);
1096
1074
  }
1097
1075
 
1076
+ function getBin(provider) {
1077
+ return 'clarityBin' in provider ? provider.clarityBin : provider;
1078
+ }
1079
+
1098
1080
  function getBlockHeight(_x2) {
1099
1081
  return _getBlockHeight.apply(this, arguments);
1100
1082
  }
1101
1083
 
1102
1084
  function _getBlockHeight() {
1103
1085
  _getBlockHeight = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(provider) {
1104
- var _yield$evalJson, output_serialized, outputCV, blockHeight;
1086
+ var bin, _yield$evalJson, output_serialized, outputCV, blockHeight;
1105
1087
 
1106
1088
  return runtime_1.wrap(function _callee2$(_context2) {
1107
1089
  while (1) {
1108
1090
  switch (_context2.prev = _context2.next) {
1109
1091
  case 0:
1110
- _context2.next = 2;
1092
+ bin = getBin(provider);
1093
+ _context2.next = 3;
1111
1094
  return evalJson({
1112
1095
  contractAddress: UTIL_CONTRACT_ID,
1113
1096
  functionName: 'get-block-height',
1114
1097
  args: [],
1115
- provider: provider
1098
+ provider: bin
1116
1099
  });
1117
1100
 
1118
- case 2:
1101
+ case 3:
1119
1102
  _yield$evalJson = _context2.sent;
1120
1103
  output_serialized = _yield$evalJson.output_serialized;
1121
- outputCV = transactions.deserializeCV(Buffer.from(output_serialized, 'hex'));
1104
+ outputCV = clarity.hexToCV(output_serialized);
1122
1105
  blockHeight = core.cvToValue(outputCV);
1123
1106
  return _context2.abrupt("return", blockHeight);
1124
1107
 
1125
- case 7:
1108
+ case 8:
1126
1109
  case "end":
1127
1110
  return _context2.stop();
1128
1111
  }
@@ -1138,20 +1121,22 @@ function mineBlock(_x3) {
1138
1121
 
1139
1122
  function _mineBlock() {
1140
1123
  _mineBlock = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(provider) {
1124
+ var bin;
1141
1125
  return runtime_1.wrap(function _callee3$(_context3) {
1142
1126
  while (1) {
1143
1127
  switch (_context3.prev = _context3.next) {
1144
1128
  case 0:
1145
- _context3.next = 2;
1129
+ bin = getBin(provider);
1130
+ _context3.next = 3;
1146
1131
  return executeJson({
1147
1132
  contractAddress: UTIL_CONTRACT_ID,
1148
1133
  functionName: 'mine-block',
1149
1134
  args: [],
1150
- provider: provider,
1135
+ provider: bin,
1151
1136
  senderAddress: 'ST000000000000000000002AMW42H'
1152
1137
  });
1153
1138
 
1154
- case 2:
1139
+ case 3:
1155
1140
  case "end":
1156
1141
  return _context3.stop();
1157
1142
  }
@@ -1166,29 +1151,30 @@ function mineBlocks(_x4, _x5) {
1166
1151
  }
1167
1152
 
1168
1153
  function _mineBlocks() {
1169
- _mineBlocks = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(blocks, provider) {
1170
- var index;
1154
+ _mineBlocks = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(_blocks, provider) {
1155
+ var blocks, index;
1171
1156
  return runtime_1.wrap(function _callee4$(_context4) {
1172
1157
  while (1) {
1173
1158
  switch (_context4.prev = _context4.next) {
1174
1159
  case 0:
1160
+ blocks = common.intToBigInt(_blocks);
1175
1161
  index = 0;
1176
1162
 
1177
- case 1:
1163
+ case 2:
1178
1164
  if (!(index < blocks)) {
1179
- _context4.next = 7;
1165
+ _context4.next = 8;
1180
1166
  break;
1181
1167
  }
1182
1168
 
1183
- _context4.next = 4;
1169
+ _context4.next = 5;
1184
1170
  return mineBlock(provider);
1185
1171
 
1186
- case 4:
1172
+ case 5:
1187
1173
  index++;
1188
- _context4.next = 1;
1174
+ _context4.next = 2;
1189
1175
  break;
1190
1176
 
1191
- case 7:
1177
+ case 8:
1192
1178
  case "end":
1193
1179
  return _context4.stop();
1194
1180
  }
@@ -1204,28 +1190,29 @@ function getStxBalance(_x6, _x7) {
1204
1190
 
1205
1191
  function _getStxBalance() {
1206
1192
  _getStxBalance = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(provider, account) {
1207
- var _yield$evalJson2, output_serialized, outputCV, balance;
1193
+ var bin, _yield$evalJson2, output_serialized, outputCV, balance;
1208
1194
 
1209
1195
  return runtime_1.wrap(function _callee5$(_context5) {
1210
1196
  while (1) {
1211
1197
  switch (_context5.prev = _context5.next) {
1212
1198
  case 0:
1213
- _context5.next = 2;
1199
+ bin = getBin(provider);
1200
+ _context5.next = 3;
1214
1201
  return evalJson({
1215
1202
  contractAddress: UTIL_CONTRACT_ID,
1216
1203
  functionName: 'get-stx-balance',
1217
1204
  args: ["'" + account],
1218
- provider: provider
1205
+ provider: bin
1219
1206
  });
1220
1207
 
1221
- case 2:
1208
+ case 3:
1222
1209
  _yield$evalJson2 = _context5.sent;
1223
1210
  output_serialized = _yield$evalJson2.output_serialized;
1224
- outputCV = transactions.deserializeCV(Buffer.from(output_serialized, 'hex'));
1211
+ outputCV = clarity.hexToCV(output_serialized);
1225
1212
  balance = core.cvToValue(outputCV);
1226
1213
  return _context5.abrupt("return", balance);
1227
1214
 
1228
- case 7:
1215
+ case 8:
1229
1216
  case "end":
1230
1217
  return _context5.stop();
1231
1218
  }
@@ -1235,141 +1222,284 @@ function _getStxBalance() {
1235
1222
  return _getStxBalance.apply(this, arguments);
1236
1223
  }
1237
1224
 
1238
- function tx(_x, _x2) {
1239
- return _tx2.apply(this, arguments);
1225
+ function makeRandomAddress(version) {
1226
+ if (version === void 0) {
1227
+ version = crypto.StacksNetworkVersion.testnetP2PKH;
1228
+ }
1229
+
1230
+ var privateKey = transactions.makeRandomPrivKey();
1231
+ var publicKey = transactions.getPublicKeyFromStacksPrivateKey(privateKey);
1232
+ var address = crypto.publicKeyToStxAddress(publicKey.data, version);
1233
+ return address;
1234
+ }
1235
+
1236
+ function formatArguments(args) {
1237
+ return args.map(function (arg) {
1238
+ return core.cvToString(arg);
1239
+ });
1240
+ }
1241
+
1242
+ function getIdentifier(tx) {
1243
+ return tx.contractAddress + "." + tx.contractName;
1240
1244
  }
1241
1245
 
1242
- function _tx2() {
1243
- _tx2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(tx, sender) {
1244
- var receipt, result;
1246
+ function getLogs(stderr) {
1247
+ if (stderr === '') return [];
1248
+ return stderr.split('\n').map(function (line) {
1249
+ return line.slice(62);
1250
+ });
1251
+ }
1252
+
1253
+ function makeEvalResult(result) {
1254
+ var resultCV = clarity.hexToCV(result.output_serialized);
1255
+ var value = core.cvToValue(resultCV, true);
1256
+ return {
1257
+ value: value,
1258
+ clarityValue: resultCV,
1259
+ logs: getLogs(result.stderr),
1260
+ costs: result.costs
1261
+ };
1262
+ }
1263
+
1264
+ function ro(_x, _x2) {
1265
+ return _ro.apply(this, arguments);
1266
+ }
1267
+
1268
+ function _ro() {
1269
+ _ro = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(tx, bin) {
1270
+ var result;
1245
1271
  return runtime_1.wrap(function _callee$(_context) {
1246
1272
  while (1) {
1247
1273
  switch (_context.prev = _context.next) {
1248
1274
  case 0:
1249
1275
  _context.next = 2;
1250
- return tx.submit({
1251
- sender: sender
1276
+ return evalJson({
1277
+ functionName: tx["function"].name,
1278
+ args: formatArguments(tx.functionArgs),
1279
+ contractAddress: getIdentifier(tx),
1280
+ provider: bin
1252
1281
  });
1253
1282
 
1254
1283
  case 2:
1255
- receipt = _context.sent;
1256
- _context.next = 5;
1257
- return receipt.getResult();
1258
-
1259
- case 5:
1260
1284
  result = _context.sent;
1261
- return _context.abrupt("return", result);
1285
+ return _context.abrupt("return", makeEvalResult(result));
1262
1286
 
1263
- case 7:
1287
+ case 4:
1264
1288
  case "end":
1265
1289
  return _context.stop();
1266
1290
  }
1267
1291
  }
1268
1292
  }, _callee);
1269
1293
  }));
1270
- return _tx2.apply(this, arguments);
1294
+ return _ro.apply(this, arguments);
1271
1295
  }
1272
1296
 
1273
- function txOk(_x3, _x4) {
1274
- return _txOk.apply(this, arguments);
1297
+ function evalCode(_x3) {
1298
+ return _evalCode.apply(this, arguments);
1275
1299
  }
1276
1300
 
1277
- function _txOk() {
1278
- _txOk = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_tx, sender) {
1279
- var result;
1301
+ function _evalCode() {
1302
+ _evalCode = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref) {
1303
+ var contractAddress, code, bin, result;
1280
1304
  return runtime_1.wrap(function _callee2$(_context2) {
1281
1305
  while (1) {
1282
1306
  switch (_context2.prev = _context2.next) {
1283
1307
  case 0:
1284
- _context2.next = 2;
1285
- return tx(_tx, sender);
1308
+ contractAddress = _ref.contractAddress, code = _ref.code, bin = _ref.bin;
1309
+ _context2.next = 3;
1310
+ return evalRaw({
1311
+ contractAddress: contractAddress,
1312
+ code: code,
1313
+ provider: bin
1314
+ });
1286
1315
 
1287
- case 2:
1316
+ case 3:
1288
1317
  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);
1318
+ return _context2.abrupt("return", makeEvalResult(result));
1296
1319
 
1297
1320
  case 5:
1298
- return _context2.abrupt("return", result);
1299
-
1300
- case 6:
1301
1321
  case "end":
1302
1322
  return _context2.stop();
1303
1323
  }
1304
1324
  }
1305
1325
  }, _callee2);
1306
1326
  }));
1307
- return _txOk.apply(this, arguments);
1327
+ return _evalCode.apply(this, arguments);
1308
1328
  }
1309
1329
 
1310
- function txErr(_x5, _x6) {
1311
- return _txErr.apply(this, arguments);
1330
+ function tx(_x4) {
1331
+ return _tx.apply(this, arguments);
1312
1332
  }
1313
1333
 
1314
- function _txErr() {
1315
- _txErr = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(_tx, sender) {
1316
- var result;
1334
+ function _tx() {
1335
+ _tx = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(_ref2) {
1336
+ var tx, senderAddress, bin, result, resultCV, value, baseReturn;
1317
1337
  return runtime_1.wrap(function _callee3$(_context3) {
1318
1338
  while (1) {
1319
1339
  switch (_context3.prev = _context3.next) {
1320
1340
  case 0:
1321
- _context3.next = 2;
1322
- return tx(_tx, sender);
1341
+ tx = _ref2.tx, senderAddress = _ref2.senderAddress, bin = _ref2.bin;
1342
+ _context3.next = 3;
1343
+ return executeJson({
1344
+ contractAddress: getIdentifier(tx),
1345
+ senderAddress: senderAddress,
1346
+ provider: bin,
1347
+ functionName: tx["function"].name,
1348
+ args: formatArguments(tx.functionArgs)
1349
+ });
1323
1350
 
1324
- case 2:
1351
+ case 3:
1325
1352
  result = _context3.sent;
1353
+ resultCV = clarity.hexToCV(result.output_serialized);
1354
+ value = core.cvToValue(resultCV);
1355
+ baseReturn = {
1356
+ value: value,
1357
+ logs: getLogs(result.stderr),
1358
+ costs: result.costs
1359
+ };
1326
1360
 
1327
- if (!result.isOk) {
1328
- _context3.next = 5;
1361
+ if (!result.success) {
1362
+ _context3.next = 9;
1329
1363
  break;
1330
1364
  }
1331
1365
 
1332
- throw new Error("Expected transaction error, got ok: " + result.value);
1366
+ return _context3.abrupt("return", _extends({}, baseReturn, {
1367
+ isOk: true,
1368
+ response: clarity.responseOkCV(resultCV),
1369
+ assets: result.assets,
1370
+ events: result.events,
1371
+ prints: getPrints(result.events)
1372
+ }));
1333
1373
 
1334
- case 5:
1335
- return _context3.abrupt("return", result);
1374
+ case 9:
1375
+ return _context3.abrupt("return", _extends({}, baseReturn, {
1376
+ isOk: false,
1377
+ response: clarity.responseErrorCV(resultCV)
1378
+ }));
1336
1379
 
1337
- case 6:
1380
+ case 10:
1338
1381
  case "end":
1339
1382
  return _context3.stop();
1340
1383
  }
1341
1384
  }
1342
1385
  }, _callee3);
1343
1386
  }));
1344
- return _txErr.apply(this, arguments);
1387
+ return _tx.apply(this, arguments);
1388
+ }
1389
+
1390
+ function mapGet(_x5) {
1391
+ return _mapGet.apply(this, arguments);
1392
+ }
1393
+
1394
+ function _mapGet() {
1395
+ _mapGet = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(_ref3) {
1396
+ var map, bin, code, result;
1397
+ return runtime_1.wrap(function _callee4$(_context4) {
1398
+ while (1) {
1399
+ switch (_context4.prev = _context4.next) {
1400
+ case 0:
1401
+ map = _ref3.map, bin = _ref3.bin;
1402
+ code = "(map-get? " + map.map.name + " " + core.cvToString(map.key) + ")";
1403
+ _context4.next = 4;
1404
+ return evalCode({
1405
+ contractAddress: getIdentifier(map),
1406
+ code: code,
1407
+ bin: bin
1408
+ });
1409
+
1410
+ case 4:
1411
+ result = _context4.sent;
1412
+ return _context4.abrupt("return", result.value);
1413
+
1414
+ case 6:
1415
+ case "end":
1416
+ return _context4.stop();
1417
+ }
1418
+ }
1419
+ }, _callee4);
1420
+ }));
1421
+ return _mapGet.apply(this, arguments);
1345
1422
  }
1346
1423
 
1347
1424
  var TestProvider = /*#__PURE__*/function () {
1348
- function TestProvider(clarityBin, contractIdentifier, contractFile) {
1425
+ function TestProvider(clarityBin) {
1349
1426
  this.clarityBin = clarityBin;
1350
- this.contractIdentifier = contractIdentifier;
1351
- this.contractFile = contractFile;
1352
1427
  }
1353
1428
 
1354
- TestProvider.create = /*#__PURE__*/function () {
1355
- var _create = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref) {
1356
- var clarityBin, contractFilePath, contractIdentifier;
1429
+ TestProvider.fromContracts = /*#__PURE__*/function () {
1430
+ var _fromContracts = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(contracts, options) {
1431
+ var clarityBin, instances, k, contract, identifier, instance, provider;
1357
1432
  return runtime_1.wrap(function _callee$(_context) {
1358
1433
  while (1) {
1359
1434
  switch (_context.prev = _context.next) {
1360
1435
  case 0:
1361
- clarityBin = _ref.clarityBin, contractFilePath = _ref.contractFilePath, contractIdentifier = _ref.contractIdentifier;
1362
- _context.next = 3;
1436
+ if (options === void 0) {
1437
+ options = {};
1438
+ }
1439
+
1440
+ _context.t0 = options.clarityBin;
1441
+
1442
+ if (_context.t0) {
1443
+ _context.next = 6;
1444
+ break;
1445
+ }
1446
+
1447
+ _context.next = 5;
1448
+ return nativeBin.createClarityBin();
1449
+
1450
+ case 5:
1451
+ _context.t0 = _context.sent;
1452
+
1453
+ case 6:
1454
+ clarityBin = _context.t0;
1455
+ instances = {};
1456
+ _context.next = 10;
1457
+ return deployUtilContract(clarityBin);
1458
+
1459
+ case 10:
1460
+ _context.t1 = runtime_1.keys(contracts);
1461
+
1462
+ case 11:
1463
+ if ((_context.t2 = _context.t1()).done) {
1464
+ _context.next = 22;
1465
+ break;
1466
+ }
1467
+
1468
+ k = _context.t2.value;
1469
+
1470
+ if (!Object.prototype.hasOwnProperty.call(contracts, k)) {
1471
+ _context.next = 20;
1472
+ break;
1473
+ }
1474
+
1475
+ contract = contracts[k];
1476
+ identifier = core.getContractIdentifier(contract);
1477
+ _context.next = 18;
1363
1478
  return deployContract({
1364
- contractIdentifier: contractIdentifier,
1365
- contractFilePath: contractFilePath,
1479
+ contractIdentifier: identifier,
1480
+ contractFilePath: contract.contractFile,
1366
1481
  provider: clarityBin
1367
1482
  });
1368
1483
 
1369
- case 3:
1370
- return _context.abrupt("return", new this(clarityBin, contractIdentifier, contractFilePath));
1484
+ case 18:
1485
+ instance = contract.contract(contract.address, contract.name);
1486
+ instances[k] = {
1487
+ identifier: core.getContractIdentifier(contract),
1488
+ contract: instance
1489
+ };
1371
1490
 
1372
- case 4:
1491
+ case 20:
1492
+ _context.next = 11;
1493
+ break;
1494
+
1495
+ case 22:
1496
+ provider = new this(clarityBin);
1497
+ return _context.abrupt("return", {
1498
+ deployed: instances,
1499
+ provider: provider
1500
+ });
1501
+
1502
+ case 24:
1373
1503
  case "end":
1374
1504
  return _context.stop();
1375
1505
  }
@@ -1377,44 +1507,34 @@ var TestProvider = /*#__PURE__*/function () {
1377
1507
  }, _callee, this);
1378
1508
  }));
1379
1509
 
1380
- function create(_x) {
1381
- return _create.apply(this, arguments);
1510
+ function fromContracts(_x, _x2) {
1511
+ return _fromContracts.apply(this, arguments);
1382
1512
  }
1383
1513
 
1384
- return create;
1514
+ return fromContracts;
1385
1515
  }();
1386
1516
 
1387
- TestProvider.fromContract = /*#__PURE__*/function () {
1388
- var _fromContract = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref2) {
1389
- var contract, clarityBin, address, contractName, provider;
1517
+ var _proto = TestProvider.prototype;
1518
+
1519
+ _proto.ro = function ro$1(tx) {
1520
+ return ro(tx, this.clarityBin);
1521
+ };
1522
+
1523
+ _proto.rov = /*#__PURE__*/function () {
1524
+ var _rov = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(tx) {
1525
+ var result;
1390
1526
  return runtime_1.wrap(function _callee2$(_context2) {
1391
1527
  while (1) {
1392
1528
  switch (_context2.prev = _context2.next) {
1393
1529
  case 0:
1394
- contract = _ref2.contract, clarityBin = _ref2.clarityBin;
1395
- address = contract.address;
1530
+ _context2.next = 2;
1531
+ return this.ro(tx);
1396
1532
 
1397
- if (address) {
1398
- _context2.next = 4;
1399
- break;
1400
- }
1401
-
1402
- throw new Error('TestProvider must have an address');
1533
+ case 2:
1534
+ result = _context2.sent;
1535
+ return _context2.abrupt("return", result.value);
1403
1536
 
1404
1537
  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
1538
  case "end":
1419
1539
  return _context2.stop();
1420
1540
  }
@@ -1422,211 +1542,270 @@ var TestProvider = /*#__PURE__*/function () {
1422
1542
  }, _callee2, this);
1423
1543
  }));
1424
1544
 
1425
- function fromContract(_x2) {
1426
- return _fromContract.apply(this, arguments);
1545
+ function rov(_x3) {
1546
+ return _rov.apply(this, arguments);
1427
1547
  }
1428
1548
 
1429
- return fromContract;
1549
+ return rov;
1430
1550
  }();
1431
1551
 
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;
1552
+ _proto.roOk = /*#__PURE__*/function () {
1553
+ var _roOk = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(tx) {
1554
+ var result;
1435
1555
  return runtime_1.wrap(function _callee3$(_context3) {
1436
1556
  while (1) {
1437
1557
  switch (_context3.prev = _context3.next) {
1438
1558
  case 0:
1439
1559
  _context3.next = 2;
1440
- return getDefaultClarityBin(clarityBinOrAccounts);
1560
+ return this.ro(tx);
1441
1561
 
1442
1562
  case 2:
1443
- clarityBin = _context3.sent;
1444
- instances = {};
1445
- _context3.next = 6;
1446
- return deployUtilContract(clarityBin);
1563
+ result = _context3.sent;
1564
+ return _context3.abrupt("return", result.value.match(function (ok) {
1565
+ return _extends({}, result, {
1566
+ value: ok
1567
+ });
1568
+ }, function (err) {
1569
+ throw new Error("Expected OK, received error: " + err);
1570
+ }));
1447
1571
 
1448
- case 6:
1449
- _context3.t0 = runtime_1.keys(contracts);
1572
+ case 4:
1573
+ case "end":
1574
+ return _context3.stop();
1575
+ }
1576
+ }
1577
+ }, _callee3, this);
1578
+ }));
1450
1579
 
1451
- case 7:
1452
- if ((_context3.t1 = _context3.t0()).done) {
1453
- _context3.next = 16;
1454
- break;
1455
- }
1580
+ function roOk(_x4) {
1581
+ return _roOk.apply(this, arguments);
1582
+ }
1456
1583
 
1457
- k = _context3.t1.value;
1458
- contract = contracts[k];
1459
- _context3.next = 12;
1460
- return this.fromContract({
1461
- contract: contract,
1462
- clarityBin: clarityBin
1463
- });
1584
+ return roOk;
1585
+ }();
1464
1586
 
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;
1587
+ _proto.roErr = /*#__PURE__*/function () {
1588
+ var _roErr = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(tx) {
1589
+ var result;
1590
+ return runtime_1.wrap(function _callee4$(_context4) {
1591
+ while (1) {
1592
+ switch (_context4.prev = _context4.next) {
1593
+ case 0:
1594
+ _context4.next = 2;
1595
+ return this.ro(tx);
1473
1596
 
1474
- case 16:
1475
- return _context3.abrupt("return", instances);
1597
+ case 2:
1598
+ result = _context4.sent;
1599
+ return _context4.abrupt("return", result.value.match(function (ok) {
1600
+ throw new Error("Expected err, received ok: " + ok);
1601
+ }, function (err) {
1602
+ return _extends({}, result, {
1603
+ value: err
1604
+ });
1605
+ }));
1476
1606
 
1477
- case 17:
1607
+ case 4:
1478
1608
  case "end":
1479
- return _context3.stop();
1609
+ return _context4.stop();
1480
1610
  }
1481
1611
  }
1482
- }, _callee3, this);
1612
+ }, _callee4, this);
1483
1613
  }));
1484
1614
 
1485
- function fromContracts(_x3, _x4) {
1486
- return _fromContracts.apply(this, arguments);
1615
+ function roErr(_x5) {
1616
+ return _roErr.apply(this, arguments);
1487
1617
  }
1488
1618
 
1489
- return fromContracts;
1619
+ return roErr;
1490
1620
  }();
1491
1621
 
1492
- var _proto = TestProvider.prototype;
1622
+ _proto.rovOk = /*#__PURE__*/function () {
1623
+ var _rovOk = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(tx) {
1624
+ return runtime_1.wrap(function _callee5$(_context5) {
1625
+ while (1) {
1626
+ switch (_context5.prev = _context5.next) {
1627
+ case 0:
1628
+ _context5.next = 2;
1629
+ return this.roOk(tx);
1493
1630
 
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) {
1631
+ case 2:
1632
+ return _context5.abrupt("return", _context5.sent.value);
1633
+
1634
+ case 3:
1635
+ case "end":
1636
+ return _context5.stop();
1637
+ }
1638
+ }
1639
+ }, _callee5, this);
1640
+ }));
1641
+
1642
+ function rovOk(_x6) {
1643
+ return _rovOk.apply(this, arguments);
1644
+ }
1645
+
1646
+ return rovOk;
1647
+ }();
1648
+
1649
+ _proto.rovErr = /*#__PURE__*/function () {
1650
+ var _rovErr = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(tx) {
1651
+ return runtime_1.wrap(function _callee6$(_context6) {
1498
1652
  while (1) {
1499
- switch (_context4.prev = _context4.next) {
1653
+ switch (_context6.prev = _context6.next) {
1500
1654
  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
- });
1655
+ _context6.next = 2;
1656
+ return this.roErr(tx);
1657
+
1658
+ case 2:
1659
+ return _context6.abrupt("return", _context6.sent.value);
1509
1660
 
1510
1661
  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;
1662
+ case "end":
1663
+ return _context6.stop();
1664
+ }
1665
+ }
1666
+ }, _callee6, this);
1667
+ }));
1517
1668
 
1518
- case 9:
1519
- return _context4.abrupt("return", neverthrow.ok(value));
1669
+ function rovErr(_x7) {
1670
+ return _rovErr.apply(this, arguments);
1671
+ }
1520
1672
 
1521
- case 10:
1522
- return _context4.abrupt("return", neverthrow.err(value));
1673
+ return rovErr;
1674
+ }();
1523
1675
 
1524
- case 11:
1525
- return _context4.abrupt("return", value);
1676
+ _proto.tx = function tx$1(_tx2, senderAddress) {
1677
+ return tx({
1678
+ tx: _tx2,
1679
+ senderAddress: senderAddress,
1680
+ bin: this.clarityBin
1681
+ });
1682
+ };
1526
1683
 
1527
- case 12:
1684
+ _proto.txOk = /*#__PURE__*/function () {
1685
+ var _txOk = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(tx, senderAddress) {
1686
+ var result;
1687
+ return runtime_1.wrap(function _callee7$(_context7) {
1688
+ while (1) {
1689
+ switch (_context7.prev = _context7.next) {
1690
+ case 0:
1691
+ _context7.next = 2;
1692
+ return this.tx(tx, senderAddress);
1693
+
1694
+ case 2:
1695
+ result = _context7.sent;
1696
+
1697
+ if (result.isOk) {
1698
+ _context7.next = 5;
1699
+ break;
1700
+ }
1701
+
1702
+ throw new Error("Expected OK, received error: " + result.value);
1703
+
1704
+ case 5:
1705
+ return _context7.abrupt("return", result);
1706
+
1707
+ case 6:
1528
1708
  case "end":
1529
- return _context4.stop();
1709
+ return _context7.stop();
1530
1710
  }
1531
1711
  }
1532
- }, _callee4, this);
1712
+ }, _callee7, this);
1533
1713
  }));
1534
1714
 
1535
- function callReadOnly(_x5, _x6) {
1536
- return _callReadOnly.apply(this, arguments);
1715
+ function txOk(_x8, _x9) {
1716
+ return _txOk.apply(this, arguments);
1537
1717
  }
1538
1718
 
1539
- return callReadOnly;
1719
+ return txOk;
1540
1720
  }();
1541
1721
 
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
- });
1722
+ _proto.txErr = /*#__PURE__*/function () {
1723
+ var _txErr = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(tx, senderAddress) {
1724
+ var result;
1725
+ return runtime_1.wrap(function _callee8$(_context8) {
1726
+ while (1) {
1727
+ switch (_context8.prev = _context8.next) {
1728
+ case 0:
1729
+ _context8.next = 2;
1730
+ return this.tx(tx, senderAddress);
1570
1731
 
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
- });
1732
+ case 2:
1733
+ result = _context8.sent;
1600
1734
 
1601
- case 7:
1602
- case "end":
1603
- return _context5.stop();
1604
- }
1735
+ if (!result.isOk) {
1736
+ _context8.next = 5;
1737
+ break;
1738
+ }
1739
+
1740
+ throw new Error("Expected Err, received ok: " + result.value);
1741
+
1742
+ case 5:
1743
+ return _context8.abrupt("return", result);
1744
+
1745
+ case 6:
1746
+ case "end":
1747
+ return _context8.stop();
1605
1748
  }
1606
- }, _callee5);
1607
- }));
1749
+ }
1750
+ }, _callee8, this);
1751
+ }));
1608
1752
 
1609
- return function submit(_x7) {
1610
- return _ref3.apply(this, arguments);
1611
- };
1612
- }();
1753
+ function txErr(_x10, _x11) {
1754
+ return _txErr.apply(this, arguments);
1755
+ }
1613
1756
 
1614
- return {
1615
- submit: submit
1616
- };
1757
+ return txErr;
1758
+ }();
1759
+
1760
+ _proto.evalCode = function evalCode$1(code, contractAddress) {
1761
+ if (contractAddress === void 0) {
1762
+ contractAddress = UTIL_CONTRACT_ID;
1763
+ }
1764
+
1765
+ return evalCode({
1766
+ contractAddress: contractAddress,
1767
+ code: code,
1768
+ bin: this.clarityBin
1769
+ });
1617
1770
  };
1618
1771
 
1619
- _proto.formatArguments = function formatArguments(func, args) {
1620
- return args.map(function (arg, index) {
1621
- var type = func.args[index].type;
1772
+ _proto.eval = /*#__PURE__*/function () {
1773
+ var _eval2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(code, contractAddress) {
1774
+ var result;
1775
+ return runtime_1.wrap(function _callee9$(_context9) {
1776
+ while (1) {
1777
+ switch (_context9.prev = _context9.next) {
1778
+ case 0:
1779
+ if (contractAddress === void 0) {
1780
+ contractAddress = UTIL_CONTRACT_ID;
1781
+ }
1782
+
1783
+ _context9.next = 3;
1784
+ return this.evalCode(code, contractAddress);
1622
1785
 
1623
- if (type === 'trait_reference') {
1624
- return "'" + arg;
1625
- }
1786
+ case 3:
1787
+ result = _context9.sent;
1788
+ return _context9.abrupt("return", result.value);
1789
+
1790
+ case 5:
1791
+ case "end":
1792
+ return _context9.stop();
1793
+ }
1794
+ }
1795
+ }, _callee9, this);
1796
+ }));
1797
+
1798
+ function _eval(_x12, _x13) {
1799
+ return _eval2.apply(this, arguments);
1800
+ }
1801
+
1802
+ return _eval;
1803
+ }();
1626
1804
 
1627
- var argCV = core.parseToCV(arg, type);
1628
- var cvString = core.cvToString(argCV);
1629
- return cvString;
1805
+ _proto.mapGet = function mapGet$1(map) {
1806
+ return mapGet({
1807
+ map: map,
1808
+ bin: this.clarityBin
1630
1809
  });
1631
1810
  };
1632
1811
 
@@ -1639,8 +1818,6 @@ exports.evalJson = evalJson;
1639
1818
  exports.executeJson = executeJson;
1640
1819
  exports.getBlockHeight = getBlockHeight;
1641
1820
  exports.getStxBalance = getStxBalance;
1821
+ exports.makeRandomAddress = makeRandomAddress;
1642
1822
  exports.mineBlocks = mineBlocks;
1643
- exports.tx = tx;
1644
- exports.txErr = txErr;
1645
- exports.txOk = txOk;
1646
1823
  //# sourceMappingURL=test.cjs.development.js.map