errors.spec.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // SPDX-License-Identifier: Apache-2.0
  2. import { BN } from '@coral-xyz/anchor';
  3. import expect from 'expect';
  4. import { loadContractAndCallConstructor } from './setup';
  5. describe('Testing errors', function () {
  6. this.timeout(500000);
  7. it('errors', async function () {
  8. const { program, storage } = await loadContractAndCallConstructor('errors');
  9. let res = await program.methods.doRevert(false).view();
  10. expect(res).toEqual(new BN(3124445));
  11. try {
  12. res = await program.methods.doRevert(true).simulate();
  13. } catch (e: any) {
  14. const logs = e.simulationResponse.logs;
  15. expect(logs).toContain('Program log: Going to revert');
  16. return;
  17. }
  18. try {
  19. res = await program.methods.doRevert(true)
  20. .accounts({ dataAccount: storage.publicKey })
  21. .rpc();
  22. } catch (e: any) {
  23. const logs = e.simulationResponse.logs;
  24. expect(logs).toContain('Program log: Going to revert');
  25. return;
  26. }
  27. });
  28. });