|
| 1 | +var chai = require('chai'); |
| 2 | +var assert = chai.assert; |
| 3 | +var FakeIpcProvider = require('./helpers/FakeIpcProvider'); |
| 4 | +var Web3 = require('../packages/web3'); |
| 5 | + |
| 6 | +describe('call revert', function () { |
| 7 | + var provider; |
| 8 | + var web3; |
| 9 | + |
| 10 | + beforeEach(function () { |
| 11 | + provider = new FakeIpcProvider(); |
| 12 | + web3 = new Web3(provider); |
| 13 | + web3.eth.handleRevert = true; |
| 14 | + }); |
| 15 | + |
| 16 | + it('Errors with revert reason string through MetaMask', async function() { |
| 17 | + provider.injectRawError({ |
| 18 | + "code": -32603, |
| 19 | + "message": "execution reverted: DeadlineExpired", |
| 20 | + "data": { |
| 21 | + "originalError": { |
| 22 | + "code": 3, |
| 23 | + "data": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f446561646c696e65457870697265640000000000000000000000000000000000", |
| 24 | + "message": "execution reverted: DeadlineExpired" |
| 25 | + } |
| 26 | + } |
| 27 | + }); |
| 28 | + provider.injectValidation(function (payload) { |
| 29 | + assert.equal(payload.jsonrpc, '2.0'); |
| 30 | + assert.equal(payload.method, 'eth_call'); |
| 31 | + assert.deepEqual( |
| 32 | + payload.params, |
| 33 | + [{ |
| 34 | + to: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b', |
| 35 | + data: '0x23455654', |
| 36 | + gas: '0xb', |
| 37 | + gasPrice: '0xb' |
| 38 | + }, 'latest'] |
| 39 | + ); |
| 40 | + }); |
| 41 | + |
| 42 | + var options = { |
| 43 | + to: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b', |
| 44 | + data: '0x23455654', |
| 45 | + gas: 11, |
| 46 | + gasPrice: 11 |
| 47 | + }; |
| 48 | + |
| 49 | + try { |
| 50 | + await web3.eth.call(options, 'latest'); |
| 51 | + assert.fail('call should have failed!'); |
| 52 | + } catch (error) { |
| 53 | + assert.equal(error.reason, 'DeadlineExpired'); |
| 54 | + } |
| 55 | + }); |
| 56 | + |
| 57 | + it('Errors with revert reason string from Ganache through MetaMask', async function() { |
| 58 | + provider.injectRawError({ |
| 59 | + "code": -32603, |
| 60 | + "message": "Internal JSON-RPC error.", |
| 61 | + "data": { |
| 62 | + "message": "VM Exception while processing transaction: revert ImproperState", |
| 63 | + "stack": "CallError: VM Exception while processing transaction: revert ImproperState\n at Blockchain.simulateTransaction (C:\\Users\\nicos\\AppData\\Roaming\\npm\\node_modules\\ganache\\dist\\node\\1.js:2:82786)", |
| 64 | + "code": -32000, |
| 65 | + "name": "CallError", |
| 66 | + "data": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000d496d70726f706572537461746500000000000000000000000000000000000000" |
| 67 | + } |
| 68 | + }); |
| 69 | + provider.injectValidation(function (payload) { |
| 70 | + assert.equal(payload.jsonrpc, '2.0'); |
| 71 | + assert.equal(payload.method, 'eth_call'); |
| 72 | + assert.deepEqual( |
| 73 | + payload.params, |
| 74 | + [{ |
| 75 | + to: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b', |
| 76 | + data: '0x23455654', |
| 77 | + gas: '0xb', |
| 78 | + gasPrice: '0xb' |
| 79 | + }, 'latest'] |
| 80 | + ); |
| 81 | + }); |
| 82 | + |
| 83 | + var options = { |
| 84 | + to: '0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b', |
| 85 | + data: '0x23455654', |
| 86 | + gas: 11, |
| 87 | + gasPrice: 11 |
| 88 | + }; |
| 89 | + |
| 90 | + try { |
| 91 | + await web3.eth.call(options, 'latest'); |
| 92 | + assert.fail('call should have failed!'); |
| 93 | + } catch (error) { |
| 94 | + assert.equal(error.reason, 'ImproperState'); |
| 95 | + } |
| 96 | + }); |
| 97 | + |
| 98 | +}); |
0 commit comments