Apply prettier
This commit is contained in:
parent
6a5965d73b
commit
6a6739ebbe
@ -50,9 +50,9 @@ describe('ZeroEx library', () => {
|
||||
const address = '0x5409ed021d9299bf6814279a6a1411a7e866a631';
|
||||
const bytes32Zeros = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
||||
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(
|
||||
false,
|
||||
);
|
||||
return expect(
|
||||
(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 () => {
|
||||
const validUnrelatedAddress = '0x8b0292b11a196601ed2ce54b665cafeca0347d42';
|
||||
|
@ -95,7 +95,11 @@ export class BaseContract {
|
||||
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)`);
|
||||
throw new Error(
|
||||
`Cannot safely encode argument: ${params.names[i]} (${original}) of type ${
|
||||
params.types[i]
|
||||
}. (Possible type overflow or other encoding error)`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,20 +8,20 @@ const { expect } = chai;
|
||||
describe('BaseContract', () => {
|
||||
describe('strictArgumentEncodingCheck', () => {
|
||||
it('works for simple types', () => {
|
||||
BaseContract.strictArgumentEncodingCheck([{ name: 'to', type: 'address' }], ['0xe834ec434daba538cd1b9fe1582052b880bd7e63']);
|
||||
BaseContract.strictArgumentEncodingCheck(
|
||||
[{ name: 'to', type: 'address' }],
|
||||
['0xe834ec434daba538cd1b9fe1582052b880bd7e63'],
|
||||
);
|
||||
});
|
||||
it('works for array types', () => {
|
||||
const inputAbi = [{
|
||||
const inputAbi = [
|
||||
{
|
||||
name: 'takerAssetFillAmounts',
|
||||
type: 'uint256[]',
|
||||
}];
|
||||
},
|
||||
];
|
||||
const args = [
|
||||
[
|
||||
'9000000000000000000',
|
||||
'79000000000000000000',
|
||||
'979000000000000000000',
|
||||
'7979000000000000000000',
|
||||
],
|
||||
['9000000000000000000', '79000000000000000000', '979000000000000000000', '7979000000000000000000'],
|
||||
];
|
||||
BaseContract.strictArgumentEncodingCheck(inputAbi, args);
|
||||
});
|
||||
@ -101,10 +101,14 @@ describe('BaseContract', () => {
|
||||
BaseContract.strictArgumentEncodingCheck(inputAbi, args);
|
||||
});
|
||||
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', () => {
|
||||
expect(() => BaseContract.strictArgumentEncodingCheck([{ name: 'hash', type: 'bytes8' }], ['0x001122334455667788'])).to.throw();
|
||||
expect(() =>
|
||||
BaseContract.strictArgumentEncodingCheck([{ name: 'hash', type: 'bytes8' }], ['0x001122334455667788']),
|
||||
).to.throw();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -21,10 +21,12 @@ function parseEthersParams(params: DataItem[]): { names: EthersParamName[]; type
|
||||
if (param.components != null) {
|
||||
let suffix = '';
|
||||
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);
|
||||
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);
|
||||
} else {
|
||||
names.push(param.name || null);
|
||||
@ -74,7 +76,9 @@ function isAbiDataEqual(name: EthersParamName, type: string, x: any, y: any): bo
|
||||
// one individually.
|
||||
const types = splitTupleTypes(type);
|
||||
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 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])) {
|
||||
return false;
|
||||
}
|
||||
|
@ -3,8 +3,5 @@
|
||||
"compilerOptions": {
|
||||
"outDir": "lib"
|
||||
},
|
||||
"include": [
|
||||
"src/**/*",
|
||||
"test/**/*"
|
||||
]
|
||||
"include": ["src/**/*", "test/**/*"]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user