Add a Test for an Untransferrable ERC20 token
This commit is contained in:
parent
18c613a611
commit
8b70762e34
@ -32,6 +32,7 @@
|
|||||||
"src/interfaces/IEtherToken.sol",
|
"src/interfaces/IEtherToken.sol",
|
||||||
"test/DummyERC20Token.sol",
|
"test/DummyERC20Token.sol",
|
||||||
"test/DummyMultipleReturnERC20Token.sol",
|
"test/DummyMultipleReturnERC20Token.sol",
|
||||||
"test/DummyNoReturnERC20Token.sol"
|
"test/DummyNoReturnERC20Token.sol",
|
||||||
|
"test/UntransferrableDummyERC20Token.sol"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright 2018 ZeroEx Intl.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
pragma solidity ^0.5.5;
|
||||||
|
|
||||||
|
import "./DummyERC20Token.sol";
|
||||||
|
|
||||||
|
|
||||||
|
// solhint-disable no-empty-blocks
|
||||||
|
contract UntransferrableDummyERC20Token is
|
||||||
|
DummyERC20Token
|
||||||
|
{
|
||||||
|
bool internal _paused;
|
||||||
|
|
||||||
|
constructor (
|
||||||
|
string memory _name,
|
||||||
|
string memory _symbol,
|
||||||
|
uint256 _decimals,
|
||||||
|
uint256 _totalSupply
|
||||||
|
)
|
||||||
|
public
|
||||||
|
DummyERC20Token(
|
||||||
|
_name,
|
||||||
|
_symbol,
|
||||||
|
_decimals,
|
||||||
|
_totalSupply
|
||||||
|
)
|
||||||
|
{}
|
||||||
|
|
||||||
|
// /// @dev send `value` token to `to` from `msg.sender`
|
||||||
|
// /// @param _to The address of the recipient
|
||||||
|
// /// @param _value The amount of token to be transferred
|
||||||
|
// function transfer(address _to, uint256 _value)
|
||||||
|
// external
|
||||||
|
// returns (bool)
|
||||||
|
// {
|
||||||
|
// require(
|
||||||
|
// false,
|
||||||
|
// "TRANSFER_DISABLED"
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
|
/// @dev send `value` token to `to` from `from` on the condition it is approved by `from`
|
||||||
|
/// @param _from The address of the sender
|
||||||
|
/// @param _to The address of the recipient
|
||||||
|
/// @param _value The amount of token to be transferred
|
||||||
|
function transferFrom(
|
||||||
|
address _from,
|
||||||
|
address _to,
|
||||||
|
uint256 _value
|
||||||
|
)
|
||||||
|
external
|
||||||
|
returns (bool)
|
||||||
|
{
|
||||||
|
require(
|
||||||
|
false,
|
||||||
|
"TRANSFER_DISABLED"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
@ -1,3 +1,4 @@
|
|||||||
|
import { DummyERC20TokenContract } from '@0x/abi-gen-wrappers';
|
||||||
import { BlockchainLifecycle, callbackErrorReporter } from '@0x/dev-utils';
|
import { BlockchainLifecycle, callbackErrorReporter } from '@0x/dev-utils';
|
||||||
import { FillScenarios } from '@0x/fill-scenarios';
|
import { FillScenarios } from '@0x/fill-scenarios';
|
||||||
import { assetDataUtils, orderHashUtils, signatureUtils } from '@0x/order-utils';
|
import { assetDataUtils, orderHashUtils, signatureUtils } from '@0x/order-utils';
|
||||||
@ -10,6 +11,7 @@ import 'mocha';
|
|||||||
import { ContractWrappers, ExchangeCancelEventArgs, ExchangeEvents, ExchangeFillEventArgs, OrderStatus } from '../src';
|
import { ContractWrappers, ExchangeCancelEventArgs, ExchangeEvents, ExchangeFillEventArgs, OrderStatus } from '../src';
|
||||||
import { DecodedLogEvent } from '../src/types';
|
import { DecodedLogEvent } from '../src/types';
|
||||||
|
|
||||||
|
import { UntransferrableDummyERC20Token } from './artifacts/UntransferrableDummyERC20Token';
|
||||||
import { chaiSetup } from './utils/chai_setup';
|
import { chaiSetup } from './utils/chai_setup';
|
||||||
import { constants } from './utils/constants';
|
import { constants } from './utils/constants';
|
||||||
import { migrateOnceAsync } from './utils/migrate';
|
import { migrateOnceAsync } from './utils/migrate';
|
||||||
@ -315,6 +317,29 @@ describe('ExchangeWrapper', () => {
|
|||||||
}),
|
}),
|
||||||
).to.eventually.to.be.rejected();
|
).to.eventually.to.be.rejected();
|
||||||
});
|
});
|
||||||
|
it('should throw when the ERC20 token has transfer restrictions', async () => {
|
||||||
|
const untransferrableToken = await DummyERC20TokenContract.deployFrom0xArtifactAsync(
|
||||||
|
UntransferrableDummyERC20Token,
|
||||||
|
provider,
|
||||||
|
{ from: userAddresses[0] },
|
||||||
|
'UntransferrableToken',
|
||||||
|
'UTT',
|
||||||
|
new BigNumber(constants.ZRX_DECIMALS),
|
||||||
|
// tslint:disable-next-line:custom-no-magic-numbers
|
||||||
|
new BigNumber(2).pow(20).minus(1),
|
||||||
|
);
|
||||||
|
const untransferrableMakerAssetData = assetDataUtils.encodeERC20AssetData(untransferrableToken.address);
|
||||||
|
signedOrder = await fillScenarios.createFillableSignedOrderAsync(
|
||||||
|
untransferrableMakerAssetData,
|
||||||
|
takerAssetData,
|
||||||
|
makerAddress,
|
||||||
|
takerAddress,
|
||||||
|
fillableAmount,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
contractWrappers.exchange.validateOrderFillableOrThrowAsync(signedOrder),
|
||||||
|
).to.eventually.to.be.rejectedWith(RevertReason.TransferFailed);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('#isValidSignature', () => {
|
describe('#isValidSignature', () => {
|
||||||
it('should check if the signature is valid', async () => {
|
it('should check if the signature is valid', async () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user