@marinade.finance/bankrun-utils 2.4.10 → 2.4.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/bankrun.js +22 -120
- package/src/bankrun.js.map +1 -1
- package/src/extendedProvider.js +37 -164
- package/src/extendedProvider.js.map +1 -1
- package/src/testInit.js +95 -158
- package/src/testInit.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marinade.finance/bankrun-utils",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.11",
|
|
4
4
|
"description": "Bankrun library utilities",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
],
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@solana/web3.js": "^1.98.0",
|
|
26
|
-
"@marinade.finance/web3js-common": "2.4.
|
|
26
|
+
"@marinade.finance/web3js-common": "2.4.11",
|
|
27
27
|
"solana-bankrun": "^0.2.0",
|
|
28
28
|
"anchor-bankrun": "^0.2.0",
|
|
29
29
|
"class-transformer": "^0.5.1"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"@solana/web3.js": "^1.98.0",
|
|
33
|
-
"@marinade.finance/web3js-common": "2.4.
|
|
33
|
+
"@marinade.finance/web3js-common": "2.4.11",
|
|
34
34
|
"solana-bankrun": "^0.2.0",
|
|
35
35
|
"anchor-bankrun": "^0.2.0",
|
|
36
36
|
"class-transformer": "^0.5.1"
|
package/src/bankrun.js
CHANGED
|
@@ -1,67 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
exports.__esModule = true;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.warpToNextSlot = exports.warpOffsetSlot = exports.currentSlot = exports.warpToNextEpoch = exports.warpOffsetEpoch = exports.currentEpoch = exports.warpToEpoch = exports.MINIMUM_SLOTS_PER_EPOCH = exports.assertNotExist = void 0;
|
|
40
|
-
function assertNotExist(provider, account) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return __generator(this, function (_a) {
|
|
44
|
-
switch (_a.label) {
|
|
45
|
-
case 0: return [4 /*yield*/, provider.context.banksClient.getAccount(account)];
|
|
46
|
-
case 1:
|
|
47
|
-
accountInfo = _a.sent();
|
|
48
|
-
expect(accountInfo).toBeNull();
|
|
49
|
-
return [2 /*return*/];
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
});
|
|
4
|
+
async function assertNotExist(provider, account) {
|
|
5
|
+
const accountInfo = await provider.context.banksClient.getAccount(account);
|
|
6
|
+
expect(accountInfo).toBeNull();
|
|
53
7
|
}
|
|
54
8
|
exports.assertNotExist = assertNotExist;
|
|
55
9
|
// https://github.com/solana-labs/solana/blob/v1.17.7/sdk/program/src/epoch_schedule.rs#L29C1-L29C45
|
|
56
10
|
exports.MINIMUM_SLOTS_PER_EPOCH = BigInt(32);
|
|
57
11
|
// https://github.com/solana-labs/solana/blob/v1.17.7/sdk/program/src/epoch_schedule.rs#L167
|
|
58
12
|
function warpToEpoch(provider, epoch) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
13
|
+
const epochBigInt = BigInt(epoch);
|
|
14
|
+
const { slotsPerEpoch, firstNormalEpoch, firstNormalSlot } = provider.context.genesisConfig.epochSchedule;
|
|
15
|
+
let warpToSlot;
|
|
62
16
|
if (epochBigInt <= firstNormalEpoch) {
|
|
63
17
|
warpToSlot =
|
|
64
|
-
(
|
|
18
|
+
(BigInt(2) ** epochBigInt - BigInt(1)) * exports.MINIMUM_SLOTS_PER_EPOCH;
|
|
65
19
|
}
|
|
66
20
|
else {
|
|
67
21
|
warpToSlot =
|
|
@@ -70,82 +24,30 @@ function warpToEpoch(provider, epoch) {
|
|
|
70
24
|
provider.context.warpToSlot(warpToSlot);
|
|
71
25
|
}
|
|
72
26
|
exports.warpToEpoch = warpToEpoch;
|
|
73
|
-
function currentEpoch(provider) {
|
|
74
|
-
return
|
|
75
|
-
return __generator(this, function (_a) {
|
|
76
|
-
switch (_a.label) {
|
|
77
|
-
case 0: return [4 /*yield*/, provider.context.banksClient.getClock()];
|
|
78
|
-
case 1: return [2 /*return*/, (_a.sent()).epoch];
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
});
|
|
27
|
+
async function currentEpoch(provider) {
|
|
28
|
+
return (await provider.context.banksClient.getClock()).epoch;
|
|
82
29
|
}
|
|
83
30
|
exports.currentEpoch = currentEpoch;
|
|
84
|
-
function warpOffsetEpoch(provider, plusEpochs) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return __generator(this, function (_a) {
|
|
88
|
-
switch (_a.label) {
|
|
89
|
-
case 0: return [4 /*yield*/, currentEpoch(provider)];
|
|
90
|
-
case 1:
|
|
91
|
-
nextEpoch = (_a.sent()) + BigInt(plusEpochs);
|
|
92
|
-
warpToEpoch(provider, nextEpoch);
|
|
93
|
-
return [2 /*return*/];
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
});
|
|
31
|
+
async function warpOffsetEpoch(provider, plusEpochs) {
|
|
32
|
+
const nextEpoch = (await currentEpoch(provider)) + BigInt(plusEpochs);
|
|
33
|
+
warpToEpoch(provider, nextEpoch);
|
|
97
34
|
}
|
|
98
35
|
exports.warpOffsetEpoch = warpOffsetEpoch;
|
|
99
|
-
function warpToNextEpoch(provider) {
|
|
100
|
-
|
|
101
|
-
return __generator(this, function (_a) {
|
|
102
|
-
switch (_a.label) {
|
|
103
|
-
case 0: return [4 /*yield*/, warpOffsetEpoch(provider, 1)];
|
|
104
|
-
case 1:
|
|
105
|
-
_a.sent();
|
|
106
|
-
return [2 /*return*/];
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
});
|
|
36
|
+
async function warpToNextEpoch(provider) {
|
|
37
|
+
await warpOffsetEpoch(provider, 1);
|
|
110
38
|
}
|
|
111
39
|
exports.warpToNextEpoch = warpToNextEpoch;
|
|
112
|
-
function currentSlot(provider) {
|
|
113
|
-
return
|
|
114
|
-
return __generator(this, function (_a) {
|
|
115
|
-
switch (_a.label) {
|
|
116
|
-
case 0: return [4 /*yield*/, provider.context.banksClient.getClock()];
|
|
117
|
-
case 1: return [2 /*return*/, (_a.sent()).slot];
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
});
|
|
40
|
+
async function currentSlot(provider) {
|
|
41
|
+
return (await provider.context.banksClient.getClock()).slot;
|
|
121
42
|
}
|
|
122
43
|
exports.currentSlot = currentSlot;
|
|
123
|
-
function warpOffsetSlot(provider, plusSlots) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return __generator(this, function (_a) {
|
|
127
|
-
switch (_a.label) {
|
|
128
|
-
case 0: return [4 /*yield*/, currentSlot(provider)];
|
|
129
|
-
case 1:
|
|
130
|
-
nextSlot = (_a.sent()) + BigInt(plusSlots);
|
|
131
|
-
provider.context.warpToSlot(nextSlot);
|
|
132
|
-
return [2 /*return*/];
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
});
|
|
44
|
+
async function warpOffsetSlot(provider, plusSlots) {
|
|
45
|
+
const nextSlot = (await currentSlot(provider)) + BigInt(plusSlots);
|
|
46
|
+
provider.context.warpToSlot(nextSlot);
|
|
136
47
|
}
|
|
137
48
|
exports.warpOffsetSlot = warpOffsetSlot;
|
|
138
|
-
function warpToNextSlot(provider) {
|
|
139
|
-
|
|
140
|
-
return __generator(this, function (_a) {
|
|
141
|
-
switch (_a.label) {
|
|
142
|
-
case 0: return [4 /*yield*/, warpOffsetSlot(provider, 1)];
|
|
143
|
-
case 1:
|
|
144
|
-
_a.sent();
|
|
145
|
-
return [2 /*return*/];
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
});
|
|
49
|
+
async function warpToNextSlot(provider) {
|
|
50
|
+
await warpOffsetSlot(provider, 1);
|
|
149
51
|
}
|
|
150
52
|
exports.warpToNextSlot = warpToNextSlot;
|
|
151
53
|
//# sourceMappingURL=bankrun.js.map
|
package/src/bankrun.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bankrun.js","sourceRoot":"","sources":["../../../../../packages/lib/bankrun-utils/src/bankrun.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bankrun.js","sourceRoot":"","sources":["../../../../../packages/lib/bankrun-utils/src/bankrun.ts"],"names":[],"mappings":";;;AAGO,KAAK,UAAU,cAAc,CAClC,QAAyB,EACzB,OAAkB;IAElB,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;IAC1E,MAAM,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,CAAA;AAChC,CAAC;AAND,wCAMC;AAED,oGAAoG;AACvF,QAAA,uBAAuB,GAAG,MAAM,CAAC,EAAE,CAAC,CAAA;AACjD,4FAA4F;AAC5F,SAAgB,WAAW,CAAC,QAAyB,EAAE,KAAsB;IAC3E,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;IACjC,MAAM,EAAE,aAAa,EAAE,gBAAgB,EAAE,eAAe,EAAE,GACxD,QAAQ,CAAC,OAAO,CAAC,aAAa,CAAC,aAAa,CAAA;IAC9C,IAAI,UAAkB,CAAA;IACtB,IAAI,WAAW,IAAI,gB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CAAC;AAND,wCAMC;AAEM,KAAK,UAAU,cAAc,CAAC,QAAyB;IAC5D,MAAM,cAAc,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAA;AACnC,CAAC;AAFD,wCAEC"}
|
package/src/extendedProvider.js
CHANGED
|
@@ -1,176 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (_) try {
|
|
33
|
-
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;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
54
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
55
|
-
if (ar || !(i in from)) {
|
|
56
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
57
|
-
ar[i] = from[i];
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
61
|
-
};
|
|
62
|
-
exports.__esModule = true;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
63
3
|
exports.bankrunExecute = exports.bankrunExecuteIx = exports.bankrunTransaction = exports.BankrunExtendedProvider = void 0;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
4
|
+
const web3js_common_1 = require("@marinade.finance/web3js-common");
|
|
5
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
+
const anchor_bankrun_1 = require("anchor-bankrun");
|
|
7
|
+
class BankrunExtendedProvider extends anchor_bankrun_1.BankrunProvider {
|
|
8
|
+
async sendIx(signers, ...ixes) {
|
|
9
|
+
const tx = await bankrunTransaction(this);
|
|
10
|
+
tx.add(...ixes);
|
|
11
|
+
await bankrunExecute(this, [this.wallet, ...signers], tx);
|
|
71
12
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
-
var tx;
|
|
79
|
-
return __generator(this, function (_a) {
|
|
80
|
-
switch (_a.label) {
|
|
81
|
-
case 0: return [4 /*yield*/, bankrunTransaction(this)];
|
|
82
|
-
case 1:
|
|
83
|
-
tx = _a.sent();
|
|
84
|
-
tx.add.apply(tx, ixes);
|
|
85
|
-
return [4 /*yield*/, bankrunExecute(this, __spreadArray([this.wallet], signers, true), tx)];
|
|
86
|
-
case 2:
|
|
87
|
-
_a.sent();
|
|
88
|
-
return [2 /*return*/];
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
Object.defineProperty(BankrunExtendedProvider.prototype, "walletPubkey", {
|
|
94
|
-
get: function () {
|
|
95
|
-
return this.wallet.publicKey;
|
|
96
|
-
},
|
|
97
|
-
enumerable: false,
|
|
98
|
-
configurable: true
|
|
99
|
-
});
|
|
100
|
-
return BankrunExtendedProvider;
|
|
101
|
-
}(anchor_bankrun_1.BankrunProvider));
|
|
13
|
+
get walletPubkey() {
|
|
14
|
+
return this.wallet.publicKey;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
102
17
|
exports.BankrunExtendedProvider = BankrunExtendedProvider;
|
|
103
|
-
function bankrunTransaction(provider) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
bh = _a.sent();
|
|
111
|
-
lastValidBlockHeight = (bh === null ? Number.MAX_VALUE : bh[1]);
|
|
112
|
-
return [2 /*return*/, new web3_js_1.Transaction({
|
|
113
|
-
feePayer: provider.wallet.publicKey,
|
|
114
|
-
blockhash: provider.context.lastBlockhash,
|
|
115
|
-
lastValidBlockHeight: lastValidBlockHeight
|
|
116
|
-
})];
|
|
117
|
-
}
|
|
118
|
-
});
|
|
18
|
+
async function bankrunTransaction(provider) {
|
|
19
|
+
const bh = await provider.context.banksClient.getLatestBlockhash();
|
|
20
|
+
const lastValidBlockHeight = (bh === null ? Number.MAX_VALUE : bh[1]);
|
|
21
|
+
return new web3_js_1.Transaction({
|
|
22
|
+
feePayer: provider.wallet.publicKey,
|
|
23
|
+
blockhash: provider.context.lastBlockhash,
|
|
24
|
+
lastValidBlockHeight,
|
|
119
25
|
});
|
|
120
26
|
}
|
|
121
27
|
exports.bankrunTransaction = bankrunTransaction;
|
|
122
|
-
function bankrunExecuteIx(provider, signers) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
128
|
-
var tx;
|
|
129
|
-
return __generator(this, function (_a) {
|
|
130
|
-
switch (_a.label) {
|
|
131
|
-
case 0: return [4 /*yield*/, bankrunTransaction(provider)];
|
|
132
|
-
case 1:
|
|
133
|
-
tx = _a.sent();
|
|
134
|
-
tx.add.apply(tx, ixes);
|
|
135
|
-
return [4 /*yield*/, bankrunExecute(provider, signers, tx)];
|
|
136
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
});
|
|
28
|
+
async function bankrunExecuteIx(provider, signers, ...ixes) {
|
|
29
|
+
const tx = await bankrunTransaction(provider);
|
|
30
|
+
tx.add(...ixes);
|
|
31
|
+
return await bankrunExecute(provider, signers, tx);
|
|
140
32
|
}
|
|
141
33
|
exports.bankrunExecuteIx = bankrunExecuteIx;
|
|
142
|
-
function bankrunExecute(provider, signers, tx) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
case 2:
|
|
156
|
-
_a.sent();
|
|
157
|
-
return [3 /*break*/, 4];
|
|
158
|
-
case 3:
|
|
159
|
-
if (signer instanceof web3_js_1.Keypair || 'secretKey' in signer) {
|
|
160
|
-
tx.partialSign(signer);
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
throw new Error('bankrunExecute: provided signer parameter is not a signer: ' + signer);
|
|
164
|
-
}
|
|
165
|
-
_a.label = 4;
|
|
166
|
-
case 4:
|
|
167
|
-
_i++;
|
|
168
|
-
return [3 /*break*/, 1];
|
|
169
|
-
case 5: return [4 /*yield*/, provider.context.banksClient.processTransaction(tx)];
|
|
170
|
-
case 6: return [2 /*return*/, _a.sent()];
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
});
|
|
34
|
+
async function bankrunExecute(provider, signers, tx) {
|
|
35
|
+
for (const signer of signers) {
|
|
36
|
+
if ((0, web3js_common_1.instanceOfWallet)(signer)) {
|
|
37
|
+
await signer.signTransaction(tx);
|
|
38
|
+
}
|
|
39
|
+
else if (signer instanceof web3_js_1.Keypair || 'secretKey' in signer) {
|
|
40
|
+
tx.partialSign(signer);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw new Error('bankrunExecute: provided signer parameter is not a signer: ' + signer);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return await provider.context.banksClient.processTransaction(tx);
|
|
174
47
|
}
|
|
175
48
|
exports.bankrunExecute = bankrunExecute;
|
|
176
49
|
//# sourceMappingURL=extendedProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extendedProvider.js","sourceRoot":"","sources":["../../../../../packages/lib/bankrun-utils/src/extendedProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extendedProvider.js","sourceRoot":"","sources":["../../../../../packages/lib/bankrun-utils/src/extendedProvider.ts"],"names":[],"mappings":";;;AAAA,mEAIwC;AACxC,6CAOwB;AACxB,mDAAgD;AAGhD,MAAa,uBACX,SAAQ,gCAAe;IAGvB,KAAK,CAAC,MAAM,CACV,OAAsC,EACtC,GAAG,IAIA;QAEH,MAAM,EAAE,GAAG,MAAM,kBAAkB,CAAC,IAAI,CAAC,CAAA;QACzC,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAA;QACf,MAAM,cAAc,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,EAAE,EAAE,CAAC,CAAA;IAC3D,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAA;IAC9B,CAAC;CACF;AApBD,0DAoBC;AAEM,KAAK,UAAU,kBAAkB,CACtC,QAAyB;IAEzB,MAAM,EAAE,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,kBAAkB,EAAE,CAAA;IAClE,MAAM,oBAAoB,GAAG,CAC3B,EAAE,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAC7B,CAAA;IACX,OAAO,IAAI,qBAAW,CAAC;QACrB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS;QACnC,SAAS,EAAE,QAAQ,CAAC,OAAO,CAAC,aAAa;QACzC,oBAAoB;KACrB,CAAC,CAAA;AACJ,CAAC;AAZD,gDAYC;AAEM,KAAK,UAAU,gBAAgB,CACpC,QAAyB,EACzB,OAAsC,EACtC,GAAG,IAIA;IAEH,MAAM,EAAE,GAAG,MAAM,kBAAkB,CAAC,QAAQ,CAAC,CAAA;IAC7C,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAA;IACf,OAAO,MAAM,cAAc,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAC,CAAA;AACpD,CAAC;AAZD,4CAYC;AAEM,KAAK,UAAU,cAAc,CAClC,QAAyB,EACzB,OAAsC,EACtC,EAAe;IAEf,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,IAAA,gCAAgB,EAAC,MAAM,CAAC,EAAE,CAAC;YAC7B,MAAM,MAAM,CAAC,eAAe,CAAC,EAAE,CAAC,CAAA;QAClC,CAAC;aAAM,IAAI,MAAM,YAAY,iBAAO,IAAI,WAAW,IAAI,MAAM,EAAE,CAAC;YAC9D,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;QACxB,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CACb,6DAA6D,GAAG,MAAM,CACvE,CAAA;QACH,CAAC;IACH,CAAC;IACD,OAAO,MAAM,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAA;AAClE,CAAC;AAjBD,wCAiBC"}
|
package/src/testInit.js
CHANGED
|
@@ -5,174 +5,122 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
-
|
|
9
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
18
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
19
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
20
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
21
|
-
function step(op) {
|
|
22
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
23
|
-
while (_) try {
|
|
24
|
-
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;
|
|
25
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
26
|
-
switch (op[0]) {
|
|
27
|
-
case 0: case 1: t = op; break;
|
|
28
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
29
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
30
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
31
|
-
default:
|
|
32
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
33
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
34
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
35
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
36
|
-
if (t[2]) _.ops.pop();
|
|
37
|
-
_.trys.pop(); continue;
|
|
38
|
-
}
|
|
39
|
-
op = body.call(thisArg, _);
|
|
40
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
41
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
exports.__esModule = true;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
9
|
exports.testInit = exports.calculateRentExemption = exports.loadPrograms = exports.loadAccountFromJson = exports.loadAccountsFromDirectory = exports.toAccountInfoBytes = exports.JsonAccount = exports.JsonAccountData = void 0;
|
|
46
|
-
|
|
47
|
-
|
|
10
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
11
|
+
const solana_bankrun_1 = require("solana-bankrun");
|
|
48
12
|
require("reflect-metadata");
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
13
|
+
const class_transformer_1 = require("class-transformer");
|
|
14
|
+
const fs_1 = require("fs");
|
|
15
|
+
const path_1 = require("path");
|
|
16
|
+
const extendedProvider_1 = require("./extendedProvider");
|
|
53
17
|
// note: VsCode error:
|
|
54
18
|
// https://github.com/microsoft/TypeScript/issues/52396#issuecomment-1409152884
|
|
55
19
|
// https://bobbyhadz.com/blog/typescript-experimental-support-for-decorators-warning#solve-the-error-in-visual-studio-code
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return Number(value);
|
|
64
|
-
})
|
|
65
|
-
], JsonAccountData.prototype, "lamports");
|
|
66
|
-
__decorate([
|
|
67
|
-
(0, class_transformer_1.Expose)()
|
|
68
|
-
], JsonAccountData.prototype, "data");
|
|
69
|
-
__decorate([
|
|
70
|
-
(0, class_transformer_1.Expose)(),
|
|
71
|
-
(0, class_transformer_1.Transform)(function (_a) {
|
|
72
|
-
var value = _a.value;
|
|
73
|
-
return new web3_js_1.PublicKey(value);
|
|
74
|
-
})
|
|
75
|
-
], JsonAccountData.prototype, "owner");
|
|
76
|
-
__decorate([
|
|
77
|
-
(0, class_transformer_1.Expose)(),
|
|
78
|
-
(0, class_transformer_1.Transform)(function (_a) {
|
|
79
|
-
var value = _a.value;
|
|
80
|
-
return Boolean(value);
|
|
81
|
-
})
|
|
82
|
-
], JsonAccountData.prototype, "executable");
|
|
83
|
-
__decorate([
|
|
84
|
-
(0, class_transformer_1.Expose)(),
|
|
85
|
-
(0, class_transformer_1.Transform)(function (_a) {
|
|
86
|
-
var value = _a.value;
|
|
87
|
-
return Number(value);
|
|
88
|
-
})
|
|
89
|
-
], JsonAccountData.prototype, "rentEpoch");
|
|
90
|
-
return JsonAccountData;
|
|
91
|
-
}());
|
|
20
|
+
class JsonAccountData {
|
|
21
|
+
lamports;
|
|
22
|
+
data;
|
|
23
|
+
owner;
|
|
24
|
+
executable;
|
|
25
|
+
rentEpoch;
|
|
26
|
+
}
|
|
92
27
|
exports.JsonAccountData = JsonAccountData;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, class_transformer_1.Expose)(),
|
|
30
|
+
(0, class_transformer_1.Transform)(({ value }) => Number(value))
|
|
31
|
+
], JsonAccountData.prototype, "lamports", void 0);
|
|
32
|
+
__decorate([
|
|
33
|
+
(0, class_transformer_1.Expose)()
|
|
34
|
+
], JsonAccountData.prototype, "data", void 0);
|
|
35
|
+
__decorate([
|
|
36
|
+
(0, class_transformer_1.Expose)(),
|
|
37
|
+
(0, class_transformer_1.Transform)(({ value }) => new web3_js_1.PublicKey(value))
|
|
38
|
+
], JsonAccountData.prototype, "owner", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, class_transformer_1.Expose)(),
|
|
41
|
+
(0, class_transformer_1.Transform)(({ value }) => Boolean(value))
|
|
42
|
+
], JsonAccountData.prototype, "executable", void 0);
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, class_transformer_1.Expose)(),
|
|
45
|
+
(0, class_transformer_1.Transform)(({ value }) => Number(value))
|
|
46
|
+
], JsonAccountData.prototype, "rentEpoch", void 0);
|
|
47
|
+
class JsonAccount {
|
|
48
|
+
pubkey;
|
|
49
|
+
account;
|
|
50
|
+
}
|
|
109
51
|
exports.JsonAccount = JsonAccount;
|
|
52
|
+
__decorate([
|
|
53
|
+
(0, class_transformer_1.Expose)(),
|
|
54
|
+
(0, class_transformer_1.Transform)(({ value }) => new web3_js_1.PublicKey(value))
|
|
55
|
+
], JsonAccount.prototype, "pubkey", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
(0, class_transformer_1.Expose)(),
|
|
58
|
+
(0, class_transformer_1.Type)(() => JsonAccountData)
|
|
59
|
+
], JsonAccount.prototype, "account", void 0);
|
|
110
60
|
function toAccountInfoBytes(jsonAccount) {
|
|
111
|
-
|
|
61
|
+
const dataField = jsonAccount.account.data;
|
|
112
62
|
return {
|
|
113
63
|
executable: jsonAccount.account.executable,
|
|
114
64
|
owner: jsonAccount.account.owner,
|
|
115
65
|
lamports: jsonAccount.account.lamports,
|
|
116
66
|
data: Buffer.from(dataField[0], dataField[1]),
|
|
117
|
-
rentEpoch: jsonAccount.account.rentEpoch
|
|
67
|
+
rentEpoch: jsonAccount.account.rentEpoch,
|
|
118
68
|
};
|
|
119
69
|
}
|
|
120
70
|
exports.toAccountInfoBytes = toAccountInfoBytes;
|
|
121
71
|
function loadAccountsFromDirectory(directory) {
|
|
122
|
-
|
|
123
|
-
for (
|
|
72
|
+
const accounts = [];
|
|
73
|
+
for (const jsonFile of (0, fs_1.readdirSync)(directory, {
|
|
124
74
|
recursive: true,
|
|
125
|
-
encoding: null
|
|
126
|
-
}).filter(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
var loadedAccount = loadAccountFromJson(jsonPath);
|
|
75
|
+
encoding: null,
|
|
76
|
+
}).filter(f => f.endsWith('.json'))) {
|
|
77
|
+
const jsonPath = (0, path_1.join)(directory, jsonFile);
|
|
78
|
+
const loadedAccount = loadAccountFromJson(jsonPath);
|
|
130
79
|
accounts.push(loadedAccount);
|
|
131
80
|
}
|
|
132
81
|
return accounts;
|
|
133
82
|
}
|
|
134
83
|
exports.loadAccountsFromDirectory = loadAccountsFromDirectory;
|
|
135
84
|
function loadAccountFromJson(jsonPath) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
85
|
+
const fileBuffer = (0, fs_1.readFileSync)(jsonPath);
|
|
86
|
+
const parsedData = JSON.parse(fileBuffer.toString());
|
|
87
|
+
const jsonAccount = (0, class_transformer_1.plainToInstance)(JsonAccount, parsedData);
|
|
139
88
|
return {
|
|
140
89
|
address: jsonAccount.pubkey,
|
|
141
|
-
info: toAccountInfoBytes(jsonAccount)
|
|
90
|
+
info: toAccountInfoBytes(jsonAccount),
|
|
142
91
|
};
|
|
143
92
|
}
|
|
144
93
|
exports.loadAccountFromJson = loadAccountFromJson;
|
|
145
94
|
function loadPrograms(programs) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
95
|
+
const addedPrograms = [];
|
|
96
|
+
let hookDeleteDir = false;
|
|
97
|
+
const hookDeleteProgramNames = [];
|
|
149
98
|
// programs that should be loaded just by name based on the rules of the solana-test-program
|
|
150
99
|
programs
|
|
151
|
-
.filter(
|
|
152
|
-
.forEach(
|
|
100
|
+
.filter(p => p.path === undefined)
|
|
101
|
+
.forEach(p => {
|
|
153
102
|
addedPrograms.push({
|
|
154
103
|
name: p.name,
|
|
155
|
-
programId: p.pubkey
|
|
104
|
+
programId: p.pubkey,
|
|
156
105
|
});
|
|
157
106
|
});
|
|
158
107
|
// programs that provided the path would be copied to the fixtures directory where
|
|
159
108
|
// the solana-test-program looks for the program data
|
|
160
109
|
// see: https://github.com/solana-labs/solana/blob/v1.18.14/program-test/src/lib.rs#L428
|
|
161
|
-
|
|
110
|
+
const fixturesPath = (0, path_1.join)(process.cwd(), 'tests', 'fixtures');
|
|
162
111
|
if (!(0, fs_1.existsSync)(fixturesPath)) {
|
|
163
112
|
(0, fs_1.mkdirSync)(fixturesPath, { recursive: true });
|
|
164
113
|
hookDeleteDir = true;
|
|
165
114
|
}
|
|
166
|
-
for (
|
|
167
|
-
|
|
168
|
-
var programPath = path;
|
|
115
|
+
for (const { pubkey, path, name } of programs.filter(p => p.path !== undefined)) {
|
|
116
|
+
const programPath = path;
|
|
169
117
|
if (!(0, fs_1.existsSync)(programPath)) {
|
|
170
|
-
console.error(
|
|
118
|
+
console.error(`bankrun startup: program ${pubkey.toBase58()} at path ${programPath} does not exist cannot be loaded`);
|
|
171
119
|
continue;
|
|
172
120
|
}
|
|
173
|
-
|
|
121
|
+
const fixturesProgramSoPath = (0, path_1.join)(fixturesPath, `${name}.so`);
|
|
174
122
|
if ((0, fs_1.existsSync)(fixturesProgramSoPath)) {
|
|
175
|
-
console.log(
|
|
123
|
+
console.log(`bankrun startup: skipping to upload the program ${pubkey.toBase58()} from path ${path} to ${fixturesProgramSoPath} as it already exists`);
|
|
176
124
|
}
|
|
177
125
|
else {
|
|
178
126
|
console.debug('bankrun startup: copying program', fixturesProgramSoPath, 'to', fixturesProgramSoPath);
|
|
@@ -180,13 +128,13 @@ function loadPrograms(programs) {
|
|
|
180
128
|
hookDeleteProgramNames.push(fixturesProgramSoPath);
|
|
181
129
|
}
|
|
182
130
|
addedPrograms.push({
|
|
183
|
-
name
|
|
184
|
-
programId: pubkey
|
|
131
|
+
name,
|
|
132
|
+
programId: pubkey,
|
|
185
133
|
});
|
|
186
134
|
}
|
|
187
135
|
// TODO: exit hooks somehow does not work in jest
|
|
188
|
-
registerCleanup(
|
|
189
|
-
hookDeleteProgramNames.forEach(
|
|
136
|
+
registerCleanup(() => {
|
|
137
|
+
hookDeleteProgramNames.forEach(p => {
|
|
190
138
|
console.log('Deleting program file', p);
|
|
191
139
|
(0, fs_1.rmSync)(p);
|
|
192
140
|
});
|
|
@@ -227,8 +175,8 @@ exitHandler) {
|
|
|
227
175
|
* > Rent-exempt minimum: 0.00089784 SOL
|
|
228
176
|
*/
|
|
229
177
|
function calculateRentExemption(dataSize) {
|
|
230
|
-
|
|
231
|
-
|
|
178
|
+
const basePaymentLamports = 890880;
|
|
179
|
+
const perByteLamports = 6960;
|
|
232
180
|
return basePaymentLamports + perByteLamports * dataSize;
|
|
233
181
|
}
|
|
234
182
|
exports.calculateRentExemption = calculateRentExemption;
|
|
@@ -246,38 +194,27 @@ exports.calculateRentExemption = calculateRentExemption;
|
|
|
246
194
|
* The 'path' is optional and when provided the file is copied to place where the solana-test-program looks for the program data.
|
|
247
195
|
* see: https://github.com/solana-labs/solana/blob/v1.18.14/program-test/src/lib.rs#L428
|
|
248
196
|
*/
|
|
249
|
-
function testInit(
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
if (accounts !== undefined) {
|
|
262
|
-
additionalAccounts.push.apply(additionalAccounts, accounts.flatMap(function (acc) {
|
|
263
|
-
var accountData = loadAccountFromJson(acc.path);
|
|
264
|
-
if (acc.pubkey !== undefined) {
|
|
265
|
-
// rewriting the address when passed in
|
|
266
|
-
accountData.address = acc.pubkey;
|
|
267
|
-
}
|
|
268
|
-
return accountData;
|
|
269
|
-
}));
|
|
270
|
-
}
|
|
271
|
-
if (programs !== undefined) {
|
|
272
|
-
additionalPrograms = loadPrograms(programs);
|
|
273
|
-
}
|
|
274
|
-
return [4 /*yield*/, (0, solana_bankrun_1.startAnchor)('./', additionalPrograms, additionalAccounts)];
|
|
275
|
-
case 1:
|
|
276
|
-
context = _b.sent();
|
|
277
|
-
return [2 /*return*/, new extendedProvider_1.BankrunExtendedProvider(context)];
|
|
197
|
+
async function testInit({ accountDirs, accounts, programs, }) {
|
|
198
|
+
let additionalAccounts = [];
|
|
199
|
+
let additionalPrograms = [];
|
|
200
|
+
if (accountDirs !== undefined) {
|
|
201
|
+
additionalAccounts = accountDirs.flatMap(loadAccountsFromDirectory);
|
|
202
|
+
}
|
|
203
|
+
if (accounts !== undefined) {
|
|
204
|
+
additionalAccounts.push(...accounts.flatMap(acc => {
|
|
205
|
+
const accountData = loadAccountFromJson(acc.path);
|
|
206
|
+
if (acc.pubkey !== undefined) {
|
|
207
|
+
// rewriting the address when passed in
|
|
208
|
+
accountData.address = acc.pubkey;
|
|
278
209
|
}
|
|
279
|
-
|
|
280
|
-
|
|
210
|
+
return accountData;
|
|
211
|
+
}));
|
|
212
|
+
}
|
|
213
|
+
if (programs !== undefined) {
|
|
214
|
+
additionalPrograms = loadPrograms(programs);
|
|
215
|
+
}
|
|
216
|
+
const context = await (0, solana_bankrun_1.startAnchor)('./', additionalPrograms, additionalAccounts);
|
|
217
|
+
return new extendedProvider_1.BankrunExtendedProvider(context);
|
|
281
218
|
}
|
|
282
219
|
exports.testInit = testInit;
|
|
283
220
|
//# sourceMappingURL=testInit.js.map
|
package/src/testInit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testInit.js","sourceRoot":"","sources":["../../../../../packages/lib/bankrun-utils/src/testInit.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"testInit.js","sourceRoot":"","sources":["../../../../../packages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