@muritavo/testing-toolkit 0.6.3 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/client/emulator.d.ts +1 -1
  2. package/dist/native/blockchain.js +29 -60
  3. package/dist/native/blockchain.js.map +1 -1
  4. package/package.json +1 -1
  5. package/dist/shared/blockchain.d.ts +0 -19
  6. package/dist/shared/blockchain.js +0 -4
  7. package/dist/shared/blockchain.js.map +0 -1
  8. package/dist/src/client/blockchain.d.ts +0 -13
  9. package/dist/src/client/blockchain.js +0 -149
  10. package/dist/src/client/blockchain.js.map +0 -1
  11. package/dist/src/client/emulator.d.ts +0 -65
  12. package/dist/src/client/emulator.js +0 -250
  13. package/dist/src/client/emulator.js.map +0 -1
  14. package/dist/src/client/utility.d.ts +0 -7
  15. package/dist/src/client/utility.js +0 -39
  16. package/dist/src/client/utility.js.map +0 -1
  17. package/dist/src/native/blockchain.d.ts +0 -50
  18. package/dist/src/native/blockchain.js +0 -649
  19. package/dist/src/native/blockchain.js.map +0 -1
  20. package/dist/src/native/consts.d.ts +0 -5
  21. package/dist/src/native/consts.js +0 -9
  22. package/dist/src/native/consts.js.map +0 -1
  23. package/dist/src/native/emulator.d.ts +0 -49
  24. package/dist/src/native/emulator.js +0 -274
  25. package/dist/src/native/emulator.js.map +0 -1
  26. package/dist/src/types/contract.d.ts +0 -79
  27. package/dist/src/types/contract.js +0 -31
  28. package/dist/src/types/contract.js.map +0 -1
  29. package/dist/src/utility/index.d.ts +0 -1
  30. package/dist/src/utility/index.js +0 -12
  31. package/dist/src/utility/index.js.map +0 -1
  32. package/dist/test/hardhat-configs/hardhat-with-graphql/hardhat.config.d.ts +0 -42
  33. package/dist/test/hardhat-configs/hardhat-with-graphql/hardhat.config.js +0 -76
  34. package/dist/test/hardhat-configs/hardhat-with-graphql/hardhat.config.js.map +0 -1
@@ -1,649 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- var desc = Object.getOwnPropertyDescriptor(m, k);
16
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
- desc = { enumerable: true, get: function() { return m[k]; } };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }) : (function(o, m, k, k2) {
21
- if (k2 === undefined) k2 = k;
22
- o[k2] = m[k];
23
- }));
24
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
- Object.defineProperty(o, "default", { enumerable: true, value: v });
26
- }) : function(o, v) {
27
- o["default"] = v;
28
- });
29
- var __importStar = (this && this.__importStar) || function (mod) {
30
- if (mod && mod.__esModule) return mod;
31
- var result = {};
32
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
- __setModuleDefault(result, mod);
34
- return result;
35
- };
36
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
- return new (P || (P = Promise))(function (resolve, reject) {
39
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
- step((generator = generator.apply(thisArg, _arguments || [])).next());
43
- });
44
- };
45
- var __generator = (this && this.__generator) || function (thisArg, body) {
46
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
47
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
48
- function verb(n) { return function (v) { return step([n, v]); }; }
49
- function step(op) {
50
- if (f) throw new TypeError("Generator is already executing.");
51
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
52
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
53
- if (y = 0, t) op = [op[0] & 2, t.value];
54
- switch (op[0]) {
55
- case 0: case 1: t = op; break;
56
- case 4: _.label++; return { value: op[1], done: false };
57
- case 5: _.label++; y = op[1]; op = [0]; continue;
58
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
59
- default:
60
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
61
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
62
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
63
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
64
- if (t[2]) _.ops.pop();
65
- _.trys.pop(); continue;
66
- }
67
- op = body.call(thisArg, _);
68
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
69
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
70
- }
71
- };
72
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
73
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
74
- if (ar || !(i in from)) {
75
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
76
- ar[i] = from[i];
77
- }
78
- }
79
- return to.concat(ar || Array.prototype.slice.call(from));
80
- };
81
- var __importDefault = (this && this.__importDefault) || function (mod) {
82
- return (mod && mod.__esModule) ? mod : { "default": mod };
83
- };
84
- Object.defineProperty(exports, "__esModule", { value: true });
85
- exports.stopBlockchain = exports.deployGraph = exports.deployContract = exports.deriveWallet = exports.startBlockchain = exports.bindToBlockchain = exports.blockchainLogger = void 0;
86
- var debug_1 = __importDefault(require("debug"));
87
- var blockchain_1 = require("../client/blockchain");
88
- var child_process_1 = require("child_process");
89
- var utility_1 = require("../utility");
90
- var fs_1 = require("fs");
91
- var path_1 = require("path");
92
- var ethers_1 = require("ethers");
93
- exports.blockchainLogger = (0, debug_1.default)("@muritavo/testing-toolkit/blockchain");
94
- var instance;
95
- function bindToBlockchain(_a) {
96
- return __awaiter(this, arguments, void 0, function (_b) {
97
- var ethers, projectConfig, prevFork, blockNumberBeforeReset, blockNumberAfterReset, advanceBlockNumbersBy, _c, _d, _e, e_1, accounts;
98
- var projectFolder = _b.projectFolder, graphqlProject = _b.graphqlProject, hardhatConfigImportPromiseFactory = _b.hardhatConfigImportPromiseFactory, port = _b.port;
99
- return __generator(this, function (_f) {
100
- switch (_f.label) {
101
- case 0: return [4 /*yield*/, initHardhat(projectFolder)];
102
- case 1:
103
- ethers = (_f.sent()).ethers;
104
- return [4 /*yield*/, hardhatConfigImportPromiseFactory()];
105
- case 2:
106
- projectConfig = _f.sent();
107
- if (!instance) return [3 /*break*/, 11];
108
- prevFork = projectConfig.networks.hardhat.forking;
109
- (0, exports.blockchainLogger)(prevFork ? "Reseting blockchain fork" : "No previous fork, skipping reset");
110
- if (!prevFork) return [3 /*break*/, 10];
111
- _f.label = 3;
112
- case 3:
113
- _f.trys.push([3, 9, , 10]);
114
- return [4 /*yield*/, ethers.provider.getBlockNumber()];
115
- case 4:
116
- blockNumberBeforeReset = _f.sent();
117
- (0, exports.blockchainLogger)("Previous block number ".concat(blockNumberBeforeReset));
118
- /** This will clear any logs/changes made during testing */
119
- return [4 /*yield*/, ethers.provider.send("hardhat_reset", [
120
- {
121
- forking: {
122
- jsonRpcUrl: prevFork.url,
123
- blockNumber: prevFork.blockNumber,
124
- },
125
- },
126
- ])];
127
- case 5:
128
- /** This will clear any logs/changes made during testing */
129
- _f.sent();
130
- return [4 /*yield*/, ethers.provider.getBlockNumber()];
131
- case 6:
132
- blockNumberAfterReset = _f.sent();
133
- (0, exports.blockchainLogger)("Reset back to block number ".concat(blockNumberAfterReset));
134
- advanceBlockNumbersBy = blockNumberBeforeReset - blockNumberAfterReset;
135
- /**
136
- * When using graph-node, it refuses to reprocess previous blocks
137
- * So in a cenario where we republish a graph after this reset, it doesn't read the new logs
138
- *
139
- * That's why, after the reset, we "skip" blocks back to the latest block, and continue testing from there
140
- * */
141
- return [4 /*yield*/, ethers.provider.send("hardhat_mine", [
142
- "0x".concat(advanceBlockNumbersBy.toString(16)),
143
- ])];
144
- case 7:
145
- /**
146
- * When using graph-node, it refuses to reprocess previous blocks
147
- * So in a cenario where we republish a graph after this reset, it doesn't read the new logs
148
- *
149
- * That's why, after the reset, we "skip" blocks back to the latest block, and continue testing from there
150
- * */
151
- _f.sent();
152
- _c = exports.blockchainLogger;
153
- _e = (_d = "Reset hardhat state (#".concat(blockNumberBeforeReset, " to #").concat(blockNumberAfterReset, ") and now it's at block ")).concat;
154
- return [4 /*yield*/, ethers.provider.getBlockNumber()];
155
- case 8:
156
- _c.apply(void 0, [_e.apply(_d, [_f.sent()])]);
157
- return [3 /*break*/, 10];
158
- case 9:
159
- e_1 = _f.sent();
160
- (0, exports.blockchainLogger)("Error when trying to reset fork", e_1);
161
- return [3 /*break*/, 10];
162
- case 10: return [2 /*return*/, instance.addresses];
163
- case 11:
164
- if (projectFolder)
165
- (0, exports.blockchainLogger)("Starting blockchain server at \"".concat(projectFolder, "\""));
166
- if (graphqlProject) {
167
- (0, child_process_1.execSync)("docker compose up --detach", {
168
- cwd: graphqlProject,
169
- stdio: "ignore",
170
- });
171
- process.on("SIGINT", function () {
172
- (0, child_process_1.execSync)("docker compose down", {
173
- cwd: graphqlProject,
174
- stdio: "ignore",
175
- });
176
- });
177
- }
178
- accounts = new Array(30).fill(undefined).reduce(function (res, _, idx) {
179
- var _a;
180
- var account = deriveWallet(idx, {
181
- ethers: ethers,
182
- config: projectConfig,
183
- });
184
- return __assign(__assign({}, res), (_a = {}, _a[account.address] = {
185
- secretKey: account.key,
186
- }, _a));
187
- }, {});
188
- instance = {
189
- // process: serverInstance,
190
- rootFolder: projectFolder,
191
- contracts: {},
192
- addresses: accounts,
193
- port: port,
194
- graphqlProject: graphqlProject,
195
- // hardhatServer,
196
- };
197
- // setPort(port);
198
- return [2 /*return*/, accounts];
199
- }
200
- });
201
- });
202
- }
203
- exports.bindToBlockchain = bindToBlockchain;
204
- function startBlockchain(_a) {
205
- return __awaiter(this, arguments, void 0, function (_b) {
206
- var prevFork, blockNumberBeforeReset, blockNumberAfterReset, advanceBlockNumbersBy, _c, _d, _e, e_2, serverInstance, hardhatServer, accounts;
207
- var _this = this;
208
- var projectFolder = _b.projectRootFolder, _f = _b.port, port = _f === void 0 ? 8545 : _f, graphqlProject = _b.graphqlProject;
209
- return __generator(this, function (_g) {
210
- switch (_g.label) {
211
- case 0:
212
- if (!instance) return [3 /*break*/, 9];
213
- prevFork = instance.process.config.networks.hardhat.forking;
214
- (0, exports.blockchainLogger)(prevFork ? "Reseting blockchain fork" : "No previous fork, skipping reset");
215
- if (!prevFork) return [3 /*break*/, 8];
216
- _g.label = 1;
217
- case 1:
218
- _g.trys.push([1, 7, , 8]);
219
- return [4 /*yield*/, instance.process.ethers.provider.getBlockNumber()];
220
- case 2:
221
- blockNumberBeforeReset = _g.sent();
222
- (0, exports.blockchainLogger)("Previous block number ".concat(blockNumberBeforeReset));
223
- /** This will clear any logs/changes made during testing */
224
- return [4 /*yield*/, instance.process.network.provider.request({
225
- method: "hardhat_reset",
226
- params: [
227
- {
228
- forking: {
229
- jsonRpcUrl: prevFork.url,
230
- blockNumber: prevFork.blockNumber,
231
- },
232
- },
233
- ],
234
- })];
235
- case 3:
236
- /** This will clear any logs/changes made during testing */
237
- _g.sent();
238
- return [4 /*yield*/, instance.process.ethers.provider.getBlockNumber()];
239
- case 4:
240
- blockNumberAfterReset = _g.sent();
241
- (0, exports.blockchainLogger)("Reset back to block number ".concat(blockNumberAfterReset));
242
- advanceBlockNumbersBy = blockNumberBeforeReset - blockNumberAfterReset;
243
- /**
244
- * When using graph-node, it refuses to reprocess previous blocks
245
- * So in a cenario where we republish a graph after this reset, it doesn't read the new logs
246
- *
247
- * That's why, after the reset, we "skip" blocks back to the latest block, and continue testing from there
248
- * */
249
- return [4 /*yield*/, instance.process.network.provider.request({
250
- method: "hardhat_mine",
251
- params: ["0x".concat(advanceBlockNumbersBy.toString(16))],
252
- })];
253
- case 5:
254
- /**
255
- * When using graph-node, it refuses to reprocess previous blocks
256
- * So in a cenario where we republish a graph after this reset, it doesn't read the new logs
257
- *
258
- * That's why, after the reset, we "skip" blocks back to the latest block, and continue testing from there
259
- * */
260
- _g.sent();
261
- _c = exports.blockchainLogger;
262
- _e = (_d = "Reset hardhat state (#".concat(blockNumberBeforeReset, " to #").concat(blockNumberAfterReset, ") and now it's at block ")).concat;
263
- return [4 /*yield*/, instance.process.ethers.provider.getBlockNumber()];
264
- case 6:
265
- _c.apply(void 0, [_e.apply(_d, [_g.sent()])]);
266
- return [3 /*break*/, 8];
267
- case 7:
268
- e_2 = _g.sent();
269
- (0, exports.blockchainLogger)("Error when trying to reset fork", e_2);
270
- return [3 /*break*/, 8];
271
- case 8: return [2 /*return*/, instance.addresses];
272
- case 9:
273
- if (projectFolder)
274
- (0, exports.blockchainLogger)("Starting blockchain server at \"".concat(projectFolder, "\""));
275
- if (graphqlProject) {
276
- (0, child_process_1.execSync)("docker compose up --detach", {
277
- cwd: graphqlProject,
278
- stdio: "ignore",
279
- });
280
- process.on("SIGINT", function () {
281
- (0, child_process_1.execSync)("docker compose down", {
282
- cwd: graphqlProject,
283
- stdio: "ignore",
284
- });
285
- });
286
- }
287
- return [4 /*yield*/, initHardhat(projectFolder)];
288
- case 10:
289
- serverInstance = _g.sent();
290
- return [4 /*yield*/, new Promise(function (r, rej) {
291
- var timeoutId = setTimeout(function () {
292
- rej(new Error("Something went wrong while starting hardhat node"));
293
- }, 30000);
294
- serverInstance.tasks[serverInstance.taskNames.TASK_NODE_SERVER_READY].setAction(function (args) { return __awaiter(_this, void 0, void 0, function () {
295
- return __generator(this, function (_a) {
296
- hardhatServer = args.server;
297
- clearTimeout(timeoutId);
298
- r();
299
- return [2 /*return*/];
300
- });
301
- }); });
302
- serverInstance.run("node", {
303
- port: port,
304
- noDeploy: true,
305
- });
306
- })];
307
- case 11:
308
- _g.sent();
309
- accounts = new Array(serverInstance.config.networks.hardhat.accounts.count)
310
- .fill(undefined)
311
- .reduce(function (res, _, idx) {
312
- var _a;
313
- var account = deriveWallet(idx, serverInstance);
314
- return __assign(__assign({}, res), (_a = {}, _a[account.address] = {
315
- secretKey: account.key,
316
- }, _a));
317
- }, {});
318
- instance = {
319
- process: serverInstance,
320
- rootFolder: projectFolder,
321
- contracts: {},
322
- addresses: accounts,
323
- port: port,
324
- graphqlProject: graphqlProject,
325
- hardhatServer: hardhatServer,
326
- };
327
- (0, blockchain_1.setPort)(port);
328
- return [2 /*return*/, accounts];
329
- }
330
- });
331
- });
332
- }
333
- exports.startBlockchain = startBlockchain;
334
- function deriveWallet(index, hardhat) {
335
- var _a;
336
- if (index === void 0) { index = 0; }
337
- var ethers = hardhat.ethers;
338
- var accounts = hardhat.config.networks.hardhat.accounts;
339
- var accountPath = (_a = accounts.path) !== null && _a !== void 0 ? _a : "m/44'/60'/0'/0";
340
- var wallet = ethers.HDNodeWallet.fromMnemonic(ethers.Mnemonic.fromPhrase(accounts.mnemonic), accountPath + "/".concat(index));
341
- return {
342
- key: wallet.privateKey,
343
- address: wallet.address,
344
- };
345
- }
346
- exports.deriveWallet = deriveWallet;
347
- function initHardhat(dir) {
348
- return __awaiter(this, void 0, void 0, function () {
349
- var startingDir, hardhat, _a, ret, e_3;
350
- var _this = this;
351
- return __generator(this, function (_b) {
352
- switch (_b.label) {
353
- case 0:
354
- startingDir = process.cwd();
355
- process.chdir(dir);
356
- _b.label = 1;
357
- case 1:
358
- _b.trys.push([1, 4, , 5]);
359
- return [4 /*yield*/, (function () { return __awaiter(_this, void 0, void 0, function () {
360
- return __generator(this, function (_a) {
361
- switch (_a.label) {
362
- case 0:
363
- if (!require) return [3 /*break*/, 1];
364
- require("hardhat/register");
365
- return [3 /*break*/, 3];
366
- case 1: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require("hardhat/register")); })];
367
- case 2:
368
- (_a.sent()).default;
369
- _a.label = 3;
370
- case 3:
371
- if (!require) return [3 /*break*/, 4];
372
- return [2 /*return*/, require("hardhat")];
373
- case 4: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require("hardhat")); })];
374
- case 5: return [2 /*return*/, (_a.sent()).default];
375
- }
376
- });
377
- }); })()];
378
- case 2:
379
- hardhat = (_b.sent());
380
- _a = hardhat;
381
- return [4 /*yield*/, (function () { return __awaiter(_this, void 0, void 0, function () {
382
- return __generator(this, function (_a) {
383
- switch (_a.label) {
384
- case 0:
385
- if (!require) return [3 /*break*/, 1];
386
- return [2 /*return*/, require("hardhat/builtin-tasks/task-names")];
387
- case 1: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require("hardhat/builtin-tasks/task-names")); })];
388
- case 2: return [2 /*return*/, _a.sent()];
389
- }
390
- });
391
- }); })()];
392
- case 3:
393
- _a.taskNames = (_b.sent());
394
- process.chdir(startingDir);
395
- ret = hardhat;
396
- ret.ethers.provider = new ret.ethers.JsonRpcProvider("http://".concat("127.0.0.1", ":").concat(8545));
397
- return [2 /*return*/, ret];
398
- case 4:
399
- e_3 = _b.sent();
400
- process.chdir(startingDir);
401
- throw e_3;
402
- case 5: return [2 /*return*/];
403
- }
404
- });
405
- });
406
- }
407
- function deployContract(_a) {
408
- return __awaiter(this, arguments, void 0, function (_b) {
409
- var getContract, ethers, owner, Factory, lock_1, connection, initializationKey_1, e_4;
410
- var _c, _d;
411
- var _this = this;
412
- var contractAbi = _b.contractAbi, contractName = _b.contractName, args = _b.args;
413
- return __generator(this, function (_e) {
414
- switch (_e.label) {
415
- case 0:
416
- (0, exports.blockchainLogger)("Deploying contract ".concat(contractName, " with ").concat(args.length, " parameters ").concat(args
417
- .map(function (a) { return "".concat(a, " (").concat(Array.isArray(a) ? "array" : typeof a, ")"); })
418
- .join(", ")));
419
- _e.label = 1;
420
- case 1:
421
- _e.trys.push([1, 17, , 18]);
422
- if (!(instance === null || instance === void 0 ? void 0 : instance.rootFolder))
423
- throw new Error("You are trying to deploy a contract without defining the Blockchain Project folder. Please define it at startBlockchain command.");
424
- getContract = function () { return __awaiter(_this, void 0, void 0, function () {
425
- var Web3, web3, _a, _b, _c;
426
- return __generator(this, function (_d) {
427
- switch (_d.label) {
428
- case 0: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require("web3")); })];
429
- case 1:
430
- Web3 = (_d.sent()).default;
431
- web3 = new Web3(new Web3.providers.HttpProvider("http://".concat("127.0.0.1", ":").concat(instance.port)));
432
- _b = (_a = web3.eth.Contract).bind;
433
- _c = [void 0, contractAbi];
434
- return [4 /*yield*/, lock_1.getAddress()];
435
- case 2: return [2 /*return*/, new (_b.apply(_a, _c.concat([_d.sent()])))()];
436
- }
437
- });
438
- }); };
439
- return [4 /*yield*/, initHardhat(instance.rootFolder)];
440
- case 2:
441
- ethers = (_e.sent()).ethers;
442
- return [4 /*yield*/, ethers.getSigners()];
443
- case 3:
444
- owner = (_e.sent())[0];
445
- return [4 /*yield*/, ethers.getContractFactory(contractName)];
446
- case 4:
447
- Factory = _e.sent();
448
- return [4 /*yield*/, Factory.deploy()];
449
- case 5:
450
- lock_1 = _e.sent();
451
- return [4 /*yield*/, lock_1.waitForDeployment()];
452
- case 6:
453
- _e.sent();
454
- if (!(args.length > 0)) return [3 /*break*/, 12];
455
- (0, exports.blockchainLogger)("Initializing contract with owner ".concat(owner, " and args ").concat(args));
456
- connection = lock_1.connect(owner);
457
- initializationKey_1 = "initialize";
458
- connection.interface.forEachFunction(function (func) {
459
- var funcName = func.name;
460
- if (funcName.split(",", args.length) &&
461
- funcName.startsWith("initialize("))
462
- initializationKey_1 = funcName;
463
- });
464
- if (!connection[initializationKey_1]) return [3 /*break*/, 8];
465
- /**
466
- * The way to decide which overloaded function to call is to pass overrides at the end 🤡
467
- * https://github.com/ethers-io/ethers.js/issues/4383
468
- */
469
- return [4 /*yield*/, connection[initializationKey_1].apply(connection, __spreadArray(__spreadArray([], args, false), [ethers_1.Typed.overrides({})], false))];
470
- case 7:
471
- /**
472
- * The way to decide which overloaded function to call is to pass overrides at the end 🤡
473
- * https://github.com/ethers-io/ethers.js/issues/4383
474
- */
475
- _e.sent();
476
- _e.label = 8;
477
- case 8:
478
- _c = {};
479
- return [4 /*yield*/, lock_1.getAddress()];
480
- case 9:
481
- _c.address = _e.sent();
482
- return [4 /*yield*/, owner.getAddress()];
483
- case 10:
484
- _c.owner = _e.sent();
485
- return [4 /*yield*/, getContract()];
486
- case 11: return [2 /*return*/, (_c.contract = _e.sent(),
487
- _c)];
488
- case 12:
489
- _d = {};
490
- return [4 /*yield*/, lock_1.getAddress()];
491
- case 13:
492
- _d.address = _e.sent();
493
- return [4 /*yield*/, owner.getAddress()];
494
- case 14:
495
- _d.owner = _e.sent();
496
- return [4 /*yield*/, getContract()];
497
- case 15: return [2 /*return*/, (_d.contract = _e.sent(),
498
- _d)];
499
- case 16: return [3 /*break*/, 18];
500
- case 17:
501
- e_4 = _e.sent();
502
- (0, exports.blockchainLogger)("Something has gone wrong", e_4);
503
- throw e_4;
504
- case 18: return [2 /*return*/];
505
- }
506
- });
507
- });
508
- }
509
- exports.deployContract = deployContract;
510
- /**
511
- * Takes a graph and deploys it into the graph-node
512
- */
513
- function deployGraph(graphPath, contractAddresses, graphName, networkName) {
514
- return __awaiter(this, void 0, void 0, function () {
515
- function generateGraphManifest() {
516
- var subgraphYml = parse((0, fs_1.readFileSync)((0, path_1.resolve)(graphPath, "subgraph.yaml")).toString());
517
- function relativeToAbsolutePath(relativePath) {
518
- return (0, path_1.resolve)(graphPath, relativePath);
519
- }
520
- subgraphYml.schema.file = relativeToAbsolutePath(subgraphYml.schema.file);
521
- for (var _i = 0, _a = subgraphYml.dataSources; _i < _a.length; _i++) {
522
- var dataSource = _a[_i];
523
- /** If we don't have the address for said source, we remove the source from the deployed graph */
524
- if (!contractAddresses[dataSource.source.abi]) {
525
- (0, exports.blockchainLogger)("Address for the contract \"".concat(dataSource.source.abi, "\" wasn't provided. Removing this data source from graph."));
526
- subgraphYml.dataSources[subgraphYml.dataSources.indexOf(dataSource)] =
527
- undefined;
528
- continue;
529
- }
530
- dataSource.network = networkName;
531
- dataSource.source.address = contractAddresses[dataSource.source.abi];
532
- if (instance.process.config.networks.hardhat.forking)
533
- dataSource.source.startBlock = currentBlock;
534
- dataSource.mapping.file = relativeToAbsolutePath(dataSource.mapping.file);
535
- for (var _b = 0, _c = dataSource.mapping.abis; _b < _c.length; _b++) {
536
- var abi = _c[_b];
537
- abi.file = relativeToAbsolutePath(abi.file);
538
- }
539
- }
540
- subgraphYml.dataSources = subgraphYml.dataSources.filter(Boolean);
541
- var graphManifestPath = (0, path_1.resolve)(graphManifestCacheDir, "subgraph.yaml");
542
- if (!(0, fs_1.existsSync)(graphManifestCacheDir))
543
- (0, fs_1.mkdirSync)(graphManifestCacheDir, { recursive: true });
544
- (0, fs_1.writeFileSync)(graphManifestPath, stringify(subgraphYml));
545
- return graphManifestPath;
546
- }
547
- var _a, parse, stringify, cacheDir, graphManifestCacheDir, currentBlock, stdioMode, error_1, localhostGraphManifest;
548
- return __generator(this, function (_b) {
549
- switch (_b.label) {
550
- case 0: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require("yaml")); })];
551
- case 1:
552
- _a = _b.sent(), parse = _a.parse, stringify = _a.stringify;
553
- return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require("find-cache-dir")); })];
554
- case 2:
555
- cacheDir = (_b.sent()).default;
556
- graphManifestCacheDir = cacheDir({
557
- name: "graph-manifest",
558
- cwd: graphPath,
559
- });
560
- return [4 /*yield*/, instance.process.ethers.provider.getBlockNumber()];
561
- case 3:
562
- currentBlock = _b.sent();
563
- stdioMode = exports.blockchainLogger.enabled ? "inherit" : "ignore";
564
- _b.label = 4;
565
- case 4:
566
- if (!true) return [3 /*break*/, 9];
567
- _b.label = 5;
568
- case 5:
569
- _b.trys.push([5, 6, , 8]);
570
- (0, exports.blockchainLogger)("Trying to create graph");
571
- (0, child_process_1.execSync)("graph create --node http://localhost:8020/ ".concat(graphName), {
572
- cwd: graphPath,
573
- stdio: stdioMode,
574
- env: {
575
- PATH: process.env.PATH,
576
- },
577
- });
578
- return [3 /*break*/, 9];
579
- case 6:
580
- error_1 = _b.sent();
581
- return [4 /*yield*/, (0, utility_1.wait)(1000)];
582
- case 7:
583
- _b.sent();
584
- return [3 /*break*/, 8];
585
- case 8: return [3 /*break*/, 4];
586
- case 9:
587
- localhostGraphManifest = generateGraphManifest();
588
- (0, exports.blockchainLogger)("Trying to deploy graph");
589
- return [4 /*yield*/, new Promise(function (res, rej) {
590
- (0, child_process_1.exec)("graph deploy --node http://localhost:8020/ --ipfs http://localhost:5031 ".concat(graphName, " ").concat(localhostGraphManifest, " -l v0.0.1"), {
591
- cwd: graphPath,
592
- env: {
593
- PATH: "".concat(process.env.PATH),
594
- },
595
- }, function (error, stdOut) {
596
- console.log(stdOut);
597
- if (error) {
598
- rej(error);
599
- }
600
- res();
601
- });
602
- })];
603
- case 10:
604
- _b.sent();
605
- return [4 /*yield*/, (0, utility_1.wait)(1000)];
606
- case 11:
607
- _b.sent();
608
- return [2 /*return*/];
609
- }
610
- });
611
- });
612
- }
613
- exports.deployGraph = deployGraph;
614
- function stopBlockchain() {
615
- return __awaiter(this, void 0, void 0, function () {
616
- var e_5;
617
- return __generator(this, function (_a) {
618
- switch (_a.label) {
619
- case 0:
620
- (0, exports.blockchainLogger)("Closing blockchain infrastructure.", "Has blockchain instance:", String(!!instance));
621
- if (!instance) return [3 /*break*/, 5];
622
- _a.label = 1;
623
- case 1:
624
- _a.trys.push([1, 3, , 4]);
625
- (0, exports.blockchainLogger)("Closing hardhat server");
626
- if (instance.graphqlProject) {
627
- (0, exports.blockchainLogger)("Ending graphql docker container");
628
- (0, child_process_1.execSync)("docker compose down", {
629
- cwd: instance.graphqlProject,
630
- stdio: "ignore",
631
- });
632
- }
633
- return [4 /*yield*/, instance.hardhatServer.close()];
634
- case 2:
635
- _a.sent();
636
- return [3 /*break*/, 4];
637
- case 3:
638
- e_5 = _a.sent();
639
- return [3 /*break*/, 4];
640
- case 4:
641
- instance = null;
642
- _a.label = 5;
643
- case 5: return [2 /*return*/];
644
- }
645
- });
646
- });
647
- }
648
- exports.stopBlockchain = stopBlockchain;
649
- //# sourceMappingURL=blockchain.js.map