@0xcert/ethereum-sandbox
Version:
Test server for local running testing of modules on the Ethereum blockchain.
50 lines • 2.07 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Sandbox = void 0;
const ganache = require("ganache-core");
const Web3 = require("web3");
const protocol_1 = require("./protocol");
class Sandbox {
static createProvider(options) {
const provider = ganache['provider'](options);
provider.setMaxListeners(999999);
return provider;
}
static listen(options) {
return new Sandbox().listen(options);
}
listen(options) {
return __awaiter(this, void 0, void 0, function* () {
options = Object.assign({}, options);
yield new Promise((resolve, reject) => {
this.server = ganache['server']();
this.server.listen(options.port, (e) => e ? reject(e) : resolve(null));
});
this.web3 = new Web3(Sandbox.createProvider(options));
this.protocol = yield protocol_1.Protocol.deploy(this.web3);
return this;
});
}
close() {
return __awaiter(this, void 0, void 0, function* () {
if (this.server) {
this.server.close();
this.server = null;
this.web3 = undefined;
this.protocol = undefined;
}
return this;
});
}
}
exports.Sandbox = Sandbox;
//# sourceMappingURL=sandbox.js.map