@saberhq/chai-solana
Advanced tools
Comparing version 1.12.17 to 1.12.18
@@ -67,3 +67,3 @@ "use strict"; | ||
const parsed = (0, solana_contrib_1.parseTransactionLogs)(logs, simulation.value.err); | ||
const fmt = (0, printInstructionLogs_1.formatInstructionLogs)(parsed); | ||
const fmt = (0, printInstructionLogs_1.formatInstructionLogsForConsole)(parsed); | ||
console.log(fmt); | ||
@@ -90,3 +90,3 @@ } | ||
} | ||
console.log(" ", simulation.value.err); | ||
console.log(" ", JSON.stringify(simulation.value.err, null, 2)); | ||
} | ||
@@ -93,0 +93,0 @@ } |
import type { InstructionLogs } from "@saberhq/solana-contrib"; | ||
import type { SendTransactionError } from "@solana/web3.js"; | ||
/** | ||
@@ -6,3 +7,4 @@ * Formats instruction logs to be printed to the console. | ||
*/ | ||
export declare const formatInstructionLogs: (logs: readonly InstructionLogs[]) => string; | ||
export declare const formatInstructionLogsForConsole: (logs: readonly InstructionLogs[]) => string; | ||
export declare const printSendTransactionError: (err: SendTransactionError) => void; | ||
//# sourceMappingURL=printInstructionLogs.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.formatInstructionLogs = void 0; | ||
exports.printSendTransactionError = exports.formatInstructionLogsForConsole = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -11,3 +11,3 @@ const solana_contrib_1 = require("@saberhq/solana-contrib"); | ||
*/ | ||
const formatInstructionLogs = (logs) => logs | ||
const formatInstructionLogsForConsole = (logs) => logs | ||
.map((log, i) => { | ||
@@ -26,3 +26,3 @@ return [ | ||
case "text": | ||
return safe_1.default.gray(entryStr); | ||
return safe_1.default.white(entryStr); | ||
case "cpi": | ||
@@ -35,3 +35,3 @@ return safe_1.default.cyan(entryStr); | ||
case "system": | ||
return safe_1.default.gray(entryStr); | ||
return safe_1.default.white(entryStr); | ||
case "success": | ||
@@ -44,3 +44,15 @@ return safe_1.default.green(entryStr); | ||
.join("\n"); | ||
exports.formatInstructionLogs = formatInstructionLogs; | ||
exports.formatInstructionLogsForConsole = formatInstructionLogsForConsole; | ||
const printSendTransactionError = (err) => { | ||
var _a; | ||
try { | ||
const parsed = (0, solana_contrib_1.parseTransactionLogs)((_a = err.logs) !== null && _a !== void 0 ? _a : null, err); | ||
console.error((0, exports.formatInstructionLogsForConsole)(parsed)); | ||
} | ||
catch (e) { | ||
console.error(`Could not parse transaction error`, e); | ||
console.error("SendTransactionError", err); | ||
} | ||
}; | ||
exports.printSendTransactionError = printSendTransactionError; | ||
//# sourceMappingURL=printInstructionLogs.js.map |
@@ -7,3 +7,5 @@ "use strict"; | ||
const solana_contrib_1 = require("@saberhq/solana-contrib"); | ||
const web3_js_1 = require("@solana/web3.js"); | ||
const chai_1 = require("chai"); | ||
const printInstructionLogs_1 = require("./printInstructionLogs"); | ||
const expectTX = (tx, msg, cb) => { | ||
@@ -33,3 +35,8 @@ const handleReceipt = (receipt) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { | ||
else { | ||
return (0, chai_1.expect)(tx === null || tx === void 0 ? void 0 : tx.send().then((res) => res.wait()).then(handleReceipt), msg).eventually; | ||
return (0, chai_1.expect)(tx === null || tx === void 0 ? void 0 : tx.send({ printLogs: false }).catch((err) => { | ||
if (err instanceof web3_js_1.SendTransactionError) { | ||
(0, printInstructionLogs_1.printSendTransactionError)(err); | ||
} | ||
throw err; | ||
}).then((res) => res.wait()).then(handleReceipt), msg).eventually; | ||
} | ||
@@ -36,0 +43,0 @@ }; |
import { parseTransactionLogs, printTXTable } from "@saberhq/solana-contrib"; | ||
import { formatInstructionLogs } from "./printInstructionLogs"; | ||
import { formatInstructionLogsForConsole } from "./printInstructionLogs"; | ||
import { expectTX } from "./utils"; | ||
@@ -64,3 +64,3 @@ /** | ||
const parsed = parseTransactionLogs(logs, simulation.value.err); | ||
const fmt = formatInstructionLogs(parsed); | ||
const fmt = formatInstructionLogsForConsole(parsed); | ||
console.log(fmt); | ||
@@ -87,3 +87,3 @@ } | ||
} | ||
console.log(" ", simulation.value.err); | ||
console.log(" ", JSON.stringify(simulation.value.err, null, 2)); | ||
} | ||
@@ -90,0 +90,0 @@ } |
import type { InstructionLogs } from "@saberhq/solana-contrib"; | ||
import type { SendTransactionError } from "@solana/web3.js"; | ||
/** | ||
@@ -6,3 +7,4 @@ * Formats instruction logs to be printed to the console. | ||
*/ | ||
export declare const formatInstructionLogs: (logs: readonly InstructionLogs[]) => string; | ||
export declare const formatInstructionLogsForConsole: (logs: readonly InstructionLogs[]) => string; | ||
export declare const printSendTransactionError: (err: SendTransactionError) => void; | ||
//# sourceMappingURL=printInstructionLogs.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { formatLogEntry } from "@saberhq/solana-contrib"; | ||
import { formatLogEntry, parseTransactionLogs } from "@saberhq/solana-contrib"; | ||
import colors from "colors/safe"; | ||
@@ -7,3 +7,3 @@ /** | ||
*/ | ||
export const formatInstructionLogs = (logs) => logs | ||
export const formatInstructionLogsForConsole = (logs) => logs | ||
.map((log, i) => { | ||
@@ -22,3 +22,3 @@ return [ | ||
case "text": | ||
return colors.gray(entryStr); | ||
return colors.white(entryStr); | ||
case "cpi": | ||
@@ -31,3 +31,3 @@ return colors.cyan(entryStr); | ||
case "system": | ||
return colors.gray(entryStr); | ||
return colors.white(entryStr); | ||
case "success": | ||
@@ -40,2 +40,13 @@ return colors.green(entryStr); | ||
.join("\n"); | ||
export const printSendTransactionError = (err) => { | ||
var _a; | ||
try { | ||
const parsed = parseTransactionLogs((_a = err.logs) !== null && _a !== void 0 ? _a : null, err); | ||
console.error(formatInstructionLogsForConsole(parsed)); | ||
} | ||
catch (e) { | ||
console.error(`Could not parse transaction error`, e); | ||
console.error("SendTransactionError", err); | ||
} | ||
}; | ||
//# sourceMappingURL=printInstructionLogs.js.map |
import { __awaiter } from "tslib"; | ||
import "chai-as-promised"; | ||
import { PendingTransaction } from "@saberhq/solana-contrib"; | ||
import { SendTransactionError } from "@solana/web3.js"; | ||
import { assert, expect } from "chai"; | ||
import { printSendTransactionError } from "./printInstructionLogs"; | ||
export const expectTX = (tx, msg, cb) => { | ||
@@ -29,3 +31,8 @@ const handleReceipt = (receipt) => __awaiter(void 0, void 0, void 0, function* () { | ||
else { | ||
return expect(tx === null || tx === void 0 ? void 0 : tx.send().then((res) => res.wait()).then(handleReceipt), msg).eventually; | ||
return expect(tx === null || tx === void 0 ? void 0 : tx.send({ printLogs: false }).catch((err) => { | ||
if (err instanceof SendTransactionError) { | ||
printSendTransactionError(err); | ||
} | ||
throw err; | ||
}).then((res) => res.wait()).then(handleReceipt), msg).eventually; | ||
} | ||
@@ -32,0 +39,0 @@ }; |
{ | ||
"name": "@saberhq/chai-solana", | ||
"version": "1.12.17", | ||
"version": "1.12.18", | ||
"description": "Solana Chai helpers", | ||
@@ -36,3 +36,3 @@ "author": "Ian Macalinao <ian@saber.so>", | ||
}, | ||
"gitHead": "9a2b6d060996c362e367790cb975ca511e217f19", | ||
"gitHead": "9c53b6e389e5a04bb854d44decc2b0d14c83fa1e", | ||
"publishConfig": { | ||
@@ -51,4 +51,4 @@ "access": "public" | ||
"@project-serum/anchor": "^0.19.1-beta.1", | ||
"@saberhq/solana-contrib": "^1.12.17", | ||
"@saberhq/token-utils": "^1.12.17", | ||
"@saberhq/solana-contrib": "^1.12.18", | ||
"@saberhq/token-utils": "^1.12.18", | ||
"@solana/web3.js": "^1.31.0", | ||
@@ -55,0 +55,0 @@ "bn.js": "^5.2.0", |
import type { TransactionEnvelope } from "@saberhq/solana-contrib"; | ||
import { parseTransactionLogs, printTXTable } from "@saberhq/solana-contrib"; | ||
import { formatInstructionLogs } from "./printInstructionLogs"; | ||
import { formatInstructionLogsForConsole } from "./printInstructionLogs"; | ||
import { expectTX } from "./utils"; | ||
@@ -95,3 +95,3 @@ | ||
const parsed = parseTransactionLogs(logs, simulation.value.err); | ||
const fmt = formatInstructionLogs(parsed); | ||
const fmt = formatInstructionLogsForConsole(parsed); | ||
console.log(fmt); | ||
@@ -124,3 +124,3 @@ } else { | ||
} | ||
console.log(" ", simulation.value.err); | ||
console.log(" ", JSON.stringify(simulation.value.err, null, 2)); | ||
} | ||
@@ -127,0 +127,0 @@ } |
import type { InstructionLogs } from "@saberhq/solana-contrib"; | ||
import { formatLogEntry } from "@saberhq/solana-contrib"; | ||
import { formatLogEntry, parseTransactionLogs } from "@saberhq/solana-contrib"; | ||
import type { SendTransactionError } from "@solana/web3.js"; | ||
import colors from "colors/safe"; | ||
@@ -9,3 +10,3 @@ | ||
*/ | ||
export const formatInstructionLogs = ( | ||
export const formatInstructionLogsForConsole = ( | ||
logs: readonly InstructionLogs[] | ||
@@ -27,3 +28,3 @@ ): string => | ||
case "text": | ||
return colors.gray(entryStr); | ||
return colors.white(entryStr); | ||
case "cpi": | ||
@@ -36,3 +37,3 @@ return colors.cyan(entryStr); | ||
case "system": | ||
return colors.gray(entryStr); | ||
return colors.white(entryStr); | ||
case "success": | ||
@@ -45,1 +46,11 @@ return colors.green(entryStr); | ||
.join("\n"); | ||
export const printSendTransactionError = (err: SendTransactionError) => { | ||
try { | ||
const parsed = parseTransactionLogs(err.logs ?? null, err); | ||
console.error(formatInstructionLogsForConsole(parsed)); | ||
} catch (e) { | ||
console.error(`Could not parse transaction error`, e); | ||
console.error("SendTransactionError", err); | ||
} | ||
}; |
@@ -9,4 +9,7 @@ import "chai-as-promised"; | ||
import { PendingTransaction } from "@saberhq/solana-contrib"; | ||
import { SendTransactionError } from "@solana/web3.js"; | ||
import { assert, expect } from "chai"; | ||
import { printSendTransactionError } from "./printInstructionLogs"; | ||
export const expectTX = ( | ||
@@ -48,3 +51,9 @@ tx: | ||
tx | ||
?.send() | ||
?.send({ printLogs: false }) | ||
.catch((err) => { | ||
if (err instanceof SendTransactionError) { | ||
printSendTransactionError(err); | ||
} | ||
throw err; | ||
}) | ||
.then((res) => res.wait()) | ||
@@ -51,0 +60,0 @@ .then(handleReceipt), |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
128333
1282