aboutsummaryrefslogtreecommitdiffstats
path: root/packages/base-contract/src/index.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-08-14 04:01:32 +0800
committerFabio Berger <me@fabioberger.com>2018-08-14 04:01:32 +0800
commit9d3c287918389d07f884245bd1bc968955768b6f (patch)
tree460fded537c7d64154972b7d14332f88554d14c0 /packages/base-contract/src/index.ts
parentc2b5fe3d844d35966c5498326000bd8317fb547c (diff)
parent15e15f994a1b18cf2e9be151194c826d53a01601 (diff)
downloaddexon-sol-tools-9d3c287918389d07f884245bd1bc968955768b6f.tar
dexon-sol-tools-9d3c287918389d07f884245bd1bc968955768b6f.tar.gz
dexon-sol-tools-9d3c287918389d07f884245bd1bc968955768b6f.tar.bz2
dexon-sol-tools-9d3c287918389d07f884245bd1bc968955768b6f.tar.lz
dexon-sol-tools-9d3c287918389d07f884245bd1bc968955768b6f.tar.xz
dexon-sol-tools-9d3c287918389d07f884245bd1bc968955768b6f.tar.zst
dexon-sol-tools-9d3c287918389d07f884245bd1bc968955768b6f.zip
Merge branch 'sol-cov-fixes' of github.com:0xProject/0x-monorepo into sol-cov-fixes
* 'sol-cov-fixes' of github.com:0xProject/0x-monorepo: (49 commits) Add @return comments Import marshaller directly Update comment about ethers checksummed address behavior Add packages/coverage/.gitkeep file Update CI config and package.json to run @0xproject/utils tests on CI Update remaining CHANGELOG.json files Change amir picture Update CHANGELOG.json for contract-wrappers Update ethers typings for TypeScript 2.9.2 Update CHANGELOG.json for base-contract Move some ethers-related types to typescript-typings/ethers Apply prettier Add strictArgumentEncodingCheck to BaseContract and use it in contract templates fix(monorepo-scripts): Fix typo in git tag command feat(monorepo-scripts): Add confirmation prompt before publishing fix comments and styling for MixinSignatureValidator Update TypeScript to version 2.9.2 Use asm for hashEIP712Message, increment free memory pointer after asm hashing functions Fix comments, styling, and optimize hashOrder Remove assertion comments ...
Diffstat (limited to 'packages/base-contract/src/index.ts')
-rw-r--r--packages/base-contract/src/index.ts21
1 files changed, 21 insertions, 0 deletions
diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts
index a240fb8b6..12f974445 100644
--- a/packages/base-contract/src/index.ts
+++ b/packages/base-contract/src/index.ts
@@ -82,6 +82,27 @@ export class BaseContract {
}
return txDataWithDefaults;
}
+ // Throws if the given arguments cannot be safely/correctly encoded based on
+ // the given inputAbi. An argument may not be considered safely encodeable
+ // if it overflows the corresponding Solidity type, there is a bug in the
+ // encoder, or the encoder performs unsafe type coercion.
+ public static strictArgumentEncodingCheck(inputAbi: DataItem[], args: any[]): void {
+ const coder = ethers.utils.AbiCoder.defaultCoder;
+ const params = abiUtils.parseEthersParams(inputAbi);
+ const rawEncoded = coder.encode(params.names, params.types, args);
+ const rawDecoded = coder.decode(params.names, params.types, rawEncoded);
+ for (let i = 0; i < rawDecoded.length; i++) {
+ const original = args[i];
+ const decoded = rawDecoded[i];
+ if (!abiUtils.isAbiDataEqual(params.names[i], params.types[i], original, decoded)) {
+ throw new Error(
+ `Cannot safely encode argument: ${params.names[i]} (${original}) of type ${
+ params.types[i]
+ }. (Possible type overflow or other encoding error)`,
+ );
+ }
+ }
+ }
protected _lookupEthersInterface(functionSignature: string): ethers.Interface {
const ethersInterface = this._ethersInterfacesByFunctionSignature[functionSignature];
if (_.isUndefined(ethersInterface)) {