Add test for improperly padded assetData

This commit is contained in:
Amir Bandeali
2019-10-04 18:05:20 -07:00
parent c0c27ed637
commit 87906a3af1

View File

@@ -238,30 +238,6 @@ describe('AssetProxyDispatcher', () => {
expect(newBalances).to.deep.equal(erc20Balances);
});
it('should perform a noop transfer if from == to', async () => {
// Register ERC20 proxy
await assetProxyDispatcher.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, {
from: owner,
});
// Construct metadata for ERC20 proxy
const encodedAssetData = assetDataUtils.encodeERC20AssetData(erc20TokenA.address);
// Perform a transfer from makerAddress to takerAddress
const erc20Balances = await erc20Wrapper.getBalancesAsync();
const amount = new BigNumber(10);
const txReceipt = await assetProxyDispatcher.dispatchTransferFrom.awaitTransactionSuccessAsync(
orderHash,
encodedAssetData,
makerAddress,
makerAddress,
amount,
{ from: owner },
);
expect(txReceipt.logs.length).to.be.equal(1);
const newBalances = await erc20Wrapper.getBalancesAsync();
expect(newBalances).to.deep.equal(erc20Balances);
});
it('should revert if dispatching to unregistered proxy', async () => {
// Construct metadata for ERC20 proxy
const encodedAssetData = assetDataUtils.encodeERC20AssetData(erc20TokenA.address);
@@ -305,6 +281,29 @@ describe('AssetProxyDispatcher', () => {
return expect(tx).to.revertWith(expectedError);
});
it('should revert if assetData is not padded to 32 bytes (excluding the id)', async () => {
await assetProxyDispatcher.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, {
from: owner,
});
// Shave off the last byte
const encodedAssetData = assetDataUtils.encodeERC20AssetData(erc20TokenA.address).slice(0, 72);
const amount = new BigNumber(1);
const expectedError = new ExchangeRevertErrors.AssetProxyDispatchError(
ExchangeRevertErrors.AssetProxyDispatchErrorCode.InvalidAssetDataLength,
orderHash,
encodedAssetData,
);
const tx = assetProxyDispatcher.dispatchTransferFrom.sendTransactionAsync(
orderHash,
encodedAssetData,
makerAddress,
takerAddress,
amount,
{ from: owner },
);
return expect(tx).to.revertWith(expectedError);
});
it('should revert with the reason provided by the AssetProxy when a transfer fails', async () => {
await assetProxyDispatcher.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, {
from: owner,