UNPKG

@firmachain/firma-js

Version:

The Official FirmaChain Javascript SDK written in Typescript

276 lines (275 loc) 14.3 kB
"use strict"; 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()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (g && (g = 0, op[0] && (_ = 0)), _) try { 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; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; Object.defineProperty(exports, "__esModule", { value: true }); var chai_1 = require("chai"); var FirmaSDK_1 = require("../sdk/FirmaSDK"); var config_test_1 = require("./config_test"); describe('[26. cosmwasm query Test]', function () { var firma; beforeEach(function () { firma = new FirmaSDK_1.FirmaSDK(config_test_1.TestChainConfig); }); var contractAddress = ""; var codeId = ""; it('CosmWasm getCodeList', function () { return __awaiter(void 0, void 0, void 0, function () { var result, codeInfo; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, firma.CosmWasm.getCodeList()]; case 1: result = _a.sent(); (0, chai_1.expect)(result.length).to.be.greaterThan(0); codeId = result[0].code_id; codeInfo = result[0]; (0, chai_1.expect)(codeInfo).to.have.property('code_id'); (0, chai_1.expect)(codeInfo).to.have.property('creator'); (0, chai_1.expect)(codeInfo).to.have.property('data_hash'); return [2 /*return*/]; } }); }); }); it('CosmWasm getCodeData', function () { return __awaiter(void 0, void 0, void 0, function () { var result, codeInfo; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, firma.CosmWasm.getCodeData(codeId)]; case 1: result = _a.sent(); (0, chai_1.expect)(result).to.not.be.null; (0, chai_1.expect)(result).to.have.property('code_info'); (0, chai_1.expect)(result).to.have.property('data'); codeInfo = result.code_info; (0, chai_1.expect)(codeInfo).to.have.property('code_id', codeId); (0, chai_1.expect)(codeInfo).to.have.property('creator'); (0, chai_1.expect)(codeInfo).to.have.property('data_hash'); (0, chai_1.expect)(result.data).to.be.a('string'); return [2 /*return*/]; } }); }); }); it('CosmWasm getContractListFromCodeId', function () { return __awaiter(void 0, void 0, void 0, function () { var result; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, firma.CosmWasm.getContractListFromCodeId(codeId)]; case 1: result = _a.sent(); (0, chai_1.expect)(result).to.not.be.null; (0, chai_1.expect)(result).to.have.property('dataList'); (0, chai_1.expect)(result).to.have.property('pagination'); (0, chai_1.expect)(result.dataList).to.be.an('array'); (0, chai_1.expect)(result.dataList.length).to.be.greaterThan(0); (0, chai_1.expect)(result.dataList[0]).to.be.a('string'); (0, chai_1.expect)(result.pagination).to.have.property('next_key'); (0, chai_1.expect)(result.pagination).to.have.property('total'); contractAddress = result.dataList[0]; return [2 /*return*/]; } }); }); }); it('CosmWasm getPinnedCodeList', function () { return __awaiter(void 0, void 0, void 0, function () { var codeList; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, firma.CosmWasm.getPinnedCodeList()]; case 1: codeList = _a.sent(); (0, chai_1.expect)(codeList).to.be.an('array'); return [2 /*return*/]; } }); }); }); // ContractInfo gets the contract meta data it('CosmWasm getContractInfo', function () { return __awaiter(void 0, void 0, void 0, function () { var result, contractInfo; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, firma.CosmWasm.getContractInfo(contractAddress)]; case 1: result = _a.sent(); (0, chai_1.expect)(result).to.not.be.null; (0, chai_1.expect)(result).to.have.property('address', contractAddress); (0, chai_1.expect)(result).to.have.property('contract_info'); contractInfo = result.contract_info; (0, chai_1.expect)(contractInfo).to.have.property('code_id'); (0, chai_1.expect)(contractInfo).to.have.property('creator'); (0, chai_1.expect)(contractInfo).to.have.property('admin'); (0, chai_1.expect)(contractInfo).to.have.property('label'); (0, chai_1.expect)(contractInfo).to.have.property('created'); (0, chai_1.expect)(contractInfo).to.have.property('ibc_port_id'); (0, chai_1.expect)(contractInfo).to.have.property('extension'); (0, chai_1.expect)(contractInfo.created).to.have.property('block_height'); (0, chai_1.expect)(contractInfo.created).to.have.property('tx_index'); return [2 /*return*/]; } }); }); }); it('CosmWasm getContractHistory', function () { return __awaiter(void 0, void 0, void 0, function () { var result, history; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, firma.CosmWasm.getContractHistory(contractAddress)]; case 1: result = _a.sent(); (0, chai_1.expect)(result).to.be.an('array'); (0, chai_1.expect)(result.length).to.be.greaterThan(0); history = result[0]; (0, chai_1.expect)(history.code_id).to.be.equal(codeId); return [2 /*return*/]; } }); }); }); // AllContractState gets all raw store data for a single contract it('CosmWasm getContractState', function () { return __awaiter(void 0, void 0, void 0, function () { var result, model; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, firma.CosmWasm.getContractState(contractAddress)]; case 1: result = _a.sent(); (0, chai_1.expect)(result).to.be.an('array'); (0, chai_1.expect)(result.length).to.be.greaterThan(0); model = result[0]; (0, chai_1.expect)(model).to.have.property('key'); (0, chai_1.expect)(model).to.have.property('value'); return [2 /*return*/]; } }); }); }); it('CosmWasm getContractRawQueryData', function () { return __awaiter(void 0, void 0, void 0, function () { var stateResult, firstKey, result, error_1; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 3, , 4]); return [4 /*yield*/, firma.CosmWasm.getContractState(contractAddress)]; case 1: stateResult = _a.sent(); if (!stateResult || stateResult.length === 0) { return [2 /*return*/]; } firstKey = stateResult[0].key; return [4 /*yield*/, firma.CosmWasm.getContractRawQueryData(contractAddress, firstKey)]; case 2: result = _a.sent(); (0, chai_1.expect)(result).to.be.a('string'); (0, chai_1.expect)(result.length).to.be.greaterThan(0); (0, chai_1.expect)(result).to.match(/^[0-9A-Fa-f]*$/); return [3 /*break*/, 4]; case 3: error_1 = _a.sent(); return [3 /*break*/, 4]; case 4: return [2 /*return*/]; } }); }); }); it('CosmWasm getContractSmartQueryData', function () { return __awaiter(void 0, void 0, void 0, function () { var queries, successfulQuery, result, queries_1, queries_1_1, query, error_2, e_1_1, parsedResult; var e_1, _a; return __generator(this, function (_b) { switch (_b.label) { case 0: queries = [ '{"config":{}}', ]; successfulQuery = null; result = null; _b.label = 1; case 1: _b.trys.push([1, 8, 9, 10]); queries_1 = __values(queries), queries_1_1 = queries_1.next(); _b.label = 2; case 2: if (!!queries_1_1.done) return [3 /*break*/, 7]; query = queries_1_1.value; _b.label = 3; case 3: _b.trys.push([3, 5, , 6]); return [4 /*yield*/, firma.CosmWasm.getContractSmartQueryData(contractAddress, query)]; case 4: result = _b.sent(); successfulQuery = query; return [3 /*break*/, 7]; case 5: error_2 = _b.sent(); return [3 /*break*/, 6]; case 6: queries_1_1 = queries_1.next(); return [3 /*break*/, 2]; case 7: return [3 /*break*/, 10]; case 8: e_1_1 = _b.sent(); e_1 = { error: e_1_1 }; return [3 /*break*/, 10]; case 9: try { if (queries_1_1 && !queries_1_1.done && (_a = queries_1.return)) _a.call(queries_1); } finally { if (e_1) throw e_1.error; } return [7 /*endfinally*/]; case 10: (0, chai_1.expect)(successfulQuery).to.not.be.null; (0, chai_1.expect)(result).to.not.be.null; if (result) { (0, chai_1.expect)(result).to.be.a('string'); (0, chai_1.expect)(result.length).to.be.greaterThan(0); parsedResult = JSON.parse(result); (0, chai_1.expect)(parsedResult).to.be.an('object'); if (successfulQuery === '{"token_info":{}}') { (0, chai_1.expect)(parsedResult).to.have.property('name'); (0, chai_1.expect)(parsedResult).to.have.property('symbol'); (0, chai_1.expect)(parsedResult).to.have.property('decimals'); (0, chai_1.expect)(parsedResult).to.have.property('total_supply'); } } return [2 /*return*/]; } }); }); }); });