Override `transfer` and `transferFrom` in `ERC677BridgeTokenRewardable`

To deny transfer tokens to ValidatorSet contract directly.
This commit is contained in:
Vadim 2019-02-11 10:39:34 +03:00
parent 98a09a4c31
commit 27db88f489
2 changed files with 38 additions and 0 deletions

View File

@ -63,4 +63,14 @@ contract ERC677BridgeTokenRewardable is ERC677BridgeToken {
emit Transfer(validatorSetContract, _staker, _amount);
}
function transfer(address _to, uint256 _value) public returns(bool) {
require(_to != validatorSetContract);
return super.transfer(_to, _value);
}
function transferFrom(address _from, address _to, uint256 _value) public returns(bool) {
require(_to != validatorSetContract);
return super.transferFrom(_from, _to, _value);
}
}

View File

@ -330,8 +330,36 @@ async function testERC677BridgeToken(accounts, rewardable) {
await token.setBridgeContract(foreignNativeToErcBridge.address).should.be.fulfilled;
await token.transfer(foreignNativeToErcBridge.address, lessThanMin, {from: user}).should.be.rejectedWith(ERROR_MSG);
})
if (rewardable) {
it('fail to send tokens to ValidatorSet contract directly', async () => {
const amount = web3.toWei(1, "ether");
const validatorSetContractAddress = accounts[2];
const arbitraryAccountAddress = accounts[3];
await token.setValidatorSetContractMock(validatorSetContractAddress, {from: owner}).should.be.fulfilled;
await token.mint(user, amount, {from: owner}).should.be.fulfilled;
await token.transfer(validatorSetContractAddress, amount, {from: user}).should.be.rejectedWith(ERROR_MSG);
await token.transfer(arbitraryAccountAddress, amount, {from: user}).should.be.fulfilled;
});
}
})
if (rewardable) {
describe('#transferFrom', async() => {
it('fail to send tokens to ValidatorSet contract directly', async () => {
const amount = web3.toWei(1, "ether");
const user2 = accounts[2];
const validatorSetContractAddress = accounts[3];
const arbitraryAccountAddress = accounts[4];
await token.setValidatorSetContractMock(validatorSetContractAddress, {from: owner}).should.be.fulfilled;
await token.mint(user, amount, {from: owner}).should.be.fulfilled;
await token.approve(user2, amount, {from: user}).should.be.fulfilled;
await token.transferFrom(user, validatorSetContractAddress, amount, {from: user2}).should.be.rejectedWith(ERROR_MSG);
await token.transferFrom(user, arbitraryAccountAddress, amount, {from: user2}).should.be.fulfilled;
});
});
}
describe("#burn", async () => {
it('can burn', async() => {
await token.burn(100, {from: owner}).should.be.rejectedWith(ERROR_MSG);