error.spec.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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:
  155. "programs/switchboard_v2/src/actions/aggregator_save_result_action.rs",
  156. line: 235,
  157. });
  158. expect(
  159. anchorError.error.comparedValues!.map((pk) => pk.toString())
  160. ).toEqual([
  161. "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS",
  162. "SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f",
  163. ]);
  164. expect(
  165. anchorError.programErrorStack!.map((publicKey) => publicKey.toString())
  166. ).toEqual(["SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"]);
  167. expect(anchorError.errorLogs).toEqual([
  168. "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..",
  169. "Program log: Left:",
  170. "Program log: Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS",
  171. "Program log: Right:",
  172. "Program log: SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f",
  173. ]);
  174. });
  175. it("FileLine AnchorError with Values", () => {
  176. const logs = [
  177. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f invoke [1]",
  178. "Program log: Instruction: AggregatorSaveResult",
  179. "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..",
  180. "Program log: Left: 1337",
  181. "Program log: Right: 4220",
  182. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f consumed 28928 of 200000 compute units",
  183. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f failed: custom program error: 0x1785",
  184. ];
  185. const anchorError = AnchorError.parse(logs)!;
  186. expect(anchorError.program.toString()).toEqual(
  187. "SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"
  188. );
  189. expect(anchorError.error.errorCode).toEqual({
  190. code: "OracleMismatchError",
  191. number: 6021,
  192. });
  193. expect(anchorError.error.errorMessage).toEqual(
  194. "An unexpected oracle account was provided for the transaction."
  195. );
  196. expect(anchorError.error.origin).toEqual({
  197. file:
  198. "programs/switchboard_v2/src/actions/aggregator_save_result_action.rs",
  199. line: 235,
  200. });
  201. expect(anchorError.error.comparedValues!).toEqual(["1337", "4220"]);
  202. expect(
  203. anchorError.programErrorStack!.map((publicKey) => publicKey.toString())
  204. ).toEqual(["SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"]);
  205. expect(anchorError.errorLogs).toEqual([
  206. "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..",
  207. "Program log: Left: 1337",
  208. "Program log: Right: 4220",
  209. ]);
  210. });
  211. it("AccountName AnchorError with Pubkeys", () => {
  212. const logs = [
  213. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f invoke [1]",
  214. "Program log: Instruction: AggregatorSaveResult",
  215. "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..",
  216. "Program log: Left:",
  217. "Program log: Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS",
  218. "Program log: Right:",
  219. "Program log: SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f",
  220. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f consumed 28928 of 200000 compute units",
  221. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f failed: custom program error: 0x1785",
  222. ];
  223. const anchorError = AnchorError.parse(logs)!;
  224. expect(anchorError.program.toString()).toEqual(
  225. "SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"
  226. );
  227. expect(anchorError.error.errorCode).toEqual({
  228. code: "OracleMismatchError",
  229. number: 6021,
  230. });
  231. expect(anchorError.error.errorMessage).toEqual(
  232. "An unexpected oracle account was provided for the transaction."
  233. );
  234. expect(anchorError.error.origin).toEqual("some_account");
  235. expect(
  236. anchorError.error.comparedValues!.map((pk) => pk.toString())
  237. ).toEqual([
  238. "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS",
  239. "SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f",
  240. ]);
  241. expect(
  242. anchorError.programErrorStack!.map((publicKey) => publicKey.toString())
  243. ).toEqual(["SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"]);
  244. expect(anchorError.errorLogs).toEqual([
  245. "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..",
  246. "Program log: Left:",
  247. "Program log: Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS",
  248. "Program log: Right:",
  249. "Program log: SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f",
  250. ]);
  251. });
  252. it("AccountName AnchorError with Values", () => {
  253. const logs = [
  254. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f invoke [1]",
  255. "Program log: Instruction: AggregatorSaveResult",
  256. "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..",
  257. "Program log: Left: 1337",
  258. "Program log: Right: 4220",
  259. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f consumed 28928 of 200000 compute units",
  260. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f failed: custom program error: 0x1785",
  261. ];
  262. const anchorError = AnchorError.parse(logs)!;
  263. expect(anchorError.program.toString()).toEqual(
  264. "SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"
  265. );
  266. expect(anchorError.error.errorCode).toEqual({
  267. code: "OracleMismatchError",
  268. number: 6021,
  269. });
  270. expect(anchorError.error.errorMessage).toEqual(
  271. "An unexpected oracle account was provided for the transaction."
  272. );
  273. expect(anchorError.error.origin).toEqual("some_account");
  274. expect(anchorError.error.comparedValues!).toEqual(["1337", "4220"]);
  275. expect(
  276. anchorError.programErrorStack!.map((publicKey) => publicKey.toString())
  277. ).toEqual(["SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"]);
  278. expect(anchorError.errorLogs).toEqual([
  279. "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..",
  280. "Program log: Left: 1337",
  281. "Program log: Right: 4220",
  282. ]);
  283. });
  284. it("Empty AnchorError", () => {
  285. const logs = [
  286. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f invoke [1]",
  287. "Program log: Instruction: AggregatorSaveResult",
  288. "Program log: AnchorError occurred. Error Code: OracleMismatchError. Error Number: 6021. Error Message: An unexpected oracle account was provided for the transaction..",
  289. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f consumed 28928 of 200000 compute units",
  290. "Program SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f failed: custom program error: 0x1785",
  291. ];
  292. const anchorError = AnchorError.parse(logs)!;
  293. expect(anchorError.program.toString()).toEqual(
  294. "SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"
  295. );
  296. expect(anchorError.error.errorCode).toEqual({
  297. code: "OracleMismatchError",
  298. number: 6021,
  299. });
  300. expect(anchorError.error.errorMessage).toEqual(
  301. "An unexpected oracle account was provided for the transaction."
  302. );
  303. expect(anchorError.error.origin).toBeUndefined();
  304. expect(anchorError.error.comparedValues).toBeUndefined();
  305. expect(
  306. anchorError.programErrorStack!.map((publicKey) => publicKey.toString())
  307. ).toEqual(["SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"]);
  308. expect(anchorError.errorLogs).toEqual([
  309. "Program log: AnchorError occurred. Error Code: OracleMismatchError. Error Number: 6021. Error Message: An unexpected oracle account was provided for the transaction..",
  310. ]);
  311. });
  312. });