Apply prettier

This commit is contained in:
Alex Browne 2018-07-26 14:32:52 -07:00
parent 6a5965d73b
commit 6a6739ebbe
No known key found for this signature in database
GPG Key ID: 7974B08A447ABE31
5 changed files with 36 additions and 25 deletions

View File

@ -50,9 +50,9 @@ describe('ZeroEx library', () => {
const address = '0x5409ed021d9299bf6814279a6a1411a7e866a631'; const address = '0x5409ed021d9299bf6814279a6a1411a7e866a631';
const bytes32Zeros = '0x0000000000000000000000000000000000000000000000000000000000000000'; const bytes32Zeros = '0x0000000000000000000000000000000000000000000000000000000000000000';
it("should return false if the data doesn't pertain to the signature & address", async () => { it("should return false if the data doesn't pertain to the signature & address", async () => {
return expect((zeroEx.exchange as any).isValidSignatureAsync(bytes32Zeros, address, ethSignSignature)).to.become( return expect(
false, (zeroEx.exchange as any).isValidSignatureAsync(bytes32Zeros, address, ethSignSignature),
); ).to.become(false);
}); });
it("should return false if the address doesn't pertain to the signature & data", async () => { it("should return false if the address doesn't pertain to the signature & data", async () => {
const validUnrelatedAddress = '0x8b0292b11a196601ed2ce54b665cafeca0347d42'; const validUnrelatedAddress = '0x8b0292b11a196601ed2ce54b665cafeca0347d42';

View File

@ -95,7 +95,11 @@ export class BaseContract {
const original = args[i]; const original = args[i];
const decoded = rawDecoded[i]; const decoded = rawDecoded[i];
if (!abiUtils.isAbiDataEqual(params.names[i], params.types[i], original, decoded)) { 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)`); throw new Error(
`Cannot safely encode argument: ${params.names[i]} (${original}) of type ${
params.types[i]
}. (Possible type overflow or other encoding error)`,
);
} }
} }
} }

View File

@ -8,20 +8,20 @@ const { expect } = chai;
describe('BaseContract', () => { describe('BaseContract', () => {
describe('strictArgumentEncodingCheck', () => { describe('strictArgumentEncodingCheck', () => {
it('works for simple types', () => { it('works for simple types', () => {
BaseContract.strictArgumentEncodingCheck([{ name: 'to', type: 'address' }], ['0xe834ec434daba538cd1b9fe1582052b880bd7e63']); BaseContract.strictArgumentEncodingCheck(
[{ name: 'to', type: 'address' }],
['0xe834ec434daba538cd1b9fe1582052b880bd7e63'],
);
}); });
it('works for array types', () => { it('works for array types', () => {
const inputAbi = [{ const inputAbi = [
name: 'takerAssetFillAmounts', {
type: 'uint256[]', name: 'takerAssetFillAmounts',
}]; type: 'uint256[]',
},
];
const args = [ const args = [
[ ['9000000000000000000', '79000000000000000000', '979000000000000000000', '7979000000000000000000'],
'9000000000000000000',
'79000000000000000000',
'979000000000000000000',
'7979000000000000000000',
],
]; ];
BaseContract.strictArgumentEncodingCheck(inputAbi, args); BaseContract.strictArgumentEncodingCheck(inputAbi, args);
}); });
@ -101,10 +101,14 @@ describe('BaseContract', () => {
BaseContract.strictArgumentEncodingCheck(inputAbi, args); BaseContract.strictArgumentEncodingCheck(inputAbi, args);
}); });
it('throws for integer overflows', () => { it('throws for integer overflows', () => {
expect(() => BaseContract.strictArgumentEncodingCheck([{ name: 'amount', type: 'uint8' }], ['256'])).to.throw(); expect(() =>
BaseContract.strictArgumentEncodingCheck([{ name: 'amount', type: 'uint8' }], ['256']),
).to.throw();
}); });
it('throws for fixed byte array overflows', () => { it('throws for fixed byte array overflows', () => {
expect(() => BaseContract.strictArgumentEncodingCheck([{ name: 'hash', type: 'bytes8' }], ['0x001122334455667788'])).to.throw(); expect(() =>
BaseContract.strictArgumentEncodingCheck([{ name: 'hash', type: 'bytes8' }], ['0x001122334455667788']),
).to.throw();
}); });
}); });
}); });

View File

@ -21,10 +21,12 @@ function parseEthersParams(params: DataItem[]): { names: EthersParamName[]; type
if (param.components != null) { if (param.components != null) {
let suffix = ''; let suffix = '';
const arrayBracket = param.type.indexOf('['); const arrayBracket = param.type.indexOf('[');
if (arrayBracket >= 0) { suffix = param.type.substring(arrayBracket); } if (arrayBracket >= 0) {
suffix = param.type.substring(arrayBracket);
}
const result = parseEthersParams(param.components); const result = parseEthersParams(param.components);
names.push({ name: (param.name || null), names: result.names }); names.push({ name: param.name || null, names: result.names });
types.push('tuple(' + result.types.join(',') + ')' + suffix); types.push('tuple(' + result.types.join(',') + ')' + suffix);
} else { } else {
names.push(param.name || null); names.push(param.name || null);
@ -74,7 +76,9 @@ function isAbiDataEqual(name: EthersParamName, type: string, x: any, y: any): bo
// one individually. // one individually.
const types = splitTupleTypes(type); const types = splitTupleTypes(type);
if (types.length !== name.names.length) { if (types.length !== name.names.length) {
throw new Error(`Internal error: parameter types/names length mismatch (${types.length} != ${name.names.length})`); throw new Error(
`Internal error: parameter types/names length mismatch (${types.length} != ${name.names.length})`,
);
} }
for (let i = 0; i < types.length; i++) { for (let i = 0; i < types.length; i++) {
// For tuples, name is an object with a names property that is an // For tuples, name is an object with a names property that is an
@ -89,7 +93,9 @@ function isAbiDataEqual(name: EthersParamName, type: string, x: any, y: any): bo
// ] // ]
// } // }
// //
const nestedName = _.isString(name.names[i]) ? name.names[i] as string : (name.names[i] as EthersNestedParamName).name as string; const nestedName = _.isString(name.names[i])
? (name.names[i] as string)
: ((name.names[i] as EthersNestedParamName).name as string);
if (!isAbiDataEqual(name.names[i], types[i], x[nestedName], y[nestedName])) { if (!isAbiDataEqual(name.names[i], types[i], x[nestedName], y[nestedName])) {
return false; return false;
} }

View File

@ -3,8 +3,5 @@
"compilerOptions": { "compilerOptions": {
"outDir": "lib" "outDir": "lib"
}, },
"include": [ "include": ["src/**/*", "test/**/*"]
"src/**/*",
"test/**/*"
]
} }