try_catch.spec.ts 1.2 KB

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