try_catch.spec.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import expect from 'expect';
  2. import { createConnection, deploy, aliceKeypair, query, } from './index';
  3. import { ContractPromise } from '@polkadot/api-contract';
  4. import { ApiPromise } from '@polkadot/api';
  5. import { KeyringPair } from '@polkadot/keyring/types';
  6. describe('Deploy and test the try_catch contract', () => {
  7. let conn: ApiPromise;
  8. let caller: ContractPromise;
  9. let alice: KeyringPair;
  10. before(async function () {
  11. alice = aliceKeypair();
  12. conn = await createConnection();
  13. await deploy(conn, alice, 'TryCatchCallee.contract', 0n);
  14. const caller_contract = await deploy(conn, alice, 'TryCatchCaller.contract', 1000000000n);
  15. caller = new ContractPromise(conn, caller_contract.abi, caller_contract.address);
  16. });
  17. after(async function () {
  18. await conn.disconnect();
  19. });
  20. it('Tests all catch clauses', async function () {
  21. this.timeout(20000);
  22. for (let in_out = 0; in_out < 5; in_out++) {
  23. console.log("Testing case: " + in_out);
  24. const answer = await query(conn, alice, caller, "test", [in_out]);
  25. expect(answer.output?.toJSON()).toStrictEqual(in_out);
  26. }
  27. });
  28. });