Remove promisified web3 functions from tests
This commit is contained in:
parent
e56b2ceebb
commit
6f13d107c4
@ -20,12 +20,6 @@ describe('EtherToken', () => {
|
||||
const gasPrice = ZeroEx.toBaseUnitAmount(new BigNumber(20), 9);
|
||||
let zeroEx: ZeroEx;
|
||||
let etherTokenAddress: string;
|
||||
const sendTransactionAsync = promisify<string>(web3.eth.sendTransaction);
|
||||
const getEthBalanceAsync = async (owner: string) => {
|
||||
const balanceStr = await promisify<string>(web3.eth.getBalance)(owner);
|
||||
const balance = new BigNumber(balanceStr);
|
||||
return balance;
|
||||
};
|
||||
before(async () => {
|
||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
account = accounts[0];
|
||||
@ -45,7 +39,7 @@ describe('EtherToken', () => {
|
||||
});
|
||||
describe('deposit', () => {
|
||||
it('should throw if caller attempts to deposit more Ether than caller balance', async () => {
|
||||
const initEthBalance = await getEthBalanceAsync(account);
|
||||
const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
|
||||
const ethToDeposit = initEthBalance.plus(1);
|
||||
|
||||
return expect(zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account)).to.be.rejectedWith(
|
||||
@ -54,7 +48,7 @@ describe('EtherToken', () => {
|
||||
});
|
||||
|
||||
it('should convert deposited Ether to wrapped Ether tokens', async () => {
|
||||
const initEthBalance = await getEthBalanceAsync(account);
|
||||
const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
|
||||
const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
|
||||
|
||||
const ethToDeposit = new BigNumber(web3.toWei(1, 'ether'));
|
||||
@ -63,7 +57,7 @@ describe('EtherToken', () => {
|
||||
const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
|
||||
|
||||
const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
|
||||
const finalEthBalance = await getEthBalanceAsync(account);
|
||||
const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
|
||||
const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
|
||||
|
||||
expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas)));
|
||||
@ -85,7 +79,7 @@ describe('EtherToken', () => {
|
||||
const ethToDeposit = new BigNumber(web3.toWei(1, 'ether'));
|
||||
await zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account);
|
||||
const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
|
||||
const initEthBalance = await getEthBalanceAsync(account);
|
||||
const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
|
||||
const ethTokensToWithdraw = initEthTokenBalance;
|
||||
expect(ethTokensToWithdraw).to.not.be.bignumber.equal(0);
|
||||
const txHash = await zeroEx.etherToken.withdrawAsync(etherTokenAddress, ethTokensToWithdraw, account, {
|
||||
@ -94,7 +88,7 @@ describe('EtherToken', () => {
|
||||
const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
|
||||
|
||||
const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
|
||||
const finalEthBalance = await getEthBalanceAsync(account);
|
||||
const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
|
||||
const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
|
||||
|
||||
expect(finalEthBalance).to.be.bignumber.equal(
|
||||
@ -106,12 +100,12 @@ describe('EtherToken', () => {
|
||||
|
||||
describe('fallback', () => {
|
||||
it('should convert sent ether to ether tokens', async () => {
|
||||
const initEthBalance = await getEthBalanceAsync(account);
|
||||
const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
|
||||
const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
|
||||
|
||||
const ethToDeposit = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18);
|
||||
|
||||
const txHash = await sendTransactionAsync({
|
||||
const txHash = await web3Wrapper.sendTransactionAsync({
|
||||
from: account,
|
||||
to: etherTokenAddress,
|
||||
value: ethToDeposit,
|
||||
@ -121,7 +115,7 @@ describe('EtherToken', () => {
|
||||
const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
|
||||
|
||||
const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
|
||||
const finalEthBalance = await getEthBalanceAsync(account);
|
||||
const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
|
||||
const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
|
||||
|
||||
expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas)));
|
||||
|
@ -134,6 +134,10 @@ export class Web3Wrapper {
|
||||
const gas = await promisify<number>(this._web3.eth.estimateGas)({ data });
|
||||
return gas;
|
||||
}
|
||||
public async sendTransactionAsync(txData: Web3.TxData): Promise<string> {
|
||||
const txHash = await promisify<string>(this._web3.eth.sendTransaction)(txData);
|
||||
return txHash;
|
||||
}
|
||||
private async _sendRawPayloadAsync<A>(payload: Web3.JSONRPCRequestPayload): Promise<A> {
|
||||
const sendAsync = this._web3.currentProvider.sendAsync.bind(this._web3.currentProvider);
|
||||
const response = await promisify<Web3.JSONRPCResponsePayload>(sendAsync)(payload);
|
||||
|
Loading…
x
Reference in New Issue
Block a user