error.spec.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. import { ProgramErrorStack, AnchorError } from "../src/error";
  2. describe("ProgramErrorStack", () => {
  3. test("basic", () => {
  4. const logs = [
  5. "Program ERRM6YCMsccM22TEaPuu35KVU4iCY3GLCz4qMsKLYReE invoke [1]",
  6. "Program ERRM6YCMsccM22TEaPuu35KVU4iCY3GLCz4qMsKLYReE consumed 3797 of 200000 compute units",
  7. "Program ERRM6YCMsccM22TEaPuu35KVU4iCY3GLCz4qMsKLYReE failed: custom program error: 0x29",
  8. ];
  9. expect(
  10. ProgramErrorStack.parse(logs).stack.map((publicKey) =>
  11. publicKey.toString()
  12. )
  13. ).toEqual(["ERRM6YCMsccM22TEaPuu35KVU4iCY3GLCz4qMsKLYReE"]);
  14. });
  15. it("basic multiple ix", () => {
  16. const logs = [
  17. "Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin invoke [1]",
  18. "Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin consumed 4308 of 200000 compute units",
  19. "Program 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin success",
  20. "Program ERRM6YCMsccM22TEaPuu35KVU4iCY3GLCz4qMsKLYReE invoke [1]",
  21. "Program ERRM6YCMsccM22TEaPuu35KVU4iCY3GLCz4qMsKLYReE consumed 3797 of 200000 compute units",
  22. "Program ERRM6YCMsccM22TEaPuu35KVU4iCY3GLCz4qMsKLYReE failed: custom program error: 0x29",
  23. ];
  24. expect(
  25. ProgramErrorStack.parse(logs).stack.map((publicKey) =>
  26. publicKey.toString()
  27. )
  28. ).toEqual(["ERRM6YCMsccM22TEaPuu35KVU4iCY3GLCz4qMsKLYReE"]);
  29. });
  30. it("failed inner ix", () => {
  31. const logs = [
  32. "Program Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS invoke [1]",
  33. "Program log: Instruction: Create",
  34. "Program ERRM6YCMsccM22TEaPuu35KVU4iCY3GLCz4qMsKLYReE invoke [2]",
  35. "Program log: AnchorError thrown in programs/switchboard_v2/src/actions/aggregator_save_result_action.rs:235. Error Code: OracleMismatchError. Error Number: 6021. Error Message: An unexpected oracle account was provided for the transaction..",
  36. "Program Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS consumed 12619 of 1400000 compute units",
  37. "Program Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS failed: Program failed to complete",
  38. ];
  39. expect(
  40. ProgramErrorStack.parse(logs).stack.map((publicKey) =>
  41. publicKey.toString()
  42. )
  43. ).toEqual([
  44. "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS",
  45. "ERRM6YCMsccM22TEaPuu35KVU4iCY3GLCz4qMsKLYReE",
  46. ]);
  47. });
  48. it("ignore successful inner ix", () => {
  49. const logs = [
  50. "Program Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS invoke [1]",
  51. "Program log: Instruction: Create",
  52. "Program 11111111111111111111111111111111 invoke [2]",
  53. "Program 11111111111111111111111111111111 success",
  54. "Program log: panicked at programs/floats/src/lib.rs:17:9",
  55. "Program Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS consumed 12619 of 1400000 compute units",
  56. "Program failed to complete: BPF program panicked",
  57. "Program Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS failed: Program failed to complete",
  58. ];
  59. expect(
  60. ProgramErrorStack.parse(logs).stack.map((publicKey) =>
  61. publicKey.toString()
  62. )
  63. ).toEqual(["Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"]);
  64. });
  65. it("ignore successful inner ix but don't ignore failing inner ix", () => {
  66. const logs = [
  67. "Program Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS invoke [1]",
  68. "Program log: Instruction: Create",
  69. "Program 11111111111111111111111111111111 invoke [2]",
  70. "Program 11111111111111111111111111111111 success",
  71. "Program ERRM6YCMsccM22TEaPuu35KVU4iCY3GLCz4qMsKLYReE invoke [2]",
  72. "Program log: panicked at programs/floats/src/lib.rs:17:9",
  73. "Program Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS consumed 12619 of 1400000 compute units",
  74. "Program failed to complete: BPF program panicked",
  75. "Program Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS failed: Program failed to complete",
  76. ];
  77. expect(
  78. ProgramErrorStack.parse(logs).stack.map((publicKey) =>
  79. publicKey.toString()
  80. )
  81. ).toEqual([
  82. "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS",
  83. "ERRM6YCMsccM22TEaPuu35KVU4iCY3GLCz4qMsKLYReE",
  84. ]);
  85. });
  86. it("ignore successful inner ix but don't ignore failing inner ix - big nested", () => {
  87. const logs = [
  88. "Program Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS invoke [1]",
  89. "Program log: Instruction: Create",
  90. "Program 11111111111111111111111111111111 invoke [2]",
  91. "Program 11111111111111111111111111111111 success",
  92. "Program 1119iqpxV28XnisGGQVMHsABdWZAx9PjtwegepRhGm5 invoke [2]",
  93. "Program 1119iqpxV28XnisGGQVMHsABdWZAx9PjtwegepRhGm5 consumed 4308 of 200000 compute units",
  94. "Program 1119iqpxV28XnisGGQVMHsABdWZAx9PjtwegepRhGm5 success",
  95. "Program 222fsxyjMZSSpT9gpucChbiFmjZC2GtaZmKsBkh66KMZ invoke [2]",
  96. "Program 333fE7qebyWBjcaCJcVmkzwrheA1Ka9bjGChuhVD9iQr invoke [3]",
  97. "Program 444D5MLf9UbeJBiuFw5WzVG3bMejweunZHPboWm2oTsh invoke [4]",
  98. "Program 444D5MLf9UbeJBiuFw5WzVG3bMejweunZHPboWm2oTsh consumed 14343 of 200000 compute units",
  99. "Program 444D5MLf9UbeJBiuFw5WzVG3bMejweunZHPboWm2oTsh success",
  100. "Program 555CBVR14jAYjK8jRE5kurBACiSNYXkffciRSG2R3krX invoke [4]",
  101. "Program 555CBVR14jAYjK8jRE5kurBACiSNYXkffciRSG2R3krX consumed 163337 of 200000 compute units",
  102. "Program 555CBVR14jAYjK8jRE5kurBACiSNYXkffciRSG2R3krX success",
  103. "Program 666UBGVHWNP7qNqUdnYz86owJ8oErztVvgeF5Dd5v8cR invoke [4]",
  104. "Program 666UBGVHWNP7qNqUdnYz86owJ8oErztVvgeF5Dd5v8cR success",
  105. "Program 333fE7qebyWBjcaCJcVmkzwrheA1Ka9bjGChuhVD9iQr success",
  106. "Program 222fsxyjMZSSpT9gpucChbiFmjZC2GtaZmKsBkh66KMZ success",
  107. "Program 777UGK3pU4ygVWwnn7MDnetec1nSVg4Xi53DFSHu9D6A invoke [2]",
  108. "Program 888E49S65VpyDmydi6juT7tsSwNyD3ZEVkV8te1rL3iH invoke [3]",
  109. "Program 999X95icuyGzfYoeP6SPMb8aMn6ahfCpAt9VPddSNPPi invoke [4]",
  110. "Program 999X95icuyGzfYoeP6SPMb8aMn6ahfCpAt9VPddSNPPi success",
  111. "Program ERRM6YCMsccM22TEaPuu35KVU4iCY3GLCz4qMsKLYReE invoke [4]",
  112. "Program log: panicked at programs/floats/src/lib.rs:17:9",
  113. "Program Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS consumed 12619 of 1400000 compute units",
  114. "Program failed to complete: BPF program panicked",
  115. "Program Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS failed: Program failed to complete",
  116. ];
  117. expect(
  118. ProgramErrorStack.parse(logs).stack.map((publicKey) =>
  119. publicKey.toString()
  120. )
  121. ).toEqual([
  122. "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS",
  123. "777UGK3pU4ygVWwnn7MDnetec1nSVg4Xi53DFSHu9D6A",
  124. "888E49S65VpyDmydi6juT7tsSwNyD3ZEVkV8te1rL3iH",
  125. "ERRM6YCMsccM22TEaPuu35KVU4iCY3GLCz4qMsKLYReE",
  126. ]);
  127. });
  128. });
  129. describe("AnchorError", () => {
  130. it("FileLine AnchorError with Pubkeys", () => {
  131. const logs = [
  132. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f invoke [1]",
  133. "Program log: Instruction: AggregatorSaveResult",
  134. "Program log: AnchorError thrown in programs/switchboard_v2/src/actions/aggregator_save_result_action.rs:235. Error Code: OracleMismatchError. Error Number: 6021. Error Message: An unexpected oracle account was provided for the transaction..",
  135. "Program log: Left:",
  136. "Program log: Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS",
  137. "Program log: Right:",
  138. "Program log: SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f",
  139. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f consumed 28928 of 200000 compute units",
  140. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f failed: custom program error: 0x1785",
  141. ];
  142. const anchorError = AnchorError.parse(logs)!;
  143. expect(anchorError.program.toString()).toEqual(
  144. "SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"
  145. );
  146. expect(anchorError.error.errorCode).toEqual({
  147. code: "OracleMismatchError",
  148. number: 6021,
  149. });
  150. expect(anchorError.error.errorMessage).toEqual(
  151. "An unexpected oracle account was provided for the transaction."
  152. );
  153. expect(anchorError.error.origin).toEqual({
  154. file: "programs/switchboard_v2/src/actions/aggregator_save_result_action.rs",
  155. line: 235,
  156. });
  157. expect(
  158. anchorError.error.comparedValues!.map((pk) => pk.toString())
  159. ).toEqual([
  160. "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS",
  161. "SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f",
  162. ]);
  163. expect(
  164. anchorError.programErrorStack!.map((publicKey) => publicKey.toString())
  165. ).toEqual(["SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"]);
  166. expect(anchorError.errorLogs).toEqual([
  167. "Program log: AnchorError thrown in programs/switchboard_v2/src/actions/aggregator_save_result_action.rs:235. Error Code: OracleMismatchError. Error Number: 6021. Error Message: An unexpected oracle account was provided for the transaction..",
  168. "Program log: Left:",
  169. "Program log: Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS",
  170. "Program log: Right:",
  171. "Program log: SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f",
  172. ]);
  173. });
  174. it("FileLine AnchorError with Values", () => {
  175. const logs = [
  176. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f invoke [1]",
  177. "Program log: Instruction: AggregatorSaveResult",
  178. "Program log: AnchorError thrown in programs/switchboard_v2/src/actions/aggregator_save_result_action.rs:235. Error Code: OracleMismatchError. Error Number: 6021. Error Message: An unexpected oracle account was provided for the transaction..",
  179. "Program log: Left: 1337",
  180. "Program log: Right: 4220",
  181. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f consumed 28928 of 200000 compute units",
  182. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f failed: custom program error: 0x1785",
  183. ];
  184. const anchorError = AnchorError.parse(logs)!;
  185. expect(anchorError.program.toString()).toEqual(
  186. "SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"
  187. );
  188. expect(anchorError.error.errorCode).toEqual({
  189. code: "OracleMismatchError",
  190. number: 6021,
  191. });
  192. expect(anchorError.error.errorMessage).toEqual(
  193. "An unexpected oracle account was provided for the transaction."
  194. );
  195. expect(anchorError.error.origin).toEqual({
  196. file: "programs/switchboard_v2/src/actions/aggregator_save_result_action.rs",
  197. line: 235,
  198. });
  199. expect(anchorError.error.comparedValues!).toEqual(["1337", "4220"]);
  200. expect(
  201. anchorError.programErrorStack!.map((publicKey) => publicKey.toString())
  202. ).toEqual(["SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"]);
  203. expect(anchorError.errorLogs).toEqual([
  204. "Program log: AnchorError thrown in programs/switchboard_v2/src/actions/aggregator_save_result_action.rs:235. Error Code: OracleMismatchError. Error Number: 6021. Error Message: An unexpected oracle account was provided for the transaction..",
  205. "Program log: Left: 1337",
  206. "Program log: Right: 4220",
  207. ]);
  208. });
  209. it("AccountName AnchorError with Pubkeys", () => {
  210. const logs = [
  211. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f invoke [1]",
  212. "Program log: Instruction: AggregatorSaveResult",
  213. "Program log: AnchorError caused by account: some_account. Error Code: OracleMismatchError. Error Number: 6021. Error Message: An unexpected oracle account was provided for the transaction..",
  214. "Program log: Left:",
  215. "Program log: Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS",
  216. "Program log: Right:",
  217. "Program log: SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f",
  218. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f consumed 28928 of 200000 compute units",
  219. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f failed: custom program error: 0x1785",
  220. ];
  221. const anchorError = AnchorError.parse(logs)!;
  222. expect(anchorError.program.toString()).toEqual(
  223. "SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"
  224. );
  225. expect(anchorError.error.errorCode).toEqual({
  226. code: "OracleMismatchError",
  227. number: 6021,
  228. });
  229. expect(anchorError.error.errorMessage).toEqual(
  230. "An unexpected oracle account was provided for the transaction."
  231. );
  232. expect(anchorError.error.origin).toEqual("some_account");
  233. expect(
  234. anchorError.error.comparedValues!.map((pk) => pk.toString())
  235. ).toEqual([
  236. "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS",
  237. "SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f",
  238. ]);
  239. expect(
  240. anchorError.programErrorStack!.map((publicKey) => publicKey.toString())
  241. ).toEqual(["SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"]);
  242. expect(anchorError.errorLogs).toEqual([
  243. "Program log: AnchorError caused by account: some_account. Error Code: OracleMismatchError. Error Number: 6021. Error Message: An unexpected oracle account was provided for the transaction..",
  244. "Program log: Left:",
  245. "Program log: Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS",
  246. "Program log: Right:",
  247. "Program log: SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f",
  248. ]);
  249. });
  250. it("AccountName AnchorError with Values", () => {
  251. const logs = [
  252. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f invoke [1]",
  253. "Program log: Instruction: AggregatorSaveResult",
  254. "Program log: AnchorError caused by account: some_account. Error Code: OracleMismatchError. Error Number: 6021. Error Message: An unexpected oracle account was provided for the transaction..",
  255. "Program log: Left: 1337",
  256. "Program log: Right: 4220",
  257. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f consumed 28928 of 200000 compute units",
  258. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f failed: custom program error: 0x1785",
  259. ];
  260. const anchorError = AnchorError.parse(logs)!;
  261. expect(anchorError.program.toString()).toEqual(
  262. "SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"
  263. );
  264. expect(anchorError.error.errorCode).toEqual({
  265. code: "OracleMismatchError",
  266. number: 6021,
  267. });
  268. expect(anchorError.error.errorMessage).toEqual(
  269. "An unexpected oracle account was provided for the transaction."
  270. );
  271. expect(anchorError.error.origin).toEqual("some_account");
  272. expect(anchorError.error.comparedValues!).toEqual(["1337", "4220"]);
  273. expect(
  274. anchorError.programErrorStack!.map((publicKey) => publicKey.toString())
  275. ).toEqual(["SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"]);
  276. expect(anchorError.errorLogs).toEqual([
  277. "Program log: AnchorError caused by account: some_account. Error Code: OracleMismatchError. Error Number: 6021. Error Message: An unexpected oracle account was provided for the transaction..",
  278. "Program log: Left: 1337",
  279. "Program log: Right: 4220",
  280. ]);
  281. });
  282. it("Empty AnchorError", () => {
  283. const logs = [
  284. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f invoke [1]",
  285. "Program log: Instruction: AggregatorSaveResult",
  286. "Program log: AnchorError occurred. Error Code: OracleMismatchError. Error Number: 6021. Error Message: An unexpected oracle account was provided for the transaction..",
  287. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f consumed 28928 of 200000 compute units",
  288. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f failed: custom program error: 0x1785",
  289. ];
  290. const anchorError = AnchorError.parse(logs)!;
  291. expect(anchorError.program.toString()).toEqual(
  292. "SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"
  293. );
  294. expect(anchorError.error.errorCode).toEqual({
  295. code: "OracleMismatchError",
  296. number: 6021,
  297. });
  298. expect(anchorError.error.errorMessage).toEqual(
  299. "An unexpected oracle account was provided for the transaction."
  300. );
  301. expect(anchorError.error.origin).toBeUndefined();
  302. expect(anchorError.error.comparedValues).toBeUndefined();
  303. expect(
  304. anchorError.programErrorStack!.map((publicKey) => publicKey.toString())
  305. ).toEqual(["SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"]);
  306. expect(anchorError.errorLogs).toEqual([
  307. "Program log: AnchorError occurred. Error Code: OracleMismatchError. Error Number: 6021. Error Message: An unexpected oracle account was provided for the transaction..",
  308. ]);
  309. });
  310. });