Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
prettify generated code for easier diffing (#1944)
Browse files Browse the repository at this point in the history
  • Loading branch information
xianny authored Jul 11, 2019
1 parent 3a0b0c0 commit ccb89fb
Show file tree
Hide file tree
Showing 10 changed files with 440 additions and 558 deletions.
5 changes: 0 additions & 5 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ lib
/contracts/exchange-forwarder/generated-artifacts
/contracts/dev-utils/generated-wrappers
/contracts/dev-utils/generated-artifacts
/packages/abi-gen/test-cli/fixtures/artifacts/
/packages/abi-gen/test-cli/output
/packages/abi-gen/test-cli/expected-output
/packages/abi-gen-wrappers/src/generated-wrappers
/packages/contract-artifacts/artifacts
/python-packages/contract_artifacts/src/zero_ex/contract_artifacts/artifacts
/packages/json-schemas/schemas
/python-packages/json_schemas/src/zero_ex/json_schemas/schemas
/packages/metacoin/src/contract_wrappers
Expand Down
3 changes: 2 additions & 1 deletion packages/abi-gen-wrappers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
"build:ci": "yarn build",
"lint": "tslint --format stylish --project .",
"fix": "tslint --fix --format stylish --project .",
"pre_build": "yarn generate_contract_wrappers",
"pre_build": "yarn generate_contract_wrappers && yarn prettier_contract_wrappers",
"prettier": "prettier --write src/**/* --config ../../.prettierrc",
"prettier_contract_wrappers": "prettier --write src/generated-wrappers/* --config ../../.prettierrc",
"clean": "shx rm -rf lib src/generated-wrappers",
"generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --template ../../node_modules/@0x/abi-gen-templates/contract.handlebars --partials '../../node_modules/@0x/abi-gen-templates/partials/**/*.handlebars' --output src/generated-wrappers --backend ethers"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/abi-gen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"lint-contracts": "solhint -c ../../contracts/.solhint.json test-cli/contracts/*.sol",
"fix": "tslint --fix --format stylish --project . && yarn lint-contracts",
"clean": "shx rm -rf lib && yarn test_cli:clean",
"build": "tsc -b && yarn generate_contract_wrappers && yarn test_cli:build",
"build": "tsc -b && yarn generate_contract_wrappers && yarn prettier_contract_wrappers && yarn test_cli:build",
"build:ci": "yarn build",
"test": "yarn run_mocha && yarn test_cli",
"test:circleci": "yarn test:coverage && yarn test_cli",
Expand All @@ -29,6 +29,7 @@
"clean:sol": "rm -rf test-cli/artifacts",
"compile:sol": "sol-compiler",
"watch:sol": "sol-compiler -w",
"prettier_contract_wrappers": "prettier --write ./test-cli/output/typescript/* --config ../../.prettierrc",
"generate_contract_wrappers": "run-p gen_typescript gen_python",
"gen_typescript": "abi-gen --abis ${npm_package_config_abis} --template ../../node_modules/@0x/abi-gen-templates/contract.handlebars --partials '../../node_modules/@0x/abi-gen-templates/partials/**/*.handlebars' --output ./test-cli/output/typescript --backend ethers",
"gen_python": "abi-gen --abis ${npm_package_config_abis} --template ../../node_modules/@0x/abi-gen-templates/Python/contract.handlebars --partials '../../node_modules/@0x/abi-gen-templates/Python/partials/**/*.handlebars' --output ./test-cli/output/python --language Python",
Expand Down
228 changes: 75 additions & 153 deletions packages/abi-gen/test-cli/expected-output/typescript/abi_gen_dummy.ts

Large diffs are not rendered by default.

17 changes: 5 additions & 12 deletions packages/abi-gen/test-cli/expected-output/typescript/lib_dummy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { assert } from '@0x/assert';
import * as ethers from 'ethers';
// tslint:enable:no-unused-variable


/* istanbul ignore next */
// tslint:disable:no-parameter-reassignment
// tslint:disable-next-line:class-name
Expand All @@ -44,7 +43,7 @@ export class LibDummyContract extends BaseContract {
const provider = providerUtils.standardizeOrThrow(supportedProvider);
const bytecode = artifact.compilerOutput.evm.bytecode.object;
const abi = artifact.compilerOutput.abi;
return LibDummyContract.deployAsync(bytecode, abi, provider, txDefaults, );
return LibDummyContract.deployAsync(bytecode, abi, provider, txDefaults);
}
public static async deployAsync(
bytecode: string,
Expand All @@ -60,17 +59,13 @@ export class LibDummyContract extends BaseContract {
]);
const provider = providerUtils.standardizeOrThrow(supportedProvider);
const constructorAbi = BaseContract._lookupConstructorAbi(abi);
[] = BaseContract._formatABIDataItemList(
constructorAbi.inputs,
[],
BaseContract._bigNumberToString,
);
[] = BaseContract._formatABIDataItemList(constructorAbi.inputs, [], BaseContract._bigNumberToString);
const iface = new ethers.utils.Interface(abi);
const deployInfo = iface.deployFunction;
const txData = deployInfo.encode(bytecode, []);
const web3Wrapper = new Web3Wrapper(provider);
const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync(
{data: txData},
{ data: txData },
txDefaults,
web3Wrapper.estimateGasAsync.bind(web3Wrapper),
);
Expand All @@ -83,20 +78,18 @@ export class LibDummyContract extends BaseContract {
return contractInstance;
}


/**
* @returns The contract ABI
*/
public static ABI(): ContractAbi {
const abi = [
] as ContractAbi;
const abi = [] as ContractAbi;
return abi;
}
constructor(address: string, supportedProvider: SupportedProvider, txDefaults?: Partial<TxData>) {
super('LibDummy', LibDummyContract.ABI(), address, supportedProvider, txDefaults);
classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']);
}
}
}

// tslint:disable:max-file-line-count
// tslint:enable:no-unbound-method no-parameter-reassignment no-consecutive-blank-lines ordered-imports align
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,12 @@ import { assert } from '@0x/assert';
import * as ethers from 'ethers';
// tslint:enable:no-unused-variable


/* istanbul ignore next */
// tslint:disable:no-parameter-reassignment
// tslint:disable-next-line:class-name
export class TestLibDummyContract extends BaseContract {
public publicAddConstant = {
async callAsync(
x: BigNumber,
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber
> {
async callAsync(x: BigNumber, callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber> {
assert.isBigNumber('x', x);
assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [
schemas.addressSchema,
Expand All @@ -44,9 +38,8 @@ export class TestLibDummyContract extends BaseContract {
if (defaultBlock !== undefined) {
assert.isBlockParam('defaultBlock', defaultBlock);
}
const self = this as any as TestLibDummyContract;
const encodedData = self._strictEncodeArguments('publicAddConstant(uint256)', [x
]);
const self = (this as any) as TestLibDummyContract;
const encodedData = self._strictEncodeArguments('publicAddConstant(uint256)', [x]);
const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync(
{
to: self.address,
Expand All @@ -59,28 +52,19 @@ export class TestLibDummyContract extends BaseContract {
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('publicAddConstant(uint256)');
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<BigNumber
>(rawCallResult);
const result = abiEncoder.strictDecodeReturnValue<BigNumber>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
getABIEncodedTransactionData(
x: BigNumber,
): string {
getABIEncodedTransactionData(x: BigNumber): string {
assert.isBigNumber('x', x);
const self = this as any as TestLibDummyContract;
const abiEncodedTransactionData = self._strictEncodeArguments('publicAddConstant(uint256)', [x
]);
const self = (this as any) as TestLibDummyContract;
const abiEncodedTransactionData = self._strictEncodeArguments('publicAddConstant(uint256)', [x]);
return abiEncodedTransactionData;
},
};
public publicAddOne = {
async callAsync(
x: BigNumber,
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<BigNumber
> {
async callAsync(x: BigNumber, callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber> {
assert.isBigNumber('x', x);
assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [
schemas.addressSchema,
Expand All @@ -90,9 +74,8 @@ export class TestLibDummyContract extends BaseContract {
if (defaultBlock !== undefined) {
assert.isBlockParam('defaultBlock', defaultBlock);
}
const self = this as any as TestLibDummyContract;
const encodedData = self._strictEncodeArguments('publicAddOne(uint256)', [x
]);
const self = (this as any) as TestLibDummyContract;
const encodedData = self._strictEncodeArguments('publicAddOne(uint256)', [x]);
const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync(
{
to: self.address,
Expand All @@ -105,18 +88,14 @@ export class TestLibDummyContract extends BaseContract {
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('publicAddOne(uint256)');
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<BigNumber
>(rawCallResult);
const result = abiEncoder.strictDecodeReturnValue<BigNumber>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
getABIEncodedTransactionData(
x: BigNumber,
): string {
getABIEncodedTransactionData(x: BigNumber): string {
assert.isBigNumber('x', x);
const self = this as any as TestLibDummyContract;
const abiEncodedTransactionData = self._strictEncodeArguments('publicAddOne(uint256)', [x
]);
const self = (this as any) as TestLibDummyContract;
const abiEncodedTransactionData = self._strictEncodeArguments('publicAddOne(uint256)', [x]);
return abiEncodedTransactionData;
},
};
Expand All @@ -136,7 +115,7 @@ export class TestLibDummyContract extends BaseContract {
const provider = providerUtils.standardizeOrThrow(supportedProvider);
const bytecode = artifact.compilerOutput.evm.bytecode.object;
const abi = artifact.compilerOutput.abi;
return TestLibDummyContract.deployAsync(bytecode, abi, provider, txDefaults, );
return TestLibDummyContract.deployAsync(bytecode, abi, provider, txDefaults);
}
public static async deployAsync(
bytecode: string,
Expand All @@ -152,17 +131,13 @@ export class TestLibDummyContract extends BaseContract {
]);
const provider = providerUtils.standardizeOrThrow(supportedProvider);
const constructorAbi = BaseContract._lookupConstructorAbi(abi);
[] = BaseContract._formatABIDataItemList(
constructorAbi.inputs,
[],
BaseContract._bigNumberToString,
);
[] = BaseContract._formatABIDataItemList(constructorAbi.inputs, [], BaseContract._bigNumberToString);
const iface = new ethers.utils.Interface(abi);
const deployInfo = iface.deployFunction;
const txData = deployInfo.encode(bytecode, []);
const web3Wrapper = new Web3Wrapper(provider);
const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync(
{data: txData},
{ data: txData },
txDefaults,
web3Wrapper.estimateGasAsync.bind(web3Wrapper),
);
Expand All @@ -175,48 +150,43 @@ export class TestLibDummyContract extends BaseContract {
return contractInstance;
}


/**
* @returns The contract ABI
*/
public static ABI(): ContractAbi {
const abi = [
{
{
constant: true,
inputs: [
{
name: 'x',
type: 'uint256',

},
],
name: 'publicAddConstant',
outputs: [
{
name: 'result',
type: 'uint256',

},
],
payable: false,
stateMutability: 'pure',
type: 'function',
},
{
{
constant: true,
inputs: [
{
name: 'x',
type: 'uint256',

},
],
name: 'publicAddOne',
outputs: [
{
name: 'result',
type: 'uint256',

},
],
payable: false,
Expand All @@ -230,7 +200,7 @@ export class TestLibDummyContract extends BaseContract {
super('TestLibDummy', TestLibDummyContract.ABI(), address, supportedProvider, txDefaults);
classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']);
}
}
}

// tslint:disable:max-file-line-count
// tslint:enable:no-unbound-method no-parameter-reassignment no-consecutive-blank-lines ordered-imports align
Expand Down
Loading

0 comments on commit ccb89fb

Please sign in to comment.