Skip to content

Commit

Permalink
Add pending unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
patitonar committed Nov 22, 2019
1 parent ede2c50 commit 94b2a85
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/erc_to_native/foreign_bridge.test.js
Expand Up @@ -1231,5 +1231,49 @@ contract('ForeignBridge_ERC20_to_Native', async accounts => {
expect(await foreignBridge.relayedMessages(transactionHash)).to.be.equal(true)
})
})
describe('claimTokens', async () => {
it('can send erc20', async () => {
const foreignBridgeImpl = await ForeignBridgeErcToNativeMock.new()
const storageProxy = await EternalStorageProxy.new().should.be.fulfilled
await storageProxy.upgradeTo('1', foreignBridgeImpl.address).should.be.fulfilled
const foreignBridge = await ForeignBridgeErcToNativeMock.at(storageProxy.address)

await foreignBridge.initialize(
validatorContract.address,
dai.address,
requireBlockConfirmations,
gasPrice,
[dailyLimit, maxPerTx, minPerTx],
[homeDailyLimit, homeMaxPerTx],
owner,
decimalShiftZero,
otherSideBridge.address
)

expect(await saiTop.caged()).to.be.bignumber.equal(ZERO)

// Mint sai tokens to the bridge
await sai.mint(foreignBridge.address, halfEther)

await foreignBridge.claimTokens(sai.address, accounts[3], { from: owner }).should.be.rejectedWith(ERROR_MSG)

const block = await web3.eth.getBlock('latest')
// Trigger Emergency Shutdown
await saiTop.setCaged(block.number)

expect(await sai.balanceOf(foreignBridge.address)).to.be.bignumber.equal(halfEther)
expect(await sai.balanceOf(accounts[3])).to.be.bignumber.equal(ZERO)

await foreignBridge
.claimTokens(sai.address, accounts[3], { from: accounts[3] })
.should.be.rejectedWith(ERROR_MSG)
await foreignBridge.claimTokens(sai.address, accounts[3], { from: owner })
expect(await sai.balanceOf(foreignBridge.address)).to.be.bignumber.equal(ZERO)
expect(await sai.balanceOf(accounts[3])).to.be.bignumber.equal(halfEther)

// reset the caged value
await saiTop.setCaged(0)
})
})
})
})
14 changes: 14 additions & 0 deletions test/validators_test.js
Expand Up @@ -248,4 +248,18 @@ contract('BridgeValidators', async accounts => {
returnedList.should.be.eql(validators)
})
})
describe('#isValidatorDuty', () => {
it('should return if provided valdidator is on duty', async () => {
// Given
const validators = accounts.slice(0, 5)
const { initialize, isValidatorDuty } = bridgeValidators
await initialize(1, validators, owner, { from: owner }).should.be.fulfilled

// When
const results = await Promise.all(validators.map(v => isValidatorDuty(v)))

// Then
expect(results.filter(r => r === true).length).to.be.equal(1)
})
})
})

0 comments on commit 94b2a85

Please sign in to comment.