Throw in web3-wrapper when rawCallResult is '0x'
This commit is contained in:
parent
ae1cf74dcd
commit
bca62c813d
@ -30,3 +30,15 @@ export function expectInsufficientFunds<T>(p: Promise<T>): PromiseLike<void> {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function expectRevertOrContractCallFailed<T>(p: Promise<T>): PromiseLike<void> {
|
||||||
|
return expect(p)
|
||||||
|
.to.be.rejected()
|
||||||
|
.then(e => {
|
||||||
|
expect(e).to.satisfy(
|
||||||
|
(err: Error) =>
|
||||||
|
_.includes(err.message, constants.REVERT) ||
|
||||||
|
_.includes(err.message, constants.CONTRACT_CALL_FAILED),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@ -20,6 +20,7 @@ export const constants = {
|
|||||||
INVALID_OPCODE: 'invalid opcode',
|
INVALID_OPCODE: 'invalid opcode',
|
||||||
REVERT: 'revert',
|
REVERT: 'revert',
|
||||||
ALWAYS_FAILING_TRANSACTION: 'always failing transaction',
|
ALWAYS_FAILING_TRANSACTION: 'always failing transaction',
|
||||||
|
CONTRACT_CALL_FAILED: 'Contract call failed',
|
||||||
LIB_BYTES_GT_ZERO_LENGTH_REQUIRED: 'Length must be greater than 0.',
|
LIB_BYTES_GT_ZERO_LENGTH_REQUIRED: 'Length must be greater than 0.',
|
||||||
LIB_BYTES_GTE_4_LENGTH_REQUIRED: 'Length must be greater than or equal to 4.',
|
LIB_BYTES_GTE_4_LENGTH_REQUIRED: 'Length must be greater than or equal to 4.',
|
||||||
LIB_BYTES_GTE_20_LENGTH_REQUIRED: 'Length must be greater than or equal to 20.',
|
LIB_BYTES_GTE_20_LENGTH_REQUIRED: 'Length must be greater than or equal to 20.',
|
||||||
|
@ -15,7 +15,7 @@ import {
|
|||||||
} from '../src/contract_wrappers/generated/asset_proxy_owner';
|
} from '../src/contract_wrappers/generated/asset_proxy_owner';
|
||||||
import { MixinAuthorizableContract } from '../src/contract_wrappers/generated/mixin_authorizable';
|
import { MixinAuthorizableContract } from '../src/contract_wrappers/generated/mixin_authorizable';
|
||||||
import { artifacts } from '../src/utils/artifacts';
|
import { artifacts } from '../src/utils/artifacts';
|
||||||
import { expectRevertOrAlwaysFailingTransaction } from '../src/utils/assertions';
|
import { expectRevertOrAlwaysFailingTransaction, expectRevertOrContractCallFailed } from '../src/utils/assertions';
|
||||||
import { chaiSetup } from '../src/utils/chai_setup';
|
import { chaiSetup } from '../src/utils/chai_setup';
|
||||||
import { constants } from '../src/utils/constants';
|
import { constants } from '../src/utils/constants';
|
||||||
import { increaseTimeAndMineBlockAsync } from '../src/utils/increase_time';
|
import { increaseTimeAndMineBlockAsync } from '../src/utils/increase_time';
|
||||||
@ -118,15 +118,13 @@ describe('AssetProxyOwner', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('isFunctionRemoveAuthorizedAddress', () => {
|
describe('isFunctionRemoveAuthorizedAddress', () => {
|
||||||
// TODO(albrow):
|
it('should throw if data is not for removeAuthorizedAddress', async () => {
|
||||||
// AssertionError: expected promise to be rejected with an error including 'revert' but got 'invalid data for function output (arg="data", errorArg=null, errorValue="0x", value="0x", reason="insufficient data for boolean type")'
|
|
||||||
it.skip('should throw if data is not for removeAuthorizedAddress', async () => {
|
|
||||||
const notRemoveAuthorizedAddressData = erc20Proxy.addAuthorizedAddress.getABIEncodedTransactionData(
|
const notRemoveAuthorizedAddressData = erc20Proxy.addAuthorizedAddress.getABIEncodedTransactionData(
|
||||||
owners[0],
|
owners[0],
|
||||||
);
|
);
|
||||||
return expect(
|
return expectRevertOrContractCallFailed(
|
||||||
multiSig.isFunctionRemoveAuthorizedAddress.callAsync(notRemoveAuthorizedAddressData),
|
multiSig.isFunctionRemoveAuthorizedAddress.callAsync(notRemoveAuthorizedAddressData),
|
||||||
).to.be.rejectedWith(constants.REVERT);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true if data is for removeAuthorizedAddress', async () => {
|
it('should return true if data is for removeAuthorizedAddress', async () => {
|
||||||
|
@ -315,6 +315,9 @@ export class Web3Wrapper {
|
|||||||
*/
|
*/
|
||||||
public async callAsync(callData: CallData, defaultBlock?: BlockParam): Promise<string> {
|
public async callAsync(callData: CallData, defaultBlock?: BlockParam): Promise<string> {
|
||||||
const rawCallResult = await promisify<string>(this._web3.eth.call)(callData, defaultBlock);
|
const rawCallResult = await promisify<string>(this._web3.eth.call)(callData, defaultBlock);
|
||||||
|
if (rawCallResult === '0x') {
|
||||||
|
throw new Error('Contract call failed (returned null)');
|
||||||
|
}
|
||||||
return rawCallResult;
|
return rawCallResult;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user