runtime_errors.spec.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { createConnection, deploy, aliceKeypair, debug_buffer } from "./index";
  2. import expect from 'expect';
  3. import { ContractPromise } from "@polkadot/api-contract";
  4. describe('Deploy runtime_errors.sol and test the debug buffer', () => {
  5. it('logs errors to the debug buffer', async function () {
  6. let conn = await createConnection();
  7. const alice = aliceKeypair();
  8. let deployed_contract = await deploy(
  9. conn,
  10. alice,
  11. "RuntimeErrors.contract",
  12. BigInt(0)
  13. );
  14. let contract = new ContractPromise(
  15. conn,
  16. deployed_contract.abi,
  17. deployed_contract.address
  18. );
  19. let child_contract = await deploy(conn, alice, 'child_runtime_errors.contract', BigInt(0));
  20. let res = await debug_buffer(conn, contract, `get_storage_bytes`, [])
  21. expect(res).toContain(`runtime_error: storage array index out of bounds in runtime_errors.sol:46:19-23`)
  22. let res1 = await debug_buffer(conn, contract, `transfer_abort`, [])
  23. expect(res1).toContain(`runtime_error: value transfer failure in runtime_errors.sol:53:9-32`)
  24. let res2 = await debug_buffer(conn, contract, `pop_empty_storage`, [])
  25. expect(res2).toContain(`runtime_error: pop from empty storage array in runtime_errors.sol:58:13-16`)
  26. let res3 = await debug_buffer(conn, contract, `call_ext`, [child_contract.address])
  27. expect(res3).toContain(`runtime_error: external call failed in runtime_errors.sol:63:9-24`)
  28. let res4 = await debug_buffer(conn, contract, `create_child`);
  29. expect(res4).toContain(`runtime_error: contract creation failed in runtime_errors.sol:68`)
  30. let res5 = await debug_buffer(conn, contract, `set_storage_bytes`, [])
  31. expect(res5).toContain(`runtime_error: storage index out of bounds in runtime_errors.sol:39:11-12`)
  32. let res6 = await debug_buffer(conn, contract, `dont_pay_me`, [], 1);
  33. expect(res6).toContain(`runtime_error: non payable function dont_pay_me received value`)
  34. let res7 = await debug_buffer(conn, contract, `assert_test`, [9], 0);
  35. expect(res7).toContain(`runtime_error: assert failure in runtime_errors.sol:32:16-24`)
  36. let res8 = await debug_buffer(conn, contract, `i_will_revert`, [], 0);
  37. expect(res8).toContain(`runtime_error: unspecified revert encountered in runtime_errors.sol:77:9-17`)
  38. let res9 = await debug_buffer(conn, contract, `write_integer_failure`, [1], 0);
  39. expect(res9).toContain(`runtime_error: integer too large to write in buffer in runtime_errors.sol:82:18-31`)
  40. let res10 = await debug_buffer(conn, contract, `write_bytes_failure`, [9], 0);
  41. expect(res10).toContain(`runtime_error: data does not fit into buffer in runtime_errors.sol:88:18-28`)
  42. let res11 = await debug_buffer(conn, contract, `read_integer_failure`, [2], 0);
  43. expect(res11).toContain(`runtime_error: read integer out of bounds in runtime_errors.sol:93:18-30`)
  44. let res12 = await debug_buffer(conn, contract, `trunc_failure`, [BigInt(`999999999999999999999999`)], 0);
  45. expect(res12).toContain(`runtime_error: truncated type overflows in runtime_errors.sol:98:37-42`)
  46. let res13 = await debug_buffer(conn, contract, `out_of_bounds`, [19], 0);
  47. expect(res13).toContain(`runtime_error: array index out of bounds in runtime_errors.sol:104:16-21`)
  48. let res14 = await debug_buffer(conn, contract, `invalid_instruction`, [], 0);
  49. expect(res14).toContain(`runtime_error: reached invalid instruction in runtime_errors.sol:109:13-22`)
  50. let res15 = await debug_buffer(conn, contract, `byte_cast_failure`, [33], 0);
  51. expect(res15).toContain(`runtime_error: bytes cast error in runtime_errors.sol:115:23-40`)
  52. conn.disconnect();
  53. });
  54. });