asserts.spec.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import expect from 'expect';
  2. import { weight, createConnection, deploy, transaction, aliceKeypair, query, } from './index';
  3. import { ContractPromise } from '@polkadot/api-contract';
  4. import { ApiPromise } from '@polkadot/api';
  5. describe('Deploy asserts contract and test', () => {
  6. let conn: ApiPromise;
  7. before(async function () {
  8. conn = await createConnection();
  9. });
  10. after(async function () {
  11. await conn.disconnect();
  12. });
  13. it('asserts', async function () {
  14. this.timeout(50000);
  15. const alice = aliceKeypair();
  16. // call the constructors
  17. let deploy_contract = await deploy(conn, alice, 'asserts.contract', BigInt(0));
  18. let contract = new ContractPromise(conn, deploy_contract.abi, deploy_contract.address);
  19. let res0 = await query(conn, alice, contract, "var");
  20. expect(res0.output?.toJSON()).toEqual(1);
  21. let res1 = await query(conn, alice, contract, "testAssertRpc");
  22. expect(res1.result.toHuman()).toEqual({ "Err": { "Module": { "error": "0x0b000000", "index": "7" } } });
  23. let gasLimit = await weight(conn, contract, "testAssert");
  24. let tx = contract.tx.testAssert({ gasLimit });
  25. let res2 = await transaction(tx, alice).then(() => {
  26. throw new Error("should not succeed");
  27. }, (res) => res);
  28. expect(res2.dispatchError.toHuman()).toEqual({ "Module": { "error": "0x0b000000", "index": "7" } });
  29. let res3 = await query(conn, alice, contract, "var");
  30. expect(res3.output?.toJSON()).toEqual(1);
  31. });
  32. });