github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/js/src/test/revert.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 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          function getString(uint key) public view returns (string memory){
    15            if (key != 42){
    16              revert("Did not pass correct key");
    17            } else {
    18              return s;
    19            }
    20          }
    21        }
    22      `;
    23  
    24      instance = await compile(source, 'c').deploy(client);
    25    });
    26  
    27    it('gets the string when revert not called', async () => {
    28      return instance.getString(42).then((str: string) => {
    29        assert.deepStrictEqual(str, ['secret']);
    30      });
    31    });
    32  
    33    it('It catches a revert with the revert string', async () => {
    34      return instance
    35        .getString(1)
    36        .then((str: string) => {
    37          throw new Error('Did not catch revert error');
    38        })
    39        .catch((err: grpc.ServiceError) => {
    40          assert.strictEqual(err.code, grpc.status.ABORTED);
    41          assert.strictEqual(err.message, '10 ABORTED: Did not pass correct key');
    42        });
    43    });
    44  });