-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
581 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@ethereum-waffle/chai": patch | ||
--- | ||
|
||
Allow chaining matchers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,37 @@ | ||
import {BigNumber, BigNumberish} from 'ethers'; | ||
import {Account, getAddressOf} from './misc/account'; | ||
import {getBalanceChange} from './changeEtherBalance'; | ||
import {transactionPromise} from '../transaction-promise'; | ||
|
||
export function supportChangeBalance(Assertion: Chai.AssertionStatic) { | ||
Assertion.addMethod('changeBalance', function ( | ||
this: any, | ||
account: Account, | ||
balanceChange: BigNumberish | ||
) { | ||
const subject = this._obj; | ||
const derivedPromise = Promise.all([ | ||
getBalanceChange(subject, account, {includeFee: true}), | ||
getAddressOf(account) | ||
]).then( | ||
([actualChange, address]) => { | ||
this.assert( | ||
actualChange.eq(BigNumber.from(balanceChange)), | ||
`Expected "${address}" to change balance by ${balanceChange} wei, ` + | ||
`but it has changed by ${actualChange} wei`, | ||
`Expected "${address}" to not change balance by ${balanceChange} wei,`, | ||
balanceChange, | ||
actualChange | ||
); | ||
} | ||
); | ||
transactionPromise(this); | ||
const isNegated = this.__flags.negate === true; | ||
const derivedPromise = this.txPromise.then(() => { | ||
return Promise.all([ | ||
getBalanceChange(this.txResponse, account, {includeFee: true}), | ||
getAddressOf(account) | ||
]); | ||
}).then(([actualChange, address]: [BigNumber, string]) => { | ||
const isCurrentlyNegated = this.__flags.negate === true; | ||
this.__flags.negate = isNegated; | ||
this.assert( | ||
actualChange.eq(BigNumber.from(balanceChange)), | ||
`Expected "${address}" to change balance by ${balanceChange} wei, ` + | ||
`but it has changed by ${actualChange} wei`, | ||
`Expected "${address}" to not change balance by ${balanceChange} wei,`, | ||
balanceChange, | ||
actualChange | ||
); | ||
this.__flags.negate = isCurrentlyNegated; | ||
}); | ||
this.then = derivedPromise.then.bind(derivedPromise); | ||
this.catch = derivedPromise.catch.bind(derivedPromise); | ||
this.promise = derivedPromise; | ||
this.txPromise = derivedPromise; | ||
return this; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.