github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/js/src/test/revert2.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("Did not pass correct key");
    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('gets the string when revert not called', async () => {
    30      return instance.getString(42).then((str: string) => {
    31        assert.deepStrictEqual(str, ['secret']);
    32      });
    33    });
    34  
    35    it('It catches a revert with the revert string', async () => {
    36      return instance
    37        .getString(1)
    38        .then((str: string) => {
    39          throw new Error('Did not catch revert error');
    40        })
    41        .catch((err: grpc.ServiceError) => {
    42          assert.strictEqual(err.code, grpc.status.ABORTED);
    43          assert.strictEqual(err.message, '10 ABORTED: Did not pass correct key');
    44        });
    45    });
    46  });