evtjs
Version:
Javascript API Bindings for the everiToken blockchain.
739 lines (654 loc) • 30.8 kB
JavaScript
"use strict";
var _keys = require("babel-runtime/core-js/object/keys");
var _keys2 = _interopRequireDefault(_keys);
var _regenerator = require("babel-runtime/regenerator");
var _regenerator2 = _interopRequireDefault(_regenerator);
var _asyncToGenerator2 = require("babel-runtime/helpers/asyncToGenerator");
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var CHECKALL = typeof process.env.DEV === "undefined" ? true : !process.env.DEV;
/* eslint-env mocha */
var assert = require("assert");
var EVT = require(".");
var Key = require("./key");
var logger = require("./logger");
var wif = "5J1by7KRQujRdXrurEsvEr2zQGcdPaMJRjewER6XsAR2eCcpt3D"; // EVT6Qz3wuRjyN6gaU3P3XRxpnEZnM4oPxortemaWDwFRvsv2FxgND
var wif2 = "5JVC3ivLUT2zq3yEXkwJ2ihukZq5reufC3iW26hbVHvjepFXsiu"; // EVT7rbe5ZqAEtwQT6Tw39R29vojFqrCQasK3nT5s2pEzXh1BABXHF
var publicKey = EVT.EvtKey.privateToPublic(wif);
var publicKey2 = EVT.EvtKey.privateToPublic(wif2);
var network = {
host: "testnet1.everitoken.io",
port: 8888,
protocol: "http"
};
var testingTmpData = {
newDomainName: "nd" + new Date().valueOf(),
addedTokenNamePrefix: "tk" + new Date().valueOf() / 500
};
logger.writeLog = true;
var newCaller = function newCaller() {
return new EVT({
keyProvider: wif,
endpoint: network
});
};
var testAbi = function () {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(testAction) {
var print = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var apiCaller, action, throughFC, throughAPI;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
apiCaller = newCaller();
_context.next = 3;
return apiCaller.getInfo();
case 3:
_context.next = 5;
return testAction.calculateDomainAndKey();
case 5:
action = { action: testAction.actionName, args: testAction.abi };
throughFC = void 0, throughAPI = void 0;
_context.next = 9;
return apiCaller.__chainAbiJsonToBinByAPI(action);
case 9:
throughAPI = _context.sent;
_context.prev = 10;
_context.next = 13;
return apiCaller.__chainAbiJsonToBinByFC(action);
case 13:
throughFC = _context.sent;
_context.next = 20;
break;
case 16:
_context.prev = 16;
_context.t0 = _context["catch"](10);
console.info("API:\t", throughAPI.binargs);
throw _context.t0;
case 20:
if (throughFC.binargs !== throughAPI.binargs || print) {
console.info("LFC:\t", throughFC.binargs);
console.info("API:\t", throughAPI.binargs);
}
if (!(throughFC.binargs !== throughAPI.binargs)) {
_context.next = 23;
break;
}
throw new Error("Not Equal!");
case 23:
case "end":
return _context.stop();
}
}
}, _callee, undefined, [[10, 16]]);
}));
return function testAbi(_x2) {
return _ref.apply(this, arguments);
};
}();
/* New Actions Test Script Here */
/**
* Including:
* - recycle
* - lock
*/
var balanceThrd = {
"1": 100
};
describe("Preparation", function () {
if (!"Check Remainings" || CHECKALL) it('check remains', (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() {
var apiCaller1, apiCaller2, response;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
apiCaller1 = EVT({
endpoint: network,
keyProvider: wif
});
apiCaller2 = EVT({
endpoint: network,
keyProvider: wif2
});
_context2.next = 4;
return apiCaller1.getFungibleBalance(publicKey);
case 4:
_context2.t0 = _context2.sent;
_context2.next = 7;
return apiCaller2.getFungibleBalance(publicKey2);
case 7:
_context2.t1 = _context2.sent;
response = [_context2.t0, _context2.t1];
response.forEach(function (balanceList, i) {
if (!Array.isArray(balanceList) || !balanceList.length) throw Error("NO." + (i + 1) + " Account does not have any Asset.");
(0, _keys2.default)(balanceThrd).forEach(function (key) {
var matched = false;
var balance = 0;
balanceList.forEach(function (p) {
if (p.includes(" S#" + key)) {
balance = parseFloat(p.replace(" S#" + key, ""));
if (balance > balanceThrd[key]) matched = true;
}
});
if (!matched) throw Error("NO." + (i + 1) + " Account does not have sufficient Asset S#" + key + ". (" + balance + " given, " + balanceThrd[key] + " needed).");
});
});
case 10:
case "end":
return _context2.stop();
}
}
}, _callee2, undefined);
}))).timeout(5000);
});
describe("Action ABI Test", function () {
if (!"Check newdomain / updatedomain" || CHECKALL) it("newdomain", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3() {
var perm, perm2, perm3;
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
perm = {
name: "issue",
threshold: 1,
authorizers: [{
ref: "[A] " + publicKey2,
weight: 1
}]
};
perm2 = {
name: "issue",
threshold: 1,
authorizers: [{
ref: "[G] vastchain.technology",
weight: 2
}]
};
perm3 = {
name: "issue",
threshold: 1,
authorizers: [{
ref: "[G] .OWNER",
weight: 3
}]
};
_context3.next = 5;
return testAbi(new EVT.EvtAction("newdomain", {
name: "test112",
creator: publicKey2,
issue: perm,
transfer: perm2,
manage: perm3
}));
case 5:
_context3.next = 7;
return testAbi(new EVT.EvtAction("updatedomain", {
name: "test",
issue: perm
}));
case 7:
case "end":
return _context3.stop();
}
}
}, _callee3, this);
}))).timeout(10000);
if (!"Check Token" || CHECKALL) it("issuetoken", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4() {
return _regenerator2.default.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.next = 2;
return testAbi(new EVT.EvtAction("issuetoken", {
"domain": "shoRt",
"names": ["oneUnder10", "moreStrUnder.15", "largestCanGetBelow-21"],
"owner": [Key.privateToPublic(wif), Key.privateToPublic(wif2)]
// ["EVT00000000000000000000000000000000000000000000000000"] => "010000"
// ["EVT00000000000000000000000000000000000000000000000000" x2] => "0200000000"
// ["EVT0000009tDnxK74wjkVZidAeyT339HkhMozkmdkju2pFx32QS95"]
}));
case 2:
case "end":
return _context4.stop();
}
}
}, _callee4, undefined);
}))).timeout(5000);
if (!"Check Transfer" || CHECKALL) it("transfer", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5() {
return _regenerator2.default.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return testAbi(new EVT.EvtAction("transfer", {
"domain": "shoRt",
"name": "moreStrUnder.15",
"to": [Key.privateToPublic(wif), Key.privateToPublic(wif2)],
"memo": "Test"
}));
case 2:
case "end":
return _context5.stop();
}
}
}, _callee5, undefined);
}))).timeout(5000);
if (!"Check Destroy Token" || CHECKALL) it("destroytoken", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6() {
return _regenerator2.default.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
_context6.next = 2;
return testAbi(new EVT.EvtAction("destroytoken", {
"domain": "shoRt",
"name": "moreStrUnder.15"
}));
case 2:
case "end":
return _context6.stop();
}
}
}, _callee6, undefined);
}))).timeout(5000);
if (!"Check New Group / Update Group" || CHECKALL) it("newgroup / Update Group", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee7() {
var groupArgs;
return _regenerator2.default.wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
groupArgs = {
"name": "newGrou.p",
"group": {
"name": "newGrou.p",
"key": Key.privateToPublic(wif2),
"root": {
"threshold": 6,
"nodes": [{
"key": Key.privateToPublic(wif),
"weight": 3
}, {
"key": Key.privateToPublic(wif2),
"weight": 2
}, {
"threshold": 1,
"weight": 3,
"nodes": [{
"key": Key.privateToPublic(wif2),
"weight": 1
}, {
"key": Key.privateToPublic(wif),
"weight": 1
}]
}]
}
}
};
_context7.next = 3;
return testAbi(new EVT.EvtAction("newgroup", groupArgs));
case 3:
_context7.next = 5;
return testAbi(new EVT.EvtAction("updategroup", groupArgs));
case 5:
case "end":
return _context7.stop();
}
}
}, _callee7, undefined);
}))).timeout(10000);
if (!"Check New Fungible" || CHECKALL) it("newfungible", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8() {
var perm;
return _regenerator2.default.wrap(function _callee8$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
perm = {
name: "issue",
threshold: 1,
authorizers: [{
ref: "[A] " + publicKey2,
weight: 1
}]
};
_context8.next = 3;
return testAbi(new EVT.EvtAction("newfungible", {
"name": "testtoken",
"sym_name": "testtoken",
"sym": "7,S#1059",
"creator": publicKey2,
"issue": perm,
"manage": perm,
"total_supply": "10000.0003000 S#1059"
}));
case 3:
case "end":
return _context8.stop();
}
}
}, _callee8, undefined);
}))).timeout(5000);
if (!"Check Update Fungible" || CHECKALL) it("updfungible", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9() {
var perm;
return _regenerator2.default.wrap(function _callee9$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
perm = {
name: "issue",
threshold: 1,
authorizers: [{
ref: "[A] " + publicKey2,
weight: 1
}]
};
_context9.next = 3;
return testAbi(new EVT.EvtAction("updfungible", {
"sym_id": 1059,
"manage": perm
}));
case 3:
case "end":
return _context9.stop();
}
}
}, _callee9, undefined);
}))).timeout(5000);
if (!"Check Issue Fungible" || CHECKALL) it("issuefungible", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee10() {
return _regenerator2.default.wrap(function _callee10$(_context10) {
while (1) {
switch (_context10.prev = _context10.next) {
case 0:
_context10.next = 2;
return testAbi(new EVT.EvtAction("issuefungible", {
"address": publicKey2,
"number": "2.0040310 S#1059",
"memo": "Test"
}));
case 2:
case "end":
return _context10.stop();
}
}
}, _callee10, undefined);
}))).timeout(5000);
if (!"Check Transferft" || CHECKALL) it("transferft", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee11() {
return _regenerator2.default.wrap(function _callee11$(_context11) {
while (1) {
switch (_context11.prev = _context11.next) {
case 0:
_context11.next = 2;
return testAbi(new EVT.EvtAction("transferft", {
"from": publicKey2,
"to": publicKey,
"number": "2.0040310 S#1059",
"memo": "Test"
}));
case 2:
case "end":
return _context11.stop();
}
}
}, _callee11, undefined);
}))).timeout(5000);
if (!"Check Recycleft" || CHECKALL) it("recycleft", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee12() {
return _regenerator2.default.wrap(function _callee12$(_context12) {
while (1) {
switch (_context12.prev = _context12.next) {
case 0:
_context12.next = 2;
return testAbi(new EVT.EvtAction("recycleft", {
address: publicKey2,
number: "1.01942 S#1",
memo: "Test of recycleft"
}));
case 2:
case "end":
return _context12.stop();
}
}
}, _callee12, this);
}))).timeout(5000);
if (!"Check Destroyft" || CHECKALL) it("destroyft", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee13() {
return _regenerator2.default.wrap(function _callee13$(_context13) {
while (1) {
switch (_context13.prev = _context13.next) {
case 0:
_context13.next = 2;
return testAbi(new EVT.EvtAction("destroyft", {
address: publicKey2,
number: "1.01942 S#1",
memo: "Test of recycleft"
}));
case 2:
case "end":
return _context13.stop();
}
}
}, _callee13, this);
}))).timeout(5000);
if (!"Check Evt2pevt" || CHECKALL) it("evt2pevt", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee14() {
return _regenerator2.default.wrap(function _callee14$(_context14) {
while (1) {
switch (_context14.prev = _context14.next) {
case 0:
_context14.next = 2;
return testAbi(new EVT.EvtAction("evt2pevt", {
from: publicKey2,
to: publicKey2,
number: "1.01942 S#1",
memo: "Test of recycleft"
}));
case 2:
case "end":
return _context14.stop();
}
}
}, _callee14, this);
}))).timeout(5000);
if (!"Check Addmeta" || CHECKALL) it("addmeta", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee15() {
return _regenerator2.default.wrap(function _callee15$(_context15) {
while (1) {
switch (_context15.prev = _context15.next) {
case 0:
_context15.next = 2;
return testAbi(new EVT.EvtAction("addmeta", {
key: "newdata",
value: "somevalueishere",
creator: "[A] " + publicKey2
}));
case 2:
case "end":
return _context15.stop();
}
}
}, _callee15, this);
}))).timeout(5000);
if (!"Check NewSuspend" || CHECKALL) it("newsuspend", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee16() {
return _regenerator2.default.wrap(function _callee16$(_context16) {
while (1) {
switch (_context16.prev = _context16.next) {
case 0:
_context16.next = 2;
return testAbi(new EVT.EvtAction("newsuspend", {
name: "test",
proposer: publicKey,
trx: {
"expiration": "2018-05-20T12:25:51",
"ref_block_num": 8643,
"ref_block_prefix": 842752750,
"max_charge": 10000,
"payer": "EVT8MGU4aKiVzqMtWi9zLpu8KuTHZWjQQrX475ycSxEkLd6aBpraX",
"actions": [{
"name": "newdomain",
"domain": "test2",
"key": ".create",
"data": "000000000000000000000000109f077d0003c7e3ff0060d848bd31bf53daf1d5fed7d82c9b1121394ee15dcafb07e913a9700000000000a5317601000000010100000003c7e3ff0060d848bd31bf53daf1d5fed7d82c9b1121394ee15dcafb07e913a9706d4859000000000100000000572d3ccdcd010000000102000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000002866a69101000000010100000003c7e3ff0060d848bd31bf53daf1d5fed7d82c9b1121394ee15dcafb07e913a9706d4859000000000100"
}],
"transaction_extensions": []
}
}));
case 2:
case "end":
return _context16.stop();
}
}
}, _callee16, this);
}))).timeout(5000);
if (!"Check AprvSuspend" || CHECKALL) it("aprvsuspend", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee17() {
return _regenerator2.default.wrap(function _callee17$(_context17) {
while (1) {
switch (_context17.prev = _context17.next) {
case 0:
_context17.next = 2;
return testAbi(new EVT.EvtAction("aprvsuspend", {
name: "test",
signatures: ["SIG_K1_JzrdhWW46N5nFUZzTUmhg2sK4nKNGktPz2UdRz9bSAP5pY4nhicKWCuo6Uc6U7KBBwD8VfjsSxzHWT87R41xMaubnzMq8w"]
}));
case 2:
case "end":
return _context17.stop();
}
}
}, _callee17, this);
}))).timeout(5000);
if (!"Check CancelSuspend" || CHECKALL) it("cancelsuspend", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee18() {
return _regenerator2.default.wrap(function _callee18$(_context18) {
while (1) {
switch (_context18.prev = _context18.next) {
case 0:
_context18.next = 2;
return testAbi(new EVT.EvtAction("cancelsuspend", {
name: "test"
}));
case 2:
case "end":
return _context18.stop();
}
}
}, _callee18, this);
}))).timeout(5000);
if (!"Check ExecSuspend" || CHECKALL) it("execsuspend", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee19() {
return _regenerator2.default.wrap(function _callee19$(_context19) {
while (1) {
switch (_context19.prev = _context19.next) {
case 0:
_context19.next = 2;
return testAbi(new EVT.EvtAction("execsuspend", {
name: "test",
executor: publicKey2
}));
case 2:
case "end":
return _context19.stop();
}
}
}, _callee19, this);
}))).timeout(5000);
if (!"Check Everipass" || CHECKALL) it("everipass", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee20() {
return _regenerator2.default.wrap(function _callee20$(_context20) {
while (1) {
switch (_context20.prev = _context20.next) {
case 0:
_context20.next = 2;
return testAbi(new EVT.EvtAction("everipass", {
link: "0DFYZXZO9-:Y:JLF*3/4JCPG7V1346OZ:R/G2M93-2L*BBT9S0YQ0+JNRIW95*HF*94J0OVUN$KS01-GZ-N7FWK9_FXXJORONB7B58VU9Z2MZKZ5*:NP3::K7UYKD:Y9I1V508HBQZK2AE*ZS85PJZ2N47/41LQ-MZ/4Q6THOX**YN0VMQ*3/CG9-KX2:E7C-OCM*KJJT:Z7640Q6B*FWIQBYMDPIXB4CM:-8*TW-QNY$$AY5$UA3+N-7L/ZSDCWO1I7M*3Q6*SMAYOWWTF5RJAJ:NG**8U5J6WC2VM5Z:OLZPVJXX*12I*6V9FL1HX095$5:$*C3KGCM3FIS-WWRE14E:7VYNFA-3QCH5ULZJ*CRH91BTXIK-N+J1"
}));
case 2:
case "end":
return _context20.stop();
}
}
}, _callee20, this);
}))).timeout(5000);
if (!"Check Everipay" || CHECKALL) it("everipay", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee21() {
return _regenerator2.default.wrap(function _callee21$(_context21) {
while (1) {
switch (_context21.prev = _context21.next) {
case 0:
_context21.next = 2;
return testAbi(new EVT.EvtAction("everipay", {
link: "0IR$/H2QRH0UC+8K3WC1BZQIP0+-4R+:FZ52-BBI3OKV-E2E-780SC1Z0IS7E_QMVKIXWYQ2BFOF4WBLW/6-00:IT$A5HY3:ETDY2863VI2K6800N7VXTU8ZXZHK6CM+W-86*FB-YVHH7RUJQTE14FCR241WRW",
payee: publicKey,
number: "0.00010 S#1"
}));
case 2:
case "end":
return _context21.stop();
}
}
}, _callee21, this);
}))).timeout(5000);
// if ("Check NewLock" || CHECKALL)
// it("newlock", async function () {
// await testAbi(new EVT.EvtAction("newlock", {
// name: "test",
// proposer: publicKey,
// status: 1,
// unlock_time: "2019-03-02T12:00:00",
// deadline: "2020-03-02T12:00:00",
// assets: [{
// tokens: {
// domain: "test",
// names: ["test"]
// },
// fungible: {
// domain: `test`,
// names: ["test"]
// },
// }],
// condition: {
// cond_keys: {
// threshold: 8,
// cond_keys: publicKey
// }
// },
// succeed: [publicKey],
// failed: [publicKey]
// }));
// }).timeout(5000);
// if ("Check AprvLock" || CHECKALL)
// it("aprvlock", async function () {
// await testAbi(new EVT.EvtAction("aprvlock", {
// name: "test",
// approver: publicKey,
// data: "lock_aprvdata" // TODO
// }));
// }).timeout(5000);
if (!"Check TryUnlock" || CHECKALL) it("tryunlock", (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee22() {
return _regenerator2.default.wrap(function _callee22$(_context22) {
while (1) {
switch (_context22.prev = _context22.next) {
case 0:
_context22.next = 2;
return testAbi(new EVT.EvtAction("tryunlock", {
name: "test",
executor: publicKey
}));
case 2:
case "end":
return _context22.stop();
}
}
}, _callee22, this);
}))).timeout(5000);
// if ("Check SetPsvBonus" || CHECKALL)
// it("setpsvbonus", async function () {
// await testAbi(new EVT.EvtAction("setpsvbonus", {
// sym: "7,S#1059",
// rate: "0.01",
// base_charge: "0.00010 S#1",
// charge_threshold: "0.00010 S#1",
// minimum_charge: "0.00010 S#1",
// dist_threshold: "0.00010 S#1",
// rules: "dist_rule[]", // TODO
// methods: "passive_method[]" // TODO
// }));
// }).timeout(5000);
// if ("Check DistPsvBonus" || CHECKALL)
// it("distpsvbonus", async function () {
// await testAbi(new EVT.EvtAction("distpsvbonus", {
// sym: "71059",
// deadline: "2019-03-02T12:00:00",
// final_receiver: publicKey
// }));
// }).timeout(5000);
});