Skip to content

Commit

Permalink
Add claimTokensFromErc677 on erc20-to-erc20 contracts (#219)
Browse files Browse the repository at this point in the history
* Fix claimTokensFromErc677 unit test
* Add claimTokensFromErc677 on HomeBridgeErcToErc
  • Loading branch information
patitonar authored and akolotov committed Jul 1, 2019
1 parent 5a92a57 commit 79f8277
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ contract HomeBridgeErcToErc is ERC677Receiver, EternalStorage, BasicBridge, Basi
setErc677token(_erc677token);
}

function claimTokensFromErc677(address _token, address _to) external onlyIfUpgradeabilityOwner {
IBurnableMintableERC677Token(erc677token()).claimTokens(_token, _to);
}

function getBridgeMode() public pure returns(bytes4 _data) {
return bytes4(keccak256(abi.encodePacked("erc-to-erc-core")));
}
Expand Down
39 changes: 39 additions & 0 deletions test/erc_to_erc/home_bridge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,46 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
})
})
})
describe('#claimTokens', () => {
it('should be able to call claimTokens on tokenAddress', async () => {
const token = await ERC677BridgeToken.new('Bridge Token', 'BT20', 18)

const homeBridgeImpl = await HomeBridge.new()
const storageProxy = await EternalStorageProxy.new().should.be.fulfilled
await storageProxy.upgradeTo('1', homeBridgeImpl.address).should.be.fulfilled
const homeBridge = await HomeBridge.at(storageProxy.address)
await homeBridge.initialize(
validatorContract.address,
oneEther,
halfEther,
minPerTx,
gasPrice,
requireBlockConfirmations,
token.address,
foreignDailyLimit,
foreignMaxPerTx,
owner
).should.be.fulfilled

await token.transferOwnership(homeBridge.address).should.be.fulfilled

const tokenSecond = await ERC677BridgeToken.new('Test Token', 'TST', 18)

await tokenSecond.mint(accounts[0], halfEther).should.be.fulfilled
expect(await tokenSecond.balanceOf(accounts[0])).to.be.bignumber.equal(halfEther)

await tokenSecond.transfer(token.address, halfEther)
expect(await tokenSecond.balanceOf(accounts[0])).to.be.bignumber.equal(ZERO)
expect(await tokenSecond.balanceOf(token.address)).to.be.bignumber.equal(halfEther)

await homeBridge
.claimTokensFromErc677(tokenSecond.address, accounts[3], { from: accounts[3] })
.should.be.rejectedWith(ERROR_MSG)
await homeBridge.claimTokensFromErc677(tokenSecond.address, accounts[3], { from: owner }).should.be.fulfilled
expect(await tokenSecond.balanceOf(token.address)).to.be.bignumber.equal(ZERO)
expect(await tokenSecond.balanceOf(accounts[3])).to.be.bignumber.equal(halfEther)
})
})
describe('#rewardableInitialize', async () => {
let homeFee
let foreignFee
Expand Down
2 changes: 1 addition & 1 deletion test/native_to_erc/foreign_bridge_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ contract('ForeignBridge', async accounts => {
expect(await tokenSecond.balanceOf(token.address)).to.be.bignumber.equal('150')

await foreignBridge.claimTokensFromErc677(tokenSecond.address, accounts[3], { from: owner })
expect(await tokenSecond.balanceOf(foreignBridge.address)).to.be.bignumber.equal(ZERO)
expect(await tokenSecond.balanceOf(token.address)).to.be.bignumber.equal(ZERO)
expect(await tokenSecond.balanceOf(accounts[3])).to.be.bignumber.equal('150')
})
it('works with token that not return on transfer', async () => {
Expand Down

0 comments on commit 79f8277

Please sign in to comment.