bitcore-node
Version:
A blockchain indexing node with extended capabilities using bitcore
67 lines • 3.05 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const sinon = __importStar(require("sinon"));
const csp_1 = require("../../../../src/modules/moralis/api/csp");
const csp_2 = require("../../../../src/providers/chain-state/evm/api/csp");
describe('BASE Chain State Provider', function () {
const network = 'testnet';
let BASE;
before(() => {
BASE = new csp_1.MoralisStateProvider('BASE');
});
it('should be able to get web3', async () => {
const sandbox = sinon.createSandbox();
const web3Stub = { eth: { getBlockNumber: sandbox.stub().resolves(1) } };
sandbox.stub(csp_2.BaseEVMStateProvider, 'rpcs').value({ BASE: { [network]: [{ web3: web3Stub, rpc: sinon.stub(), dataType: 'combined' }] } });
const { web3 } = await BASE.getWeb3(network);
const block = await web3.eth.getBlockNumber();
const stub = web3.eth.getBlockNumber;
(0, chai_1.expect)(stub.callCount).to.eq(2);
(0, chai_1.expect)(block).to.eq(1);
sandbox.restore();
});
it('should make a new web3 if getBlockNumber fails', async () => {
const sandbox = sinon.createSandbox();
const web3Stub = { eth: { getBlockNumber: sandbox.stub().throws('Block number fails') } };
sandbox.stub(csp_2.BaseEVMStateProvider, 'rpcs').value({ BASE: { [network]: [{ web3: web3Stub, rpc: sinon.stub(), dataType: 'combined' }] } });
const { web3 } = await BASE.getWeb3(network);
const stub = web3.eth.getBlockNumber;
(0, chai_1.expect)(stub.callCount).to.not.exist;
sandbox.restore();
});
});
//# sourceMappingURL=csp.spc.js.map