errors.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. import * as anchor from "@project-serum/anchor";
  2. import { Program, AnchorError } from "@project-serum/anchor";
  3. import { Keypair, Transaction, TransactionInstruction } from "@solana/web3.js";
  4. import { TOKEN_PROGRAM_ID, Token } from "@solana/spl-token";
  5. import { assert, expect } from "chai";
  6. import { Errors } from "../target/types/errors";
  7. const withLogTest = async (callback, expectedLogs) => {
  8. let logTestOk = false;
  9. const listener = anchor.getProvider().connection.onLogs(
  10. "all",
  11. (logs) => {
  12. const index = logs.logs.findIndex(
  13. (logLine) => logLine === expectedLogs[0]
  14. );
  15. if (index === -1) {
  16. console.log("Expected: ");
  17. console.log(expectedLogs);
  18. console.log("Actual: ");
  19. console.log(logs);
  20. } else {
  21. const actualLogs = logs.logs.slice(index, index + expectedLogs.length);
  22. for (let i = 0; i < expectedLogs.length; i++) {
  23. if (actualLogs[i] !== expectedLogs[i]) {
  24. console.log("Expected: ");
  25. console.log(expectedLogs);
  26. console.log("Actual: ");
  27. console.log(logs);
  28. return;
  29. }
  30. }
  31. logTestOk = true;
  32. }
  33. },
  34. "recent"
  35. );
  36. try {
  37. await callback();
  38. } catch (err) {
  39. anchor.getProvider().connection.removeOnLogsListener(listener);
  40. throw err;
  41. }
  42. anchor.getProvider().connection.removeOnLogsListener(listener);
  43. assert.isTrue(logTestOk);
  44. };
  45. describe("errors", () => {
  46. // Configure the client to use the local cluster.
  47. const provider = anchor.AnchorProvider.local();
  48. provider.opts.skipPreflight = true;
  49. // processed failed tx do not result in AnchorErrors in the client
  50. // because we cannot get logs for them (only through overkill `onLogs`)
  51. provider.opts.commitment = "confirmed";
  52. anchor.setProvider(provider);
  53. const program = anchor.workspace.Errors as Program<Errors>;
  54. it("Emits a Hello error", async () => {
  55. await withLogTest(async () => {
  56. try {
  57. const tx = await program.methods.hello().rpc();
  58. assert.ok(false);
  59. } catch (_err) {
  60. assert.isTrue(_err instanceof AnchorError);
  61. const err: AnchorError = _err;
  62. const errMsg =
  63. "This is an error message clients will automatically display";
  64. const fullErrMsg =
  65. "AnchorError thrown in programs/errors/src/lib.rs:13. Error Code: Hello. Error Number: 6000. Error Message: This is an error message clients will automatically display.";
  66. assert.strictEqual(err.toString(), fullErrMsg);
  67. assert.strictEqual(err.error.errorMessage, errMsg);
  68. assert.strictEqual(err.error.errorCode.number, 6000);
  69. assert.strictEqual(
  70. err.program.toString(),
  71. program.programId.toString()
  72. );
  73. expect(err.error.origin).to.deep.equal({
  74. file: "programs/errors/src/lib.rs",
  75. line: 13,
  76. });
  77. }
  78. }, [
  79. "Program log: AnchorError thrown in programs/errors/src/lib.rs:13. Error Code: Hello. Error Number: 6000. Error Message: This is an error message clients will automatically display.",
  80. ]);
  81. });
  82. it("Emits a Hello error via require!", async () => {
  83. try {
  84. const tx = await program.methods.testRequire().rpc();
  85. assert.ok(false);
  86. } catch (_err) {
  87. assert.isTrue(_err instanceof AnchorError);
  88. const err: AnchorError = _err;
  89. const errMsg =
  90. "This is an error message clients will automatically display";
  91. assert.strictEqual(err.error.errorMessage, errMsg);
  92. assert.strictEqual(err.error.errorCode.number, 6000);
  93. assert.strictEqual(err.error.errorCode.code, "Hello");
  94. }
  95. });
  96. it("Emits a Hello error via err!", async () => {
  97. try {
  98. const tx = await program.methods.testErr().rpc();
  99. assert.ok(false);
  100. } catch (_err) {
  101. assert.isTrue(_err instanceof AnchorError);
  102. const err: AnchorError = _err;
  103. const errMsg =
  104. "This is an error message clients will automatically display";
  105. assert.strictEqual(err.error.errorMessage, errMsg);
  106. assert.strictEqual(err.error.errorCode.number, 6000);
  107. }
  108. });
  109. it("Logs a ProgramError", async () => {
  110. await withLogTest(async () => {
  111. try {
  112. const tx = await program.methods.testProgramError().rpc();
  113. assert.ok(false);
  114. } catch (err) {
  115. expect(err.programErrorStack.map((pk) => pk.toString())).to.deep.equal([
  116. program.programId.toString(),
  117. ]);
  118. expect(err.program.toString()).to.equal(program.programId.toString());
  119. }
  120. }, [
  121. "Program log: ProgramError occurred. Error Code: InvalidAccountData. Error Number: 17179869184. Error Message: An account's data contents was invalid.",
  122. ]);
  123. });
  124. it("Logs a ProgramError with source", async () => {
  125. await withLogTest(async () => {
  126. try {
  127. const tx = await program.methods.testProgramErrorWithSource().rpc();
  128. assert.ok(false);
  129. } catch (err) {
  130. expect(err.programErrorStack.map((pk) => pk.toString())).to.deep.equal([
  131. program.programId.toString(),
  132. ]);
  133. }
  134. }, [
  135. "Program log: ProgramError thrown in programs/errors/src/lib.rs:38. Error Code: InvalidAccountData. Error Number: 17179869184. Error Message: An account's data contents was invalid.",
  136. ]);
  137. });
  138. it("Emits a HelloNoMsg error", async () => {
  139. try {
  140. const tx = await program.methods.helloNoMsg().rpc();
  141. assert.ok(false);
  142. } catch (_err) {
  143. assert.isTrue(_err instanceof AnchorError);
  144. const err: AnchorError = _err;
  145. assert.strictEqual(err.error.errorMessage, "HelloNoMsg");
  146. assert.strictEqual(err.error.errorCode.number, 6123);
  147. }
  148. });
  149. it("Emits a HelloNext error", async () => {
  150. try {
  151. const tx = await program.methods.helloNext().rpc();
  152. assert.ok(false);
  153. } catch (_err) {
  154. assert.isTrue(_err instanceof AnchorError);
  155. const err: AnchorError = _err;
  156. assert.strictEqual(err.error.errorMessage, "HelloNext");
  157. assert.strictEqual(err.error.errorCode.number, 6124);
  158. }
  159. });
  160. it("Emits a mut error", async () => {
  161. await withLogTest(async () => {
  162. try {
  163. const tx = await program.rpc.mutError({
  164. accounts: {
  165. myAccount: anchor.web3.SYSVAR_RENT_PUBKEY,
  166. },
  167. });
  168. assert.ok(false);
  169. } catch (_err) {
  170. assert.isTrue(_err instanceof AnchorError);
  171. const err: AnchorError = _err;
  172. assert.strictEqual(
  173. err.error.errorMessage,
  174. "A mut constraint was violated"
  175. );
  176. assert.strictEqual(err.error.errorCode.number, 2000);
  177. assert.strictEqual(err.error.origin, "my_account");
  178. }
  179. }, [
  180. "Program log: AnchorError caused by account: my_account. Error Code: ConstraintMut. Error Number: 2000. Error Message: A mut constraint was violated.",
  181. ]);
  182. });
  183. it("Emits a has one error", async () => {
  184. await withLogTest(async () => {
  185. try {
  186. const account = new Keypair();
  187. const tx = await program.rpc.hasOneError({
  188. accounts: {
  189. myAccount: account.publicKey,
  190. owner: anchor.web3.SYSVAR_RENT_PUBKEY,
  191. },
  192. // this initializes the account.owner variable with Pubkey::default
  193. instructions: [
  194. await program.account.hasOneAccount.createInstruction(account),
  195. ],
  196. signers: [account],
  197. });
  198. assert.ok(false);
  199. } catch (_err) {
  200. assert.isTrue(_err instanceof AnchorError);
  201. const err: AnchorError = _err;
  202. assert.strictEqual(
  203. err.error.errorMessage,
  204. "A has one constraint was violated"
  205. );
  206. assert.strictEqual(err.error.errorCode.number, 2001);
  207. assert.strictEqual(err.error.errorCode.code, "ConstraintHasOne");
  208. assert.strictEqual(err.error.origin, "my_account");
  209. assert.strictEqual(
  210. err.program.toString(),
  211. program.programId.toString()
  212. );
  213. expect(
  214. err.error.comparedValues.map((pk) => pk.toString())
  215. ).to.deep.equal([
  216. "11111111111111111111111111111111",
  217. "SysvarRent111111111111111111111111111111111",
  218. ]);
  219. }
  220. }, [
  221. "Program log: AnchorError caused by account: my_account. Error Code: ConstraintHasOne. Error Number: 2001. Error Message: A has one constraint was violated.",
  222. "Program log: Left:",
  223. "Program log: 11111111111111111111111111111111",
  224. "Program log: Right:",
  225. "Program log: SysvarRent111111111111111111111111111111111",
  226. ]);
  227. });
  228. // This test uses a raw transaction and provider instead of a program
  229. // instance since the client won't allow one to send a transaction
  230. // with an invalid signer account.
  231. it("Emits a signer error", async () => {
  232. let signature;
  233. const listener = anchor
  234. .getProvider()
  235. .connection.onLogs("all", (logs) => (signature = logs.signature));
  236. try {
  237. const tx = new Transaction();
  238. tx.add(
  239. new TransactionInstruction({
  240. keys: [
  241. {
  242. pubkey: anchor.web3.SYSVAR_RENT_PUBKEY,
  243. isWritable: false,
  244. isSigner: false,
  245. },
  246. ],
  247. programId: program.programId,
  248. data: program.coder.instruction.encode("signer_error", {}),
  249. })
  250. );
  251. await program.provider.sendAndConfirm(tx);
  252. assert.ok(false);
  253. } catch (err) {
  254. anchor.getProvider().connection.removeOnLogsListener(listener);
  255. const errMsg = `Error: Raw transaction ${signature} failed ({"err":{"InstructionError":[0,{"Custom":3010}]}})`;
  256. assert.strictEqual(err.toString(), errMsg);
  257. } finally {
  258. anchor.getProvider().connection.removeOnLogsListener(listener);
  259. }
  260. });
  261. it("Emits a raw custom error", async () => {
  262. try {
  263. const tx = await program.rpc.rawCustomError({
  264. accounts: {
  265. myAccount: anchor.web3.SYSVAR_RENT_PUBKEY,
  266. },
  267. });
  268. assert.ok(false);
  269. } catch (_err) {
  270. assert.isTrue(_err instanceof AnchorError);
  271. const err: AnchorError = _err;
  272. const errMsg = "HelloCustom";
  273. assert.strictEqual(err.error.errorMessage, errMsg);
  274. assert.strictEqual(err.error.errorCode.number, 6125);
  275. }
  276. });
  277. it("Emits a account not initialized error", async () => {
  278. await withLogTest(async () => {
  279. try {
  280. const tx = await program.rpc.accountNotInitializedError({
  281. accounts: {
  282. notInitializedAccount: new anchor.web3.Keypair().publicKey,
  283. },
  284. });
  285. assert.fail(
  286. "Unexpected success in creating a transaction that should have fail with `AccountNotInitialized` error"
  287. );
  288. } catch (_err) {
  289. assert.isTrue(_err instanceof AnchorError);
  290. const err: AnchorError = _err;
  291. const errMsg =
  292. "The program expected this account to be already initialized";
  293. assert.strictEqual(err.error.errorMessage, errMsg);
  294. }
  295. }, [
  296. "Program log: AnchorError caused by account: not_initialized_account. Error Code: AccountNotInitialized. Error Number: 3012. Error Message: The program expected this account to be already initialized.",
  297. ]);
  298. });
  299. it("Emits an AccountOwnedByWrongProgram error", async () => {
  300. let client = await Token.createMint(
  301. program.provider.connection,
  302. (provider.wallet as anchor.Wallet).payer,
  303. provider.wallet.publicKey,
  304. provider.wallet.publicKey,
  305. 9,
  306. TOKEN_PROGRAM_ID
  307. );
  308. await withLogTest(async () => {
  309. try {
  310. const tx = await program.rpc.accountOwnedByWrongProgramError({
  311. accounts: {
  312. wrongAccount: client.publicKey,
  313. },
  314. });
  315. assert.fail(
  316. "Unexpected success in creating a transaction that should have failed with `AccountOwnedByWrongProgram` error"
  317. );
  318. } catch (_err) {
  319. assert.isTrue(_err instanceof AnchorError);
  320. const err: AnchorError = _err;
  321. const errMsg =
  322. "The given account is owned by a different program than expected";
  323. assert.strictEqual(err.error.errorMessage, errMsg);
  324. }
  325. }, [
  326. "Program log: AnchorError caused by account: wrong_account. Error Code: AccountOwnedByWrongProgram. Error Number: 3007. Error Message: The given account is owned by a different program than expected.",
  327. "Program log: Left:",
  328. "Program log: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
  329. "Program log: Right:",
  330. "Program log: Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS",
  331. ]);
  332. });
  333. it("Emits a ValueMismatch error via require_eq", async () => {
  334. await withLogTest(async () => {
  335. try {
  336. const tx = await program.methods.requireEq().rpc();
  337. assert.fail(
  338. "Unexpected success in creating a transaction that should have failed with `ValueMismatch` error"
  339. );
  340. } catch (_err) {
  341. assert.isTrue(_err instanceof AnchorError);
  342. const err: AnchorError = _err;
  343. assert.strictEqual(err.error.errorCode.number, 6126);
  344. expect(err.error.comparedValues).to.deep.equal(["5241", "124124124"]);
  345. }
  346. }, [
  347. "Program log: AnchorError thrown in programs/errors/src/lib.rs:68. Error Code: ValueMismatch. Error Number: 6126. Error Message: ValueMismatch.",
  348. "Program log: Left: 5241",
  349. "Program log: Right: 124124124",
  350. ]);
  351. });
  352. it("Emits a RequireEqViolated error via require_eq", async () => {
  353. await withLogTest(async () => {
  354. try {
  355. const tx = await program.methods.requireEqDefaultError().rpc();
  356. assert.fail(
  357. "Unexpected success in creating a transaction that should have failed with `ValueMismatch` error"
  358. );
  359. } catch (_err) {
  360. assert.isTrue(_err instanceof AnchorError);
  361. const err: AnchorError = _err;
  362. assert.strictEqual(err.error.errorCode.number, 2501);
  363. }
  364. }, [
  365. "Program log: AnchorError thrown in programs/errors/src/lib.rs:73. Error Code: RequireEqViolated. Error Number: 2501. Error Message: A require_eq expression was violated.",
  366. "Program log: Left: 5241",
  367. "Program log: Right: 124124124",
  368. ]);
  369. });
  370. it("Emits a ValueMatch error via require_neq", async () => {
  371. await withLogTest(async () => {
  372. try {
  373. const tx = await program.methods.requireNeq().rpc();
  374. assert.fail(
  375. "Unexpected success in creating a transaction that should have failed with `ValueMatch` error"
  376. );
  377. } catch (_err) {
  378. assert.isTrue(_err instanceof AnchorError);
  379. const err: AnchorError = _err;
  380. assert.strictEqual(err.error.errorCode.number, 6127);
  381. }
  382. }, [
  383. "Program log: AnchorError thrown in programs/errors/src/lib.rs:78. Error Code: ValueMatch. Error Number: 6127. Error Message: ValueMatch.",
  384. "Program log: Left: 500",
  385. "Program log: Right: 500",
  386. ]);
  387. });
  388. it("Emits a RequireNeqViolated error via require_neq", async () => {
  389. await withLogTest(async () => {
  390. try {
  391. const tx = await program.methods.requireNeqDefaultError().rpc();
  392. assert.fail(
  393. "Unexpected success in creating a transaction that should have failed with `RequireNeqViolated` error"
  394. );
  395. } catch (_err) {
  396. assert.isTrue(_err instanceof AnchorError);
  397. const err: AnchorError = _err;
  398. assert.strictEqual(err.error.errorCode.number, 2503);
  399. }
  400. }, [
  401. "Program log: AnchorError thrown in programs/errors/src/lib.rs:83. Error Code: RequireNeqViolated. Error Number: 2503. Error Message: A require_neq expression was violated.",
  402. "Program log: Left: 500",
  403. "Program log: Right: 500",
  404. ]);
  405. });
  406. it("Emits a ValueMismatch error via require_keys_eq", async () => {
  407. const someAccount = anchor.web3.Keypair.generate().publicKey;
  408. await withLogTest(async () => {
  409. try {
  410. const tx = await program.rpc.requireKeysEq({
  411. accounts: {
  412. someAccount,
  413. },
  414. });
  415. assert.fail(
  416. "Unexpected success in creating a transaction that should have failed with `ValueMismatch` error"
  417. );
  418. } catch (_err) {
  419. assert.isTrue(_err instanceof AnchorError);
  420. const err: AnchorError = _err;
  421. assert.strictEqual(err.error.errorCode.number, 6126);
  422. }
  423. }, [
  424. "Program log: AnchorError thrown in programs/errors/src/lib.rs:88. Error Code: ValueMismatch. Error Number: 6126. Error Message: ValueMismatch.",
  425. "Program log: Left:",
  426. `Program log: ${someAccount}`,
  427. "Program log: Right:",
  428. `Program log: ${program.programId}`,
  429. ]);
  430. });
  431. it("Emits a RequireKeysEqViolated error via require_keys_eq", async () => {
  432. const someAccount = anchor.web3.Keypair.generate().publicKey;
  433. await withLogTest(async () => {
  434. try {
  435. const tx = await program.rpc.requireKeysEqDefaultError({
  436. accounts: {
  437. someAccount,
  438. },
  439. });
  440. assert.fail(
  441. "Unexpected success in creating a transaction that should have failed with `ValueMismatch` error"
  442. );
  443. } catch (_err) {
  444. assert.isTrue(_err instanceof AnchorError);
  445. const err: AnchorError = _err;
  446. assert.strictEqual(err.error.errorCode.number, 2502);
  447. }
  448. }, [
  449. "Program log: AnchorError thrown in programs/errors/src/lib.rs:97. Error Code: RequireKeysEqViolated. Error Number: 2502. Error Message: A require_keys_eq expression was violated.",
  450. "Program log: Left:",
  451. `Program log: ${someAccount}`,
  452. "Program log: Right:",
  453. `Program log: ${program.programId}`,
  454. ]);
  455. });
  456. it("Emits a ValueMatch error via require_keys_neq", async () => {
  457. const someAccount = program.programId;
  458. await withLogTest(async () => {
  459. try {
  460. const tx = await program.rpc.requireKeysNeq({
  461. accounts: {
  462. someAccount,
  463. },
  464. });
  465. assert.fail(
  466. "Unexpected success in creating a transaction that should have failed with `ValueMatch` error"
  467. );
  468. } catch (_err) {
  469. assert.isTrue(_err instanceof AnchorError);
  470. const err: AnchorError = _err;
  471. assert.strictEqual(err.error.errorCode.number, 6127);
  472. }
  473. }, [
  474. "Program log: AnchorError thrown in programs/errors/src/lib.rs:102. Error Code: ValueMatch. Error Number: 6127. Error Message: ValueMatch.",
  475. "Program log: Left:",
  476. `Program log: ${someAccount}`,
  477. "Program log: Right:",
  478. `Program log: ${program.programId}`,
  479. ]);
  480. });
  481. it("Emits a RequireKeysNeqViolated error via require_keys_neq", async () => {
  482. const someAccount = program.programId;
  483. await withLogTest(async () => {
  484. try {
  485. const tx = await program.rpc.requireKeysNeqDefaultError({
  486. accounts: {
  487. someAccount,
  488. },
  489. });
  490. assert.fail(
  491. "Unexpected success in creating a transaction that should have failed with `RequireKeysNeqViolated` error"
  492. );
  493. } catch (_err) {
  494. assert.isTrue(_err instanceof AnchorError);
  495. const err: AnchorError = _err;
  496. assert.strictEqual(err.error.errorCode.number, 2504);
  497. }
  498. }, [
  499. "Program log: AnchorError thrown in programs/errors/src/lib.rs:111. Error Code: RequireKeysNeqViolated. Error Number: 2504. Error Message: A require_keys_neq expression was violated.",
  500. "Program log: Left:",
  501. `Program log: ${someAccount}`,
  502. "Program log: Right:",
  503. `Program log: ${program.programId}`,
  504. ]);
  505. });
  506. it("Emits a ValueLessOrEqual error via require_gt", async () => {
  507. await withLogTest(async () => {
  508. try {
  509. const tx = await program.methods.requireGt().rpc();
  510. assert.fail(
  511. "Unexpected success in creating a transaction that should have failed with `ValueLessOrEqual` error"
  512. );
  513. } catch (_err) {
  514. assert.isTrue(_err instanceof AnchorError);
  515. const err: AnchorError = _err;
  516. assert.strictEqual(err.error.errorCode.number, 6129);
  517. }
  518. }, [
  519. "Program log: AnchorError thrown in programs/errors/src/lib.rs:116. Error Code: ValueLessOrEqual. Error Number: 6129. Error Message: ValueLessOrEqual.",
  520. "Program log: Left: 5",
  521. "Program log: Right: 10",
  522. ]);
  523. });
  524. it("Emits a RequireGtViolated error via require_gt", async () => {
  525. await withLogTest(async () => {
  526. try {
  527. const tx = await program.methods.requireGtDefaultError().rpc();
  528. assert.fail(
  529. "Unexpected success in creating a transaction that should have failed with `RequireGtViolated` error"
  530. );
  531. } catch (_err) {
  532. assert.isTrue(_err instanceof AnchorError);
  533. const err: AnchorError = _err;
  534. assert.strictEqual(err.error.errorCode.number, 2505);
  535. }
  536. }, [
  537. "Program log: AnchorError thrown in programs/errors/src/lib.rs:121. Error Code: RequireGtViolated. Error Number: 2505. Error Message: A require_gt expression was violated.",
  538. "Program log: Left: 10",
  539. "Program log: Right: 10",
  540. ]);
  541. });
  542. it("Emits a ValueLess error via require_gte", async () => {
  543. await withLogTest(async () => {
  544. try {
  545. const tx = await program.methods.requireGte().rpc();
  546. assert.fail(
  547. "Unexpected success in creating a transaction that should have failed with `ValueLess` error"
  548. );
  549. } catch (_err) {
  550. assert.isTrue(_err instanceof AnchorError);
  551. const err: AnchorError = _err;
  552. assert.strictEqual(err.error.errorCode.number, 6128);
  553. }
  554. }, [
  555. "Program log: AnchorError thrown in programs/errors/src/lib.rs:126. Error Code: ValueLess. Error Number: 6128. Error Message: ValueLess.",
  556. "Program log: Left: 5",
  557. "Program log: Right: 10",
  558. ]);
  559. });
  560. it("Emits a RequireGteViolated error via require_gte", async () => {
  561. await withLogTest(async () => {
  562. try {
  563. const tx = await program.methods.requireGteDefaultError().rpc();
  564. assert.fail(
  565. "Unexpected success in creating a transaction that should have failed with `RequireGteViolated` error"
  566. );
  567. } catch (_err) {
  568. assert.isTrue(_err instanceof AnchorError);
  569. const err: AnchorError = _err;
  570. assert.strictEqual(err.error.errorCode.number, 2506);
  571. }
  572. }, [
  573. "Program log: AnchorError thrown in programs/errors/src/lib.rs:131. Error Code: RequireGteViolated. Error Number: 2506. Error Message: A require_gte expression was violated.",
  574. "Program log: Left: 5",
  575. "Program log: Right: 10",
  576. ]);
  577. });
  578. });