Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
beforeEach(async function() {
// If we expect this not to be the default value, we have to set the value here, as it depends on the most current time
if(!expectedCanBeDecreasedAt.eq(new BN(0))) {
this.expectedCanBeDecreasedAt = (await time.latest()).add(await this.ERC20SimpleSwap.DEFAULT_HARDDEPOSIT_DECREASE_TIMEOUT())
} else {
this.expectedCanBeDecreasedAt = expectedCanBeDecreasedAt
}
this.exptectedCanBeDecreasedAt = (await time.latest()).add(await this.ERC20SimpleSwap.DEFAULT_HARDDEPOSIT_DECREASE_TIMEOUT())
this.hardDeposits = await this.ERC20SimpleSwap.hardDeposits(beneficiary)
})
it('should return the expected amount', function() {
describe(describeTest + 'shouldReturnHardDeposits', function () {
const expectedDecreaseTimeout = new BN(0)
shouldReturnHardDeposits(beneficiary, depositAmount, toDecrease, expectedDecreaseTimeout, new BN(42)) // 42 (not BN(0)) signifies that we have to define it later
})
})
function shouldBehaveLikeERC20SimpleSwap([issuer, alice, bob, carol], DEFAULT_HARDDEPOSIT_DECREASE_TIMEOUT) {
// defaults used throught the tests
const defaults = {
beneficiary: bob,
recipient: carol,
firstCumulativePayout: new BN(500),
secondCumulativePayout: new BN(1000),
deposit: new BN(10000),
}
context('as a simple swap', function () {
describe(describeFunction + 'DEFAULT_HARDDEPOSIT_DECREASE_TIMEOUT', function () {
if (enabledTests.DEFAULT_HARDDEPOSIT_DECREASE_TIMEOUT) {
shouldReturnDEFAULT_HARDDEPOSIT_DECREASE_TIMEOUT(DEFAULT_HARDDEPOSIT_DECREASE_TIMEOUT)
}
})
describe(describeFunction + 'paidOutCheques', function () {
if (enabledTests.cheques) {
const beneficiary = defaults.beneficiary
context('when no cheque was ever cashed', function () {
describe(describeTest + 'shouldReturnPaidOut', function () {
const expectedAmount = new BN(0)
shouldReturnPaidOut(beneficiary, expectedAmount)
})
context('when the decreaseAmount is higher than the hardDepositAmount', function () {
const decreaseAmount = hardDepositAmount.add(new BN(1))
const revertMessage = "SimpleSwap: hard deposit not sufficient"
describe(describeTest + 'shouldNotPrepareDecreaseHardDeposit', function () {
shouldNotPrepareDecreaseHardDeposit(beneficiary, decreaseAmount, sender, value, revertMessage)
})
})
})
context('when there is more liquidBalance than the requested hardDepositIncrease', function () {
const deposit = hardDepositIncrease.mul(new BN(2))
describe(describePreCondition + 'shouldDeposit', function () {
shouldDeposit(deposit, issuer)
context('when we have set a customHardDepositDecreaseTimeout', function () {
const customHardDepositDecreaseTimeout = new BN(60)
describe(describePreCondition + 'shouldSetCustomHardDepositDecreaseTimeout', function () {
shouldSetCustomHardDepositDecreaseTimeout(beneficiary, customHardDepositDecreaseTimeout, issuer)
describe(describeTest + 'shouldIncreaseHardDeposit', function () {
shouldIncreaseHardDeposit(beneficiary, hardDepositIncrease, sender)
})
})
})
})
})
context('when there is as much liquidBalance as the requested hardDepositIncrease', function () {
describe(describeFunction + 'increaseHardDeposit', function () {
if (enabledTests.increaseHardDeposit) {
const hardDepositIncrease = new BN(50)
const beneficiary = defaults.beneficiary
context("when we don't send value along", function () {
const value = new BN(0)
context('when the sender is the issuer', function () {
const sender = issuer
context('when there is more liquidBalance than the requested hardDepositIncrease', function () {
const deposit = hardDepositIncrease.mul(new BN(2))
describe(describePreCondition + 'shouldDeposit', function () {
shouldDeposit(deposit, issuer)
context('when we have set a customHardDepositDecreaseTimeout', function () {
const customHardDepositDecreaseTimeout = new BN(60)
describe(describePreCondition + 'shouldSetCustomHardDepositDecreaseTimeout', function () {
shouldSetCustomHardDepositDecreaseTimeout(beneficiary, customHardDepositDecreaseTimeout, issuer)
describe(describeTest + 'shouldIncreaseHardDeposit', function () {
shouldIncreaseHardDeposit(beneficiary, hardDepositIncrease, sender)
})
context("when we have prepared the decreaseHardDeposit", function () {
const hardDeposit = new BN(50)
describe(describePreCondition + "shouldDeposit", function () {
shouldDeposit(hardDeposit, issuer)
describe(describePreCondition + "shouldIncreaseHardDeposit", function () {
shouldIncreaseHardDeposit(beneficiary, hardDeposit, issuer)
describe(describePreCondition + "shouldPrepareDecreaseHardDeposit", function () {
shouldPrepareDecreaseHardDeposit(beneficiary, hardDeposit, issuer)
context('when we have waited more than decreaseTimeout time', function () {
beforeEach(async function () {
await time.increase(await this.ERC20SimpleSwap.DEFAULT_HARDDEPOSIT_DECREASE_TIMEOUT())
})
describe(describeTest + 'shouldDecreaseHardDeposit', function () {
shouldDecreaseHardDeposit(beneficiary, sender)
})
})
context('when we have not waited more than decreaseTimeout time', function () {
describe(describeTest + 'shouldNotDecreaseHardDeposit', function () {
it('reverts', async function() {
await expectRevert(this.ERC20SimpleSwap.setCustomHardDepositDecreaseTimeout(
toSubmit.beneficiary,
toSubmit.decreaseTimeout,
this.beneficiarySig,
{from: from, value: value}),
revertMessage
)
})
}
it('reverts', async function() {
await expectRevert(this.ERC20SimpleSwap.withdraw(
amount,
{from: from, value: value}),
revertMessage
)
})
}
it('reverts', async function() {
await expectRevert(this.ERC20SimpleSwap.cashCheque(
toSubmitFields.beneficiary,
toSubmitFields.recipient,
toSubmitFields.cumulativePayout,
this.beneficiarySig,
toSubmitFields.callerPayout,
this.issuerSig,
{from: from, value: value}),
revertMessage
)
})
}