Skip to content

Commit

Permalink
Add restriction on claiming Chai token (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
k1rill-fedoseev committed Feb 20, 2020
1 parent f35a272 commit cf53cd7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ contract ForeignBridgeErcToNative is BasicForeignBridge, ERC20Bridge, OtherSideB

function claimTokens(address _token, address _to) public {
require(_token != address(erc20token()));
// Chai token is not claimable if investing into Chai is enabled
require(_token != address(chaiToken()) || !isChaiTokenEnabled());
if (_token == address(halfDuplexErc20token())) {
// SCD is not claimable if the bridge accepts deposits of this token
// solhint-disable-next-line not-rely-on-time
Expand Down
42 changes: 42 additions & 0 deletions test/erc_to_native/foreign_bridge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1897,5 +1897,47 @@ contract('ForeignBridge_ERC20_to_Native', async accounts => {
expect(await foreignBridgeProxy.dsrBalance()).to.be.bignumber.gte(ether('0.4'))
})
})

describe('claimTokens', async () => {
let foreignBridgeProxy

beforeEach(async () => {
foreignBridgeProxy = await EternalStorageProxy.new({ from: accounts[2] }).should.be.fulfilled
await foreignBridgeProxy.upgradeTo('1', foreignBridge.address, { from: accounts[2] }).should.be.fulfilled
foreignBridgeProxy = await ForeignBridgeErcToNativeMock.at(foreignBridgeProxy.address)
foreignBridgeProxy.setChaiToken(chaiToken.address)
await foreignBridgeProxy.initialize(
validatorContract.address,
token.address,
requireBlockConfirmations,
gasPrice,
[dailyLimit, maxPerTx, minPerTx],
[homeDailyLimit, homeMaxPerTx],
owner,
decimalShiftZero,
otherSideBridge.address,
{ from: accounts[2] }
)
})

it('should not allow to claim Chai, if it is enabled', async () => {
await foreignBridgeProxy.initializeChaiToken({ from: owner })
await token.mint(foreignBridgeProxy.address, halfEther)
await foreignBridgeProxy.setMinDaiTokenBalance(ether('0.1'), { from: owner })
await foreignBridgeProxy.convertDaiToChai()
expect(await foreignBridgeProxy.isChaiTokenEnabled()).to.be.equal(true)

await foreignBridgeProxy.claimTokens(chaiToken.address, accounts[2], { from: accounts[2] }).should.be.rejected
})

it('should allow to claim chai after it is disabled', async () => {
expect(await foreignBridgeProxy.isChaiTokenEnabled()).to.be.equal(false)
await token.mint(accounts[3], halfEther)
await token.approve(chaiToken.address, halfEther, { from: accounts[3] })
await chaiToken.join(accounts[3], halfEther, { from: accounts[3] }).should.be.fulfilled

await foreignBridgeProxy.claimTokens(chaiToken.address, accounts[2], { from: accounts[2] }).should.be.fulfilled
})
})
})
})

0 comments on commit cf53cd7

Please sign in to comment.