@saberhq/chai-solana
Advanced tools
Comparing version 1.13.16 to 1.13.17
@@ -28,3 +28,3 @@ import type { IdlErrorCode } from "@project-serum/anchor/dist/cjs/idl"; | ||
*/ | ||
export declare const expectTXTable: (tx: TransactionEnvelope, msg?: string | undefined, { verbosity, formatLogs, }?: { | ||
export declare const expectTXTable: (tx: TransactionEnvelope, msg?: string, { verbosity, formatLogs, }?: { | ||
/** | ||
@@ -46,3 +46,3 @@ * Logging verbosity. | ||
*/ | ||
export declare const assertTXSuccess: (tx: TransactionEnvelope, msg?: string | undefined) => Chai.PromisedAssertion; | ||
export declare const assertTXSuccess: (tx: TransactionEnvelope, msg?: string) => Chai.PromisedAssertion; | ||
/** | ||
@@ -54,3 +54,3 @@ * Assert that a transaction will throw the given error. | ||
*/ | ||
export declare const assertTXThrows: (tx: TransactionEnvelope, err: IdlErrorCode, msg?: string | undefined) => Chai.PromisedAssertion; | ||
export declare const assertTXThrows: (tx: TransactionEnvelope, err: IdlErrorCode, msg?: string) => Chai.PromisedAssertion; | ||
/** | ||
@@ -62,3 +62,3 @@ * Assert that a transaction will throw the given error. | ||
*/ | ||
export declare const assertTXThrowsCode: (tx: TransactionEnvelope, code: number, msg?: string | undefined) => Chai.PromisedAssertion; | ||
export declare const assertTXThrowsCode: (tx: TransactionEnvelope, code: number, msg?: string) => Chai.PromisedAssertion; | ||
//# sourceMappingURL=expectTXTable.d.ts.map |
@@ -43,10 +43,10 @@ "use strict"; | ||
const printSendTransactionError = (err) => { | ||
var _a; | ||
var _a, _b; | ||
try { | ||
const parsed = (0, solana_contrib_1.parseTransactionLogs)((_a = err.logs) !== null && _a !== void 0 ? _a : null, err); | ||
console.error((0, exports.formatInstructionLogsForConsole)(parsed)); | ||
console.log((0, exports.formatInstructionLogsForConsole)(parsed)); | ||
} | ||
catch (e) { | ||
console.error(`Could not parse transaction error`, e); | ||
console.error("SendTransactionError", err); | ||
console.warn(safe_1.default.yellow("Could not print logs due to error. Printing raw logs"), e); | ||
console.log((_b = err.logs) === null || _b === void 0 ? void 0 : _b.join("\n")); | ||
} | ||
@@ -53,0 +53,0 @@ }; |
import "chai-as-promised"; | ||
import type { Idl } from "@project-serum/anchor"; | ||
import type { TransactionEnvelope, TransactionReceipt } from "@saberhq/solana-contrib"; | ||
import { PendingTransaction } from "@saberhq/solana-contrib"; | ||
export declare const expectTX: (tx: TransactionEnvelope | null | Promise<TransactionEnvelope | null> | PendingTransaction | Promise<PendingTransaction>, msg?: string | undefined, cb?: ((receipt: TransactionReceipt) => Promise<void>) | undefined) => Chai.PromisedAssertion; | ||
import type { PromiseOrValue, TransactionLike, TransactionReceipt } from "@saberhq/solana-contrib"; | ||
/** | ||
* Processes a transaction, expecting rejection or fulfillment. | ||
* | ||
* @param tx | ||
* @param msg | ||
* @param cb | ||
* @returns | ||
*/ | ||
export declare const expectTX: (tx: PromiseOrValue<TransactionLike | null>, msg?: string, cb?: ((receipt: TransactionReceipt) => Promise<void>) | undefined) => Chai.PromisedAssertion; | ||
export declare type IDLError = NonNullable<Idl["errors"]>[number]; | ||
export declare const assertError: (error: IDLError, other: IDLError) => void; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -7,23 +7,10 @@ "use strict"; | ||
const chai_1 = require("chai"); | ||
const printInstructionLogs_1 = require("./printInstructionLogs"); | ||
const processTX = async (tx) => { | ||
if (tx instanceof solana_contrib_1.PendingTransaction) { | ||
return await tx.wait(); | ||
} | ||
else if (tx) { | ||
try { | ||
const pending = await tx.send({ printLogs: false }); | ||
return await pending.wait(); | ||
} | ||
catch (err) { | ||
if (err && err instanceof Error && "logs" in err) { | ||
(0, printInstructionLogs_1.printSendTransactionError)(err); | ||
} | ||
throw err; | ||
} | ||
} | ||
else { | ||
throw new Error("tx is null"); | ||
} | ||
}; | ||
/** | ||
* Processes a transaction, expecting rejection or fulfillment. | ||
* | ||
* @param tx | ||
* @param msg | ||
* @param cb | ||
* @returns | ||
*/ | ||
const expectTX = (tx, msg, cb) => { | ||
@@ -35,9 +22,18 @@ const handleReceipt = async (receipt) => { | ||
if (tx && "then" in tx) { | ||
return (0, chai_1.expect)(tx.then(processTX).then(handleReceipt), msg).eventually; | ||
return (0, chai_1.expect)(tx | ||
.then(async (v) => { | ||
if (v === null) { | ||
throw new Error("transaction is null"); | ||
} | ||
return await (0, solana_contrib_1.confirmTransactionLike)(v); | ||
}) | ||
.then(handleReceipt), msg).eventually; | ||
} | ||
if (tx instanceof solana_contrib_1.PendingTransaction) { | ||
return (0, chai_1.expect)(tx.wait().then(handleReceipt), msg).eventually; | ||
else if (tx) { | ||
return (0, chai_1.expect)((0, solana_contrib_1.confirmTransactionLike)(tx).then(handleReceipt), msg) | ||
.eventually; | ||
} | ||
else { | ||
return (0, chai_1.expect)(processTX(tx).then(handleReceipt), msg).eventually; | ||
return (0, chai_1.expect)(Promise.reject(new Error("transaction is null")), msg) | ||
.eventually; | ||
} | ||
@@ -44,0 +40,0 @@ }; |
@@ -28,3 +28,3 @@ import type { IdlErrorCode } from "@project-serum/anchor/dist/cjs/idl"; | ||
*/ | ||
export declare const expectTXTable: (tx: TransactionEnvelope, msg?: string | undefined, { verbosity, formatLogs, }?: { | ||
export declare const expectTXTable: (tx: TransactionEnvelope, msg?: string, { verbosity, formatLogs, }?: { | ||
/** | ||
@@ -46,3 +46,3 @@ * Logging verbosity. | ||
*/ | ||
export declare const assertTXSuccess: (tx: TransactionEnvelope, msg?: string | undefined) => Chai.PromisedAssertion; | ||
export declare const assertTXSuccess: (tx: TransactionEnvelope, msg?: string) => Chai.PromisedAssertion; | ||
/** | ||
@@ -54,3 +54,3 @@ * Assert that a transaction will throw the given error. | ||
*/ | ||
export declare const assertTXThrows: (tx: TransactionEnvelope, err: IdlErrorCode, msg?: string | undefined) => Chai.PromisedAssertion; | ||
export declare const assertTXThrows: (tx: TransactionEnvelope, err: IdlErrorCode, msg?: string) => Chai.PromisedAssertion; | ||
/** | ||
@@ -62,3 +62,3 @@ * Assert that a transaction will throw the given error. | ||
*/ | ||
export declare const assertTXThrowsCode: (tx: TransactionEnvelope, code: number, msg?: string | undefined) => Chai.PromisedAssertion; | ||
export declare const assertTXThrowsCode: (tx: TransactionEnvelope, code: number, msg?: string) => Chai.PromisedAssertion; | ||
//# sourceMappingURL=expectTXTable.d.ts.map |
@@ -38,12 +38,12 @@ import { formatLogEntry, parseTransactionLogs } from "@saberhq/solana-contrib"; | ||
export const printSendTransactionError = (err) => { | ||
var _a; | ||
var _a, _b; | ||
try { | ||
const parsed = parseTransactionLogs((_a = err.logs) !== null && _a !== void 0 ? _a : null, err); | ||
console.error(formatInstructionLogsForConsole(parsed)); | ||
console.log(formatInstructionLogsForConsole(parsed)); | ||
} | ||
catch (e) { | ||
console.error(`Could not parse transaction error`, e); | ||
console.error("SendTransactionError", err); | ||
console.warn(colors.yellow("Could not print logs due to error. Printing raw logs"), e); | ||
console.log((_b = err.logs) === null || _b === void 0 ? void 0 : _b.join("\n")); | ||
} | ||
}; | ||
//# sourceMappingURL=printInstructionLogs.js.map |
import "chai-as-promised"; | ||
import type { Idl } from "@project-serum/anchor"; | ||
import type { TransactionEnvelope, TransactionReceipt } from "@saberhq/solana-contrib"; | ||
import { PendingTransaction } from "@saberhq/solana-contrib"; | ||
export declare const expectTX: (tx: TransactionEnvelope | null | Promise<TransactionEnvelope | null> | PendingTransaction | Promise<PendingTransaction>, msg?: string | undefined, cb?: ((receipt: TransactionReceipt) => Promise<void>) | undefined) => Chai.PromisedAssertion; | ||
import type { PromiseOrValue, TransactionLike, TransactionReceipt } from "@saberhq/solana-contrib"; | ||
/** | ||
* Processes a transaction, expecting rejection or fulfillment. | ||
* | ||
* @param tx | ||
* @param msg | ||
* @param cb | ||
* @returns | ||
*/ | ||
export declare const expectTX: (tx: PromiseOrValue<TransactionLike | null>, msg?: string, cb?: ((receipt: TransactionReceipt) => Promise<void>) | undefined) => Chai.PromisedAssertion; | ||
export declare type IDLError = NonNullable<Idl["errors"]>[number]; | ||
export declare const assertError: (error: IDLError, other: IDLError) => void; | ||
//# sourceMappingURL=utils.d.ts.map |
import "chai-as-promised"; | ||
import { PendingTransaction } from "@saberhq/solana-contrib"; | ||
import { confirmTransactionLike } from "@saberhq/solana-contrib"; | ||
import { assert, expect } from "chai"; | ||
import { printSendTransactionError } from "./printInstructionLogs"; | ||
const processTX = async (tx) => { | ||
if (tx instanceof PendingTransaction) { | ||
return await tx.wait(); | ||
} | ||
else if (tx) { | ||
try { | ||
const pending = await tx.send({ printLogs: false }); | ||
return await pending.wait(); | ||
} | ||
catch (err) { | ||
if (err && err instanceof Error && "logs" in err) { | ||
printSendTransactionError(err); | ||
} | ||
throw err; | ||
} | ||
} | ||
else { | ||
throw new Error("tx is null"); | ||
} | ||
}; | ||
/** | ||
* Processes a transaction, expecting rejection or fulfillment. | ||
* | ||
* @param tx | ||
* @param msg | ||
* @param cb | ||
* @returns | ||
*/ | ||
export const expectTX = (tx, msg, cb) => { | ||
@@ -31,9 +18,18 @@ const handleReceipt = async (receipt) => { | ||
if (tx && "then" in tx) { | ||
return expect(tx.then(processTX).then(handleReceipt), msg).eventually; | ||
return expect(tx | ||
.then(async (v) => { | ||
if (v === null) { | ||
throw new Error("transaction is null"); | ||
} | ||
return await confirmTransactionLike(v); | ||
}) | ||
.then(handleReceipt), msg).eventually; | ||
} | ||
if (tx instanceof PendingTransaction) { | ||
return expect(tx.wait().then(handleReceipt), msg).eventually; | ||
else if (tx) { | ||
return expect(confirmTransactionLike(tx).then(handleReceipt), msg) | ||
.eventually; | ||
} | ||
else { | ||
return expect(processTX(tx).then(handleReceipt), msg).eventually; | ||
return expect(Promise.reject(new Error("transaction is null")), msg) | ||
.eventually; | ||
} | ||
@@ -40,0 +36,0 @@ }; |
{ | ||
"name": "@saberhq/chai-solana", | ||
"version": "1.13.16", | ||
"version": "1.13.17", | ||
"description": "Solana Chai helpers", | ||
@@ -27,5 +27,5 @@ "author": "Ian Macalinao <ian@saber.so>", | ||
"dependencies": { | ||
"@saberhq/anchor-contrib": "^1.13.16", | ||
"@saberhq/solana-contrib": "^1.13.16", | ||
"@saberhq/token-utils": "^1.13.16", | ||
"@saberhq/anchor-contrib": "^1.13.17", | ||
"@saberhq/solana-contrib": "^1.13.17", | ||
"@saberhq/token-utils": "^1.13.17", | ||
"@types/chai": "^4.3.1", | ||
@@ -53,6 +53,6 @@ "@types/chai-as-promised": "^7.1.5", | ||
"@solana/web3.js": "^1.43.1", | ||
"bn.js": "^5.2.0", | ||
"bn.js": "^5.2.1", | ||
"jsbi": "^4.3.0", | ||
"typescript": "^4.6.4" | ||
"typescript": "^4.7.2" | ||
} | ||
} |
@@ -47,7 +47,10 @@ import type { InstructionLogs } from "@saberhq/solana-contrib"; | ||
const parsed = parseTransactionLogs(err.logs ?? null, err); | ||
console.error(formatInstructionLogsForConsole(parsed)); | ||
console.log(formatInstructionLogsForConsole(parsed)); | ||
} catch (e) { | ||
console.error(`Could not parse transaction error`, e); | ||
console.error("SendTransactionError", err); | ||
console.warn( | ||
colors.yellow("Could not print logs due to error. Printing raw logs"), | ||
e | ||
); | ||
console.log(err.logs?.join("\n")); | ||
} | ||
}; |
@@ -5,38 +5,19 @@ import "chai-as-promised"; | ||
import type { | ||
TransactionEnvelope, | ||
PromiseOrValue, | ||
TransactionLike, | ||
TransactionReceipt, | ||
} from "@saberhq/solana-contrib"; | ||
import { PendingTransaction } from "@saberhq/solana-contrib"; | ||
import type { SendTransactionError } from "@solana/web3.js"; | ||
import { confirmTransactionLike } from "@saberhq/solana-contrib"; | ||
import { assert, expect } from "chai"; | ||
import { printSendTransactionError } from "./printInstructionLogs"; | ||
const processTX = async ( | ||
tx: TransactionEnvelope | PendingTransaction | null | ||
): Promise<TransactionReceipt> => { | ||
if (tx instanceof PendingTransaction) { | ||
return await tx.wait(); | ||
} else if (tx) { | ||
try { | ||
const pending = await tx.send({ printLogs: false }); | ||
return await pending.wait(); | ||
} catch (err) { | ||
if (err && err instanceof Error && "logs" in err) { | ||
printSendTransactionError(err as SendTransactionError); | ||
} | ||
throw err; | ||
} | ||
} else { | ||
throw new Error("tx is null"); | ||
} | ||
}; | ||
/** | ||
* Processes a transaction, expecting rejection or fulfillment. | ||
* | ||
* @param tx | ||
* @param msg | ||
* @param cb | ||
* @returns | ||
*/ | ||
export const expectTX = ( | ||
tx: | ||
| TransactionEnvelope | ||
| null | ||
| Promise<TransactionEnvelope | null> | ||
| PendingTransaction | ||
| Promise<PendingTransaction>, | ||
tx: PromiseOrValue<TransactionLike | null>, | ||
msg?: string, | ||
@@ -51,8 +32,19 @@ cb?: (receipt: TransactionReceipt) => Promise<void> | ||
if (tx && "then" in tx) { | ||
return expect(tx.then(processTX).then(handleReceipt), msg).eventually; | ||
} | ||
if (tx instanceof PendingTransaction) { | ||
return expect(tx.wait().then(handleReceipt), msg).eventually; | ||
return expect( | ||
tx | ||
.then(async (v) => { | ||
if (v === null) { | ||
throw new Error("transaction is null"); | ||
} | ||
return await confirmTransactionLike(v); | ||
}) | ||
.then(handleReceipt), | ||
msg | ||
).eventually; | ||
} else if (tx) { | ||
return expect(confirmTransactionLike(tx).then(handleReceipt), msg) | ||
.eventually; | ||
} else { | ||
return expect(processTX(tx).then(handleReceipt), msg).eventually; | ||
return expect(Promise.reject(new Error("transaction is null")), msg) | ||
.eventually; | ||
} | ||
@@ -59,0 +51,0 @@ }; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1437
150071