github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/js/src/test/revert3.test.ts (about)

     1  import * as grpc from '@grpc/grpc-js';
     2  import * as assert from 'assert';
     3  import { compile } from '../contracts/compile';
     4  import { client } from './test';
     5  
     6  describe('REVERT non-constant', function () {
     7    let instance: any;
     8  
     9    before(async () => {
    10      const source = `
    11        pragma solidity >=0.0.0;
    12        contract c {
    13          string s = "secret";
    14          uint n = 0;
    15          function getString(uint key) public returns (string memory){
    16            if (key != 42){
    17              revert();
    18            } else {
    19              n = n + 1;
    20              return s;
    21            }
    22          }
    23        }
    24      `;
    25  
    26      instance = await compile(source, 'c').deploy(client);
    27    });
    28  
    29    it('It catches a revert with the revert string', async () => {
    30      return instance
    31        .getString(1)
    32        .then((str: any) => {
    33          throw new Error('Did not catch revert error');
    34        })
    35        .catch((err: grpc.ServiceError) => {
    36          assert.strictEqual(err.code, grpc.status.ABORTED);
    37        });
    38    });
    39  });