@firmachain/firma-js
Version:
The Official FirmaChain Javascript SDK written in Typescript
259 lines (258 loc) • 13.9 kB
JavaScript
"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 (_) 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 };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var FirmaConfig_1 = require("../sdk/FirmaConfig");
var FirmaSDK_1 = require("../sdk/FirmaSDK");
var chai_1 = require("chai");
var config_test_1 = require("./config_test");
describe('[35. Bridge tx low Test]', function () {
var firma;
var aliceWallet;
var bobWallet;
var aliceAddress;
var bobAddress;
beforeEach(function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
firma = new FirmaSDK_1.FirmaSDK(FirmaConfig_1.FirmaConfig.TestNetConfig);
return [4 /*yield*/, firma.Wallet.fromMnemonic(config_test_1.aliceMnemonic)];
case 1:
aliceWallet = _a.sent();
return [4 /*yield*/, firma.Wallet.fromMnemonic(config_test_1.bobMnemonic)];
case 2:
bobWallet = _a.sent();
return [4 /*yield*/, aliceWallet.getAddress()];
case 3:
aliceAddress = _a.sent();
return [4 /*yield*/, bobWallet.getAddress()];
case 4:
bobAddress = _a.sent();
return [2 /*return*/];
}
});
});
});
var cw721ContractAddress = "firma1mp3dl27wwhdkhkyed5d4ypaq7h5dewazqkqhny98sxcy2cpu23ls369adt";
var bridgeContractAddress = "firma1zj39neajvynzv4swf3a33394z84l6nfduy5sntw58re3z7ef9p4qk8lwk4";
var codeId = "";
// low level test
//----------------------------------------------------------------------
it.skip('[low] Cw721 send_nft & lock', function () { return __awaiter(void 0, void 0, void 0, function () {
var token_id, targetContractAddress, msg, gas, fee, result, data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
token_id = "6";
targetContractAddress = bridgeContractAddress;
msg = firma.CwBridge.getCwBridgeMsgData().getMsgDataLock();
return [4 /*yield*/, firma.Cw721.getGasEstimationSendNft(aliceWallet, cw721ContractAddress, targetContractAddress, token_id, msg)];
case 1:
gas = _a.sent();
fee = Math.ceil(gas * 0.1);
return [4 /*yield*/, firma.Cw721.sendNft(aliceWallet, cw721ContractAddress, targetContractAddress, token_id, msg, { gas: gas, fee: fee })];
case 2:
result = _a.sent();
chai_1.expect(result.code).to.be.equal(0);
return [4 /*yield*/, firma.Cw721.getNftData(cw721ContractAddress, token_id)];
case 3:
data = _a.sent();
console.log(data);
return [2 /*return*/];
}
});
}); });
it.skip('[low] cw bridge unlock', function () { return __awaiter(void 0, void 0, void 0, function () {
var token_id, noFunds, msgData, gas, fee, result, data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
token_id = "1";
noFunds = [];
msgData = JSON.stringify({
"unlock": {
token_id: token_id,
}
});
return [4 /*yield*/, firma.CosmWasm.getGasEstimationExecuteContract(aliceWallet, bridgeContractAddress, msgData, noFunds)];
case 1:
gas = _a.sent();
fee = Math.ceil(gas * 0.1);
return [4 /*yield*/, firma.CosmWasm.executeContract(aliceWallet, bridgeContractAddress, msgData, noFunds, { gas: gas, fee: fee })];
case 2:
result = _a.sent();
chai_1.expect(result.code).to.be.equal(0);
return [4 /*yield*/, firma.Cw721.getNftData(cw721ContractAddress, token_id)];
case 3:
data = _a.sent();
console.log(data);
return [2 /*return*/];
}
});
}); });
it.skip('[low] Cw721 send_nft & deposit', function () { return __awaiter(void 0, void 0, void 0, function () {
var owner, new_token_id, new_token_uri, gas, fee, result, data1, targetContractAddress, msg, gas1, fee1, result, data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
owner = aliceAddress;
new_token_id = "6";
new_token_uri = "https://meta.nft.io/uri/" + new_token_id;
return [4 /*yield*/, firma.Cw721.getGasEstimationMint(aliceWallet, cw721ContractAddress, owner, new_token_id, new_token_uri)];
case 1:
gas = _a.sent();
fee = Math.ceil(gas * 0.1);
return [4 /*yield*/, firma.Cw721.mint(aliceWallet, cw721ContractAddress, owner, new_token_id, new_token_uri, { gas: gas, fee: fee })];
case 2:
result = _a.sent();
chai_1.expect(result.code).to.be.equal(0);
return [4 /*yield*/, firma.Cw721.getNftData(cw721ContractAddress, new_token_id)];
case 3:
data1 = _a.sent();
console.log(data1);
targetContractAddress = bridgeContractAddress;
msg = {
action: "deposit",
target_addr: bobAddress
};
return [4 /*yield*/, firma.Cw721.getGasEstimationSendNft(aliceWallet, cw721ContractAddress, targetContractAddress, new_token_id, msg)];
case 4:
gas1 = _a.sent();
fee1 = Math.ceil(gas1 * 0.1);
return [4 /*yield*/, firma.Cw721.sendNft(aliceWallet, cw721ContractAddress, targetContractAddress, new_token_id, msg, { gas: gas1, fee: fee1 })];
case 5:
result = _a.sent();
chai_1.expect(result.code).to.be.equal(0);
return [4 /*yield*/, firma.Cw721.getNftData(cw721ContractAddress, new_token_id)];
case 6:
data = _a.sent();
console.log(data);
return [2 /*return*/];
}
});
}); });
it.skip('[low] cw bridge withdraw', function () { return __awaiter(void 0, void 0, void 0, function () {
var token_id, noFunds, msgData, gas, fee, result, data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
token_id = "3";
noFunds = [];
msgData = JSON.stringify({
"withdraw": {
token_id: token_id,
}
});
return [4 /*yield*/, firma.CosmWasm.getGasEstimationExecuteContract(bobWallet, bridgeContractAddress, msgData, noFunds)];
case 1:
gas = _a.sent();
fee = Math.ceil(gas * 0.1);
return [4 /*yield*/, firma.CosmWasm.executeContract(bobWallet, bridgeContractAddress, msgData, noFunds, { gas: gas, fee: fee })];
case 2:
result = _a.sent();
chai_1.expect(result.code).to.be.equal(0);
return [4 /*yield*/, firma.Cw721.getNftData(cw721ContractAddress, token_id)];
case 3:
data = _a.sent();
console.log(data);
return [2 /*return*/];
}
});
}); });
it.skip('[low] cw721 send_nft & bridge lock bulk', function () { return __awaiter(void 0, void 0, void 0, function () {
var token_id1, token_id2, contractMsg, tx1, tx2, gas, fee, result, data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
token_id1 = "4";
token_id2 = "6";
contractMsg = firma.CwBridge.getCwBridgeMsgData().getMsgDataLock();
return [4 /*yield*/, firma.Cw721.getUnsignedTxSendNft(bobWallet, cw721ContractAddress, bridgeContractAddress, token_id1, contractMsg)];
case 1:
tx1 = _a.sent();
return [4 /*yield*/, firma.Cw721.getUnsignedTxSendNft(bobWallet, cw721ContractAddress, bridgeContractAddress, token_id2, contractMsg)];
case 2:
tx2 = _a.sent();
return [4 /*yield*/, firma.Cw721.getGasEstimationSignAndBroadcast(bobWallet, [tx1, tx2])];
case 3:
gas = _a.sent();
fee = Math.ceil(gas * 0.1);
return [4 /*yield*/, firma.Cw721.signAndBroadcast(bobWallet, [tx1, tx2], { gas: gas, fee: fee })];
case 4:
result = _a.sent();
chai_1.expect(result.code).to.be.equal(0);
return [4 /*yield*/, firma.Cw721.getNFTIdListOfOwner(cw721ContractAddress, bobAddress)];
case 5:
data = _a.sent();
console.log(data);
return [2 /*return*/];
}
});
}); });
it.skip('[low] cw721 send_nft & bridge deposit bulk', function () { return __awaiter(void 0, void 0, void 0, function () {
var token_id1, token_id2, contractMsg, tx1, tx2, gas, fee, result, data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
token_id1 = "4";
token_id2 = "6";
contractMsg = firma.CwBridge.getCwBridgeMsgData().getMsgDataDeposit(bobAddress);
return [4 /*yield*/, firma.Cw721.getUnsignedTxSendNft(bobWallet, cw721ContractAddress, bridgeContractAddress, token_id1, contractMsg)];
case 1:
tx1 = _a.sent();
return [4 /*yield*/, firma.Cw721.getUnsignedTxSendNft(bobWallet, cw721ContractAddress, bridgeContractAddress, token_id2, contractMsg)];
case 2:
tx2 = _a.sent();
return [4 /*yield*/, firma.Cw721.getGasEstimationSignAndBroadcast(bobWallet, [tx1, tx2])];
case 3:
gas = _a.sent();
fee = Math.ceil(gas * 0.1);
return [4 /*yield*/, firma.Cw721.signAndBroadcast(bobWallet, [tx1, tx2], { gas: gas, fee: fee })];
case 4:
result = _a.sent();
chai_1.expect(result.code).to.be.equal(0);
return [4 /*yield*/, firma.Cw721.getNFTIdListOfOwner(cw721ContractAddress, bobAddress)];
case 5:
data = _a.sent();
console.log(data);
return [2 /*return*/];
}
});
}); });
});