From da28a542c7b8dc1ba9bd734219871cf0f935b215 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Thu, 1 Aug 2019 18:54:23 +0200 Subject: [PATCH] Added abi encoder test when bad selector is passed to method decoding --- packages/utils/test/abi_encoder/methods_test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/utils/test/abi_encoder/methods_test.ts b/packages/utils/test/abi_encoder/methods_test.ts index c167db4726..5506e361fc 100644 --- a/packages/utils/test/abi_encoder/methods_test.ts +++ b/packages/utils/test/abi_encoder/methods_test.ts @@ -282,4 +282,16 @@ describe('ABI Encoder: Method Encoding / Decoding', () => { const customDecodingRules = { shouldConvertStructsToObjects: true }; // custom to improve readability runTest(method, methodArgs, expectedEncoding, defaultEncodingRules, customDecodingRules); }); + it('Should throw if decoding calldata where selector does not match the method', async () => { + const method = AbiEncoder.createMethod('foobar'); + const methodSelector = method.getSelector(); + const badMethodSelector = '0x01020304'; + expect(() => method.decode(badMethodSelector)).to.throw(`Tried to decode calldata, but it was missing the function selector. Expected prefix '${methodSelector}'. Got '${badMethodSelector}'.`); + }); + it('Should throw if strict decoding calldata where selector does not match the method', async () => { + const method = AbiEncoder.createMethod('foobar'); + const methodSelector = method.getSelector(); + const badMethodSelector = '0x01020304'; + expect(() => method.strictDecode(badMethodSelector)).to.throw(`Tried to decode calldata, but it was missing the function selector. Expected prefix '${methodSelector}'. Got '${badMethodSelector}'.`); + }); });