github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/js/src/test/infloop.test.ts (about) 1 import * as assert from 'assert'; 2 import { compile } from '../contracts/compile'; 3 import { client } from './test'; 4 5 describe('Really Long Loop', function () { 6 let instance: any; 7 this.timeout(1000000); 8 9 before(async () => { 10 const source = ` 11 pragma solidity >=0.0.0; 12 contract main { 13 function test() public returns (string memory) { 14 c sub = new c(); 15 return sub.getString(); 16 } 17 } 18 contract c { 19 string s = "secret"; 20 uint n = 0; 21 function getString() public returns (string memory){ 22 for (uint i = 0; i < 10000000000000; i++) { 23 n += 1; 24 } 25 return s; 26 } 27 } 28 `; 29 30 const contract = compile(source, 'main'); 31 instance = await contract.deployWith(client, { 32 middleware: (callTx) => { 33 // Normal gas for deploy (when address === '') 34 if (callTx.getAddress()) { 35 // Hardly any for call 36 callTx.setGaslimit(11); 37 } 38 return callTx; 39 }, 40 }); 41 }); 42 43 it('It catches a revert when gas runs out', async () => { 44 await instance 45 .test() 46 .then((str: string) => { 47 throw new Error('Did not catch revert error'); 48 }) 49 .catch((err: Error) => { 50 assert.match(err.message, /Error 5: insufficient gas/); 51 }); 52 }); 53 });