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

Remove truffle contracts dependency #151

Merged
merged 31 commits into from
Sep 6, 2017

Conversation

LogvinovLeon
Copy link
Contributor

@LogvinovLeon LogvinovLeon commented Sep 4, 2017

This PR:

  • Removes truffle-conract 🥇 💯 👍
  • Starts using custom contract abstraction
  • Stops awaiting transactions to be mined and returns transaction hash immidiately
  • Adds zeroEx.awaitTransactionMinedAsync
  • Removes web3_beta and tests, but still leaves support for the web3_beta provider, cause having both web3's breaks the instalation.

@0xProject 0xProject deleted a comment from coveralls Sep 4, 2017
@0xProject 0xProject deleted a comment from coveralls Sep 4, 2017
@0xProject 0xProject deleted a comment from coveralls Sep 4, 2017
@0xProject 0xProject deleted a comment from coveralls Sep 5, 2017
@0xProject 0xProject deleted a comment from coveralls Sep 5, 2017
@0xProject 0xProject deleted a comment from coveralls Sep 5, 2017
@0xProject 0xProject deleted a comment from coveralls Sep 5, 2017
@0xProject 0xProject deleted a comment from coveralls Sep 5, 2017
@0xProject 0xProject deleted a comment from coveralls Sep 5, 2017
@LogvinovLeon LogvinovLeon changed the title [WIP] Remove truffle contracts dependency Remove truffle contracts dependency Sep 5, 2017
@0xProject 0xProject deleted a comment from coveralls Sep 5, 2017
@LogvinovLeon LogvinovLeon force-pushed the feature/remove-truffle-contracts branch from 1d6b8cf to 876032a Compare September 5, 2017 08:52
@0xProject 0xProject deleted a comment from coveralls Sep 5, 2017
@coveralls
Copy link

Coverage Status

Coverage increased (+71.6%) to 97.995% when pulling a12df1c on feature/remove-truffle-contracts into 0275ac9 on development.

@0xProject 0xProject deleted a comment from coveralls Sep 5, 2017
src/0x.ts Outdated
@@ -249,4 +252,23 @@ export class ZeroEx {

throw new Error(ZeroExError.InvalidSignature);
}
/**
* Waits for transaction to be mined and returns the transaction receipt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waits for a transaction to be mined and returns the transaction receipt

src/0x.ts Outdated
* @return Web3.TransactionReceipt
*/
public async awaitTransactionMinedAsync(txHash: string,
pollingIntervalMs: number = 500): Promise<TransactionReceipt> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1000

@@ -0,0 +1,68 @@
import * as Web3 from 'web3';
import * as _ from 'lodash';
import promisify = require('es6-promisify');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not use the regular import style?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately. Whenever the package exports a function (non module object) we need to do it like that.
https://stackoverflow.com/a/35706271/3546986

src/contract.ts Outdated
public abi: Web3.ContractAbi;
private contract: Web3.ContractInstance;
private defaults: Partial<Web3.TxData>;
[name: string]: any;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment explaining this and where it is going to be used.

src/contract.ts Outdated
_.forEach(functionsAbi, (functionAbi: Web3.MethodAbi) => {
const cbStyleFunction = this.contract[functionAbi.name];
if (functionAbi.constant) {
this[functionAbi.name] = promisify(cbStyleFunction, this.contract);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this one and force people to use .callAsync

src/contract.ts Outdated
const promise = new Promise((resolve, reject) => {
const lastArg = args[args.length - 1];
let txData: Partial<Web3.TxData> = {};
if (_.isObject(lastArg) && !_.isArray(lastArg) && !lastArg.isBigNumber) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this validation stricter. We should make sure that it's an object that conforms to the txData schema.

src/contract.ts Outdated
}
txData = {
...txData,
...this.defaults,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The defaults should not overwrite the txData.

@@ -182,10 +181,7 @@ export class ExchangeWrapper extends ContractWrapper {
gas,
},
);
this._throwErrorLogsAsErrors(response.logs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this method

@@ -730,7 +721,9 @@ export class ExchangeWrapper extends ContractWrapper {
if (!_.isUndefined(this._exchangeContractIfExists)) {
return this._exchangeContractIfExists;
}
const contractInstance = await this._instantiateContractIfExistsAsync((ExchangeArtifacts as any));
const contractInstance = await this._instantiateContractIfExistsAsync<ExchangeContract>(
(ExchangeArtifacts as any),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we not have to cast as Artifact here?

if (_.isUndefined(artifact.networks[networkIdIfExists])) {
throw new Error(ZeroExError.ContractNotDeployedOnNetwork);
}
address = artifact.networks[networkIdIfExists].address.toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not overwrite function args.

@0xProject 0xProject deleted a comment from coveralls Sep 5, 2017
@0xProject 0xProject deleted a comment from coveralls Sep 5, 2017
@0xProject 0xProject deleted a comment from coveralls Sep 5, 2017
@0xProject 0xProject deleted a comment from coveralls Sep 5, 2017
@0xProject 0xProject deleted a comment from coveralls Sep 5, 2017
@0xProject 0xProject deleted a comment from coveralls Sep 5, 2017
// abi-decoder declarations
interface DecodedLogArg {
name: string;
value: string|BigNumber.BigNumber;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this really only be string or bignumber? What about boolean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already had this discussion.
The result of it is ContractEventArg type in types.ts, which I can't import in global.ts.
We have a rule to not define unneccessary types before they're needed.
Currently we will decode only our events and our events have only those types

src/index.ts Outdated
TransactionReceipt,
TransactionReceiptWithDecodedLogs,
LogWithDecodedArgs,
DecodedLogArgs,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please put the relevant ones in public types list in website.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do after this is finalized and merged

signedOrder, partialFillAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress);
await zeroEx.awaitTransactionMinedAsync(txHash);
expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, makerAddress))
.to.be.bignumber.equal(fillableAmount.minus(partialFillAmount));
expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, makerAddress))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test that makes sure that the decodedLogs that are returned are of the expected format and values?

@0xProject 0xProject deleted a comment from coveralls Sep 5, 2017
@0xProject 0xProject deleted a comment from coveralls Sep 5, 2017
@0xProject 0xProject deleted a comment from coveralls Sep 5, 2017
@coveralls
Copy link

Coverage Status

Coverage increased (+72.0%) to 98.393% when pulling 8ebc724 on feature/remove-truffle-contracts into 0275ac9 on development.

afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
it('return transaction receipt with decoded logs', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returns

@LogvinovLeon LogvinovLeon merged commit f0a5ad2 into development Sep 6, 2017
@LogvinovLeon LogvinovLeon deleted the feature/remove-truffle-contracts branch September 6, 2017 08:28
@coveralls
Copy link

Coverage Status

Coverage increased (+49.9%) to 76.339% when pulling 258b4fa on feature/remove-truffle-contracts into 0275ac9 on development.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants