Add claimTokensFromTokenContract function for HomeMultiAMBErc20ToErc677 contract (#573)

This commit is contained in:
Kirill Fedoseev 2021-02-02 19:45:52 +03:00 committed by GitHub
parent a85d9ab343
commit 8d11272f44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 8 deletions

View File

@ -20,6 +20,23 @@ contract HomeMultiAMBErc20ToErc677 is
event NewTokenRegistered(address indexed foreignToken, address indexed homeToken);
/**
* @dev Throws if called by any account other than the owner.
* Overrides modifier from the Ownable contract in order to reduce bytecode size.
*/
modifier onlyOwner() {
_onlyOwner();
/* solcov ignore next */
_;
}
/**
* @dev Internal function for reducing onlyOwner modifier bytecode size overhead.
*/
function _onlyOwner() internal {
require(msg.sender == owner());
}
/**
* @dev Stores the initial parameters of the mediator.
* @param _bridgeContract the address of the AMB bridge contract.
@ -320,14 +337,16 @@ contract HomeMultiAMBErc20ToErc677 is
}
/**
* @dev One-time upgrade function for transferring ownership of the STAKE token to the TokenMinter address.
* Should be called together with upgradeToAndCall function
* @dev Withdraws erc20 tokens or native coins from the bridged token contract.
* Only the proxy owner is allowed to call this method.
* @param _bridgedToken address of the bridged token contract.
* @param _token address of the claimed token or address(0) for native coins.
* @param _to address of the tokens/coins receiver.
*/
function transferTokenOwnership() external {
require(msg.sender == address(this));
Ownable(0xb7D311E2Eb55F2f68a9440da38e7989210b9A05e).transferOwnership(
0x1111111111111111111111111111111111111111
);
function claimTokensFromTokenContract(address _bridgedToken, address _token, address _to)
external
onlyIfUpgradeabilityOwner
{
IBurnableMintableERC677Token(_bridgedToken).claimTokens(_token, _to);
}
}

View File

@ -346,6 +346,20 @@ contract('HomeMultiAMBErc20ToErc677', async accounts => {
expect(toBN(await web3.eth.getBalance(contract.address))).to.be.bignumber.equal(ZERO)
expect(toBN(await web3.eth.getBalance(accounts[3]))).to.be.bignumber.equal(balanceBefore.add(oneEther))
})
it('should allow owner to claim tokens from token contract', async () => {
const homeToken = await bridgeToken(token)
await token.mint(user, 1).should.be.fulfilled
await token.transfer(homeToken.address, 1, { from: user }).should.be.fulfilled
await contract.claimTokensFromTokenContract(homeToken.address, token.address, accounts[3], { from: user }).should
.be.rejected
await contract.claimTokensFromTokenContract(homeToken.address, token.address, accounts[3], { from: owner }).should
.be.fulfilled
expect(await token.balanceOf(accounts[3])).to.be.bignumber.equal('1')
})
})
describe('afterInitialization', () => {