How to use the @openzeppelin/test-helpers.BN function in @openzeppelin/test-helpers

To help you get started, we’ve selected a few @openzeppelin/test-helpers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ethersphere / swap-swear-and-swindle / test / ERC20SimpleSwap.behavior.js View on Github external
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
                  })
                })
github ethersphere / swap-swear-and-swindle / test / ERC20SimpleSwap.behavior.js View on Github external
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)
          })
github ethersphere / swap-swear-and-swindle / test / ERC20SimpleSwap.behavior.js View on Github external
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)
                    })
                  })
                })
github ethersphere / swap-swear-and-swindle / test / ERC20SimpleSwap.behavior.js View on Github external
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 () {
github ethersphere / swap-swear-and-swindle / test / ERC20SimpleSwap.behavior.js View on Github external
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)
                    })
github ethersphere / swap-swear-and-swindle / test / ERC20SimpleSwap.behavior.js View on Github external
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 () {
github ethersphere / swap-swear-and-swindle / test / ERC20SimpleSwap.behavior.js View on Github external
context('when no hardDeposit was allocated', function () {
          const expectedAmount = new BN(0)
          const exptectedDecreaseAmount = new BN(0)
          const exptectedCanBeDecreasedAt = new BN(0)
          context('when no custom decreaseTimeout was set', function () {
            const expectedDecreaseTimeout = new BN(0)
            describe(describeTest + 'shouldReturnHardDeposits', function () {
              shouldReturnHardDeposits(beneficiary, expectedAmount, exptectedDecreaseAmount, expectedDecreaseTimeout, exptectedCanBeDecreasedAt)
            })
          })
          context('when a custom decreaseTimeout was set', function () {
            const expectedDecreaseTimeout = new BN(60)
            describe(describePreCondition + 'shouldSetCustomDecreaseTimeout', function () {
              shouldSetCustomHardDepositDecreaseTimeout(beneficiary, expectedDecreaseTimeout, issuer)
              describe(describeTest + 'shouldReturnHardDeposits', function () {
                shouldReturnHardDeposits(beneficiary, expectedAmount, exptectedDecreaseAmount, expectedDecreaseTimeout, exptectedCanBeDecreasedAt)
              })
            })
          })
        })
github ethersphere / swap-swear-and-swindle / test / ERC20SimpleSwap.behavior.js View on Github external
context('when the hardDeposit was not requested to decrease', function () {
                const expectedDecreaseAmount = new BN(0)
                const expectedCanBeDecreasedAt = new BN(0)
                const expectedDecreaseTimeout = new BN(0)
                describe(describeTest + 'shouldReturnHardDeposits', function () {
                  shouldReturnHardDeposits(beneficiary, depositAmount, expectedDecreaseAmount, expectedDecreaseTimeout, expectedCanBeDecreasedAt)
                })
              })
              context('when the hardDeposit was requested to decrease', function () {
github ethersphere / swap-swear-and-swindle / test / ERC20SimpleSwap.behavior.js View on Github external
context('when no hardDeposit was allocated', function () {
          const expectedAmount = new BN(0)
          const exptectedDecreaseAmount = new BN(0)
          const exptectedCanBeDecreasedAt = new BN(0)
          context('when no custom decreaseTimeout was set', function () {
            const expectedDecreaseTimeout = new BN(0)
            describe(describeTest + 'shouldReturnHardDeposits', function () {
              shouldReturnHardDeposits(beneficiary, expectedAmount, exptectedDecreaseAmount, expectedDecreaseTimeout, exptectedCanBeDecreasedAt)
            })
          })
          context('when a custom decreaseTimeout was set', function () {
            const expectedDecreaseTimeout = new BN(60)
            describe(describePreCondition + 'shouldSetCustomDecreaseTimeout', function () {
              shouldSetCustomHardDepositDecreaseTimeout(beneficiary, expectedDecreaseTimeout, issuer)
              describe(describeTest + 'shouldReturnHardDeposits', function () {
                shouldReturnHardDeposits(beneficiary, expectedAmount, exptectedDecreaseAmount, expectedDecreaseTimeout, exptectedCanBeDecreasedAt)
              })
            })
          })
github ethersphere / swap-swear-and-swindle / test / ERC20SimpleSwap.behavior.js View on Github external
context('when the second cumulativePayout is lower than the first cumulativePayout', function() {
                                    const secondCumulativePayout = firstCumulativePayout.sub(new BN(1))
                                    const revertMessage = 'SafeMath: subtraction overflow.'
                                    const beneficiaryToSign = {
                                      cumulativePayout: secondCumulativePayout,
                                      recipient,
                                      callerPayout
                                    }
                                    const issuerToSign = {
                                      beneficiary,
                                      cumulativePayout: secondCumulativePayout,
                                    }
                                    const toSubmit = Object.assign({}, beneficiaryToSign, issuerToSign)
                                    describe(describeTest + 'shouldNotCashCheque', function() {
                                      shouldNotCashCheque(beneficiaryToSign, issuerToSign, toSubmit, value, caller, beneficiarySignee, issuerSignee, revertMessage)
                                    })
                                  })
                                })