runtime_errors.spec.ts 3.8 KB

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