-
Notifications
You must be signed in to change notification settings - Fork 465
Conversation
…a transaction to be mined
1d6b8cf
to
876032a
Compare
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 |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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?
src/web3_wrapper.ts
Outdated
if (_.isUndefined(artifact.networks[networkIdIfExists])) { | ||
throw new Error(ZeroExError.ContractNotDeployedOnNetwork); | ||
} | ||
address = artifact.networks[networkIdIfExists].address.toLowerCase(); |
There was a problem hiding this comment.
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.
// abi-decoder declarations | ||
interface DecodedLogArg { | ||
name: string; | ||
value: string|BigNumber.BigNumber; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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?
test/0x.js_test.ts
Outdated
afterEach(async () => { | ||
await blockchainLifecycle.revertAsync(); | ||
}); | ||
it('return transaction receipt with decoded logs', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returns
This PR:
truffle-conract
🥇 💯 👍zeroEx.awaitTransactionMinedAsync
web3_beta
and tests, but still leaves support for theweb3_beta
provider, cause having bothweb3
's breaks the instalation.