Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #427 from keep-network/setLotSize-enforce1btc
Browse files Browse the repository at this point in the history
Set lot size enforce 1 btc

Always enforce a new lot size array contains 1BTC (10^8).
  • Loading branch information
Shadowfiend authored Feb 1, 2020
2 parents 39c47ee + 7e890dd commit 642e81c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
10 changes: 8 additions & 2 deletions implementation/contracts/system/TBTCSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,14 @@ contract TBTCSystem is Ownable, ITBTCSystem, DepositLog {
/// @dev Lot sizes should be
/// @param _lotSizes Array of allowed lot sizes.
function setLotSizes(uint256[] calldata _lotSizes) external onlyOwner {
lotSizesSatoshis = _lotSizes;
emit LotSizesUpdated(_lotSizes);
for( uint i = 0; i < _lotSizes.length; i++){
if (_lotSizes[i] == 10**8){
lotSizesSatoshis = _lotSizes;
emit LotSizesUpdated(_lotSizes);
return;
}
}
revert("Lot size array must always contain 1BTC");
}

/// @notice Gets the allowed lot sizes
Expand Down
28 changes: 28 additions & 0 deletions implementation/test/TBTCSystemTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,34 @@ contract('TBTCSystem', (accounts) => {
})
})

describe('setLotSizes', async () => {
it('sets a different lot size array', async () => {
const blockNumber = await web3.eth.getBlock('latest').number
const lotSizes = [10**8, 10**6]
await tbtcSystem.setLotSizes(lotSizes)

const eventList = await tbtcSystem.getPastEvents('LotSizesUpdated', { fromBlock: blockNumber, toBlock: 'latest' })
assert.equal(eventList.length, 1)
expect(eventList[0].returnValues._lotSizes).to.eql(['100000000', '1000000']) // deep equality check
})

it('reverts if lot size array is empty', async () => {
const lotSizes = []
await expectThrow(
tbtcSystem.setLotSizes(lotSizes),
'Lot size array must always contain 1BTC'
)
})

it('reverts if lot size array does not contain a 1BTC lot size', async () => {
const lotSizes = [10**7]
await expectThrow(
tbtcSystem.setLotSizes(lotSizes),
'Lot size array must always contain 1BTC'
)
})
})

describe('emergencyPauseNewDeposits', async () => {
let term

Expand Down

0 comments on commit 642e81c

Please sign in to comment.