-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nikos/5931/coverage web3 abi (#5934)
* Fix type in Events test * Add data and tests for encodeErrorSignature * Decode contract errors test * Delete unused function * Add invalid data for decode contract erros * Add tuple in data * isAbiCostructor * Update changelog
- Loading branch information
Showing
8 changed files
with
243 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
This file is part of web3.js. | ||
web3.js is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
web3.js is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public License | ||
along with web3.js. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { encodeErrorSignature } from '../../../src/api/errors_api'; | ||
import { validErrorsSignatures, invalidErrorSignatures } from '../../fixtures/data'; | ||
|
||
describe('errors_api', () => { | ||
describe('encodeErrorSignature', () => { | ||
describe('valid data', () => { | ||
it.each(validErrorsSignatures)( | ||
'should pass for valid values: %s', | ||
({ input, output }) => { | ||
expect(encodeErrorSignature(input)).toEqual(output); | ||
}, | ||
); | ||
}); | ||
|
||
describe('invalid data', () => { | ||
it.each(invalidErrorSignatures)( | ||
'should pass for valid values: %s', | ||
({ input, output }) => { | ||
expect(() => encodeErrorSignature(input)).toThrow(output); | ||
}, | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/web3-eth-abi/test/unit/decodeContractErrorData.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
This file is part of web3.js. | ||
web3.js is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
web3.js is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public License | ||
along with web3.js. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { Eip838ExecutionError } from 'web3-errors'; | ||
import { decodeContractErrorData } from '../../src/decode_contract_error_data'; | ||
|
||
import { validDecodeContractErrorData, invalidDecodeContractErrorData } from '../fixtures/data'; | ||
|
||
describe('decodeContractErrorData', () => { | ||
describe('valid data', () => { | ||
it.each(validDecodeContractErrorData)( | ||
'%#: should pass for valid values: %j', | ||
({ input: [abi, errorData], output }) => { | ||
const err = new Eip838ExecutionError( | ||
errorData.code, | ||
errorData.message, | ||
errorData.data, | ||
); | ||
|
||
decodeContractErrorData(abi, err); | ||
|
||
expect(err.errorName).toEqual(output.errorName); | ||
expect(err.errorSignature).toEqual(output.errorSignature); | ||
expect(err.errorArgs?.message).toEqual(output.errorArgs?.message); | ||
expect(Number(err.errorArgs?.code)).toEqual(output.errorArgs?.code); | ||
}, | ||
); | ||
}); | ||
|
||
describe('invalid data', () => { | ||
it.each(invalidDecodeContractErrorData)( | ||
'%#: should throw for invalid values: %j', | ||
({ input: [abi, errorData] }) => { | ||
// mock console.error | ||
const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => 'error'); | ||
const err = new Eip838ExecutionError( | ||
errorData.code, | ||
errorData.message, | ||
errorData.data, | ||
); | ||
decodeContractErrorData(abi, err); | ||
expect(consoleSpy).toHaveBeenCalled(); | ||
}, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters