@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.
package/dist/test.esm.js CHANGED
@@ -1,8 +1,10 @@
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';
1
+ import { getDefaultBinaryFilePath, getTempFilePath, NativeClarityBinProvider, hasStdErr, createClarityBin as createClarityBin$1 } from '@clarigen/native-bin';
2
+ import { cvToValue, cvToString, getContractIdentifier } from '@clarigen/core';
3
+ import { publicKeyToStxAddress, StacksNetworkVersion } from 'micro-stacks/crypto';
4
+ import { makeRandomPrivKey, getPublicKeyFromStacksPrivateKey } from 'micro-stacks/transactions';
5
+ import { hexToCV, responseErrorCV, responseOkCV } from 'micro-stacks/clarity';
5
6
  import { join } from 'path';
7
+ import { intToBigInt } from 'micro-stacks/common';
6
8
 
7
9
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
8
10
  try {
@@ -40,6 +42,24 @@ function _asyncToGenerator(fn) {
40
42
  };
41
43
  }
42
44
 
45
+ function _extends() {
46
+ _extends = Object.assign || function (target) {
47
+ for (var i = 1; i < arguments.length; i++) {
48
+ var source = arguments[i];
49
+
50
+ for (var key in source) {
51
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
52
+ target[key] = source[key];
53
+ }
54
+ }
55
+ }
56
+
57
+ return target;
58
+ };
59
+
60
+ return _extends.apply(this, arguments);
61
+ }
62
+
43
63
  function createCommonjsModule(fn, module) {
44
64
  return module = { exports: {} }, fn(module, module.exports), module.exports;
45
65
  }
@@ -805,7 +825,9 @@ var executeJson = /*#__PURE__*/function () {
805
825
  throw new Error("Execution error: " + result.stderr);
806
826
 
807
827
  case 10:
808
- return _context.abrupt("return", response);
828
+ return _context.abrupt("return", _extends({}, response, {
829
+ stderr: result.stderr
830
+ }));
809
831
 
810
832
  case 11:
811
833
  case "end":
@@ -819,22 +841,20 @@ var executeJson = /*#__PURE__*/function () {
819
841
  return _ref2.apply(this, arguments);
820
842
  };
821
843
  }();
822
- var evalJson = /*#__PURE__*/function () {
844
+ var evalRaw = /*#__PURE__*/function () {
823
845
  var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref3) {
824
- var contractAddress, functionName, provider, _ref3$args, args, evalCode, receipt, response;
825
-
846
+ var contractAddress, code, provider, receipt, response;
826
847
  return runtime_1.wrap(function _callee2$(_context2) {
827
848
  while (1) {
828
849
  switch (_context2.prev = _context2.next) {
829
850
  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;
851
+ contractAddress = _ref3.contractAddress, code = _ref3.code, provider = _ref3.provider;
852
+ _context2.next = 3;
833
853
  return provider.runCommand(['eval_at_chaintip', '--costs', contractAddress, provider.dbFilePath], {
834
- stdin: evalCode
854
+ stdin: code
835
855
  });
836
856
 
837
- case 4:
857
+ case 3:
838
858
  receipt = _context2.sent;
839
859
 
840
860
  if (process.env.PRINT_CLARIGEN_STDERR && receipt.stderr) {
@@ -844,16 +864,18 @@ var evalJson = /*#__PURE__*/function () {
844
864
  response = JSON.parse(receipt.stdout);
845
865
 
846
866
  if (response.success) {
847
- _context2.next = 9;
867
+ _context2.next = 8;
848
868
  break;
849
869
  }
850
870
 
851
871
  throw new Error(JSON.stringify(response.error, null, 2));
852
872
 
853
- case 9:
854
- return _context2.abrupt("return", response);
873
+ case 8:
874
+ return _context2.abrupt("return", _extends({}, response, {
875
+ stderr: receipt.stderr
876
+ }));
855
877
 
856
- case 10:
878
+ case 9:
857
879
  case "end":
858
880
  return _context2.stop();
859
881
  }
@@ -861,10 +883,23 @@ var evalJson = /*#__PURE__*/function () {
861
883
  }, _callee2);
862
884
  }));
863
885
 
864
- return function evalJson(_x2) {
886
+ return function evalRaw(_x2) {
865
887
  return _ref4.apply(this, arguments);
866
888
  };
867
889
  }();
890
+ var evalJson = function evalJson(_ref5) {
891
+ var contractAddress = _ref5.contractAddress,
892
+ functionName = _ref5.functionName,
893
+ provider = _ref5.provider,
894
+ _ref5$args = _ref5.args,
895
+ args = _ref5$args === void 0 ? [] : _ref5$args;
896
+ var code = "(" + functionName + " " + args.join(' ') + ")";
897
+ return evalRaw({
898
+ contractAddress: contractAddress,
899
+ provider: provider,
900
+ code: code
901
+ });
902
+ };
868
903
  function getAllocations(allocations) {
869
904
  if (!allocations) return [];
870
905
 
@@ -895,14 +930,14 @@ function stringifyAllocations(allocations) {
895
930
  }
896
931
 
897
932
  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;
933
+ var _ref6 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(_temp) {
934
+ var _ref7, allocations, _ref7$testnet, testnet, binFile, dbFileName, _allocations, provider, args;
900
935
 
901
936
  return runtime_1.wrap(function _callee3$(_context3) {
902
937
  while (1) {
903
938
  switch (_context3.prev = _context3.next) {
904
939
  case 0:
905
- _ref6 = _temp === void 0 ? {} : _temp, allocations = _ref6.allocations, _ref6$testnet = _ref6.testnet, testnet = _ref6$testnet === void 0 ? true : _ref6$testnet;
940
+ _ref7 = _temp === void 0 ? {} : _temp, allocations = _ref7.allocations, _ref7$testnet = _ref7.testnet, testnet = _ref7$testnet === void 0 ? true : _ref7$testnet;
906
941
  binFile = getDefaultBinaryFilePath();
907
942
  dbFileName = getTempFilePath();
908
943
  _allocations = getAllocations(allocations);
@@ -926,88 +961,23 @@ var createClarityBin = /*#__PURE__*/function () {
926
961
  }));
927
962
 
928
963
  return function createClarityBin(_x3) {
929
- return _ref5.apply(this, arguments);
964
+ return _ref6.apply(this, arguments);
930
965
  };
931
966
  }();
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
967
 
998
968
  function deployContract(_x5) {
999
969
  return _deployContract.apply(this, arguments);
1000
970
  }
1001
971
 
1002
972
  function _deployContract() {
1003
- _deployContract = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(_ref7) {
973
+ _deployContract = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(_ref8) {
1004
974
  var contractIdentifier, contractFilePath, provider, receipt, output, initialization, _initialization$split, error, trace, startLine, matcher, matches;
1005
975
 
1006
976
  return runtime_1.wrap(function _callee5$(_context5) {
1007
977
  while (1) {
1008
978
  switch (_context5.prev = _context5.next) {
1009
979
  case 0:
1010
- contractIdentifier = _ref7.contractIdentifier, contractFilePath = _ref7.contractFilePath, provider = _ref7.provider;
980
+ contractIdentifier = _ref8.contractIdentifier, contractFilePath = _ref8.contractFilePath, provider = _ref8.provider;
1011
981
  _context5.next = 3;
1012
982
  return provider.runCommand(['launch', contractIdentifier, contractFilePath, provider.dbFilePath, '--costs', '--assets']);
1013
983
 
@@ -1056,6 +1026,18 @@ function _deployContract() {
1056
1026
  return _deployContract.apply(this, arguments);
1057
1027
  }
1058
1028
 
1029
+ function getPrints(events) {
1030
+ var prints = [];
1031
+ events.forEach(function (e) {
1032
+ if (e.type === 'contract_event') {
1033
+ var hex = e.contract_event.raw_value;
1034
+ var cv = hexToCV(hex);
1035
+ prints.push(cvToValue(cv));
1036
+ }
1037
+ });
1038
+ return prints;
1039
+ }
1040
+
1059
1041
  var UTIL_CONTRACT_ID = 'ST000000000000000000002AMW42H.clarigen-test-utils';
1060
1042
  function deployUtilContract(_x) {
1061
1043
  return _deployUtilContract.apply(this, arguments);
@@ -1091,34 +1073,39 @@ function _deployUtilContract() {
1091
1073
  return _deployUtilContract.apply(this, arguments);
1092
1074
  }
1093
1075
 
1076
+ function getBin(provider) {
1077
+ return 'clarityBin' in provider ? provider.clarityBin : provider;
1078
+ }
1079
+
1094
1080
  function getBlockHeight(_x2) {
1095
1081
  return _getBlockHeight.apply(this, arguments);
1096
1082
  }
1097
1083
 
1098
1084
  function _getBlockHeight() {
1099
1085
  _getBlockHeight = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(provider) {
1100
- var _yield$evalJson, output_serialized, outputCV, blockHeight;
1086
+ var bin, _yield$evalJson, output_serialized, outputCV, blockHeight;
1101
1087
 
1102
1088
  return runtime_1.wrap(function _callee2$(_context2) {
1103
1089
  while (1) {
1104
1090
  switch (_context2.prev = _context2.next) {
1105
1091
  case 0:
1106
- _context2.next = 2;
1092
+ bin = getBin(provider);
1093
+ _context2.next = 3;
1107
1094
  return evalJson({
1108
1095
  contractAddress: UTIL_CONTRACT_ID,
1109
1096
  functionName: 'get-block-height',
1110
1097
  args: [],
1111
- provider: provider
1098
+ provider: bin
1112
1099
  });
1113
1100
 
1114
- case 2:
1101
+ case 3:
1115
1102
  _yield$evalJson = _context2.sent;
1116
1103
  output_serialized = _yield$evalJson.output_serialized;
1117
- outputCV = deserializeCV(Buffer.from(output_serialized, 'hex'));
1104
+ outputCV = hexToCV(output_serialized);
1118
1105
  blockHeight = cvToValue(outputCV);
1119
1106
  return _context2.abrupt("return", blockHeight);
1120
1107
 
1121
- case 7:
1108
+ case 8:
1122
1109
  case "end":
1123
1110
  return _context2.stop();
1124
1111
  }
@@ -1134,20 +1121,22 @@ function mineBlock(_x3) {
1134
1121
 
1135
1122
  function _mineBlock() {
1136
1123
  _mineBlock = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(provider) {
1124
+ var bin;
1137
1125
  return runtime_1.wrap(function _callee3$(_context3) {
1138
1126
  while (1) {
1139
1127
  switch (_context3.prev = _context3.next) {
1140
1128
  case 0:
1141
- _context3.next = 2;
1129
+ bin = getBin(provider);
1130
+ _context3.next = 3;
1142
1131
  return executeJson({
1143
1132
  contractAddress: UTIL_CONTRACT_ID,
1144
1133
  functionName: 'mine-block',
1145
1134
  args: [],
1146
- provider: provider,
1135
+ provider: bin,
1147
1136
  senderAddress: 'ST000000000000000000002AMW42H'
1148
1137
  });
1149
1138
 
1150
- case 2:
1139
+ case 3:
1151
1140
  case "end":
1152
1141
  return _context3.stop();
1153
1142
  }
@@ -1162,29 +1151,30 @@ function mineBlocks(_x4, _x5) {
1162
1151
  }
1163
1152
 
1164
1153
  function _mineBlocks() {
1165
- _mineBlocks = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(blocks, provider) {
1166
- var index;
1154
+ _mineBlocks = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(_blocks, provider) {
1155
+ var blocks, index;
1167
1156
  return runtime_1.wrap(function _callee4$(_context4) {
1168
1157
  while (1) {
1169
1158
  switch (_context4.prev = _context4.next) {
1170
1159
  case 0:
1160
+ blocks = intToBigInt(_blocks);
1171
1161
  index = 0;
1172
1162
 
1173
- case 1:
1163
+ case 2:
1174
1164
  if (!(index < blocks)) {
1175
- _context4.next = 7;
1165
+ _context4.next = 8;
1176
1166
  break;
1177
1167
  }
1178
1168
 
1179
- _context4.next = 4;
1169
+ _context4.next = 5;
1180
1170
  return mineBlock(provider);
1181
1171
 
1182
- case 4:
1172
+ case 5:
1183
1173
  index++;
1184
- _context4.next = 1;
1174
+ _context4.next = 2;
1185
1175
  break;
1186
1176
 
1187
- case 7:
1177
+ case 8:
1188
1178
  case "end":
1189
1179
  return _context4.stop();
1190
1180
  }
@@ -1200,28 +1190,29 @@ function getStxBalance(_x6, _x7) {
1200
1190
 
1201
1191
  function _getStxBalance() {
1202
1192
  _getStxBalance = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(provider, account) {
1203
- var _yield$evalJson2, output_serialized, outputCV, balance;
1193
+ var bin, _yield$evalJson2, output_serialized, outputCV, balance;
1204
1194
 
1205
1195
  return runtime_1.wrap(function _callee5$(_context5) {
1206
1196
  while (1) {
1207
1197
  switch (_context5.prev = _context5.next) {
1208
1198
  case 0:
1209
- _context5.next = 2;
1199
+ bin = getBin(provider);
1200
+ _context5.next = 3;
1210
1201
  return evalJson({
1211
1202
  contractAddress: UTIL_CONTRACT_ID,
1212
1203
  functionName: 'get-stx-balance',
1213
1204
  args: ["'" + account],
1214
- provider: provider
1205
+ provider: bin
1215
1206
  });
1216
1207
 
1217
- case 2:
1208
+ case 3:
1218
1209
  _yield$evalJson2 = _context5.sent;
1219
1210
  output_serialized = _yield$evalJson2.output_serialized;
1220
- outputCV = deserializeCV(Buffer.from(output_serialized, 'hex'));
1211
+ outputCV = hexToCV(output_serialized);
1221
1212
  balance = cvToValue(outputCV);
1222
1213
  return _context5.abrupt("return", balance);
1223
1214
 
1224
- case 7:
1215
+ case 8:
1225
1216
  case "end":
1226
1217
  return _context5.stop();
1227
1218
  }
@@ -1231,141 +1222,284 @@ function _getStxBalance() {
1231
1222
  return _getStxBalance.apply(this, arguments);
1232
1223
  }
1233
1224
 
1234
- function tx(_x, _x2) {
1235
- return _tx2.apply(this, arguments);
1225
+ function makeRandomAddress(version) {
1226
+ if (version === void 0) {
1227
+ version = StacksNetworkVersion.testnetP2PKH;
1228
+ }
1229
+
1230
+ var privateKey = makeRandomPrivKey();
1231
+ var publicKey = getPublicKeyFromStacksPrivateKey(privateKey);
1232
+ var address = publicKeyToStxAddress(publicKey.data, version);
1233
+ return address;
1236
1234
  }
1237
1235
 
1238
- function _tx2() {
1239
- _tx2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(tx, sender) {
1240
- var receipt, result;
1236
+ function formatArguments(args) {
1237
+ return args.map(function (arg) {
1238
+ return cvToString(arg);
1239
+ });
1240
+ }
1241
+
1242
+ function getIdentifier(tx) {
1243
+ return tx.contractAddress + "." + tx.contractName;
1244
+ }
1245
+
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 = hexToCV(result.output_serialized);
1255
+ var value = 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;
1241
1271
  return runtime_1.wrap(function _callee$(_context) {
1242
1272
  while (1) {
1243
1273
  switch (_context.prev = _context.next) {
1244
1274
  case 0:
1245
1275
  _context.next = 2;
1246
- return tx.submit({
1247
- sender: sender
1276
+ return evalJson({
1277
+ functionName: tx["function"].name,
1278
+ args: formatArguments(tx.functionArgs),
1279
+ contractAddress: getIdentifier(tx),
1280
+ provider: bin
1248
1281
  });
1249
1282
 
1250
1283
  case 2:
1251
- receipt = _context.sent;
1252
- _context.next = 5;
1253
- return receipt.getResult();
1254
-
1255
- case 5:
1256
1284
  result = _context.sent;
1257
- return _context.abrupt("return", result);
1285
+ return _context.abrupt("return", makeEvalResult(result));
1258
1286
 
1259
- case 7:
1287
+ case 4:
1260
1288
  case "end":
1261
1289
  return _context.stop();
1262
1290
  }
1263
1291
  }
1264
1292
  }, _callee);
1265
1293
  }));
1266
- return _tx2.apply(this, arguments);
1294
+ return _ro.apply(this, arguments);
1267
1295
  }
1268
1296
 
1269
- function txOk(_x3, _x4) {
1270
- return _txOk.apply(this, arguments);
1297
+ function evalCode(_x3) {
1298
+ return _evalCode.apply(this, arguments);
1271
1299
  }
1272
1300
 
1273
- function _txOk() {
1274
- _txOk = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_tx, sender) {
1275
- var result;
1301
+ function _evalCode() {
1302
+ _evalCode = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref) {
1303
+ var contractAddress, code, bin, result;
1276
1304
  return runtime_1.wrap(function _callee2$(_context2) {
1277
1305
  while (1) {
1278
1306
  switch (_context2.prev = _context2.next) {
1279
1307
  case 0:
1280
- _context2.next = 2;
1281
- 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
+ });
1282
1315
 
1283
- case 2:
1316
+ case 3:
1284
1317
  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);
1318
+ return _context2.abrupt("return", makeEvalResult(result));
1292
1319
 
1293
1320
  case 5:
1294
- return _context2.abrupt("return", result);
1295
-
1296
- case 6:
1297
1321
  case "end":
1298
1322
  return _context2.stop();
1299
1323
  }
1300
1324
  }
1301
1325
  }, _callee2);
1302
1326
  }));
1303
- return _txOk.apply(this, arguments);
1327
+ return _evalCode.apply(this, arguments);
1304
1328
  }
1305
1329
 
1306
- function txErr(_x5, _x6) {
1307
- return _txErr.apply(this, arguments);
1330
+ function tx(_x4) {
1331
+ return _tx.apply(this, arguments);
1308
1332
  }
1309
1333
 
1310
- function _txErr() {
1311
- _txErr = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(_tx, sender) {
1312
- var result;
1334
+ function _tx() {
1335
+ _tx = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(_ref2) {
1336
+ var tx, senderAddress, bin, result, resultCV, value, baseReturn;
1313
1337
  return runtime_1.wrap(function _callee3$(_context3) {
1314
1338
  while (1) {
1315
1339
  switch (_context3.prev = _context3.next) {
1316
1340
  case 0:
1317
- _context3.next = 2;
1318
- 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
+ });
1319
1350
 
1320
- case 2:
1351
+ case 3:
1321
1352
  result = _context3.sent;
1353
+ resultCV = hexToCV(result.output_serialized);
1354
+ value = cvToValue(resultCV);
1355
+ baseReturn = {
1356
+ value: value,
1357
+ logs: getLogs(result.stderr),
1358
+ costs: result.costs
1359
+ };
1322
1360
 
1323
- if (!result.isOk) {
1324
- _context3.next = 5;
1361
+ if (!result.success) {
1362
+ _context3.next = 9;
1325
1363
  break;
1326
1364
  }
1327
1365
 
1328
- throw new Error("Expected transaction error, got ok: " + result.value);
1366
+ return _context3.abrupt("return", _extends({}, baseReturn, {
1367
+ isOk: true,
1368
+ response: responseOkCV(resultCV),
1369
+ assets: result.assets,
1370
+ events: result.events,
1371
+ prints: getPrints(result.events)
1372
+ }));
1329
1373
 
1330
- case 5:
1331
- return _context3.abrupt("return", result);
1374
+ case 9:
1375
+ return _context3.abrupt("return", _extends({}, baseReturn, {
1376
+ isOk: false,
1377
+ response: responseErrorCV(resultCV)
1378
+ }));
1332
1379
 
1333
- case 6:
1380
+ case 10:
1334
1381
  case "end":
1335
1382
  return _context3.stop();
1336
1383
  }
1337
1384
  }
1338
1385
  }, _callee3);
1339
1386
  }));
1340
- 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 + " " + 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);
1341
1422
  }
1342
1423
 
1343
1424
  var TestProvider = /*#__PURE__*/function () {
1344
- function TestProvider(clarityBin, contractIdentifier, contractFile) {
1425
+ function TestProvider(clarityBin) {
1345
1426
  this.clarityBin = clarityBin;
1346
- this.contractIdentifier = contractIdentifier;
1347
- this.contractFile = contractFile;
1348
1427
  }
1349
1428
 
1350
- TestProvider.create = /*#__PURE__*/function () {
1351
- var _create = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref) {
1352
- 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;
1353
1432
  return runtime_1.wrap(function _callee$(_context) {
1354
1433
  while (1) {
1355
1434
  switch (_context.prev = _context.next) {
1356
1435
  case 0:
1357
- clarityBin = _ref.clarityBin, contractFilePath = _ref.contractFilePath, contractIdentifier = _ref.contractIdentifier;
1358
- _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 createClarityBin$1();
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 = getContractIdentifier(contract);
1477
+ _context.next = 18;
1359
1478
  return deployContract({
1360
- contractIdentifier: contractIdentifier,
1361
- contractFilePath: contractFilePath,
1479
+ contractIdentifier: identifier,
1480
+ contractFilePath: contract.contractFile,
1362
1481
  provider: clarityBin
1363
1482
  });
1364
1483
 
1365
- case 3:
1366
- 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: getContractIdentifier(contract),
1488
+ contract: instance
1489
+ };
1367
1490
 
1368
- 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:
1369
1503
  case "end":
1370
1504
  return _context.stop();
1371
1505
  }
@@ -1373,44 +1507,34 @@ var TestProvider = /*#__PURE__*/function () {
1373
1507
  }, _callee, this);
1374
1508
  }));
1375
1509
 
1376
- function create(_x) {
1377
- return _create.apply(this, arguments);
1510
+ function fromContracts(_x, _x2) {
1511
+ return _fromContracts.apply(this, arguments);
1378
1512
  }
1379
1513
 
1380
- return create;
1514
+ return fromContracts;
1381
1515
  }();
1382
1516
 
1383
- TestProvider.fromContract = /*#__PURE__*/function () {
1384
- var _fromContract = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref2) {
1385
- 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;
1386
1526
  return runtime_1.wrap(function _callee2$(_context2) {
1387
1527
  while (1) {
1388
1528
  switch (_context2.prev = _context2.next) {
1389
1529
  case 0:
1390
- contract = _ref2.contract, clarityBin = _ref2.clarityBin;
1391
- address = contract.address;
1530
+ _context2.next = 2;
1531
+ return this.ro(tx);
1392
1532
 
1393
- if (address) {
1394
- _context2.next = 4;
1395
- break;
1396
- }
1397
-
1398
- throw new Error('TestProvider must have an address');
1533
+ case 2:
1534
+ result = _context2.sent;
1535
+ return _context2.abrupt("return", result.value);
1399
1536
 
1400
1537
  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
1538
  case "end":
1415
1539
  return _context2.stop();
1416
1540
  }
@@ -1418,216 +1542,275 @@ var TestProvider = /*#__PURE__*/function () {
1418
1542
  }, _callee2, this);
1419
1543
  }));
1420
1544
 
1421
- function fromContract(_x2) {
1422
- return _fromContract.apply(this, arguments);
1545
+ function rov(_x3) {
1546
+ return _rov.apply(this, arguments);
1423
1547
  }
1424
1548
 
1425
- return fromContract;
1549
+ return rov;
1426
1550
  }();
1427
1551
 
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;
1552
+ _proto.roOk = /*#__PURE__*/function () {
1553
+ var _roOk = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(tx) {
1554
+ var result;
1431
1555
  return runtime_1.wrap(function _callee3$(_context3) {
1432
1556
  while (1) {
1433
1557
  switch (_context3.prev = _context3.next) {
1434
1558
  case 0:
1435
1559
  _context3.next = 2;
1436
- return getDefaultClarityBin(clarityBinOrAccounts);
1560
+ return this.ro(tx);
1437
1561
 
1438
1562
  case 2:
1439
- clarityBin = _context3.sent;
1440
- instances = {};
1441
- _context3.next = 6;
1442
- 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
+ }));
1443
1571
 
1444
- case 6:
1445
- _context3.t0 = runtime_1.keys(contracts);
1572
+ case 4:
1573
+ case "end":
1574
+ return _context3.stop();
1575
+ }
1576
+ }
1577
+ }, _callee3, this);
1578
+ }));
1446
1579
 
1447
- case 7:
1448
- if ((_context3.t1 = _context3.t0()).done) {
1449
- _context3.next = 16;
1450
- break;
1451
- }
1580
+ function roOk(_x4) {
1581
+ return _roOk.apply(this, arguments);
1582
+ }
1452
1583
 
1453
- k = _context3.t1.value;
1454
- contract = contracts[k];
1455
- _context3.next = 12;
1456
- return this.fromContract({
1457
- contract: contract,
1458
- clarityBin: clarityBin
1459
- });
1584
+ return roOk;
1585
+ }();
1460
1586
 
1461
- case 12:
1462
- instance = _context3.sent;
1463
- instances[k] = {
1464
- identifier: getContractIdentifier(contract),
1465
- contract: instance
1466
- };
1467
- _context3.next = 7;
1468
- 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);
1469
1596
 
1470
- case 16:
1471
- 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
+ }));
1472
1606
 
1473
- case 17:
1607
+ case 4:
1474
1608
  case "end":
1475
- return _context3.stop();
1609
+ return _context4.stop();
1476
1610
  }
1477
1611
  }
1478
- }, _callee3, this);
1612
+ }, _callee4, this);
1479
1613
  }));
1480
1614
 
1481
- function fromContracts(_x3, _x4) {
1482
- return _fromContracts.apply(this, arguments);
1615
+ function roErr(_x5) {
1616
+ return _roErr.apply(this, arguments);
1483
1617
  }
1484
1618
 
1485
- return fromContracts;
1619
+ return roErr;
1486
1620
  }();
1487
1621
 
1488
- 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);
1489
1630
 
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) {
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) {
1494
1652
  while (1) {
1495
- switch (_context4.prev = _context4.next) {
1653
+ switch (_context6.prev = _context6.next) {
1496
1654
  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
- });
1655
+ _context6.next = 2;
1656
+ return this.roErr(tx);
1657
+
1658
+ case 2:
1659
+ return _context6.abrupt("return", _context6.sent.value);
1505
1660
 
1506
1661
  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;
1662
+ case "end":
1663
+ return _context6.stop();
1664
+ }
1665
+ }
1666
+ }, _callee6, this);
1667
+ }));
1513
1668
 
1514
- case 9:
1515
- return _context4.abrupt("return", ok(value));
1669
+ function rovErr(_x7) {
1670
+ return _rovErr.apply(this, arguments);
1671
+ }
1516
1672
 
1517
- case 10:
1518
- return _context4.abrupt("return", err(value));
1673
+ return rovErr;
1674
+ }();
1519
1675
 
1520
- case 11:
1521
- 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
+ };
1522
1683
 
1523
- 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:
1524
1708
  case "end":
1525
- return _context4.stop();
1709
+ return _context7.stop();
1526
1710
  }
1527
1711
  }
1528
- }, _callee4, this);
1712
+ }, _callee7, this);
1529
1713
  }));
1530
1714
 
1531
- function callReadOnly(_x5, _x6) {
1532
- return _callReadOnly.apply(this, arguments);
1715
+ function txOk(_x8, _x9) {
1716
+ return _txOk.apply(this, arguments);
1533
1717
  }
1534
1718
 
1535
- return callReadOnly;
1719
+ return txOk;
1536
1720
  }();
1537
1721
 
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
- });
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);
1566
1731
 
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
- });
1732
+ case 2:
1733
+ result = _context8.sent;
1596
1734
 
1597
- case 7:
1598
- case "end":
1599
- return _context5.stop();
1600
- }
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();
1601
1748
  }
1602
- }, _callee5);
1603
- }));
1749
+ }
1750
+ }, _callee8, this);
1751
+ }));
1604
1752
 
1605
- return function submit(_x7) {
1606
- return _ref3.apply(this, arguments);
1607
- };
1608
- }();
1753
+ function txErr(_x10, _x11) {
1754
+ return _txErr.apply(this, arguments);
1755
+ }
1609
1756
 
1610
- return {
1611
- submit: submit
1612
- };
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
+ });
1613
1770
  };
1614
1771
 
1615
- _proto.formatArguments = function formatArguments(func, args) {
1616
- return args.map(function (arg, index) {
1617
- 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);
1618
1785
 
1619
- if (type === 'trait_reference') {
1620
- return "'" + arg;
1621
- }
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
+ }();
1622
1804
 
1623
- var argCV = parseToCV(arg, type);
1624
- var cvString = cvToString(argCV);
1625
- return cvString;
1805
+ _proto.mapGet = function mapGet$1(map) {
1806
+ return mapGet({
1807
+ map: map,
1808
+ bin: this.clarityBin
1626
1809
  });
1627
1810
  };
1628
1811
 
1629
1812
  return TestProvider;
1630
1813
  }();
1631
1814
 
1632
- export { TestProvider, createClarityBin, evalJson, executeJson, getBlockHeight, getStxBalance, mineBlocks, tx, txErr, txOk };
1815
+ export { TestProvider, createClarityBin, evalJson, executeJson, getBlockHeight, getStxBalance, makeRandomAddress, mineBlocks };
1633
1816
  //# sourceMappingURL=test.esm.js.map