protocol/contracts/utils/test/lib_rich_errors.ts
Xianny fcbcbac889
Remove assetDataUtils everywhere (#2373)
* remove assetDataUtils everywhere

* export IAssetDataContract from @0x/contract-wrappers to allow @0x/instant to decode asset data  synchronously

* export generic function `decodeAssetDataOrThrow` and add ERC20Bridge support

* export `hexUtils` from order-utils instead of contracts-test-utils
2019-12-04 13:08:08 -08:00

40 lines
1.4 KiB
TypeScript

import { blockchainTests, expect } from '@0x/contracts-test-utils';
import { coerceThrownErrorAsRevertError, hexUtils, StringRevertError } from '@0x/utils';
import { artifacts } from './artifacts';
import { TestLibRichErrorsContract } from './wrappers';
blockchainTests('LibRichErrors', env => {
let lib: TestLibRichErrorsContract;
before(async () => {
// Deploy SafeMath
lib = await TestLibRichErrorsContract.deployFrom0xArtifactAsync(
artifacts.TestLibRichErrors,
env.provider,
env.txDefaults,
{},
);
});
describe('_rrevert', () => {
it('should correctly revert the extra bytes', async () => {
const extraBytes = hexUtils.random(100);
try {
await lib.externalRRevert(extraBytes).callAsync();
} catch (err) {
const revertError = coerceThrownErrorAsRevertError(err);
return expect(revertError.encode()).to.eq(extraBytes);
}
return;
// TODO(xianny): NOT WORKING, v3 merge
// return expect.fail('Expected call to revert');
});
it('should correctly revert a StringRevertError', async () => {
const error = new StringRevertError('foo');
return expect(lib.externalRRevert(error.encode()).callAsync()).to.revertWith(error);
});
});
});