From 8badbb4e8e038a88fce2af1774a256542f9c5596 Mon Sep 17 00:00:00 2001 From: zajck Date: Mon, 4 Oct 2021 09:39:07 +0200 Subject: [PATCH 01/41] added event checking ETHETH --- stash/MockBosonRouter.sol | 32 +++++++++++ test/2_test_fullpath_with_permit.ts | 86 ++++++++++++++++++++++++----- testHelpers/utils.ts | 6 +- 3 files changed, 109 insertions(+), 15 deletions(-) create mode 100644 stash/MockBosonRouter.sol diff --git a/stash/MockBosonRouter.sol b/stash/MockBosonRouter.sol new file mode 100644 index 00000000..74b94cf8 --- /dev/null +++ b/stash/MockBosonRouter.sol @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +pragma solidity 0.7.6; + +import "./../BosonRouter.sol"; + +/** + * @title Mock Contract for testing purposes. + * @notice This mock passes an invalide value to createPaymentMethod from requestCreateOrderETHETH for the purpose of testing calls to VoucherKernel.createPaymentMethod and possibly other functions + */ +contract MockBosonRouter is BosonRouter { + constructor( + address _voucherKernel, + address _tokenRegistry, + address _cashierAddress + ) + BosonRouter(_voucherKernel, _tokenRegistry, _cashierAddress) + // solhint-disable-next-line + { + + } + + function requestCreateOrderETHETH(uint256[] calldata metadata) + external + payable + override + nonReentrant + whenNotPaused + { + checkLimits(metadata, address(0), address(0), 0); + requestCreateOrder(metadata, 5, address(0), address(0), 0); + } +} diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 7d734b04..81f2a048 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -1,5 +1,5 @@ import {ethers} from 'hardhat'; -import {Signer, ContractFactory, Contract} from 'ethers'; +import {Signer, ContractFactory, Contract, BigNumber} from 'ethers'; import {assert, expect} from 'chai'; import {ecsign} from 'ethereumjs-util'; import constants from '../testHelpers/constants'; @@ -16,6 +16,7 @@ import { TokenRegistry, MockERC20Permit, } from '../typechain'; +const {keccak256, solidityPack} = ethers.utils; let ERC1155ERC721_Factory: ContractFactory; let VoucherKernel_Factory: ContractFactory; @@ -34,7 +35,10 @@ const BN = ethers.BigNumber.from; let utils: Utils; let users; + describe('Cashier and VoucherKernel', () => { + let promiseId: string, tokenSupplyKey: string; // todo remove string when finished + before(async () => { const signers: Signer[] = await ethers.getSigners(); users = new Users(signers); @@ -47,6 +51,27 @@ describe('Cashier and VoucherKernel', () => { MockERC20Permit_Factory = await ethers.getContractFactory( 'MockERC20Permit' ); + + await setPeriods(); + + // calculate expected tokenSupplyID for first voucher + promiseId = keccak256( + solidityPack( + ['address', 'uint256', 'uint256', 'uint256'], + [ + users.seller.address, + constants.ZERO, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + ] + ) + ); + + // calculate expected tokenSupplyID for first voucher + const tokenIndex = constants.ONE; + const TYPE_NF_BIT = constants.ONE.shl(255); + tokenSupplyKey = TYPE_NF_BIT.or(tokenIndex.shl(128)).toString(); + }); let contractERC1155ERC721: ERC1155ERC721, @@ -57,10 +82,10 @@ describe('Cashier and VoucherKernel', () => { contractBSNTokenDeposit: MockERC20Permit, contractTokenRegistry: TokenRegistry; - let tokenSupplyKey, tokenVoucherKey, tokenVoucherKey1; + let tokenVoucherKey, tokenVoucherKey1; - const ZERO = BN(0); - const ONE_VOUCHER = 1; + const ZERO = BN(0); // TODO: use constants.zero + const ONE_VOUCHER = 1; // TODO: use constants.one const deadline = toWei(1); @@ -72,7 +97,7 @@ describe('Cashier and VoucherKernel', () => { escrowAmount: BN(0), }; - async function setPeriods() { + async function setPeriods() { // TODO use where applicable; why this async? const timestamp = await Utils.getCurrTimestamp(); constants.PROMISE_VALID_FROM = timestamp; @@ -173,7 +198,7 @@ describe('Cashier and VoucherKernel', () => { TKNTKN: 4, }; - afterEach(() => { + afterEach(() => { // TODO REMOVE remQty = constants.QTY_10; }); @@ -190,15 +215,48 @@ describe('Cashier and VoucherKernel', () => { contractBosonRouter ); - timestamp = await Utils.getCurrTimestamp(); - constants.PROMISE_VALID_FROM = timestamp; - constants.PROMISE_VALID_TO = timestamp + 2 * constants.SECONDS_IN_DAY; + // timestamp = await Utils.getCurrTimestamp(); + // constants.PROMISE_VALID_FROM = timestamp; + // constants.PROMISE_VALID_TO = timestamp + 2 * constants.SECONDS_IN_DAY; - tokenSupplyKey = await utils.createOrder( - users.seller, - timestamp, - timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, + // setPeriods(); + + // tokenSupplyKey = await utils.createOrder( + // users.seller, + // timestamp, + // timestamp + constants.SECONDS_IN_DAY, + // constants.seller_deposit, + // constants.QTY_10 + // ); + }); + + it.only('All expected events are emitted', async () => { + expect(await + utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10, + true + ) + ).to.emit(contractBosonRouter, eventNames.LOG_ORDER_CREATED) + .withArgs(tokenSupplyKey, users.seller.address, constants.QTY_10, paymentMethods.ETHETH) + .to.emit(contractVoucherKernel, eventNames.LOG_PROMISE_CREATED) + .withArgs( + promiseId, + constants.ONE, + users.seller.address, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.ZERO + ) + .to.emit(contractERC1155ERC721, eventNames.TRANSFER_SINGLE) + .withArgs( + contractVoucherKernel.address, + constants.ZERO_ADDRESS, + users.seller.address, + tokenSupplyKey, constants.QTY_10 ); }); diff --git a/testHelpers/utils.ts b/testHelpers/utils.ts index e9e52779..9230300c 100644 --- a/testHelpers/utils.ts +++ b/testHelpers/utils.ts @@ -105,6 +105,10 @@ class Utils { } ); + if (returnTx) { + return txOrder + } + const txReceipt = await txOrder.wait(); let eventArgs; @@ -115,7 +119,7 @@ class Utils { (e) => (eventArgs = e) ); - return returnTx ? txReceipt : eventArgs._tokenIdSupply.toString(); + return eventArgs._tokenIdSupply.toString(); } async requestCreateOrderETHTKNSameWithPermit( From 86807a518631d264f019a297ec5be8f96e71185d Mon Sep 17 00:00:00 2001 From: zajck Date: Mon, 4 Oct 2021 14:11:59 +0200 Subject: [PATCH 02/41] checking kernel state --- test/2_test_fullpath_with_permit.ts | 44 +++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 81f2a048..920a5eb0 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -203,7 +203,7 @@ describe('Cashier and VoucherKernel', () => { }); describe('ETHETH', () => { - before(async () => { + beforeEach(async () => { await deployContracts(); utils = await UtilsBuilder.create() @@ -230,7 +230,7 @@ describe('Cashier and VoucherKernel', () => { // ); }); - it.only('All expected events are emitted', async () => { + it('All expected events are emitted', async () => { expect(await utils.createOrder( users.seller, @@ -261,6 +261,46 @@ describe('Cashier and VoucherKernel', () => { ); }); + it.only('Promise data is correct', async () => { + await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10, + true + ) + + const promiseData = await contractVoucherKernel.getPromiseData( + promiseId + ); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.promiseId], + promiseId, + 'Promise Id incorrect' + ); + + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.nonce].toString(), + constants.ONE.toString(), + 'Nonce is incorrect' + ); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.validFrom], + constants.PROMISE_VALID_FROM.toString(), + ); + + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.validTo].toString(), + constants.PROMISE_VALID_TO.toString() + ); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.idx].toString(), + constants.ZERO.toString() + ); + + }); + it('[NEGATIVE] Should revert if validTo is set below 5 minutes from now', async () => { await expect( utils.createOrder( From 64924a83ed7785844b673a7dd5c9db92dd58ae48 Mon Sep 17 00:00:00 2001 From: zajck Date: Mon, 4 Oct 2021 15:59:54 +0200 Subject: [PATCH 03/41] creating vouchers ETHETH --- test/2_test_fullpath_with_permit.ts | 315 ++++++++++++++++------------ testHelpers/utils.ts | 16 +- 2 files changed, 194 insertions(+), 137 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 920a5eb0..94cce3ae 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -71,6 +71,7 @@ describe('Cashier and VoucherKernel', () => { const tokenIndex = constants.ONE; const TYPE_NF_BIT = constants.ONE.shl(255); tokenSupplyKey = TYPE_NF_BIT.or(tokenIndex.shl(128)).toString(); + }); @@ -185,6 +186,7 @@ describe('Cashier and VoucherKernel', () => { contractBSNTokenDeposit.address, contractBSNTokenDeposit.address ); + } describe('TOKEN SUPPLY CREATION (Voucher batch creation)', () => { @@ -202,7 +204,7 @@ describe('Cashier and VoucherKernel', () => { remQty = constants.QTY_10; }); - describe('ETHETH', () => { + describe.only('ETHETH', () => { beforeEach(async () => { await deployContracts(); @@ -261,7 +263,9 @@ describe('Cashier and VoucherKernel', () => { ); }); - it.only('Promise data is correct', async () => { + describe('Voucher Kernel state after creation', () => { + + it('Voucher Kernel state is correct', async () => { await utils.createOrder( users.seller, constants.PROMISE_VALID_FROM, @@ -283,184 +287,235 @@ describe('Cashier and VoucherKernel', () => { assert.equal( promiseData[constants.PROMISE_DATA_FIELDS.nonce].toString(), constants.ONE.toString(), - 'Nonce is incorrect' + 'Promise data field -> nonce is incorrect' ); assert.equal( - promiseData[constants.PROMISE_DATA_FIELDS.validFrom], - constants.PROMISE_VALID_FROM.toString(), + promiseData[constants.PROMISE_DATA_FIELDS.validFrom].toString(), + constants.PROMISE_VALID_FROM.toString(), + 'Promise data field -> validFrom is incorrect' ); assert.equal( promiseData[constants.PROMISE_DATA_FIELDS.validTo].toString(), - constants.PROMISE_VALID_TO.toString() + constants.PROMISE_VALID_TO.toString(), + 'Promise data field -> validTo is incorrect' ); assert.equal( promiseData[constants.PROMISE_DATA_FIELDS.idx].toString(), - constants.ZERO.toString() + constants.ZERO.toString(), + 'Promise data field -> idx is incorrect' ); - - }); - it('[NEGATIVE] Should revert if validTo is set below 5 minutes from now', async () => { - await expect( - utils.createOrder( - users.seller, - timestamp, - timestamp + constants.ONE_MINUTE, - constants.seller_deposit, - constants.QTY_10 - ) - ).to.be.revertedWith(revertReasons.INVALID_VALIDITY_TO); - }); + const promiseSeller = await contractVoucherKernel.getSupplyHolder( + tokenSupplyKey + ); - it('ESCROW has correct initial balance', async () => { - const expectedBalance = BN(constants.seller_deposit).mul(BN(remQty)); - const escrowAmount = await contractCashier.getEscrowAmount( - users.seller.address + assert.strictEqual( + promiseSeller, + users.seller.address, + 'Seller incorrect' ); + const promiseOrderData = await contractVoucherKernel.getOrderCosts( + tokenSupplyKey + ); assert.isTrue( - escrowAmount.eq(expectedBalance), - 'Escrow amount is incorrect' + promiseOrderData[constants.PROMISE_ORDER_FIELDS.price].eq( + BN(constants.PROMISE_PRICE1) + ), + 'Promise produt price mismatch' ); - }); - - it('Cashier Contract has correct amount of ETH', async () => { - const expectedBalance = BN(constants.seller_deposit).mul(BN(remQty)); - const cashierBalance = await ethers.provider.getBalance( - contractCashier.address + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositSe].eq( + BN(constants.PROMISE_DEPOSITSE1) + ), + 'Promise seller deposit mismatch' ); - assert.isTrue( - BN(cashierBalance).eq(expectedBalance), - 'Escrow amount is incorrect' + promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositBu].eq( + BN(constants.PROMISE_DEPOSITBU1) + ), + 'Promise buyer deposit mismatch' ); - }); - it('Get correct remaining qty for supply', async () => { - let remainingQtyInContract = await contractVoucherKernel.getRemQtyForSupply( - tokenSupplyKey, + const tokenNonce = await contractVoucherKernel.getTokenNonce( users.seller.address ); + assert.isTrue( + tokenNonce.eq(constants.ONE), + 'Voucher kernel nonce mismatch' + ); assert.equal( - remainingQtyInContract.toString(), - remQty.toString(), - 'Remaining qty is not correct' + promiseId, + await contractVoucherKernel.getPromiseIdFromSupplyId(tokenSupplyKey), + 'PromisId mismatch' ); + + }); - for (let i = 0; i < vouchersToBuy; i++) { - await utils.commitToBuy(users.buyer, users.seller, tokenSupplyKey); - remainingQtyInContract = await contractVoucherKernel.getRemQtyForSupply( - tokenSupplyKey, - users.seller.address - ); + it('Should create payment method ETHETH', async () => { + const tokenSupplyKey = await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10 + ); + + expect(await contractVoucherKernel.getVoucherPriceToken( + tokenSupplyKey + )).to.equal(constants.ZERO_ADDRESS, 'ETHETH Method Price Token Address mismatch'); + - remQty = BN(remQty).sub(1).toString(); + expect(await contractVoucherKernel.getVoucherDepositToken( + tokenSupplyKey + )).to.equal(constants.ZERO_ADDRESS, 'ETHETH Method Deposit Token Address mismatch'); + + }); - assert.equal( - remainingQtyInContract.toString(), - remQty, - 'Remaining qty is not correct' - ); - } - }); + it('Deposit and Price address should be zero', async () => { + const tokenSupplyKey = await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10 + ); - it('Should create payment method ETHETH', async () => { - timestamp = await Utils.getCurrTimestamp(); - const tokenSupplyKey = await utils.createOrder( - users.seller, - timestamp, - timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_10 - ); + expect(await contractVoucherKernel.getVoucherPriceToken( + tokenSupplyKey + )).to.equal(constants.ZERO_ADDRESS, 'ETHETH Method Price Token Address mismatch'); + - const paymentMethod = await contractVoucherKernel.getVoucherPaymentMethod( - tokenSupplyKey - ); + expect(await contractVoucherKernel.getVoucherDepositToken( + tokenSupplyKey + )).to.equal(constants.ZERO_ADDRESS, 'ETHETH Method Deposit Token Address mismatch'); + + }); - const addressTokenPrice = await contractVoucherKernel.getVoucherPriceToken( - tokenSupplyKey - ); + }); + it('ERC1155ERC721 state is correct', async () => { + await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10, + true + ) - const addressTokenDeposits = await contractVoucherKernel.getVoucherDepositToken( + const sellerERC1155ERC721Balance = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.seller.address, tokenSupplyKey - ); + ) + )[0]; - assert.equal( - paymentMethod.toString(), - paymentMethods.ETHETH.toString(), - 'Payment Method ETHETH not set correctly' - ); - assert.equal( - addressTokenPrice.toString(), - constants.ZERO_ADDRESS, - 'ETHETH Method Price Token Address mismatch' - ); - assert.equal( - addressTokenDeposits.toString(), - constants.ZERO_ADDRESS, - 'ETHETH Method Deposit Token Address mismatch' - ); + assert.isTrue( + sellerERC1155ERC721Balance.eq(constants.QTY_10), + 'ERC1155ERC721 seller balance mismatch' + ); + + }); + + it('ESCROW has correct balance', async () => { + + expect(await ethers.provider.getBalance(contractCashier.address)).to.equal(constants.ZERO, 'Cashier starting balance should be 0'); + + await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10 + ) + + const expectedBalance = BN(constants.PROMISE_DEPOSITSE1).mul(BN(constants.QTY_10)); + + expect(await ethers.provider.getBalance(contractCashier.address)).to.equal(expectedBalance,'Escrow balance is incorrect') + expect(await contractCashier.getEscrowAmount(users.seller.address)).to.equal(expectedBalance, 'Escrow stored amount is incorrect'); }); - it('[NEGATIVE] Should not create a supply if price is above the limit', async () => { - const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); + it('Get correct remaining qty for supply', async () => { + await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10 + ) + + expect(await contractVoucherKernel.getRemQtyForSupply( + tokenSupplyKey, + users.seller.address + )).to.equal(constants.QTY_10, 'Remaining qty is not correct') + + for (let i = 0; i < vouchersToBuy; i++) { + await utils.commitToBuy(users.buyer, users.seller, tokenSupplyKey); + expect(await contractVoucherKernel.getRemQtyForSupply( + tokenSupplyKey, + users.seller.address + )).to.equal(constants.QTY_10-i-1, `Remaining qty is not correct [${i}]`) + + } + }); - const sellerInstance = contractBosonRouter.connect(users.seller.signer); + it('[NEGATIVE] Should revert if validTo is set below 5 minutes from now', async () => { + await expect( + utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_FROM + constants.ONE_MINUTE, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10 + ) + ).to.be.revertedWith(revertReasons.INVALID_VALIDITY_TO); + }); + it.only('[NEGATIVE] Should not create a supply if price is above the limit', async () => { await expect( - sellerInstance.requestCreateOrderETHETH( - [ - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.ABOVE_ETH_LIMIT, - constants.seller_deposit, - constants.PROMISE_DEPOSITBU1, - constants.ORDER_QUANTITY1, - ], - {value: txValue} + utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_FROM + constants.ONE_MINUTE, + constants.PROMISE_DEPOSITSE1, + constants.ONE, + true, + constants.ABOVE_ETH_LIMIT, + constants.PROMISE_DEPOSITBU1 ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); + }); - it('[NEGATIVE] Should not create a supply if depositBu is above the limit', async () => { - const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); - - const sellerInstance = contractBosonRouter.connect(users.seller.signer); - + it.only('[NEGATIVE] Should not create a supply if depositBu is above the limit', async () => { await expect( - sellerInstance.requestCreateOrderETHETH( - [ - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_PRICE1, - constants.seller_deposit, - constants.ABOVE_ETH_LIMIT, - constants.ORDER_QUANTITY1, - ], - {value: txValue} + utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_FROM + constants.ONE_MINUTE, + constants.PROMISE_DEPOSITSE1, + constants.ONE, + true, + constants.PROMISE_PRICE1, + constants.ABOVE_ETH_LIMIT ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); + }); it('[NEGATIVE] Should not create a supply if depositSe is above the limit', async () => { - const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); - - const sellerInstance = contractBosonRouter.connect(users.seller.signer); - await expect( - sellerInstance.requestCreateOrderETHETH( - [ - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_PRICE1, - constants.ABOVE_ETH_LIMIT, - constants.PROMISE_DEPOSITBU1, - constants.ORDER_QUANTITY1, - ], - {value: txValue} + utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_FROM + constants.ONE_MINUTE, + constants.ABOVE_ETH_LIMIT, + constants.ONE, + true, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); diff --git a/testHelpers/utils.ts b/testHelpers/utils.ts index 9230300c..599eed7c 100644 --- a/testHelpers/utils.ts +++ b/testHelpers/utils.ts @@ -28,7 +28,7 @@ import { } from '../typechain'; class Utils { - createOrder: (seller, from, to, sellerDeposit, qty, returnTx?) => any; + createOrder: (seller, from, to, sellerDeposit, qty, returnTx?, promisePrice?, buyerDeposit?) => any; createOrderConditional: ( seller, from, @@ -84,7 +84,9 @@ class Utils { to: number, sellerDeposit: number | string, qty: number | string, - returnTx = false + returnTx = false, + promisePrice = constants.PROMISE_PRICE1, + buyerDeposit = constants.PROMISE_DEPOSITBU1 ): Promise { const txValue = BN(sellerDeposit).mul(BN(qty)); @@ -95,9 +97,9 @@ class Utils { [ from, to, - constants.product_price, + promisePrice, // TODO MAKE A INPUT PARAMETER sellerDeposit, - constants.buyer_deposit, + buyerDeposit, // TODO MAKE A INPUT PARAMETER qty, ], { @@ -602,9 +604,9 @@ class Utils { tokenSupplyId: string, returnTx = false ): Promise { - const txValue = BN(constants.buyer_deposit).add( - BN(constants.product_price) - ); + const txValue = BN(constants.PROMISE_DEPOSITBU1).add( + BN(constants.PROMISE_PRICE1) + ); // TODO MAKE PARAMETERS const buyerInstance = this.contractBSNRouter.connect( buyer.signer From 9fb08f506314559380aeaf4f08a30e42f3bcedd6 Mon Sep 17 00:00:00 2001 From: zajck Date: Tue, 5 Oct 2021 11:41:57 +0200 Subject: [PATCH 04/41] util with additional paremteres + returntx --- testHelpers/utils.ts | 187 +++++++++++++++++++++++++++++-------------- 1 file changed, 128 insertions(+), 59 deletions(-) diff --git a/testHelpers/utils.ts b/testHelpers/utils.ts index 599eed7c..a90626c1 100644 --- a/testHelpers/utils.ts +++ b/testHelpers/utils.ts @@ -37,7 +37,9 @@ class Utils { qty, gateContract, nftTokenID, - returnTx? + returnTx?, + promisePrice?, + buyerDeposit? ) => any; commitToBuy: (buyer, seller, tokenSupplyId, returnTx?) => any; factories?: { @@ -85,8 +87,8 @@ class Utils { sellerDeposit: number | string, qty: number | string, returnTx = false, - promisePrice = constants.PROMISE_PRICE1, - buyerDeposit = constants.PROMISE_DEPOSITBU1 + promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default + buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default ): Promise { const txValue = BN(sellerDeposit).mul(BN(qty)); @@ -97,9 +99,9 @@ class Utils { [ from, to, - promisePrice, // TODO MAKE A INPUT PARAMETER + promisePrice, sellerDeposit, - buyerDeposit, // TODO MAKE A INPUT PARAMETER + buyerDeposit, qty, ], { @@ -107,10 +109,10 @@ class Utils { } ); - if (returnTx) { - return txOrder - } + if (returnTx) return txOrder; + // only needed when needed to get _tokenIdSupply. Not really checking anything. + // ?TODO make returnTx = true default? const txReceipt = await txOrder.wait(); let eventArgs; @@ -124,13 +126,15 @@ class Utils { return eventArgs._tokenIdSupply.toString(); } - async requestCreateOrderETHTKNSameWithPermit( + async requestCreateOrderETHTKNSameWithPermit( // is this really needed? seller: Account, from: number, to: number, sellerDeposit: number | string, qty: number | string, - returnTx = false + returnTx = false, + promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default + buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default ): Promise { const txValue = BN(sellerDeposit).mul(BN(qty)); @@ -165,9 +169,9 @@ class Utils { [ from, to, - constants.product_price, + promisePrice, sellerDeposit, - constants.buyer_deposit, + buyerDeposit, qty, ], { @@ -175,6 +179,10 @@ class Utils { } ); + if (returnTx) return txOrder; + + // only needed when needed to get _tokenIdSupply. Not really checking anything. + // ?TODO make returnTx = true default? const txReceipt = await txOrder.wait(); let eventArgs; @@ -185,7 +193,7 @@ class Utils { (e) => (eventArgs = e) ); - return returnTx ? txReceipt : eventArgs._tokenIdSupply.toString(); + return eventArgs._tokenIdSupply.toString(); } async requestCreateOrderTKNTKNWithPermit( @@ -193,8 +201,11 @@ class Utils { from: number, to: number, sellerDeposit: number | string, - qty: number | string - ): Promise { + qty: number | string, + returnTx = false, + promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default + buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default + ): Promise{ const txValue = BN(sellerDeposit).mul(BN(qty)); const nonce = await this.contractBSNTokenDeposit.nonces(seller.address); @@ -227,9 +238,9 @@ class Utils { [ from, to, - constants.product_price, + promisePrice, sellerDeposit, - constants.buyer_deposit, + buyerDeposit, qty, ], { @@ -237,6 +248,10 @@ class Utils { } ); + if (returnTx) return txOrder; + + // only needed when needed to get _tokenIdSupply. Not really checking anything. + // ?TODO make returnTx = true default? const txReceipt = await txOrder.wait(); let eventArgs; @@ -257,8 +272,11 @@ class Utils { sellerDeposit: number | string, qty: number | string, gateContract: Account, - nftTokenId: number | string | null - ): Promise { + nftTokenId: number | string | null, + returnTx = false, + promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default + buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default + ): Promise{ const txValue = BN(sellerDeposit).mul(BN(qty)); const nonce = await this.contractBSNTokenDeposit.nonces(seller.address); @@ -280,8 +298,8 @@ class Utils { const sellerInstance = this.contractBSNRouter.connect( seller.signer ) as BosonRouter; - return sellerInstance.requestCreateOrderTKNTKNWithPermitConditional( - // const txOrder = await sellerInstance.requestCreateOrderTKNTKNWithPermitConditional( + const txOrder = await sellerInstance.requestCreateOrderTKNTKNWithPermitConditional( + this.contractBSNTokenPrice.address, this.contractBSNTokenDeposit.address, txValue, @@ -292,9 +310,9 @@ class Utils { [ from, to, - constants.product_price, + promisePrice, sellerDeposit, - constants.buyer_deposit, + buyerDeposit, qty, ], gateContract.address, @@ -304,6 +322,11 @@ class Utils { } ); + if (returnTx) return txOrder; + + // only needed when needed to get _tokenIdSupply. Not really checking anything. + // ?TODO make returnTx = true default? + // const txReceipt = await txOrder.wait(); // let eventArgs; @@ -323,7 +346,9 @@ class Utils { to: number, sellerDeposit: number | string, qty: number | string, - returnTx = false + returnTx = false, + promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default + buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default ): Promise { const txValue = BN(sellerDeposit).mul(BN(qty)); const nonce = await this.contractBSNTokenDeposit.nonces(seller.address); @@ -355,9 +380,9 @@ class Utils { [ from, to, - constants.product_price, + promisePrice, sellerDeposit, - constants.buyer_deposit, + buyerDeposit, qty, ], { @@ -365,6 +390,10 @@ class Utils { } ); + if (returnTx) return txOrder; + + // only needed when needed to get _tokenIdSupply. Not really checking anything. + // ?TODO make returnTx = true default? const txReceipt = await txOrder.wait(); let eventArgs; @@ -375,7 +404,7 @@ class Utils { (e) => (eventArgs = e) ); - return returnTx ? txReceipt : eventArgs._tokenIdSupply.toString(); + return eventArgs._tokenIdSupply.toString(); } async requestCreateOrderTKNETH( @@ -384,7 +413,9 @@ class Utils { to: number, sellerDeposit: number | string, qty: number | string, - returnTx = false + returnTx = false, + promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default + buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default ): Promise { const txValue = BN(sellerDeposit).mul(BN(qty)); @@ -396,9 +427,9 @@ class Utils { [ from, to, - constants.product_price, + promisePrice, sellerDeposit, - constants.buyer_deposit, + buyerDeposit, qty, ], { @@ -406,6 +437,10 @@ class Utils { } ); + if (returnTx) return txOrder; + + // only needed when needed to get _tokenIdSupply. Not really checking anything. + // ?TODO make returnTx = true default? const txReceipt = await txOrder.wait(); let eventArgs; @@ -416,16 +451,19 @@ class Utils { (e) => (eventArgs = e) ); - return returnTx ? txReceipt : eventArgs._tokenIdSupply.toString(); + return eventArgs._tokenIdSupply.toString(); } async commitToBuyTKNTKNWithPermit( buyer: Account, seller: Account, - tokenSupplyId: string - ): Promise { - const txValue = BN(constants.buyer_deposit).add( - BN(constants.product_price) + tokenSupplyId: string, + returnTx = false, + promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default + buyerDeposit = constants.PROMISE_DEPOSITBU1, // todo shift on right place, remove default + ): Promise { + const txValue = BN(buyerDeposit).add( + BN(promisePrice) ); const nonce1 = await this.contractBSNTokenDeposit.nonces(buyer.address); @@ -433,7 +471,7 @@ class Utils { this.contractBSNTokenDeposit, buyer.address, this.contractBSNRouter.address, - constants.buyer_deposit, + buyerDeposit, nonce1, this.deadline ); @@ -453,7 +491,7 @@ class Utils { this.contractBSNTokenPrice, buyer.address, this.contractBSNRouter.address, - constants.product_price, + promisePrice, nonce2, this.deadline ); @@ -483,6 +521,10 @@ class Utils { sDeposit ); + if (returnTx) return commitTx; + + // only needed when needed to get _tokenIdSupply. Not really checking anything. + // ?TODO make returnTx = true default? const txReceipt = await commitTx.wait(); let eventArgs; @@ -499,10 +541,13 @@ class Utils { async commitToBuyTKNTKNSameWithPermit( buyer: Account, seller: Account, - tokenSupplyId: string - ): Promise { - const txValue = BN(constants.buyer_deposit).add( - BN(constants.product_price) + tokenSupplyId: string, + returnTx = false, + promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default + buyerDeposit = constants.PROMISE_DEPOSITBU1, // todo shift on right place, remove default + ): Promise { + const txValue = BN(buyerDeposit).add( + BN(promisePrice) ); const nonce = await this.contractBSNTokenSame.nonces(buyer.address); @@ -537,6 +582,10 @@ class Utils { s ); + if (returnTx) return commitTx; + + // only needed when needed to get _tokenIdSupply. Not really checking anything. + // ?TODO make returnTx = true default? const txReceipt = await commitTx.wait(); let eventArgs; @@ -553,15 +602,18 @@ class Utils { async commitToBuyETHTKNWithPermit( buyer: Account, seller: Account, - tokenSupplyId: string - ): Promise { + tokenSupplyId: string, + returnTx = false, + promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default + buyerDeposit = constants.PROMISE_DEPOSITBU1, // todo shift on right place, remove default + ): Promise { const nonce1 = await this.contractBSNTokenDeposit.nonces(buyer.address); const digestDeposit = await getApprovalDigest( this.contractBSNTokenDeposit, buyer.address, this.contractBSNRouter.address, - constants.buyer_deposit, + buyerDeposit, nonce1, this.deadline ); @@ -574,18 +626,22 @@ class Utils { const buyerInstance = this.contractBSNRouter.connect( buyer.signer ) as BosonRouter; - const txOrder = await buyerInstance.requestVoucherETHTKNWithPermit( + const commitTx = await buyerInstance.requestVoucherETHTKNWithPermit( tokenSupplyId, seller.address, - constants.buyer_deposit, + buyerDeposit, this.deadline, v, r, s, - {value: constants.product_price.toString()} + {value: promisePrice.toString()} ); - const txReceipt = await txOrder.wait(); + if (returnTx) return commitTx; + + // only needed when needed to get _tokenIdSupply. Not really checking anything. + // ?TODO make returnTx = true default? + const txReceipt = await commitTx.wait(); let eventArgs; events.assertEventEmitted( @@ -602,10 +658,12 @@ class Utils { buyer: Account, seller: Account, tokenSupplyId: string, - returnTx = false + returnTx = false, + promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default + buyerDeposit = constants.PROMISE_DEPOSITBU1, // todo shift on right place, remove default ): Promise { - const txValue = BN(constants.PROMISE_DEPOSITBU1).add( - BN(constants.PROMISE_PRICE1) + const txValue = BN(buyerDeposit).add( + BN(promisePrice) ); // TODO MAKE PARAMETERS const buyerInstance = this.contractBSNRouter.connect( @@ -619,6 +677,10 @@ class Utils { } ); + if (returnTx) return commitTx; + + // only needed when needed to get _tokenIdSupply. Not really checking anything. + // ?TODO make returnTx = true default? const txReceipt = await commitTx.wait(); let eventArgs; @@ -629,21 +691,24 @@ class Utils { (e) => (eventArgs = e) ); - return returnTx ? txReceipt : eventArgs._tokenIdVoucher; + return eventArgs._tokenIdVoucher; } async commitToBuyTKNETHWithPermit( buyer: Account, seller: Account, - tokenSupplyId: string - ): Promise { + tokenSupplyId: string, + returnTx = false, + promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default + buyerDeposit = constants.PROMISE_DEPOSITBU1, // todo shift on right place, remove default + ): Promise { const nonce1 = await this.contractBSNTokenPrice.nonces(buyer.address); const digestDeposit = await getApprovalDigest( this.contractBSNTokenPrice, buyer.address, this.contractBSNRouter.address, - constants.product_price, + promisePrice, nonce1, this.deadline ); @@ -656,18 +721,22 @@ class Utils { const buyerInstance = this.contractBSNRouter.connect( buyer.signer ) as BosonRouter; - const txOrder = await buyerInstance.requestVoucherTKNETHWithPermit( + const commitTx = await buyerInstance.requestVoucherTKNETHWithPermit( tokenSupplyId, seller.address, - constants.product_price, + promisePrice, this.deadline, v, r, s, - {value: constants.buyer_deposit} + {value: buyerDeposit} ); - const txReceipt = await txOrder.wait(); + if (returnTx) return commitTx; + + // only needed when needed to get _tokenIdSupply. Not really checking anything. + // ?TODO make returnTx = true default? + const txReceipt = await commitTx.wait(); let eventArgs; events.assertEventEmitted( From b212080169059a8b87aecfb6b8136089ec55178c Mon Sep 17 00:00:00 2001 From: zajck Date: Tue, 5 Oct 2021 13:10:13 +0200 Subject: [PATCH 05/41] ETHTKN createorder unit test --- test/2_test_fullpath_with_permit.ts | 629 ++++++++++++++++++---------- 1 file changed, 405 insertions(+), 224 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 94cce3ae..6080fc1e 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -204,7 +204,7 @@ describe('Cashier and VoucherKernel', () => { remQty = constants.QTY_10; }); - describe.only('ETHETH', () => { + describe('ETHETH', () => { beforeEach(async () => { await deployContracts(); @@ -265,7 +265,7 @@ describe('Cashier and VoucherKernel', () => { describe('Voucher Kernel state after creation', () => { - it('Voucher Kernel state is correct', async () => { + it('Promise info is correct', async () => { await utils.createOrder( users.seller, constants.PROMISE_VALID_FROM, @@ -363,15 +363,10 @@ describe('Cashier and VoucherKernel', () => { constants.QTY_10 ); - expect(await contractVoucherKernel.getVoucherPriceToken( + expect(await contractVoucherKernel.getVoucherPaymentMethod( tokenSupplyKey - )).to.equal(constants.ZERO_ADDRESS, 'ETHETH Method Price Token Address mismatch'); - + )).to.equal(paymentMethods.ETHETH, 'Payment Method ETHETH not set correctly'); - expect(await contractVoucherKernel.getVoucherDepositToken( - tokenSupplyKey - )).to.equal(constants.ZERO_ADDRESS, 'ETHETH Method Deposit Token Address mismatch'); - }); it('Deposit and Price address should be zero', async () => { @@ -473,7 +468,7 @@ describe('Cashier and VoucherKernel', () => { ).to.be.revertedWith(revertReasons.INVALID_VALIDITY_TO); }); - it.only('[NEGATIVE] Should not create a supply if price is above the limit', async () => { + it('[NEGATIVE] Should not create a supply if price is above the limit', async () => { await expect( utils.createOrder( users.seller, @@ -489,7 +484,7 @@ describe('Cashier and VoucherKernel', () => { }); - it.only('[NEGATIVE] Should not create a supply if depositBu is above the limit', async () => { + it('[NEGATIVE] Should not create a supply if depositBu is above the limit', async () => { await expect( utils.createOrder( users.seller, @@ -522,8 +517,8 @@ describe('Cashier and VoucherKernel', () => { }); describe('[WITH PERMIT]', () => { - describe('ETHTKN', () => { - before(async () => { + describe.only('ETHTKN', () => { + beforeEach(async () => { await deployContracts(); utils = await UtilsBuilder.create() @@ -552,128 +547,278 @@ describe('Cashier and VoucherKernel', () => { users.buyer.address, tokensToMint ); - - timestamp = await Utils.getCurrTimestamp(); - constants.PROMISE_VALID_FROM = timestamp; - constants.PROMISE_VALID_TO = timestamp + 2 * constants.SECONDS_IN_DAY; - - tokenSupplyKey = await utils.createOrder( - users.seller, - timestamp, - timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_10 - ); + }); - it('[NEGATIVE] Should revert if validTo is set below 5 minutes from now', async () => { + it('All expected events are emitted', async () => { await expect( utils.createOrder( users.seller, - timestamp, - timestamp + constants.ONE_MINUTE, - constants.seller_deposit, - constants.QTY_10 + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10, + true ) - ).to.be.revertedWith(revertReasons.INVALID_VALIDITY_TO); - }); - - it('Cashier has correct balance in Deposit Contract', async () => { - const expectedBalance = BN(constants.seller_deposit).mul( - BN(constants.QTY_10) - ); - const escrowAmount = await contractBSNTokenDeposit.balanceOf( - contractCashier.address - ); - - assert.isTrue( - escrowAmount.eq(expectedBalance), - 'Escrow amount is incorrect' - ); - }); - - it('escrowTokens has correct balance', async () => { - const expectedBalance = BN(constants.seller_deposit).mul( - BN(constants.QTY_10) - ); - const escrowTokens = await contractCashier.getEscrowTokensAmount( - contractBSNTokenDeposit.address, - users.seller.address - ); - - assert.isTrue( - escrowTokens.eq(expectedBalance), - 'Escrow amount is incorrect' + ) + .to.emit(contractBosonRouter, eventNames.LOG_ORDER_CREATED) + .withArgs( + tokenSupplyKey, + users.seller.address, + constants.QTY_10, + paymentMethods.ETHTKN + ) + .to.emit(contractVoucherKernel, eventNames.LOG_PROMISE_CREATED) + .withArgs( + promiseId, + constants.ONE, + users.seller.address, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.ZERO + ) + .to.emit(contractERC1155ERC721, eventNames.TRANSFER_SINGLE) + .withArgs( + contractVoucherKernel.address, + constants.ZERO_ADDRESS, + users.seller.address, + tokenSupplyKey, + constants.QTY_10 ); }); - it('Get correct remaining qty for supply', async () => { - let remainingQtyInContract = await contractVoucherKernel.getRemQtyForSupply( - tokenSupplyKey, - users.seller.address - ); - assert.equal( - remainingQtyInContract.toString(), - remQty.toString(), - 'Remaining qty is not correct' - ); + describe('Voucher Kernel state after creation', () => { - for (let i = 0; i < vouchersToBuy; i++) { - await utils.commitToBuy(users.buyer, users.seller, tokenSupplyKey); - remainingQtyInContract = await contractVoucherKernel.getRemQtyForSupply( - tokenSupplyKey, + it('Promise info is correct', async () => { + await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10, + true + ) + + const promiseData = await contractVoucherKernel.getPromiseData( + promiseId + ); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.promiseId], + promiseId, + 'Promise Id incorrect' + ); + + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.nonce].toString(), + constants.ONE.toString(), + 'Promise data field -> nonce is incorrect' + ); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.validFrom].toString(), + constants.PROMISE_VALID_FROM.toString(), + 'Promise data field -> validFrom is incorrect' + ); + + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.validTo].toString(), + constants.PROMISE_VALID_TO.toString(), + 'Promise data field -> validTo is incorrect' + ); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.idx].toString(), + constants.ZERO.toString(), + 'Promise data field -> idx is incorrect' + ); + + const promiseSeller = await contractVoucherKernel.getSupplyHolder( + tokenSupplyKey + ); + + assert.strictEqual( + promiseSeller, + users.seller.address, + 'Seller incorrect' + ); + + const promiseOrderData = await contractVoucherKernel.getOrderCosts( + tokenSupplyKey + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.price].eq( + BN(constants.PROMISE_PRICE1) + ), + 'Promise produt price mismatch' + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositSe].eq( + BN(constants.PROMISE_DEPOSITSE1) + ), + 'Promise seller deposit mismatch' + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositBu].eq( + BN(constants.PROMISE_DEPOSITBU1) + ), + 'Promise buyer deposit mismatch' + ); + + const tokenNonce = await contractVoucherKernel.getTokenNonce( users.seller.address ); - - remQty = BN(remQty).sub(1).toString(); - + assert.isTrue( + tokenNonce.eq(constants.ONE), + 'Voucher kernel nonce mismatch' + ); + assert.equal( - remainingQtyInContract.toString(), - remQty, - 'Remaining qty is not correct' + promiseId, + await contractVoucherKernel.getPromiseIdFromSupplyId(tokenSupplyKey), + 'PromisId mismatch' ); - } + }); it('Should create payment method ETHTKN', async () => { tokenSupplyKey = await utils.createOrder( users.seller, - timestamp, - timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, constants.QTY_10 ); - const paymentMethod = await contractVoucherKernel.getVoucherPaymentMethod( + expect(await contractVoucherKernel.getVoucherPaymentMethod( tokenSupplyKey - ); + )).to.equal(paymentMethods.ETHTKN, 'Payment Method ETHTKN not set correctly'); - const addressTokenPrice = await contractVoucherKernel.getVoucherPriceToken( - tokenSupplyKey + + }); + + it('Deposit contract should be correct and Price address should be zero', async () => { + tokenSupplyKey = await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10 ); + + expect(await contractVoucherKernel.getVoucherPriceToken( + tokenSupplyKey + )).to.equal(constants.ZERO_ADDRESS, 'ETHTKN Method Price Token Address mismatch'); - const addressTokenDeposits = await contractVoucherKernel.getVoucherDepositToken( + expect(await contractVoucherKernel.getVoucherDepositToken( tokenSupplyKey - ); + )).to.equal(contractBSNTokenDeposit.address, 'ETHTKN Method Deposit Token Address mismatch'); - assert.equal( - paymentMethod.toString(), - paymentMethods.ETHTKN.toString(), - 'Payment Method ETHTKN not set correctly' - ); - assert.equal( - addressTokenPrice.toString(), - constants.ZERO_ADDRESS, - 'ETHTKN Method Price Token Address mismatch' - ); - assert.equal( - addressTokenDeposits.toString(), - contractBSNTokenDeposit.address, - 'ETHTKN Method Deposit Token Address mismatch' + }); + + + }); + + it('ERC1155ERC721 state is correct', async () => { + await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10, + true + ) + + const sellerERC1155ERC721Balance = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.seller.address, + tokenSupplyKey + ) + )[0]; + + assert.isTrue( + sellerERC1155ERC721Balance.eq(constants.QTY_10), + 'ERC1155ERC721 seller balance mismatch' ); + + }); + + it('Cashier has correct balance in Deposit Contract', async () => { + await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10, + true + ) + + const expectedBalance = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(constants.QTY_10) + ); + expect(await contractBSNTokenDeposit.balanceOf( + contractCashier.address + )).to.equal(expectedBalance, 'Escrow amount is incorrect'); + }); + + it('escrowTokens has correct balance', async () => { + await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10 + ) + + const expectedBalance = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(constants.QTY_10) + ); + const escrowTokens = await contractCashier.getEscrowTokensAmount( + contractBSNTokenDeposit.address, + users.seller.address + ); + + assert.isTrue( + escrowTokens.eq(expectedBalance), + 'Escrow amount is incorrect' + ); + }); + + it('Get correct remaining qty for supply', async () => { + await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10 + ) + + expect(await contractVoucherKernel.getRemQtyForSupply( + tokenSupplyKey, + users.seller.address + )).to.equal(constants.QTY_10, 'Remaining qty is not correct') + + for (let i = 0; i < vouchersToBuy; i++) { + await utils.commitToBuy(users.buyer, users.seller, tokenSupplyKey); + expect(await contractVoucherKernel.getRemQtyForSupply( + tokenSupplyKey, + users.seller.address + )).to.equal(constants.QTY_10-i-1, `Remaining qty is not correct [${i}]`) + + } }); + it.only('[NEGATIVE] Should revert if validTo is set below 5 minutes from now', async () => { + await expect( + utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_FROM + constants.ONE_MINUTE, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10 + ) + ).to.be.revertedWith(revertReasons.INVALID_VALIDITY_TO); + }); + it('[NEGATIVE] Should fail if token deposit contract address is not provided', async () => { + // todo refactor? const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); const nonce = await contractBSNTokenDeposit.nonces( users.seller.address @@ -718,6 +863,7 @@ describe('Cashier and VoucherKernel', () => { }); it('[NEGATIVE] Should revert if token deposit contract address is zero address', async () => { + // todo refactor? const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); const nonce = await contractBSNTokenDeposit.nonces( users.seller.address @@ -762,138 +908,173 @@ describe('Cashier and VoucherKernel', () => { }); it('[NEGATIVE] Should not create a supply if price is above the limit', async () => { - const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); - const nonce = await contractBSNTokenDeposit.nonces( - users.seller.address - ); - const deadline = toWei(1); - - const digest = await getApprovalDigest( - contractBSNTokenDeposit, - users.seller.address, - contractBosonRouter.address, - txValue, - nonce, - deadline - ); - - const {v, r, s} = ecsign( - Buffer.from(digest.slice(2), 'hex'), - Buffer.from(users.seller.privateKey.slice(2), 'hex') - ); - - const sellerInstance = contractBosonRouter.connect( - users.seller.signer - ); + // const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); + // const nonce = await contractBSNTokenDeposit.nonces( + // users.seller.address + // ); + // const deadline = toWei(1); + + // const digest = await getApprovalDigest( + // contractBSNTokenDeposit, + // users.seller.address, + // contractBosonRouter.address, + // txValue, + // nonce, + // deadline + // ); + + // const {v, r, s} = ecsign( + // Buffer.from(digest.slice(2), 'hex'), + // Buffer.from(users.seller.privateKey.slice(2), 'hex') + // ); + + // const sellerInstance = contractBosonRouter.connect( + // users.seller.signer + // ); + + // await expect( + // sellerInstance.requestCreateOrderETHTKNWithPermit( + // contractBSNTokenDeposit.address, + // txValue, + // deadline, + // v, + // r, + // s, + // [ + // constants.PROMISE_VALID_FROM, + // constants.PROMISE_VALID_TO, + // constants.ABOVE_ETH_LIMIT, + // constants.seller_deposit, + // constants.PROMISE_DEPOSITBU1, + // constants.ORDER_QUANTITY1, + // ] + // ) + // ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); await expect( - sellerInstance.requestCreateOrderETHTKNWithPermit( - contractBSNTokenDeposit.address, - txValue, - deadline, - v, - r, - s, - [ - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.ABOVE_ETH_LIMIT, - constants.seller_deposit, - constants.PROMISE_DEPOSITBU1, - constants.ORDER_QUANTITY1, - ] - ) - ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); + utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10, + true, + constants.ABOVE_ETH_LIMIT, + constants.PROMISE_DEPOSITBU1 + )).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); it('[NEGATIVE] Should not create a supply if depositBu is above the limit', async () => { - const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); - const nonce = await contractBSNTokenDeposit.nonces( - users.seller.address - ); - const deadline = toWei(1); - - const digest = await getApprovalDigest( - contractBSNTokenDeposit, - users.seller.address, - contractBosonRouter.address, - txValue, - nonce, - deadline - ); - - const {v, r, s} = ecsign( - Buffer.from(digest.slice(2), 'hex'), - Buffer.from(users.seller.privateKey.slice(2), 'hex') - ); - - const sellerInstance = contractBosonRouter.connect( - users.seller.signer - ); + // const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); + // const nonce = await contractBSNTokenDeposit.nonces( + // users.seller.address + // ); + // const deadline = toWei(1); + + // const digest = await getApprovalDigest( + // contractBSNTokenDeposit, + // users.seller.address, + // contractBosonRouter.address, + // txValue, + // nonce, + // deadline + // ); + + // const {v, r, s} = ecsign( + // Buffer.from(digest.slice(2), 'hex'), + // Buffer.from(users.seller.privateKey.slice(2), 'hex') + // ); + + // const sellerInstance = contractBosonRouter.connect( + // users.seller.signer + // ); + + // await expect( + // sellerInstance.requestCreateOrderETHTKNWithPermit( + // contractBSNTokenDeposit.address, + // txValue, + // deadline, + // v, + // r, + // s, + // [ + // constants.PROMISE_VALID_FROM, + // constants.PROMISE_VALID_TO, + // constants.PROMISE_PRICE1, + // constants.seller_deposit, + // constants.ABOVE_TOKEN_LIMIT, + // constants.ORDER_QUANTITY1, + // ] + // ) + // ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); await expect( - sellerInstance.requestCreateOrderETHTKNWithPermit( - contractBSNTokenDeposit.address, - txValue, - deadline, - v, - r, - s, - [ - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_PRICE1, - constants.seller_deposit, - constants.ABOVE_TOKEN_LIMIT, - constants.ORDER_QUANTITY1, - ] - ) - ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); + utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10, + true, + constants.PROMISE_PRICE1, + constants.ABOVE_TOKEN_LIMIT + )).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); it('[NEGATIVE] Should not create a supply if depositSe is above the limit', async () => { - const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); - const nonce = await contractBSNTokenDeposit.nonces( - users.seller.address - ); - const deadline = toWei(1); - - const digest = await getApprovalDigest( - contractBSNTokenDeposit, - users.seller.address, - contractBosonRouter.address, - txValue, - nonce, - deadline - ); - - const {v, r, s} = ecsign( - Buffer.from(digest.slice(2), 'hex'), - Buffer.from(users.seller.privateKey.slice(2), 'hex') - ); - - const sellerInstance = contractBosonRouter.connect( - users.seller.signer - ); - + // const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); + // const nonce = await contractBSNTokenDeposit.nonces( + // users.seller.address + // ); + // const deadline = toWei(1); + + // const digest = await getApprovalDigest( + // contractBSNTokenDeposit, + // users.seller.address, + // contractBosonRouter.address, + // txValue, + // nonce, + // deadline + // ); + + // const {v, r, s} = ecsign( + // Buffer.from(digest.slice(2), 'hex'), + // Buffer.from(users.seller.privateKey.slice(2), 'hex') + // ); + + // const sellerInstance = contractBosonRouter.connect( + // users.seller.signer + // ); + + // await expect( + // sellerInstance.requestCreateOrderETHTKNWithPermit( + // contractBSNTokenDeposit.address, + // txValue, + // deadline, + // v, + // r, + // s, + // [ + // constants.PROMISE_VALID_FROM, + // constants.PROMISE_VALID_TO, + // constants.PROMISE_PRICE1, + // constants.ABOVE_TOKEN_LIMIT, + // constants.PROMISE_DEPOSITBU1, + // constants.ORDER_QUANTITY1, + // ] + // ) + // ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); await expect( - sellerInstance.requestCreateOrderETHTKNWithPermit( - contractBSNTokenDeposit.address, - txValue, - deadline, - v, - r, - s, - [ - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_PRICE1, - constants.ABOVE_TOKEN_LIMIT, - constants.PROMISE_DEPOSITBU1, - constants.ORDER_QUANTITY1, - ] - ) - ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); + utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.ABOVE_TOKEN_LIMIT, + constants.QTY_10, + true, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 + )).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); }); From efe56ba6d854b323ea3a1010d969639fa3645527 Mon Sep 17 00:00:00 2001 From: zajck Date: Tue, 5 Oct 2021 14:40:21 +0200 Subject: [PATCH 06/41] beforeEach after createorder --- test/2_test_fullpath_with_permit.ts | 856 +++++++++++++--------------- 1 file changed, 402 insertions(+), 454 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 6080fc1e..da2a0b06 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -1,5 +1,5 @@ import {ethers} from 'hardhat'; -import {Signer, ContractFactory, Contract, BigNumber} from 'ethers'; +import {Signer, ContractFactory, Contract} from 'ethers'; import {assert, expect} from 'chai'; import {ecsign} from 'ethereumjs-util'; import constants from '../testHelpers/constants'; @@ -35,7 +35,6 @@ const BN = ethers.BigNumber.from; let utils: Utils; let users; - describe('Cashier and VoucherKernel', () => { let promiseId: string, tokenSupplyKey: string; // todo remove string when finished @@ -71,8 +70,6 @@ describe('Cashier and VoucherKernel', () => { const tokenIndex = constants.ONE; const TYPE_NF_BIT = constants.ONE.shl(255); tokenSupplyKey = TYPE_NF_BIT.or(tokenIndex.shl(128)).toString(); - - }); let contractERC1155ERC721: ERC1155ERC721, @@ -85,7 +82,7 @@ describe('Cashier and VoucherKernel', () => { let tokenVoucherKey, tokenVoucherKey1; - const ZERO = BN(0); // TODO: use constants.zero + const ZERO = BN(0); // TODO: use constants.zero const ONE_VOUCHER = 1; // TODO: use constants.one const deadline = toWei(1); @@ -98,7 +95,8 @@ describe('Cashier and VoucherKernel', () => { escrowAmount: BN(0), }; - async function setPeriods() { // TODO use where applicable; why this async? + async function setPeriods() { + // TODO use where applicable; why this async? const timestamp = await Utils.getCurrTimestamp(); constants.PROMISE_VALID_FROM = timestamp; @@ -186,7 +184,6 @@ describe('Cashier and VoucherKernel', () => { contractBSNTokenDeposit.address, contractBSNTokenDeposit.address ); - } describe('TOKEN SUPPLY CREATION (Voucher batch creation)', () => { @@ -200,7 +197,8 @@ describe('Cashier and VoucherKernel', () => { TKNTKN: 4, }; - afterEach(() => { // TODO REMOVE + afterEach(() => { + // TODO REMOVE remQty = constants.QTY_10; }); @@ -216,25 +214,11 @@ describe('Cashier and VoucherKernel', () => { contractCashier, contractBosonRouter ); - - // timestamp = await Utils.getCurrTimestamp(); - // constants.PROMISE_VALID_FROM = timestamp; - // constants.PROMISE_VALID_TO = timestamp + 2 * constants.SECONDS_IN_DAY; - - // setPeriods(); - - // tokenSupplyKey = await utils.createOrder( - // users.seller, - // timestamp, - // timestamp + constants.SECONDS_IN_DAY, - // constants.seller_deposit, - // constants.QTY_10 - // ); }); it('All expected events are emitted', async () => { - expect(await - utils.createOrder( + expect( + await utils.createOrder( users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, @@ -242,218 +226,203 @@ describe('Cashier and VoucherKernel', () => { constants.QTY_10, true ) - ).to.emit(contractBosonRouter, eventNames.LOG_ORDER_CREATED) - .withArgs(tokenSupplyKey, users.seller.address, constants.QTY_10, paymentMethods.ETHETH) - .to.emit(contractVoucherKernel, eventNames.LOG_PROMISE_CREATED) - .withArgs( - promiseId, - constants.ONE, - users.seller.address, - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.ZERO ) - .to.emit(contractERC1155ERC721, eventNames.TRANSFER_SINGLE) - .withArgs( - contractVoucherKernel.address, - constants.ZERO_ADDRESS, - users.seller.address, - tokenSupplyKey, - constants.QTY_10 - ); + .to.emit(contractBosonRouter, eventNames.LOG_ORDER_CREATED) + .withArgs( + tokenSupplyKey, + users.seller.address, + constants.QTY_10, + paymentMethods.ETHETH + ) + .to.emit(contractVoucherKernel, eventNames.LOG_PROMISE_CREATED) + .withArgs( + promiseId, + constants.ONE, + users.seller.address, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.ZERO + ) + .to.emit(contractERC1155ERC721, eventNames.TRANSFER_SINGLE) + .withArgs( + contractVoucherKernel.address, + constants.ZERO_ADDRESS, + users.seller.address, + tokenSupplyKey, + constants.QTY_10 + ); }); - describe('Voucher Kernel state after creation', () => { - - it('Promise info is correct', async () => { - await utils.createOrder( - users.seller, - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10, - true - ) - - const promiseData = await contractVoucherKernel.getPromiseData( - promiseId - ); - assert.equal( - promiseData[constants.PROMISE_DATA_FIELDS.promiseId], - promiseId, - 'Promise Id incorrect' - ); - - assert.equal( - promiseData[constants.PROMISE_DATA_FIELDS.nonce].toString(), - constants.ONE.toString(), - 'Promise data field -> nonce is incorrect' - ); - assert.equal( - promiseData[constants.PROMISE_DATA_FIELDS.validFrom].toString(), - constants.PROMISE_VALID_FROM.toString(), - 'Promise data field -> validFrom is incorrect' - ); - - assert.equal( - promiseData[constants.PROMISE_DATA_FIELDS.validTo].toString(), - constants.PROMISE_VALID_TO.toString(), - 'Promise data field -> validTo is incorrect' - ); - assert.equal( - promiseData[constants.PROMISE_DATA_FIELDS.idx].toString(), - constants.ZERO.toString(), - 'Promise data field -> idx is incorrect' - ); - - const promiseSeller = await contractVoucherKernel.getSupplyHolder( - tokenSupplyKey - ); - - assert.strictEqual( - promiseSeller, - users.seller.address, - 'Seller incorrect' - ); + describe('After creation', () => { + beforeEach(async () => { + await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10 + ); + }); - const promiseOrderData = await contractVoucherKernel.getOrderCosts( - tokenSupplyKey - ); - assert.isTrue( - promiseOrderData[constants.PROMISE_ORDER_FIELDS.price].eq( - BN(constants.PROMISE_PRICE1) - ), - 'Promise produt price mismatch' - ); - assert.isTrue( - promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositSe].eq( - BN(constants.PROMISE_DEPOSITSE1) - ), - 'Promise seller deposit mismatch' - ); - assert.isTrue( - promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositBu].eq( - BN(constants.PROMISE_DEPOSITBU1) - ), - 'Promise buyer deposit mismatch' - ); + describe('Voucher Kernel state', () => { + it('Promise info is correct', async () => { + const promiseData = await contractVoucherKernel.getPromiseData( + promiseId + ); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.promiseId], + promiseId, + 'Promise Id incorrect' + ); - const tokenNonce = await contractVoucherKernel.getTokenNonce( - users.seller.address - ); - assert.isTrue( - tokenNonce.eq(constants.ONE), - 'Voucher kernel nonce mismatch' - ); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.nonce].toString(), + constants.ONE.toString(), + 'Promise data field -> nonce is incorrect' + ); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.validFrom].toString(), + constants.PROMISE_VALID_FROM.toString(), + 'Promise data field -> validFrom is incorrect' + ); - assert.equal( - promiseId, - await contractVoucherKernel.getPromiseIdFromSupplyId(tokenSupplyKey), - 'PromisId mismatch' - ); - - }); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.validTo].toString(), + constants.PROMISE_VALID_TO.toString(), + 'Promise data field -> validTo is incorrect' + ); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.idx].toString(), + constants.ZERO.toString(), + 'Promise data field -> idx is incorrect' + ); - it('Should create payment method ETHETH', async () => { - const tokenSupplyKey = await utils.createOrder( - users.seller, - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10 - ); - - expect(await contractVoucherKernel.getVoucherPaymentMethod( - tokenSupplyKey - )).to.equal(paymentMethods.ETHETH, 'Payment Method ETHETH not set correctly'); + const promiseSeller = await contractVoucherKernel.getSupplyHolder( + tokenSupplyKey + ); - }); + assert.strictEqual( + promiseSeller, + users.seller.address, + 'Seller incorrect' + ); - it('Deposit and Price address should be zero', async () => { - const tokenSupplyKey = await utils.createOrder( - users.seller, - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10 - ); + const promiseOrderData = await contractVoucherKernel.getOrderCosts( + tokenSupplyKey + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.price].eq( + BN(constants.PROMISE_PRICE1) + ), + 'Promise produt price mismatch' + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositSe].eq( + BN(constants.PROMISE_DEPOSITSE1) + ), + 'Promise seller deposit mismatch' + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositBu].eq( + BN(constants.PROMISE_DEPOSITBU1) + ), + 'Promise buyer deposit mismatch' + ); - expect(await contractVoucherKernel.getVoucherPriceToken( - tokenSupplyKey - )).to.equal(constants.ZERO_ADDRESS, 'ETHETH Method Price Token Address mismatch'); - + const tokenNonce = await contractVoucherKernel.getTokenNonce( + users.seller.address + ); - expect(await contractVoucherKernel.getVoucherDepositToken( - tokenSupplyKey - )).to.equal(constants.ZERO_ADDRESS, 'ETHETH Method Deposit Token Address mismatch'); - - }); + assert.isTrue( + tokenNonce.eq(constants.ONE.toString()), + 'Voucher kernel nonce mismatch' + ); - }); - it('ERC1155ERC721 state is correct', async () => { - await utils.createOrder( - users.seller, - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10, - true - ) + assert.equal( + promiseId, + await contractVoucherKernel.getPromiseIdFromSupplyId( + tokenSupplyKey + ), + 'PromisId mismatch' + ); + }); - const sellerERC1155ERC721Balance = ( - await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( - users.seller.address, - tokenSupplyKey - ) - )[0]; + it('Should create payment method ETHETH', async () => { + expect( + await contractVoucherKernel.getVoucherPaymentMethod( + tokenSupplyKey + ) + ).to.equal( + paymentMethods.ETHETH, + 'Payment Method ETHETH not set correctly' + ); + }); - assert.isTrue( - sellerERC1155ERC721Balance.eq(constants.QTY_10), - 'ERC1155ERC721 seller balance mismatch' - ); - - }); + it('Deposit and Price address should be zero', async () => { + expect( + await contractVoucherKernel.getVoucherPriceToken(tokenSupplyKey) + ).to.equal( + constants.ZERO_ADDRESS, + 'ETHETH Method Price Token Address mismatch' + ); - it('ESCROW has correct balance', async () => { - - expect(await ethers.provider.getBalance(contractCashier.address)).to.equal(constants.ZERO, 'Cashier starting balance should be 0'); + expect( + await contractVoucherKernel.getVoucherDepositToken(tokenSupplyKey) + ).to.equal( + constants.ZERO_ADDRESS, + 'ETHETH Method Deposit Token Address mismatch' + ); + }); + }); - await utils.createOrder( - users.seller, - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10 - ) + it('ERC1155ERC721 state is correct', async () => { + const sellerERC1155ERC721Balance = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.seller.address, + tokenSupplyKey + ) + )[0]; - const expectedBalance = BN(constants.PROMISE_DEPOSITSE1).mul(BN(constants.QTY_10)); + assert.isTrue( + sellerERC1155ERC721Balance.eq(constants.QTY_10), + 'ERC1155ERC721 seller balance mismatch' + ); + }); - expect(await ethers.provider.getBalance(contractCashier.address)).to.equal(expectedBalance,'Escrow balance is incorrect') - expect(await contractCashier.getEscrowAmount(users.seller.address)).to.equal(expectedBalance, 'Escrow stored amount is incorrect'); - }); + it('ESCROW has correct balance', async () => { + const expectedBalance = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(constants.QTY_10) + ); - it('Get correct remaining qty for supply', async () => { - await utils.createOrder( - users.seller, - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10 - ) - - expect(await contractVoucherKernel.getRemQtyForSupply( - tokenSupplyKey, - users.seller.address - )).to.equal(constants.QTY_10, 'Remaining qty is not correct') + expect( + await ethers.provider.getBalance(contractCashier.address) + ).to.equal(expectedBalance, 'Escrow balance is incorrect'); + expect( + await contractCashier.getEscrowAmount(users.seller.address) + ).to.equal(expectedBalance, 'Escrow stored amount is incorrect'); + }); - for (let i = 0; i < vouchersToBuy; i++) { - await utils.commitToBuy(users.buyer, users.seller, tokenSupplyKey); - expect(await contractVoucherKernel.getRemQtyForSupply( - tokenSupplyKey, - users.seller.address - )).to.equal(constants.QTY_10-i-1, `Remaining qty is not correct [${i}]`) + it('Get correct remaining qty for supply', async () => { + expect( + await contractVoucherKernel.getRemQtyForSupply( + tokenSupplyKey, + users.seller.address + ) + ).to.equal(constants.QTY_10, 'Remaining qty is not correct'); - } + for (let i = 0; i < vouchersToBuy; i++) { + await utils.commitToBuy(users.buyer, users.seller, tokenSupplyKey); + expect( + await contractVoucherKernel.getRemQtyForSupply( + tokenSupplyKey, + users.seller.address + ) + ).to.equal( + constants.QTY_10 - i - 1, + `Remaining qty is not correct [${i}]` + ); + } + }); }); it('[NEGATIVE] Should revert if validTo is set below 5 minutes from now', async () => { @@ -481,7 +450,6 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_DEPOSITBU1 ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); - }); it('[NEGATIVE] Should not create a supply if depositBu is above the limit', async () => { @@ -497,7 +465,6 @@ describe('Cashier and VoucherKernel', () => { constants.ABOVE_ETH_LIMIT ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); - }); it('[NEGATIVE] Should not create a supply if depositSe is above the limit', async () => { @@ -517,7 +484,7 @@ describe('Cashier and VoucherKernel', () => { }); describe('[WITH PERMIT]', () => { - describe.only('ETHTKN', () => { + describe('ETHTKN', () => { beforeEach(async () => { await deployContracts(); @@ -547,7 +514,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer.address, tokensToMint ); - }); it('All expected events are emitted', async () => { @@ -561,262 +527,241 @@ describe('Cashier and VoucherKernel', () => { true ) ) - .to.emit(contractBosonRouter, eventNames.LOG_ORDER_CREATED) - .withArgs( - tokenSupplyKey, - users.seller.address, - constants.QTY_10, - paymentMethods.ETHTKN - ) - .to.emit(contractVoucherKernel, eventNames.LOG_PROMISE_CREATED) - .withArgs( - promiseId, - constants.ONE, - users.seller.address, - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.ZERO - ) - .to.emit(contractERC1155ERC721, eventNames.TRANSFER_SINGLE) - .withArgs( - contractVoucherKernel.address, - constants.ZERO_ADDRESS, - users.seller.address, - tokenSupplyKey, - constants.QTY_10 - ); + .to.emit(contractBosonRouter, eventNames.LOG_ORDER_CREATED) + .withArgs( + tokenSupplyKey, + users.seller.address, + constants.QTY_10, + paymentMethods.ETHTKN + ) + .to.emit(contractVoucherKernel, eventNames.LOG_PROMISE_CREATED) + .withArgs( + promiseId, + constants.ONE, + users.seller.address, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.ZERO + ) + .to.emit(contractERC1155ERC721, eventNames.TRANSFER_SINGLE) + .withArgs( + contractVoucherKernel.address, + constants.ZERO_ADDRESS, + users.seller.address, + tokenSupplyKey, + constants.QTY_10 + ); }); - describe('Voucher Kernel state after creation', () => { - - it('Promise info is correct', async () => { + describe('After creation', () => { + beforeEach(async () => { await utils.createOrder( users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, - constants.QTY_10, - true - ) - - const promiseData = await contractVoucherKernel.getPromiseData( - promiseId - ); - assert.equal( - promiseData[constants.PROMISE_DATA_FIELDS.promiseId], - promiseId, - 'Promise Id incorrect' - ); - - assert.equal( - promiseData[constants.PROMISE_DATA_FIELDS.nonce].toString(), - constants.ONE.toString(), - 'Promise data field -> nonce is incorrect' - ); - assert.equal( - promiseData[constants.PROMISE_DATA_FIELDS.validFrom].toString(), - constants.PROMISE_VALID_FROM.toString(), - 'Promise data field -> validFrom is incorrect' - ); - - assert.equal( - promiseData[constants.PROMISE_DATA_FIELDS.validTo].toString(), - constants.PROMISE_VALID_TO.toString(), - 'Promise data field -> validTo is incorrect' - ); - assert.equal( - promiseData[constants.PROMISE_DATA_FIELDS.idx].toString(), - constants.ZERO.toString(), - 'Promise data field -> idx is incorrect' - ); - - const promiseSeller = await contractVoucherKernel.getSupplyHolder( - tokenSupplyKey - ); - - assert.strictEqual( - promiseSeller, - users.seller.address, - 'Seller incorrect' - ); - - const promiseOrderData = await contractVoucherKernel.getOrderCosts( - tokenSupplyKey - ); - assert.isTrue( - promiseOrderData[constants.PROMISE_ORDER_FIELDS.price].eq( - BN(constants.PROMISE_PRICE1) - ), - 'Promise produt price mismatch' - ); - assert.isTrue( - promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositSe].eq( - BN(constants.PROMISE_DEPOSITSE1) - ), - 'Promise seller deposit mismatch' - ); - assert.isTrue( - promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositBu].eq( - BN(constants.PROMISE_DEPOSITBU1) - ), - 'Promise buyer deposit mismatch' - ); - - const tokenNonce = await contractVoucherKernel.getTokenNonce( - users.seller.address - ); - assert.isTrue( - tokenNonce.eq(constants.ONE), - 'Voucher kernel nonce mismatch' - ); - - assert.equal( - promiseId, - await contractVoucherKernel.getPromiseIdFromSupplyId(tokenSupplyKey), - 'PromisId mismatch' + constants.QTY_10 ); - - }); + }); - it('Should create payment method ETHTKN', async () => { - tokenSupplyKey = await utils.createOrder( - users.seller, - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10 - ); + describe('Voucher Kernel state', () => { + it('Promise info is correct', async () => { + await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10, + true + ); - expect(await contractVoucherKernel.getVoucherPaymentMethod( - tokenSupplyKey - )).to.equal(paymentMethods.ETHTKN, 'Payment Method ETHTKN not set correctly'); + const promiseData = await contractVoucherKernel.getPromiseData( + promiseId + ); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.promiseId], + promiseId, + 'Promise Id incorrect' + ); - - }); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.nonce].toString(), + constants.ONE.toString(), + 'Promise data field -> nonce is incorrect' + ); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.validFrom].toString(), + constants.PROMISE_VALID_FROM.toString(), + 'Promise data field -> validFrom is incorrect' + ); - it('Deposit contract should be correct and Price address should be zero', async () => { - tokenSupplyKey = await utils.createOrder( - users.seller, - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10 - ); - - expect(await contractVoucherKernel.getVoucherPriceToken( - tokenSupplyKey - )).to.equal(constants.ZERO_ADDRESS, 'ETHTKN Method Price Token Address mismatch'); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.validTo].toString(), + constants.PROMISE_VALID_TO.toString(), + 'Promise data field -> validTo is incorrect' + ); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.idx].toString(), + constants.ZERO.toString(), + 'Promise data field -> idx is incorrect' + ); - expect(await contractVoucherKernel.getVoucherDepositToken( - tokenSupplyKey - )).to.equal(contractBSNTokenDeposit.address, 'ETHTKN Method Deposit Token Address mismatch'); + const promiseSeller = await contractVoucherKernel.getSupplyHolder( + tokenSupplyKey + ); - }); + assert.strictEqual( + promiseSeller, + users.seller.address, + 'Seller incorrect' + ); + const promiseOrderData = await contractVoucherKernel.getOrderCosts( + tokenSupplyKey + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.price].eq( + BN(constants.PROMISE_PRICE1) + ), + 'Promise produt price mismatch' + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositSe].eq( + BN(constants.PROMISE_DEPOSITSE1) + ), + 'Promise seller deposit mismatch' + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositBu].eq( + BN(constants.PROMISE_DEPOSITBU1) + ), + 'Promise buyer deposit mismatch' + ); - }); + const tokenNonce = await contractVoucherKernel.getTokenNonce( + users.seller.address + ); + assert.isTrue( + tokenNonce.eq(constants.ONE), + 'Voucher kernel nonce mismatch' + ); - it('ERC1155ERC721 state is correct', async () => { - await utils.createOrder( - users.seller, - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10, - true - ) - - const sellerERC1155ERC721Balance = ( - await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( - users.seller.address, - tokenSupplyKey - ) - )[0]; - - assert.isTrue( - sellerERC1155ERC721Balance.eq(constants.QTY_10), - 'ERC1155ERC721 seller balance mismatch' - ); - - }); + assert.equal( + promiseId, + await contractVoucherKernel.getPromiseIdFromSupplyId( + tokenSupplyKey + ), + 'PromisId mismatch' + ); + }); + + it('Should create payment method ETHTKN', async () => { + expect( + await contractVoucherKernel.getVoucherPaymentMethod( + tokenSupplyKey + ) + ).to.equal( + paymentMethods.ETHTKN, + 'Payment Method ETHTKN not set correctly' + ); + }); + + it('Deposit contract should be correct and Price address should be zero', async () => { + expect( + await contractVoucherKernel.getVoucherPriceToken(tokenSupplyKey) + ).to.equal( + constants.ZERO_ADDRESS, + 'ETHTKN Method Price Token Address mismatch' + ); - it('Cashier has correct balance in Deposit Contract', async () => { - await utils.createOrder( - users.seller, - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10, - true - ) + expect( + await contractVoucherKernel.getVoucherDepositToken( + tokenSupplyKey + ) + ).to.equal( + contractBSNTokenDeposit.address, + 'ETHTKN Method Deposit Token Address mismatch' + ); + }); + }); - const expectedBalance = BN(constants.PROMISE_DEPOSITSE1).mul( - BN(constants.QTY_10) - ); - expect(await contractBSNTokenDeposit.balanceOf( - contractCashier.address - )).to.equal(expectedBalance, 'Escrow amount is incorrect'); - }); + it('ERC1155ERC721 state is correct', async () => { + const sellerERC1155ERC721Balance = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.seller.address, + tokenSupplyKey + ) + )[0]; - it('escrowTokens has correct balance', async () => { - await utils.createOrder( - users.seller, - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10 - ) - - const expectedBalance = BN(constants.PROMISE_DEPOSITSE1).mul( - BN(constants.QTY_10) - ); - const escrowTokens = await contractCashier.getEscrowTokensAmount( - contractBSNTokenDeposit.address, - users.seller.address - ); + assert.isTrue( + sellerERC1155ERC721Balance.eq(constants.QTY_10), + 'ERC1155ERC721 seller balance mismatch' + ); + }); - assert.isTrue( - escrowTokens.eq(expectedBalance), - 'Escrow amount is incorrect' - ); - }); + it('Cashier has correct balance in Deposit Contract', async () => { + const expectedBalance = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(constants.QTY_10) + ); + expect( + await contractBSNTokenDeposit.balanceOf(contractCashier.address) + ).to.equal(expectedBalance, 'Escrow amount is incorrect'); + }); - it('Get correct remaining qty for supply', async () => { - await utils.createOrder( - users.seller, - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10 - ) - - expect(await contractVoucherKernel.getRemQtyForSupply( - tokenSupplyKey, - users.seller.address - )).to.equal(constants.QTY_10, 'Remaining qty is not correct') - - for (let i = 0; i < vouchersToBuy; i++) { - await utils.commitToBuy(users.buyer, users.seller, tokenSupplyKey); - expect(await contractVoucherKernel.getRemQtyForSupply( - tokenSupplyKey, + it('escrowTokens has correct balance', async () => { + const expectedBalance = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(constants.QTY_10) + ); + const escrowTokens = await contractCashier.getEscrowTokensAmount( + contractBSNTokenDeposit.address, users.seller.address - )).to.equal(constants.QTY_10-i-1, `Remaining qty is not correct [${i}]`) - - } + ); + + assert.isTrue( + escrowTokens.eq(expectedBalance), + 'Escrow amount is incorrect' + ); + }); + + it('Get correct remaining qty for supply', async () => { + expect( + await contractVoucherKernel.getRemQtyForSupply( + tokenSupplyKey, + users.seller.address + ) + ).to.equal(constants.QTY_10, 'Remaining qty is not correct'); + + for (let i = 0; i < vouchersToBuy; i++) { + await utils.commitToBuy( + users.buyer, + users.seller, + tokenSupplyKey + ); + expect( + await contractVoucherKernel.getRemQtyForSupply( + tokenSupplyKey, + users.seller.address + ) + ).to.equal( + constants.QTY_10 - i - 1, + `Remaining qty is not correct [${i}]` + ); + } + }); }); - it.only('[NEGATIVE] Should revert if validTo is set below 5 minutes from now', async () => { - await expect( - utils.createOrder( - users.seller, - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_FROM + constants.ONE_MINUTE, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10 - ) - ).to.be.revertedWith(revertReasons.INVALID_VALIDITY_TO); + it('[NEGATIVE] Should revert if validTo is set below 5 minutes from now', async () => { + await expect( + utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_FROM + constants.ONE_MINUTE, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10 + ) + ).to.be.revertedWith(revertReasons.INVALID_VALIDITY_TO); }); - + it('[NEGATIVE] Should fail if token deposit contract address is not provided', async () => { // todo refactor? const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); @@ -961,7 +906,8 @@ describe('Cashier and VoucherKernel', () => { true, constants.ABOVE_ETH_LIMIT, constants.PROMISE_DEPOSITBU1 - )).to.be.revertedWith(revertReasons.ABOVE_LIMIT); + ) + ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); it('[NEGATIVE] Should not create a supply if depositBu is above the limit', async () => { @@ -1017,8 +963,9 @@ describe('Cashier and VoucherKernel', () => { constants.QTY_10, true, constants.PROMISE_PRICE1, - constants.ABOVE_TOKEN_LIMIT - )).to.be.revertedWith(revertReasons.ABOVE_LIMIT); + constants.ABOVE_TOKEN_LIMIT + ) + ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); it('[NEGATIVE] Should not create a supply if depositSe is above the limit', async () => { @@ -1073,8 +1020,9 @@ describe('Cashier and VoucherKernel', () => { constants.QTY_10, true, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 - )).to.be.revertedWith(revertReasons.ABOVE_LIMIT); + constants.PROMISE_DEPOSITBU1 + ) + ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); }); From f82b1d44c379a5bc4a31801795103656c65fc292 Mon Sep 17 00:00:00 2001 From: zajck Date: Tue, 5 Oct 2021 15:18:19 +0200 Subject: [PATCH 07/41] formatting --- testHelpers/utils.ts | 97 +++++++++++++------------------------------- 1 file changed, 29 insertions(+), 68 deletions(-) diff --git a/testHelpers/utils.ts b/testHelpers/utils.ts index a90626c1..b82db0b5 100644 --- a/testHelpers/utils.ts +++ b/testHelpers/utils.ts @@ -28,7 +28,16 @@ import { } from '../typechain'; class Utils { - createOrder: (seller, from, to, sellerDeposit, qty, returnTx?, promisePrice?, buyerDeposit?) => any; + createOrder: ( + seller, + from, + to, + sellerDeposit, + qty, + returnTx?, + promisePrice?, + buyerDeposit? + ) => any; createOrderConditional: ( seller, from, @@ -38,7 +47,7 @@ class Utils { gateContract, nftTokenID, returnTx?, - promisePrice?, + promisePrice?, buyerDeposit? ) => any; commitToBuy: (buyer, seller, tokenSupplyId, returnTx?) => any; @@ -96,14 +105,7 @@ class Utils { seller.signer ) as BosonRouter; const txOrder = await sellerInstance.requestCreateOrderETHETH( - [ - from, - to, - promisePrice, - sellerDeposit, - buyerDeposit, - qty, - ], + [from, to, promisePrice, sellerDeposit, buyerDeposit, qty], { value: txValue, } @@ -126,7 +128,8 @@ class Utils { return eventArgs._tokenIdSupply.toString(); } - async requestCreateOrderETHTKNSameWithPermit( // is this really needed? + async requestCreateOrderETHTKNSameWithPermit( + // is this really needed? seller: Account, from: number, to: number, @@ -166,14 +169,7 @@ class Utils { v, r, s, - [ - from, - to, - promisePrice, - sellerDeposit, - buyerDeposit, - qty, - ], + [from, to, promisePrice, sellerDeposit, buyerDeposit, qty], { from: seller.address, } @@ -205,7 +201,7 @@ class Utils { returnTx = false, promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default - ): Promise{ + ): Promise { const txValue = BN(sellerDeposit).mul(BN(qty)); const nonce = await this.contractBSNTokenDeposit.nonces(seller.address); @@ -235,14 +231,7 @@ class Utils { v, r, s, - [ - from, - to, - promisePrice, - sellerDeposit, - buyerDeposit, - qty, - ], + [from, to, promisePrice, sellerDeposit, buyerDeposit, qty], { from: seller.address, } @@ -276,7 +265,7 @@ class Utils { returnTx = false, promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default - ): Promise{ + ): Promise { const txValue = BN(sellerDeposit).mul(BN(qty)); const nonce = await this.contractBSNTokenDeposit.nonces(seller.address); @@ -299,7 +288,6 @@ class Utils { seller.signer ) as BosonRouter; const txOrder = await sellerInstance.requestCreateOrderTKNTKNWithPermitConditional( - this.contractBSNTokenPrice.address, this.contractBSNTokenDeposit.address, txValue, @@ -307,14 +295,7 @@ class Utils { v, r, s, - [ - from, - to, - promisePrice, - sellerDeposit, - buyerDeposit, - qty, - ], + [from, to, promisePrice, sellerDeposit, buyerDeposit, qty], gateContract.address, nftTokenId || '0', { @@ -377,14 +358,7 @@ class Utils { v, r, s, - [ - from, - to, - promisePrice, - sellerDeposit, - buyerDeposit, - qty, - ], + [from, to, promisePrice, sellerDeposit, buyerDeposit, qty], { from: seller.address, } @@ -424,14 +398,7 @@ class Utils { ) as BosonRouter; const txOrder = await sellerInstance.requestCreateOrderTKNETH( this.contractBSNTokenPrice.address, - [ - from, - to, - promisePrice, - sellerDeposit, - buyerDeposit, - qty, - ], + [from, to, promisePrice, sellerDeposit, buyerDeposit, qty], { value: txValue, } @@ -460,11 +427,9 @@ class Utils { tokenSupplyId: string, returnTx = false, promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default - buyerDeposit = constants.PROMISE_DEPOSITBU1, // todo shift on right place, remove default + buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default ): Promise { - const txValue = BN(buyerDeposit).add( - BN(promisePrice) - ); + const txValue = BN(buyerDeposit).add(BN(promisePrice)); const nonce1 = await this.contractBSNTokenDeposit.nonces(buyer.address); const digestDeposit = await getApprovalDigest( @@ -544,11 +509,9 @@ class Utils { tokenSupplyId: string, returnTx = false, promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default - buyerDeposit = constants.PROMISE_DEPOSITBU1, // todo shift on right place, remove default + buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default ): Promise { - const txValue = BN(buyerDeposit).add( - BN(promisePrice) - ); + const txValue = BN(buyerDeposit).add(BN(promisePrice)); const nonce = await this.contractBSNTokenSame.nonces(buyer.address); const digestTxValue = await getApprovalDigest( @@ -605,7 +568,7 @@ class Utils { tokenSupplyId: string, returnTx = false, promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default - buyerDeposit = constants.PROMISE_DEPOSITBU1, // todo shift on right place, remove default + buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default ): Promise { const nonce1 = await this.contractBSNTokenDeposit.nonces(buyer.address); @@ -660,11 +623,9 @@ class Utils { tokenSupplyId: string, returnTx = false, promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default - buyerDeposit = constants.PROMISE_DEPOSITBU1, // todo shift on right place, remove default + buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default ): Promise { - const txValue = BN(buyerDeposit).add( - BN(promisePrice) - ); // TODO MAKE PARAMETERS + const txValue = BN(buyerDeposit).add(BN(promisePrice)); // TODO MAKE PARAMETERS const buyerInstance = this.contractBSNRouter.connect( buyer.signer @@ -700,7 +661,7 @@ class Utils { tokenSupplyId: string, returnTx = false, promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default - buyerDeposit = constants.PROMISE_DEPOSITBU1, // todo shift on right place, remove default + buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default ): Promise { const nonce1 = await this.contractBSNTokenPrice.nonces(buyer.address); From 1a3430977bc11223cc7dfe605b424ccfdb2369dc Mon Sep 17 00:00:00 2001 From: zajck Date: Tue, 5 Oct 2021 15:37:58 +0200 Subject: [PATCH 08/41] TKNETH unit tests --- test/2_test_fullpath_with_permit.ts | 561 +++++++++++----------------- 1 file changed, 220 insertions(+), 341 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index da2a0b06..2de4ad51 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -762,53 +762,7 @@ describe('Cashier and VoucherKernel', () => { ).to.be.revertedWith(revertReasons.INVALID_VALIDITY_TO); }); - it('[NEGATIVE] Should fail if token deposit contract address is not provided', async () => { - // todo refactor? - const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); - const nonce = await contractBSNTokenDeposit.nonces( - users.seller.address - ); - - const digest = await getApprovalDigest( - contractBSNTokenDeposit, - users.seller.address, - contractCashier.address, - txValue, - nonce, - deadline - ); - - const {v, r, s} = ecsign( - Buffer.from(digest.slice(2), 'hex'), - Buffer.from(users.seller.privateKey.slice(2), 'hex') - ); - - const sellerInstance = contractBosonRouter.connect( - users.seller.signer - ); - - await expect( - sellerInstance.requestCreateOrderETHTKNWithPermit( - '', - txValue, - deadline, - v, - r, - s, - [ - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_PRICE1, - constants.seller_deposit, - constants.PROMISE_DEPOSITBU1, - constants.ORDER_QUANTITY1, - ] - ) - ).to.be.reverted; - }); - it('[NEGATIVE] Should revert if token deposit contract address is zero address', async () => { - // todo refactor? const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); const nonce = await contractBSNTokenDeposit.nonces( users.seller.address @@ -853,49 +807,6 @@ describe('Cashier and VoucherKernel', () => { }); it('[NEGATIVE] Should not create a supply if price is above the limit', async () => { - // const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); - // const nonce = await contractBSNTokenDeposit.nonces( - // users.seller.address - // ); - // const deadline = toWei(1); - - // const digest = await getApprovalDigest( - // contractBSNTokenDeposit, - // users.seller.address, - // contractBosonRouter.address, - // txValue, - // nonce, - // deadline - // ); - - // const {v, r, s} = ecsign( - // Buffer.from(digest.slice(2), 'hex'), - // Buffer.from(users.seller.privateKey.slice(2), 'hex') - // ); - - // const sellerInstance = contractBosonRouter.connect( - // users.seller.signer - // ); - - // await expect( - // sellerInstance.requestCreateOrderETHTKNWithPermit( - // contractBSNTokenDeposit.address, - // txValue, - // deadline, - // v, - // r, - // s, - // [ - // constants.PROMISE_VALID_FROM, - // constants.PROMISE_VALID_TO, - // constants.ABOVE_ETH_LIMIT, - // constants.seller_deposit, - // constants.PROMISE_DEPOSITBU1, - // constants.ORDER_QUANTITY1, - // ] - // ) - // ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); - await expect( utils.createOrder( users.seller, @@ -911,49 +822,6 @@ describe('Cashier and VoucherKernel', () => { }); it('[NEGATIVE] Should not create a supply if depositBu is above the limit', async () => { - // const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); - // const nonce = await contractBSNTokenDeposit.nonces( - // users.seller.address - // ); - // const deadline = toWei(1); - - // const digest = await getApprovalDigest( - // contractBSNTokenDeposit, - // users.seller.address, - // contractBosonRouter.address, - // txValue, - // nonce, - // deadline - // ); - - // const {v, r, s} = ecsign( - // Buffer.from(digest.slice(2), 'hex'), - // Buffer.from(users.seller.privateKey.slice(2), 'hex') - // ); - - // const sellerInstance = contractBosonRouter.connect( - // users.seller.signer - // ); - - // await expect( - // sellerInstance.requestCreateOrderETHTKNWithPermit( - // contractBSNTokenDeposit.address, - // txValue, - // deadline, - // v, - // r, - // s, - // [ - // constants.PROMISE_VALID_FROM, - // constants.PROMISE_VALID_TO, - // constants.PROMISE_PRICE1, - // constants.seller_deposit, - // constants.ABOVE_TOKEN_LIMIT, - // constants.ORDER_QUANTITY1, - // ] - // ) - // ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); - await expect( utils.createOrder( users.seller, @@ -969,48 +837,6 @@ describe('Cashier and VoucherKernel', () => { }); it('[NEGATIVE] Should not create a supply if depositSe is above the limit', async () => { - // const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); - // const nonce = await contractBSNTokenDeposit.nonces( - // users.seller.address - // ); - // const deadline = toWei(1); - - // const digest = await getApprovalDigest( - // contractBSNTokenDeposit, - // users.seller.address, - // contractBosonRouter.address, - // txValue, - // nonce, - // deadline - // ); - - // const {v, r, s} = ecsign( - // Buffer.from(digest.slice(2), 'hex'), - // Buffer.from(users.seller.privateKey.slice(2), 'hex') - // ); - - // const sellerInstance = contractBosonRouter.connect( - // users.seller.signer - // ); - - // await expect( - // sellerInstance.requestCreateOrderETHTKNWithPermit( - // contractBSNTokenDeposit.address, - // txValue, - // deadline, - // v, - // r, - // s, - // [ - // constants.PROMISE_VALID_FROM, - // constants.PROMISE_VALID_TO, - // constants.PROMISE_PRICE1, - // constants.ABOVE_TOKEN_LIMIT, - // constants.PROMISE_DEPOSITBU1, - // constants.ORDER_QUANTITY1, - // ] - // ) - // ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); await expect( utils.createOrder( users.seller, @@ -1026,8 +852,8 @@ describe('Cashier and VoucherKernel', () => { }); }); - describe('TKNETH', () => { - before(async () => { + describe.only('TKNETH', () => { + beforeEach(async () => { await deployContracts(); utils = await UtilsBuilder.create() @@ -1042,10 +868,6 @@ describe('Cashier and VoucherKernel', () => { '' ); - timestamp = await Utils.getCurrTimestamp(); - constants.PROMISE_VALID_FROM = timestamp; - constants.PROMISE_VALID_TO = timestamp + 2 * constants.SECONDS_IN_DAY; - const tokensToMint = BN(constants.product_price).mul( BN(constants.QTY_10) ); @@ -1054,140 +876,221 @@ describe('Cashier and VoucherKernel', () => { users.buyer.address, tokensToMint ); - - tokenSupplyKey = await utils.createOrder( - users.seller, - timestamp, - timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_10 - ); }); - it('[NEGATIVE] Should revert if validTo is set below 5 minutes from now', async () => { + it('All expected events are emitted', async () => { await expect( utils.createOrder( users.seller, - timestamp, - timestamp + constants.ONE_MINUTE, - constants.seller_deposit, - constants.QTY_10 + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10, + true ) - ).to.be.revertedWith(revertReasons.INVALID_VALIDITY_TO); + ) + .to.emit(contractBosonRouter, eventNames.LOG_ORDER_CREATED) + .withArgs( + tokenSupplyKey, + users.seller.address, + constants.QTY_10, + paymentMethods.TKNETH + ) + .to.emit(contractVoucherKernel, eventNames.LOG_PROMISE_CREATED) + .withArgs( + promiseId, + constants.ONE, + users.seller.address, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.ZERO + ) + .to.emit(contractERC1155ERC721, eventNames.TRANSFER_SINGLE) + .withArgs( + contractVoucherKernel.address, + constants.ZERO_ADDRESS, + users.seller.address, + tokenSupplyKey, + constants.QTY_10 + ); }); - it('ESCROW has correct balance', async () => { - const expectedBalance = BN(constants.seller_deposit).mul(BN(remQty)); - const escrowAmount = await contractCashier.getEscrowAmount( - users.seller.address - ); + describe('After creation', () => { + beforeEach(async () => { + await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10 + ); + }); - assert.isTrue( - escrowAmount.eq(expectedBalance), - 'Escrow amount is incorrect' - ); - }); + describe('Voucher Kernel state', () => { + it('Promise info is correct', async () => { + const promiseData = await contractVoucherKernel.getPromiseData( + promiseId + ); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.promiseId], + promiseId, + 'Promise Id incorrect' + ); - it('Cashier Contract has correct amount of ETH', async () => { - const expectedBalance = BN(constants.seller_deposit).mul(BN(remQty)); - const cashierBalance = await ethers.provider.getBalance( - contractCashier.address - ); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.nonce].toString(), + constants.ONE.toString(), + 'Promise data field -> nonce is incorrect' + ); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.validFrom].toString(), + constants.PROMISE_VALID_FROM.toString(), + 'Promise data field -> validFrom is incorrect' + ); - assert.isTrue( - BN(cashierBalance).eq(expectedBalance), - 'Escrow amount is incorrect' - ); - }); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.validTo].toString(), + constants.PROMISE_VALID_TO.toString(), + 'Promise data field -> validTo is incorrect' + ); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.idx].toString(), + constants.ZERO.toString(), + 'Promise data field -> idx is incorrect' + ); - it('Get correct remaining qty for supply', async () => { - let remainingQtyInContract = await contractVoucherKernel.getRemQtyForSupply( - tokenSupplyKey, - users.seller.address - ); + const promiseSeller = await contractVoucherKernel.getSupplyHolder( + tokenSupplyKey + ); - assert.equal( - remainingQtyInContract.toString(), - remQty.toString(), - 'Remaining qty is not correct' - ); + assert.strictEqual( + promiseSeller, + users.seller.address, + 'Seller incorrect' + ); - for (let i = 0; i < vouchersToBuy; i++) { - await utils.commitToBuy(users.buyer, users.seller, tokenSupplyKey); - remainingQtyInContract = await contractVoucherKernel.getRemQtyForSupply( - tokenSupplyKey, - users.seller.address - ); + const promiseOrderData = await contractVoucherKernel.getOrderCosts( + tokenSupplyKey + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.price].eq( + BN(constants.PROMISE_PRICE1) + ), + 'Promise produt price mismatch' + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositSe].eq( + BN(constants.PROMISE_DEPOSITSE1) + ), + 'Promise seller deposit mismatch' + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositBu].eq( + BN(constants.PROMISE_DEPOSITBU1) + ), + 'Promise buyer deposit mismatch' + ); - remQty = BN(remQty).sub(1).toString(); + const tokenNonce = await contractVoucherKernel.getTokenNonce( + users.seller.address + ); - assert.equal( - remainingQtyInContract.toString(), - remQty, - 'Remaining qty is not correct' - ); - } - }); + assert.isTrue( + tokenNonce.eq(constants.ONE.toString()), + 'Voucher kernel nonce mismatch' + ); - it('Should create payment method TKNETH', async () => { - tokenSupplyKey = await utils.createOrder( - users.seller, - timestamp, - timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_1 - ); + assert.equal( + promiseId, + await contractVoucherKernel.getPromiseIdFromSupplyId( + tokenSupplyKey + ), + 'PromisId mismatch' + ); + }); - const paymentMethod = await contractVoucherKernel.getVoucherPaymentMethod( - tokenSupplyKey - ); + it('Should create payment method TKNETH', async () => { + expect( + await contractVoucherKernel.getVoucherPaymentMethod( + tokenSupplyKey + ) + ).to.equal( + paymentMethods.TKNETH, + 'Payment Method TKNETH not set correctly' + ); + }); - const addressTokenPrice = await contractVoucherKernel.getVoucherPriceToken( - tokenSupplyKey - ); + it('Price address should be correct and Deposit should be zero', async () => { + expect( + await contractVoucherKernel.getVoucherPriceToken(tokenSupplyKey) + ).to.equal( + contractBSNTokenPrice.address, + 'TKNETH Method Price Token Address mismatch' + ); - const addressTokenDeposits = await contractVoucherKernel.getVoucherDepositToken( - tokenSupplyKey - ); + expect( + await contractVoucherKernel.getVoucherDepositToken( + tokenSupplyKey + ) + ).to.equal( + constants.ZERO_ADDRESS, + 'TKNETH Method Deposit Token Address mismatch' + ); + }); + }); - assert.equal( - paymentMethod.toString(), - paymentMethods.TKNETH.toString(), - 'Payment Method TKNETH not set correctly' - ); - assert.equal( - addressTokenPrice.toString(), - contractBSNTokenPrice.address, - 'TKNETH Method Price Token Address mismatch' - ); - assert.equal( - addressTokenDeposits.toString(), - constants.ZERO_ADDRESS, - 'TKNETH Method Deposit Token Address mismatch' - ); - }); + it('ERC1155ERC721 state is correct', async () => { + const sellerERC1155ERC721Balance = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.seller.address, + tokenSupplyKey + ) + )[0]; - it('[NEGATIVE] Should fail if price token contract address is not provided', async () => { - const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); + assert.isTrue( + sellerERC1155ERC721Balance.eq(constants.QTY_10), + 'ERC1155ERC721 seller balance mismatch' + ); + }); - const sellerInstance = contractBosonRouter.connect( - users.seller.signer - ); + it('ESCROW has correct balance', async () => { + const expectedBalance = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(constants.QTY_10) + ); - await expect( - sellerInstance.requestCreateOrderTKNETH( - '', - [ - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_PRICE1, - constants.seller_deposit, - constants.PROMISE_DEPOSITBU1, - constants.ORDER_QUANTITY1, - ], - {value: txValue.toString()} - ) - ).to.be.reverted; + expect( + await ethers.provider.getBalance(contractCashier.address) + ).to.equal(expectedBalance, 'Escrow balance is incorrect'); + expect( + await contractCashier.getEscrowAmount(users.seller.address) + ).to.equal(expectedBalance, 'Escrow stored amount is incorrect'); + }); + + it('Get correct remaining qty for supply', async () => { + expect( + await contractVoucherKernel.getRemQtyForSupply( + tokenSupplyKey, + users.seller.address + ) + ).to.equal(constants.QTY_10, 'Remaining qty is not correct'); + + for (let i = 0; i < vouchersToBuy; i++) { + await utils.commitToBuy( + users.buyer, + users.seller, + tokenSupplyKey + ); + expect( + await contractVoucherKernel.getRemQtyForSupply( + tokenSupplyKey, + users.seller.address + ) + ).to.equal( + constants.QTY_10 - i - 1, + `Remaining qty is not correct [${i}]` + ); + } + }); }); it('[NEGATIVE] Should fail if token price contract is zero address', async () => { @@ -1208,70 +1111,46 @@ describe('Cashier and VoucherKernel', () => { }); it('[NEGATIVE] Should not create a supply if price is above the limit', async () => { - const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); - - const sellerInstance = contractBosonRouter.connect( - users.seller.signer - ); - await expect( - sellerInstance.requestCreateOrderTKNETH( - contractBSNTokenPrice.address, - [ - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.ABOVE_TOKEN_LIMIT, - constants.seller_deposit, - constants.PROMISE_DEPOSITBU1, - constants.ORDER_QUANTITY1, - ], - {value: txValue.toString()} + utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10, + true, + constants.ABOVE_ETH_LIMIT, + constants.PROMISE_DEPOSITBU1 ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); it('[NEGATIVE] Should not create a supply if depositBu is above the limit', async () => { - const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); - - const sellerInstance = contractBosonRouter.connect( - users.seller.signer - ); - await expect( - sellerInstance.requestCreateOrderTKNETH( - contractBSNTokenPrice.address, - [ - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_PRICE1, - constants.seller_deposit, - constants.ABOVE_ETH_LIMIT, - constants.ORDER_QUANTITY1, - ], - {value: txValue.toString()} + utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10, + true, + constants.PROMISE_PRICE1, + constants.ABOVE_ETH_LIMIT ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); it('[NEGATIVE] Should not create a supply if depositSe is above the limit', async () => { - const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); - - const sellerInstance = contractBosonRouter.connect( - users.seller.signer - ); - await expect( - sellerInstance.requestCreateOrderTKNETH( - contractBSNTokenPrice.address, - [ - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_PRICE1, - constants.ABOVE_ETH_LIMIT, - constants.PROMISE_DEPOSITBU1, - constants.ORDER_QUANTITY1, - ], - {value: txValue.toString()} + utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.ABOVE_ETH_LIMIT, + constants.QTY_10, + true, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); From cb172f1950a01335070e36226e7bc42231064b1f Mon Sep 17 00:00:00 2001 From: zajck Date: Tue, 5 Oct 2021 17:10:31 +0200 Subject: [PATCH 09/41] TKNTKN unit tests --- test/2_test_fullpath_with_permit.ts | 703 +++++++++++++++------------- 1 file changed, 390 insertions(+), 313 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 2de4ad51..728078a0 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -852,7 +852,7 @@ describe('Cashier and VoucherKernel', () => { }); }); - describe.only('TKNETH', () => { + describe('TKNETH', () => { beforeEach(async () => { await deployContracts(); @@ -1119,7 +1119,7 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_DEPOSITSE1, constants.QTY_10, true, - constants.ABOVE_ETH_LIMIT, + constants.ABOVE_TOKEN_LIMIT, constants.PROMISE_DEPOSITBU1 ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); @@ -1135,7 +1135,7 @@ describe('Cashier and VoucherKernel', () => { constants.QTY_10, true, constants.PROMISE_PRICE1, - constants.ABOVE_ETH_LIMIT + constants.ABOVE_TOKEN_LIMIT ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); @@ -1157,7 +1157,7 @@ describe('Cashier and VoucherKernel', () => { }); describe('TKNTKN', () => { - before(async () => { + beforeEach(async () => { await deployContracts(); utils = await UtilsBuilder.create() @@ -1172,10 +1172,6 @@ describe('Cashier and VoucherKernel', () => { contractBSNTokenDeposit ); - timestamp = await Utils.getCurrTimestamp(); - constants.PROMISE_VALID_FROM = timestamp; - constants.PROMISE_VALID_TO = timestamp + 2 * constants.SECONDS_IN_DAY; - const tokensToMint = BN(constants.product_price).mul( BN(constants.QTY_20) ); @@ -1195,230 +1191,273 @@ describe('Cashier and VoucherKernel', () => { users.buyer.address, tokensToMint ); - - tokenSupplyKey = await utils.createOrder( - users.seller, - timestamp, - timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_10 - ); }); - it('[NEGATIVE] Should revert if validTo is set below 5 minutes from now', async () => { + it('All expected events are emitted', async () => { await expect( utils.createOrder( users.seller, - timestamp, - timestamp + constants.ONE_MINUTE, - constants.seller_deposit, - constants.QTY_10 + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITBU1, + constants.QTY_10, + true ) - ).to.be.revertedWith(revertReasons.INVALID_VALIDITY_TO); + ) + .to.emit(contractBosonRouter, eventNames.LOG_ORDER_CREATED) + .withArgs( + tokenSupplyKey, + users.seller.address, + constants.QTY_10, + paymentMethods.TKNTKN + ) + .to.emit(contractVoucherKernel, eventNames.LOG_PROMISE_CREATED) + .withArgs( + promiseId, + constants.ONE, + users.seller.address, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.ZERO + ) + .to.emit(contractERC1155ERC721, eventNames.TRANSFER_SINGLE) + .withArgs( + contractVoucherKernel.address, + constants.ZERO_ADDRESS, + users.seller.address, + tokenSupplyKey, + constants.QTY_10 + ); }); - it('Cashier has correct balance in Deposit Contract', async () => { - const expectedBalance = BN(constants.seller_deposit).mul(BN(remQty)); - const escrowAmount = await contractBSNTokenDeposit.balanceOf( - contractCashier.address - ); + describe('After creation', () => { + beforeEach(async () => { + await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10 + ); + }); - assert.isTrue( - escrowAmount.eq(expectedBalance), - 'Escrow amount is incorrect' - ); - }); + describe('Voucher Kernel state', () => { + it('Promise info is correct', async () => { + const promiseData = await contractVoucherKernel.getPromiseData( + promiseId + ); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.promiseId], + promiseId, + 'Promise Id incorrect' + ); - it('escrowTokens has correct balance', async () => { - const expectedBalance = BN(constants.seller_deposit).mul( - BN(constants.QTY_10) - ); - const escrowTokens = await contractCashier.getEscrowTokensAmount( - contractBSNTokenDeposit.address, - users.seller.address - ); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.nonce].toString(), + constants.ONE.toString(), + 'Promise data field -> nonce is incorrect' + ); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.validFrom].toString(), + constants.PROMISE_VALID_FROM.toString(), + 'Promise data field -> validFrom is incorrect' + ); - assert.isTrue( - escrowTokens.eq(expectedBalance), - 'Escrow amount is incorrect' - ); - }); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.validTo].toString(), + constants.PROMISE_VALID_TO.toString(), + 'Promise data field -> validTo is incorrect' + ); + assert.equal( + promiseData[constants.PROMISE_DATA_FIELDS.idx].toString(), + constants.ZERO.toString(), + 'Promise data field -> idx is incorrect' + ); - it('Get correct remaining qty for supply', async () => { - let remainingQtyInContract = await contractVoucherKernel.getRemQtyForSupply( - tokenSupplyKey, - users.seller.address - ); + const promiseSeller = await contractVoucherKernel.getSupplyHolder( + tokenSupplyKey + ); - assert.equal( - remainingQtyInContract.toString(), - remQty.toString(), - 'Remaining qty is not correct' - ); + assert.strictEqual( + promiseSeller, + users.seller.address, + 'Seller incorrect' + ); - for (let i = 0; i < vouchersToBuy; i++) { - await utils.commitToBuy(users.buyer, users.seller, tokenSupplyKey); - remainingQtyInContract = await contractVoucherKernel.getRemQtyForSupply( - tokenSupplyKey, - users.seller.address - ); + const promiseOrderData = await contractVoucherKernel.getOrderCosts( + tokenSupplyKey + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.price].eq( + BN(constants.PROMISE_PRICE1) + ), + 'Promise produt price mismatch' + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositSe].eq( + BN(constants.PROMISE_DEPOSITSE1) + ), + 'Promise seller deposit mismatch' + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositBu].eq( + BN(constants.PROMISE_DEPOSITBU1) + ), + 'Promise buyer deposit mismatch' + ); - remQty = BN(remQty).sub(1).toString(); + const tokenNonce = await contractVoucherKernel.getTokenNonce( + users.seller.address + ); - assert.equal( - remainingQtyInContract.toString(), - remQty, - 'Remaining qty is not correct' - ); - } + assert.isTrue( + tokenNonce.eq(constants.ONE.toString()), + 'Voucher kernel nonce mismatch' + ); - it('Create Conditional Commit', async () => { - expect( - await utils.createOrderConditional( - users.seller, - timestamp, - timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_10, - users.seller, - 0 - ) - ).to.emit( - contractBosonRouter, - eventNames.LOG_CONDITIONAL_ORDER_CREATED - ); + assert.equal( + promiseId, + await contractVoucherKernel.getPromiseIdFromSupplyId( + tokenSupplyKey + ), + 'PromisId mismatch' + ); + }); - // .withArgs(); should calculate token supply id and compare it it - // console.log(tokenSupplyID) - }); - }); + it('Should create payment method ETHETH', async () => { + expect( + await contractVoucherKernel.getVoucherPaymentMethod( + tokenSupplyKey + ) + ).to.equal( + paymentMethods.TKNTKN, + 'Payment Method TKNTKN not set correctly' + ); + }); - it('Should create payment method TKNTKN', async () => { - tokenSupplyKey = await utils.createOrder( - users.seller, - timestamp, - timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_1 - ); + it('Deposit and Price address should be correctly set', async () => { + expect( + await contractVoucherKernel.getVoucherPriceToken(tokenSupplyKey) + ).to.equal( + contractBSNTokenPrice.address, + 'TKNTKN Method Price Token Address mismatch' + ); - const paymentMethod = await contractVoucherKernel.getVoucherPaymentMethod( - tokenSupplyKey - ); + expect( + await contractVoucherKernel.getVoucherDepositToken( + tokenSupplyKey + ) + ).to.equal( + contractBSNTokenDeposit.address, + 'TKNTKN Method Deposit Token Address mismatch' + ); + }); + }); - const addressTokenPrice = await contractVoucherKernel.getVoucherPriceToken( - tokenSupplyKey - ); + it('ERC1155ERC721 state is correct', async () => { + const sellerERC1155ERC721Balance = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.seller.address, + tokenSupplyKey + ) + )[0]; - const addressTokenDeposits = await contractVoucherKernel.getVoucherDepositToken( - tokenSupplyKey - ); + assert.isTrue( + sellerERC1155ERC721Balance.eq(constants.QTY_10), + 'ERC1155ERC721 seller balance mismatch' + ); + }); - assert.equal( - paymentMethod.toString(), - paymentMethods.TKNTKN.toString(), - 'Payment Method TKNTKN not set correctly' - ); - assert.equal( - addressTokenPrice.toString(), - contractBSNTokenPrice.address, - 'TKNTKN Method Price Token Address mismatch' - ); - assert.equal( - addressTokenDeposits.toString(), - contractBSNTokenDeposit.address, - 'TKNTKN Method Deposit Token Address mismatch' - ); - }); + it('Cashier has correct balance in Deposit Contract', async () => { + // REWRITE + const expectedBalance = BN(constants.PROMISE_DEPOSITSE1).mul( + constants.QTY_10 + ); + const escrowAmount = await contractBSNTokenDeposit.balanceOf( + contractCashier.address + ); - it('[NEGATIVE] Should fail if token price contract address is not provided', async () => { - const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); - const nonce = await contractBSNTokenDeposit.nonces( - users.seller.address - ); + assert.isTrue( + escrowAmount.eq(expectedBalance), + 'Escrow amount is incorrect' + ); + }); - const digest = await getApprovalDigest( - contractBSNTokenDeposit, - users.seller.address, - contractCashier.address, - txValue, - nonce, - deadline - ); + it('escrowTokens has correct balance', async () => { + // REWRITE + const expectedBalance = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(constants.QTY_10) + ); + const escrowTokens = await contractCashier.getEscrowTokensAmount( + contractBSNTokenDeposit.address, + users.seller.address + ); - const {v, r, s} = ecsign( - Buffer.from(digest.slice(2), 'hex'), - Buffer.from(users.seller.privateKey.slice(2), 'hex') - ); + assert.isTrue( + escrowTokens.eq(expectedBalance), + 'Escrow amount is incorrect' + ); + }); - const sellerInstance = contractBosonRouter.connect( - users.seller.signer - ); + it('Get correct remaining qty for supply', async () => { + expect( + await contractVoucherKernel.getRemQtyForSupply( + tokenSupplyKey, + users.seller.address + ) + ).to.equal(constants.QTY_10, 'Remaining qty is not correct'); + for (let i = 0; i < vouchersToBuy; i++) { + await utils.commitToBuy( + users.buyer, + users.seller, + tokenSupplyKey + ); + expect( + await contractVoucherKernel.getRemQtyForSupply( + tokenSupplyKey, + users.seller.address + ) + ).to.equal( + constants.QTY_10 - i - 1, + `Remaining qty is not correct [${i}]` + ); + } + }); + }); + + it('[NEGATIVE] Should revert if validTo is set below 5 minutes from now', async () => { await expect( - sellerInstance.requestCreateOrderTKNTKNWithPermit( - '', - contractBSNTokenDeposit.address, - txValue, - deadline, - v, - r, - s, - [ - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_PRICE1, - constants.seller_deposit, - constants.PROMISE_DEPOSITBU1, - constants.ORDER_QUANTITY1, - ] + utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_FROM + constants.ONE_MINUTE, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10 ) - ).to.be.reverted; + ).to.be.revertedWith(revertReasons.INVALID_VALIDITY_TO); }); - it('[NEGATIVE] Should fail if token deposit contract address is not provided', async () => { - const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); - const nonce = await contractBSNTokenDeposit.nonces( - users.seller.address - ); - - const digest = await getApprovalDigest( - contractBSNTokenDeposit, - users.seller.address, - contractCashier.address, - txValue, - nonce, - deadline - ); - - const {v, r, s} = ecsign( - Buffer.from(digest.slice(2), 'hex'), - Buffer.from(users.seller.privateKey.slice(2), 'hex') - ); - - const sellerInstance = contractBosonRouter.connect( - users.seller.signer + it.only('Create Conditional Commit', async () => { + // ?? todo + expect( + await utils.createOrderConditional( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.seller_deposit, + constants.QTY_10, + users.seller, + 0, + true + ) + ).to.emit( + contractBosonRouter, + eventNames.LOG_CONDITIONAL_ORDER_CREATED ); - await expect( - sellerInstance.requestCreateOrderTKNTKNWithPermit( - contractBSNTokenPrice.address, - '', - txValue, - deadline, - v, - r, - s, - [ - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_PRICE1, - constants.seller_deposit, - constants.PROMISE_DEPOSITBU1, - constants.ORDER_QUANTITY1, - ] - ) - ).to.be.reverted; + // .withArgs(); should calculate token supply id and compare it it + // console.log(tokenSupplyID) }); it('[NEGATIVE] Should revert if token price contract address is zero address', async () => { @@ -1513,136 +1552,174 @@ describe('Cashier and VoucherKernel', () => { }); it('[NEGATIVE] Should not create a supply if price is above the limit', async () => { - const txValue = BN(constants.seller_deposit).mul(BN(constants.QTY_1)); - const nonce = await contractBSNTokenDeposit.nonces( - users.seller.address - ); - - const digest = await getApprovalDigest( - contractBSNTokenDeposit, - users.seller.address, - contractBosonRouter.address, - txValue, - nonce, - deadline - ); - - const {v, r, s} = ecsign( - Buffer.from(digest.slice(2), 'hex'), - Buffer.from(users.seller.privateKey.slice(2), 'hex') - ); - - const sellerInstance = contractBosonRouter.connect( - users.seller.signer - ); + // const txValue = BN(constants.seller_deposit).mul(BN(constants.QTY_1)); + // const nonce = await contractBSNTokenDeposit.nonces( + // users.seller.address + // ); + + // const digest = await getApprovalDigest( + // contractBSNTokenDeposit, + // users.seller.address, + // contractBosonRouter.address, + // txValue, + // nonce, + // deadline + // ); + + // const {v, r, s} = ecsign( + // Buffer.from(digest.slice(2), 'hex'), + // Buffer.from(users.seller.privateKey.slice(2), 'hex') + // ); + + // const sellerInstance = contractBosonRouter.connect( + // users.seller.signer + // ); + + // await expect( + // sellerInstance.requestCreateOrderTKNTKNWithPermit( + // contractBSNTokenPrice.address, + // contractBSNTokenDeposit.address, + // txValue, + // deadline, + // v, + // r, + // s, + // [ + // constants.PROMISE_VALID_FROM, + // constants.PROMISE_VALID_TO, + // constants.ABOVE_TOKEN_LIMIT, + // constants.seller_deposit, + // constants.PROMISE_DEPOSITBU1, + // constants.ORDER_QUANTITY1, + // ] + // ) + // ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); await expect( - sellerInstance.requestCreateOrderTKNTKNWithPermit( - contractBSNTokenPrice.address, - contractBSNTokenDeposit.address, - txValue, - deadline, - v, - r, - s, - [ - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.ABOVE_TOKEN_LIMIT, - constants.seller_deposit, - constants.PROMISE_DEPOSITBU1, - constants.ORDER_QUANTITY1, - ] + utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10, + true, + constants.ABOVE_TOKEN_LIMIT, + constants.PROMISE_DEPOSITBU1 ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); it('[NEGATIVE] Should not create a supply if depositBu is above the limit', async () => { - const txValue = BN(constants.seller_deposit).mul(BN(constants.QTY_1)); - const nonce = await contractBSNTokenDeposit.nonces( - users.seller.address - ); - - const digest = await getApprovalDigest( - contractBSNTokenDeposit, - users.seller.address, - contractBosonRouter.address, - txValue, - nonce, - deadline - ); - - const {v, r, s} = ecsign( - Buffer.from(digest.slice(2), 'hex'), - Buffer.from(users.seller.privateKey.slice(2), 'hex') - ); - - const sellerInstance = contractBosonRouter.connect( - users.seller.signer - ); + // const txValue = BN(constants.seller_deposit).mul(BN(constants.QTY_1)); + // const nonce = await contractBSNTokenDeposit.nonces( + // users.seller.address + // ); + + // const digest = await getApprovalDigest( + // contractBSNTokenDeposit, + // users.seller.address, + // contractBosonRouter.address, + // txValue, + // nonce, + // deadline + // ); + + // const {v, r, s} = ecsign( + // Buffer.from(digest.slice(2), 'hex'), + // Buffer.from(users.seller.privateKey.slice(2), 'hex') + // ); + + // const sellerInstance = contractBosonRouter.connect( + // users.seller.signer + // ); + + // await expect( + // sellerInstance.requestCreateOrderTKNTKNWithPermit( + // contractBSNTokenPrice.address, + // contractBSNTokenDeposit.address, + // txValue, + // deadline, + // v, + // r, + // s, + // [ + // constants.PROMISE_VALID_FROM, + // constants.PROMISE_VALID_TO, + // constants.PROMISE_PRICE1, + // constants.seller_deposit, + // constants.ABOVE_TOKEN_LIMIT, + // constants.ORDER_QUANTITY1, + // ] + // ) + // ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); await expect( - sellerInstance.requestCreateOrderTKNTKNWithPermit( - contractBSNTokenPrice.address, - contractBSNTokenDeposit.address, - txValue, - deadline, - v, - r, - s, - [ - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_PRICE1, - constants.seller_deposit, - constants.ABOVE_TOKEN_LIMIT, - constants.ORDER_QUANTITY1, - ] + utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10, + true, + constants.PROMISE_PRICE1, + constants.ABOVE_TOKEN_LIMIT ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); it('[NEGATIVE] Should not create a supply if depositSe is above the limit', async () => { - const txValue = BN(constants.seller_deposit).mul(BN(constants.QTY_1)); - const nonce = await contractBSNTokenDeposit.nonces( - users.seller.address - ); - - const digest = await getApprovalDigest( - contractBSNTokenDeposit, - users.seller.address, - contractBosonRouter.address, - txValue, - nonce, - deadline - ); - - const {v, r, s} = ecsign( - Buffer.from(digest.slice(2), 'hex'), - Buffer.from(users.seller.privateKey.slice(2), 'hex') - ); - - const sellerInstance = contractBosonRouter.connect( - users.seller.signer - ); - + // const txValue = BN(constants.seller_deposit).mul(BN(constants.QTY_1)); + // const nonce = await contractBSNTokenDeposit.nonces( + // users.seller.address + // ); + + // const digest = await getApprovalDigest( + // contractBSNTokenDeposit, + // users.seller.address, + // contractBosonRouter.address, + // txValue, + // nonce, + // deadline + // ); + + // const {v, r, s} = ecsign( + // Buffer.from(digest.slice(2), 'hex'), + // Buffer.from(users.seller.privateKey.slice(2), 'hex') + // ); + + // const sellerInstance = contractBosonRouter.connect( + // users.seller.signer + // ); + + // await expect( + // sellerInstance.requestCreateOrderTKNTKNWithPermit( + // contractBSNTokenPrice.address, + // contractBSNTokenDeposit.address, + // txValue, + // deadline, + // v, + // r, + // s, + // [ + // constants.PROMISE_VALID_FROM, + // constants.PROMISE_VALID_TO, + // constants.PROMISE_PRICE1, + // constants.ABOVE_TOKEN_LIMIT, + // constants.PROMISE_DEPOSITBU1, + // constants.ORDER_QUANTITY1, + // ] + // ) + // ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); await expect( - sellerInstance.requestCreateOrderTKNTKNWithPermit( - contractBSNTokenPrice.address, - contractBSNTokenDeposit.address, - txValue, - deadline, - v, - r, - s, - [ - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_PRICE1, - constants.ABOVE_TOKEN_LIMIT, - constants.PROMISE_DEPOSITBU1, - constants.ORDER_QUANTITY1, - ] + utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.ABOVE_TOKEN_LIMIT, + constants.QTY_10, + true, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); From cc2d27bb8b8c9aea9333e57eecaf5206ef4f5478 Mon Sep 17 00:00:00 2001 From: zajck Date: Tue, 5 Oct 2021 18:16:15 +0200 Subject: [PATCH 10/41] ETHETH commitToBuy unit test --- test/2_test_fullpath_with_permit.ts | 357 +++++++++------------------- testHelpers/utils.ts | 9 +- 2 files changed, 124 insertions(+), 242 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 728078a0..87f4e940 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -1373,30 +1373,23 @@ describe('Cashier and VoucherKernel', () => { const expectedBalance = BN(constants.PROMISE_DEPOSITSE1).mul( constants.QTY_10 ); - const escrowAmount = await contractBSNTokenDeposit.balanceOf( - contractCashier.address - ); - assert.isTrue( - escrowAmount.eq(expectedBalance), - 'Escrow amount is incorrect' - ); + expect( + await contractBSNTokenDeposit.balanceOf(contractCashier.address) + ).to.equal(expectedBalance, 'Escrow amount is incorrect'); }); it('escrowTokens has correct balance', async () => { - // REWRITE const expectedBalance = BN(constants.PROMISE_DEPOSITSE1).mul( BN(constants.QTY_10) ); - const escrowTokens = await contractCashier.getEscrowTokensAmount( - contractBSNTokenDeposit.address, - users.seller.address - ); - assert.isTrue( - escrowTokens.eq(expectedBalance), - 'Escrow amount is incorrect' - ); + expect( + await contractCashier.getEscrowTokensAmount( + contractBSNTokenDeposit.address, + users.seller.address + ) + ).to.equal(expectedBalance, 'Escrow amount is incorrect'); }); it('Get correct remaining qty for supply', async () => { @@ -1438,7 +1431,7 @@ describe('Cashier and VoucherKernel', () => { ).to.be.revertedWith(revertReasons.INVALID_VALIDITY_TO); }); - it.only('Create Conditional Commit', async () => { + it('Create Conditional Commit', async () => { // ?? todo expect( await utils.createOrderConditional( @@ -1552,49 +1545,6 @@ describe('Cashier and VoucherKernel', () => { }); it('[NEGATIVE] Should not create a supply if price is above the limit', async () => { - // const txValue = BN(constants.seller_deposit).mul(BN(constants.QTY_1)); - // const nonce = await contractBSNTokenDeposit.nonces( - // users.seller.address - // ); - - // const digest = await getApprovalDigest( - // contractBSNTokenDeposit, - // users.seller.address, - // contractBosonRouter.address, - // txValue, - // nonce, - // deadline - // ); - - // const {v, r, s} = ecsign( - // Buffer.from(digest.slice(2), 'hex'), - // Buffer.from(users.seller.privateKey.slice(2), 'hex') - // ); - - // const sellerInstance = contractBosonRouter.connect( - // users.seller.signer - // ); - - // await expect( - // sellerInstance.requestCreateOrderTKNTKNWithPermit( - // contractBSNTokenPrice.address, - // contractBSNTokenDeposit.address, - // txValue, - // deadline, - // v, - // r, - // s, - // [ - // constants.PROMISE_VALID_FROM, - // constants.PROMISE_VALID_TO, - // constants.ABOVE_TOKEN_LIMIT, - // constants.seller_deposit, - // constants.PROMISE_DEPOSITBU1, - // constants.ORDER_QUANTITY1, - // ] - // ) - // ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); - await expect( utils.createOrder( users.seller, @@ -1610,49 +1560,6 @@ describe('Cashier and VoucherKernel', () => { }); it('[NEGATIVE] Should not create a supply if depositBu is above the limit', async () => { - // const txValue = BN(constants.seller_deposit).mul(BN(constants.QTY_1)); - // const nonce = await contractBSNTokenDeposit.nonces( - // users.seller.address - // ); - - // const digest = await getApprovalDigest( - // contractBSNTokenDeposit, - // users.seller.address, - // contractBosonRouter.address, - // txValue, - // nonce, - // deadline - // ); - - // const {v, r, s} = ecsign( - // Buffer.from(digest.slice(2), 'hex'), - // Buffer.from(users.seller.privateKey.slice(2), 'hex') - // ); - - // const sellerInstance = contractBosonRouter.connect( - // users.seller.signer - // ); - - // await expect( - // sellerInstance.requestCreateOrderTKNTKNWithPermit( - // contractBSNTokenPrice.address, - // contractBSNTokenDeposit.address, - // txValue, - // deadline, - // v, - // r, - // s, - // [ - // constants.PROMISE_VALID_FROM, - // constants.PROMISE_VALID_TO, - // constants.PROMISE_PRICE1, - // constants.seller_deposit, - // constants.ABOVE_TOKEN_LIMIT, - // constants.ORDER_QUANTITY1, - // ] - // ) - // ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); - await expect( utils.createOrder( users.seller, @@ -1668,48 +1575,6 @@ describe('Cashier and VoucherKernel', () => { }); it('[NEGATIVE] Should not create a supply if depositSe is above the limit', async () => { - // const txValue = BN(constants.seller_deposit).mul(BN(constants.QTY_1)); - // const nonce = await contractBSNTokenDeposit.nonces( - // users.seller.address - // ); - - // const digest = await getApprovalDigest( - // contractBSNTokenDeposit, - // users.seller.address, - // contractBosonRouter.address, - // txValue, - // nonce, - // deadline - // ); - - // const {v, r, s} = ecsign( - // Buffer.from(digest.slice(2), 'hex'), - // Buffer.from(users.seller.privateKey.slice(2), 'hex') - // ); - - // const sellerInstance = contractBosonRouter.connect( - // users.seller.signer - // ); - - // await expect( - // sellerInstance.requestCreateOrderTKNTKNWithPermit( - // contractBSNTokenPrice.address, - // contractBSNTokenDeposit.address, - // txValue, - // deadline, - // v, - // r, - // s, - // [ - // constants.PROMISE_VALID_FROM, - // constants.PROMISE_VALID_TO, - // constants.PROMISE_PRICE1, - // constants.ABOVE_TOKEN_LIMIT, - // constants.PROMISE_DEPOSITBU1, - // constants.ORDER_QUANTITY1, - // ] - // ) - // ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); await expect( utils.createOrder( users.seller, @@ -1728,6 +1593,7 @@ describe('Cashier and VoucherKernel', () => { }); describe('TOKEN SUPPLY CANCELLATION', () => { + // TODO: rewrite to match style before(async () => { await deployContracts(); @@ -1751,7 +1617,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it('Should process suppy/voucher set cancellation properly', async () => { + it('Should process supply/voucher set cancellation properly', async () => { const sellerBalanceBefore = await users.seller.signer.getBalance( 'latest' ); @@ -1823,8 +1689,15 @@ describe('Cashier and VoucherKernel', () => { const ORDER_QTY = 5; let TOKEN_SUPPLY_ID; - describe('ETHETH', () => { - before(async () => { + // calculate expected tokenSupplyID for first voucher + const tokenIndex = constants.ONE; + const TYPE_NF_BIT = constants.ONE.shl(255); + tokenSupplyKey = TYPE_NF_BIT.or(tokenIndex.shl(128)).toString(); + + const voucherTokenId = BN(tokenSupplyKey).or(constants.ONE); + + describe.only('ETHETH', () => { + beforeEach(async () => { await deployContracts(); utils = await UtilsBuilder.create() .ETHETH() @@ -1835,43 +1708,102 @@ describe('Cashier and VoucherKernel', () => { contractBosonRouter ); - timestamp = await Utils.getCurrTimestamp(); - constants.PROMISE_VALID_FROM = timestamp; - constants.PROMISE_VALID_TO = timestamp + 2 * constants.SECONDS_IN_DAY; + // timestamp = await Utils.getCurrTimestamp(); + // constants.PROMISE_VALID_FROM = timestamp; + // constants.PROMISE_VALID_TO = timestamp + 2 * constants.SECONDS_IN_DAY; TOKEN_SUPPLY_ID = await utils.createOrder( users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, + constants.PROMISE_DEPOSITSE1, constants.QTY_10 ); }); it('Should create order', async () => { - const txValue = BN(constants.buyer_deposit).add( - BN(constants.product_price) - ); - const buyerInstance = contractBosonRouter.connect(users.buyer.signer); - const txFillOrder = await buyerInstance.requestVoucherETHETH( - TOKEN_SUPPLY_ID, - users.seller.address, - { - value: txValue, - } - ); + await expect( + utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, true) + ) + .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_DELIVERED) + .withArgs( + tokenSupplyKey, + voucherTokenId, + users.seller.address, + users.buyer.address, + promiseId + ) + .to.emit(contractERC1155ERC721, eventNames.TRANSFER_SINGLE) + .withArgs( + contractVoucherKernel.address, + users.seller.address, + constants.ZERO, + tokenSupplyKey, + constants.ONE + ) + .to.emit(contractERC1155ERC721, eventNames.TRANSFER) + .withArgs(constants.ZERO, users.buyer.address, voucherTokenId); + }); - const txReceipt = await txFillOrder.wait(); + describe('After request', () => { + beforeEach(async () => { + await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID); + }); - eventUtils.assertEventEmitted( - txReceipt, - VoucherKernel_Factory, - eventNames.LOG_VOUCHER_DELIVERED, - (ev) => { - assert.equal(ev._issuer, users.seller.address); - tokenVoucherKey = ev._tokenIdVoucher; - } - ); + it('Voucher Kernel state is correct', async () => { + const voucherStatus = await contractVoucherKernel.getVoucherStatus( + voucherTokenId + ); + + const expectedStatus = constants.ZERO.or(constants.ONE.shl(7)); // as per contract implementations + + assert.equal( + voucherStatus[0], + expectedStatus.toNumber(), + 'Wrong status' + ); + assert.isFalse(voucherStatus[1], 'Payment should not be released'); + assert.isFalse(voucherStatus[2], 'Deposit should not be released'); + assert.isTrue( + voucherStatus[3].eq(constants.ZERO), + 'Complaint period should not started yet' + ); + assert.isTrue( + voucherStatus[4].eq(constants.ZERO), + 'COF period should not started yet' + ); + }); + + it('Cashier Contract has correct amount of funds', async () => { + const sellerDeposits = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(constants.QTY_10) + ); + const buyerETHSent = BN(constants.PROMISE_PRICE1).add( + BN(constants.PROMISE_DEPOSITSE1) + ); + const expectedBalance = sellerDeposits.add(buyerETHSent); + + expect( + await ethers.provider.getBalance(contractCashier.address) + ).to.equal(expectedBalance, 'Escrow amount is incorrect'); + }); + + it('Escrow should be updated', async () => { + const sellerDeposits = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(constants.QTY_10) + ); + const buyerETHSent = BN(constants.PROMISE_PRICE1).add( + BN(constants.PROMISE_DEPOSITBU1) + ); + + expect( + await contractCashier.getEscrowAmount(users.seller.address) + ).to.equal(sellerDeposits, 'Seller escrow amount is incorrect'); + + expect( + await contractCashier.getEscrowAmount(users.buyer.address) + ).to.equal(buyerETHSent, 'Buyer escrow amount is incorrect'); + }); }); it('[NEGATIVE] Should not create order from a wrong payment type', async () => { @@ -1889,86 +1821,29 @@ describe('Cashier and VoucherKernel', () => { await expect( utilsTknEth.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID) - ).to.be.reverted; - }); - - it('Cashier Contract has correct amount of funds', async () => { - const sellerDeposits = BN(constants.seller_deposit).mul( - BN(constants.QTY_10) - ); - const buyerETHSent = BN(constants.product_price).add( - BN(constants.buyer_deposit) - ); - const expectedBalance = sellerDeposits.add(buyerETHSent); - - const cashierBalance = await ethers.provider.getBalance( - contractCashier.address - ); - - assert.isTrue( - BN(cashierBalance).eq(expectedBalance), - 'Escrow amount is incorrect' - ); - }); - - it('Escrow should be updated', async () => { - const sellerDeposits = BN(constants.seller_deposit).mul( - BN(constants.QTY_10) - ); - const buyerETHSent = BN(constants.product_price).add( - BN(constants.buyer_deposit) - ); - - const escrowSeller = await contractCashier.getEscrowAmount( - users.seller.address - ); - const escrowBuyer = await contractCashier.getEscrowAmount( - users.buyer.address - ); - - assert.isTrue( - BN(sellerDeposits).eq(escrowSeller), - 'Escrow amount is incorrect' - ); - - assert.isTrue( - BN(buyerETHSent).eq(escrowBuyer), - 'Escrow amount is incorrect' - ); + ).to.be.revertedWith(revertReasons.INCORRECT_PAYMENT_METHOD); }); it('[NEGATIVE] Should not create order with incorrect price', async () => { - const txValue = BN(constants.buyer_deposit).add( - BN(constants.incorrect_product_price) - ); - - const buyerInstance = contractBosonRouter.connect(users.buyer.signer); - await expect( - buyerInstance.requestVoucherETHETH( + utils.commitToBuy( + users.buyer, + users.seller, TOKEN_SUPPLY_ID, - users.seller.address, - { - value: txValue, - } + constants.incorrect_product_price, + constants.PROMISE_DEPOSITBU1 ) ).to.be.revertedWith(revertReasons.INVALID_FUNDS); }); it('[NEGATIVE] Should not create order with incorrect deposit', async () => { - const txValue = BN(constants.buyer_incorrect_deposit).add( - BN(constants.product_price) - ); - - const buyerInstance = contractBosonRouter.connect(users.buyer.signer); - await expect( - buyerInstance.requestVoucherETHETH( + utils.commitToBuy( + users.buyer, + users.seller, TOKEN_SUPPLY_ID, - users.seller.address, - { - value: txValue, - } + constants.PROMISE_PRICE1, + constants.buyer_incorrect_deposit ) ).to.be.revertedWith(revertReasons.INVALID_FUNDS); }); diff --git a/testHelpers/utils.ts b/testHelpers/utils.ts index b82db0b5..22c45524 100644 --- a/testHelpers/utils.ts +++ b/testHelpers/utils.ts @@ -50,7 +50,14 @@ class Utils { promisePrice?, buyerDeposit? ) => any; - commitToBuy: (buyer, seller, tokenSupplyId, returnTx?) => any; + commitToBuy: ( + buyer, + seller, + tokenSupplyId, + returnTx?, + promisePrice?, + buyerDeposit? + ) => any; factories?: { ERC1155ERC721: ERC1155ERC721__factory | any; VoucherKernel: VoucherKernel__factory | any; From f4e23cd385d6e75b9f41b3679ee519f9897c17ae Mon Sep 17 00:00:00 2001 From: zajck Date: Wed, 6 Oct 2021 09:34:40 +0200 Subject: [PATCH 11/41] ETHTKN commitToBuy unit tests --- contracts/BosonRouter.sol | 16 +- test/2_test_fullpath_with_permit.ts | 301 ++++++++++++---------------- 2 files changed, 134 insertions(+), 183 deletions(-) diff --git a/contracts/BosonRouter.sol b/contracts/BosonRouter.sol index d2895222..3ab48f93 100644 --- a/contracts/BosonRouter.sol +++ b/contracts/BosonRouter.sol @@ -700,6 +700,13 @@ contract BosonRouter is address tokenPriceAddress = IVoucherKernel(voucherKernel) .getVoucherPriceToken(_tokenIdSupply); + IVoucherKernel(voucherKernel).fillOrder( + _tokenIdSupply, + _issuer, + msg.sender, + TKNETH + ); + permitTransferFromAndAddEscrow( tokenPriceAddress, price, @@ -708,14 +715,7 @@ contract BosonRouter is _r, _s ); - - IVoucherKernel(voucherKernel).fillOrder( - _tokenIdSupply, - _issuer, - msg.sender, - TKNETH - ); - + //record funds in escrow ... ICashier(cashierAddress).addEscrowAmount{value: msg.value}(msg.sender); } diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 87f4e940..9454dbd6 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -187,7 +187,6 @@ describe('Cashier and VoucherKernel', () => { } describe('TOKEN SUPPLY CREATION (Voucher batch creation)', () => { - let remQty = constants.QTY_10 as number | string; const vouchersToBuy = 5; const paymentMethods = { @@ -197,11 +196,6 @@ describe('Cashier and VoucherKernel', () => { TKNTKN: 4, }; - afterEach(() => { - // TODO REMOVE - remQty = constants.QTY_10; - }); - describe('ETHETH', () => { beforeEach(async () => { await deployContracts(); @@ -1687,7 +1681,7 @@ describe('Cashier and VoucherKernel', () => { describe('VOUCHER CREATION (Commit to buy)', () => { const ORDER_QTY = 5; - let TOKEN_SUPPLY_ID; + let TOKEN_SUPPLY_ID; // todo not really needed probably // calculate expected tokenSupplyID for first voucher const tokenIndex = constants.ONE; @@ -1696,7 +1690,7 @@ describe('Cashier and VoucherKernel', () => { const voucherTokenId = BN(tokenSupplyKey).or(constants.ONE); - describe.only('ETHETH', () => { + describe('ETHETH', () => { beforeEach(async () => { await deployContracts(); utils = await UtilsBuilder.create() @@ -1708,10 +1702,6 @@ describe('Cashier and VoucherKernel', () => { contractBosonRouter ); - // timestamp = await Utils.getCurrTimestamp(); - // constants.PROMISE_VALID_FROM = timestamp; - // constants.PROMISE_VALID_TO = timestamp + 2 * constants.SECONDS_IN_DAY; - TOKEN_SUPPLY_ID = await utils.createOrder( users.seller, constants.PROMISE_VALID_FROM, @@ -1824,24 +1814,26 @@ describe('Cashier and VoucherKernel', () => { ).to.be.revertedWith(revertReasons.INCORRECT_PAYMENT_METHOD); }); - it('[NEGATIVE] Should not create order with incorrect price', async () => { + it.only('[NEGATIVE] Should not create order with incorrect price', async () => { await expect( utils.commitToBuy( users.buyer, users.seller, TOKEN_SUPPLY_ID, + false, constants.incorrect_product_price, constants.PROMISE_DEPOSITBU1 ) ).to.be.revertedWith(revertReasons.INVALID_FUNDS); }); - it('[NEGATIVE] Should not create order with incorrect deposit', async () => { + it.only('[NEGATIVE] Should not create order with incorrect deposit', async () => { await expect( utils.commitToBuy( users.buyer, users.seller, TOKEN_SUPPLY_ID, + false, constants.PROMISE_PRICE1, constants.buyer_incorrect_deposit ) @@ -1851,7 +1843,7 @@ describe('Cashier and VoucherKernel', () => { describe('[WITH PERMIT]', () => { describe('ETHTKN', async () => { - before(async () => { + beforeEach(async () => { await deployContracts(); utils = await UtilsBuilder.create() @@ -1866,10 +1858,10 @@ describe('Cashier and VoucherKernel', () => { contractBSNTokenDeposit ); - const tokensToMintSeller = BN(constants.seller_deposit).mul( + const tokensToMintSeller = BN(constants.PROMISE_DEPOSITSE1).mul( BN(ORDER_QTY) ); - const tokensToMintBuyer = BN(constants.buyer_deposit).mul( + const tokensToMintBuyer = BN(constants.PROMISE_DEPOSITBU1).mul( BN(ORDER_QTY) ); @@ -1882,61 +1874,125 @@ describe('Cashier and VoucherKernel', () => { tokensToMintBuyer ); - timestamp = await Utils.getCurrTimestamp(); - constants.PROMISE_VALID_FROM = timestamp; - constants.PROMISE_VALID_TO = timestamp + 2 * constants.SECONDS_IN_DAY; - TOKEN_SUPPLY_ID = await utils.createOrder( users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, + constants.PROMISE_DEPOSITSE1, ORDER_QTY ); }); it('Should create order', async () => { - const nonce = await contractBSNTokenDeposit.nonces( - users.buyer.address - ); - const digestDeposit = await getApprovalDigest( - contractBSNTokenDeposit, - users.buyer.address, - contractBosonRouter.address, - constants.buyer_deposit, - nonce, - deadline - ); + await expect( + utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, true) + ) + .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_DELIVERED) + .withArgs( + tokenSupplyKey, + voucherTokenId, + users.seller.address, + users.buyer.address, + promiseId + ) + .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_DELIVERED) + .withArgs( + tokenSupplyKey, + voucherTokenId, + users.seller.address, + users.buyer.address, + promiseId + ) + .to.emit(contractERC1155ERC721, eventNames.TRANSFER_SINGLE) + .withArgs( + contractVoucherKernel.address, + users.seller.address, + constants.ZERO, + tokenSupplyKey, + constants.ONE + ) + .to.emit(contractERC1155ERC721, eventNames.TRANSFER) + .withArgs(constants.ZERO, users.buyer.address, voucherTokenId) + .to.emit(contractBSNTokenDeposit, eventNames.TRANSFER) + .withArgs( + users.buyer.address, + contractCashier.address, + constants.PROMISE_DEPOSITBU1 + ); + }); - const {v, r, s} = ecsign( - Buffer.from(digestDeposit.slice(2), 'hex'), - Buffer.from(users.buyer.privateKey.slice(2), 'hex') - ); + describe('After request', () => { + beforeEach(async () => { + await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID); + }); - const buyerInstance = contractBosonRouter.connect(users.buyer.signer); + it('Voucher Kernel state is correct', async () => { + const voucherStatus = await contractVoucherKernel.getVoucherStatus( + voucherTokenId + ); - const txFillOrder = await buyerInstance.requestVoucherETHTKNWithPermit( - TOKEN_SUPPLY_ID, - users.seller.address, - constants.buyer_deposit, - deadline, - v, - r, - s, - {value: constants.product_price} - ); + const expectedStatus = constants.ZERO.or(constants.ONE.shl(7)); // as per contract implementations - const txReceipt = await txFillOrder.wait(); + assert.equal( + voucherStatus[0], + expectedStatus.toNumber(), + 'Wrong status' + ); + assert.isFalse(voucherStatus[1], 'Payment should not be released'); + assert.isFalse(voucherStatus[2], 'Deposit should not be released'); + assert.isTrue( + voucherStatus[3].eq(constants.ZERO), + 'Complaint period should not started yet' + ); + assert.isTrue( + voucherStatus[4].eq(constants.ZERO), + 'COF period should not started yet' + ); + }); - eventUtils.assertEventEmitted( - txReceipt, - VoucherKernel_Factory, - eventNames.LOG_VOUCHER_DELIVERED, - (ev) => { - assert.equal(ev._issuer, users.seller.address); - tokenVoucherKey = ev._tokenIdVoucher; - } - ); + it('Cashier Contract has correct amount of funds', async () => { + const expectedETHBalance = BN(constants.PROMISE_PRICE1); + const sellerTokenDeposits = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(ORDER_QTY) + ); + const expectedTokenBalance = BN(constants.PROMISE_DEPOSITBU1).add( + sellerTokenDeposits + ); + + expect( + await ethers.provider.getBalance(contractCashier.address) + ).to.equal(expectedETHBalance, 'Escrow amount is incorrect'); + + expect( + await contractBSNTokenDeposit.balanceOf(contractCashier.address) + ).to.equal(expectedTokenBalance, 'Escrow amount is incorrect'); + }); + + it('Escrows should be updated', async () => { + const sellerDeposits = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(ORDER_QTY) + ); + const buyerETHSent = BN(constants.PROMISE_PRICE1); + const buyerTKNSent = BN(constants.PROMISE_DEPOSITBU1); + + expect( + await contractCashier.getEscrowTokensAmount( + contractBSNTokenDeposit.address, + users.seller.address + ) + ).to.equal(sellerDeposits, 'Escrow amount is incorrect'); + + expect( + await contractCashier.getEscrowAmount(users.buyer.address) + ).to.equal(buyerETHSent, 'Escrow amount is incorrect'); + + expect( + await contractCashier.getEscrowTokensAmount( + contractBSNTokenDeposit.address, + users.buyer.address + ) + ).to.equal(buyerTKNSent, 'Escrow amount is incorrect'); + }); }); it('[NEGATIVE] Should not create order from a wrong payment type', async () => { @@ -1957,133 +2013,28 @@ describe('Cashier and VoucherKernel', () => { ).to.be.revertedWith(revertReasons.INCORRECT_PAYMENT_METHOD); }); - it('Cashier Contract has correct amount of funds', async () => { - const expectedETHBalance = BN(constants.product_price); - const cashierETHBalance = await ethers.provider.getBalance( - contractCashier.address - ); - - const cashierDepositTokenBalance = await contractBSNTokenDeposit.balanceOf( - contractCashier.address - ); - const sellerTokenDeposits = BN(constants.seller_deposit).mul( - BN(ORDER_QTY) - ); - const expectedTokenBalance = BN(constants.buyer_deposit).add( - sellerTokenDeposits - ); - - assert.isTrue( - BN(cashierETHBalance).eq(expectedETHBalance), - 'Escrow amount is incorrect' - ); - assert.isTrue( - expectedTokenBalance.eq(cashierDepositTokenBalance), - 'Escrow amount is incorrect' - ); - }); - - it('Escrows should be updated', async () => { - const sellerDeposits = BN(constants.seller_deposit).mul( - BN(ORDER_QTY) - ); - const buyerETHSent = BN(constants.product_price); - const buyerTKNSent = BN(constants.buyer_deposit); - - const escrowSellerTkn = await contractCashier.getEscrowTokensAmount( - contractBSNTokenDeposit.address, - users.seller.address - ); - const escrowBuyerEth = await contractCashier.getEscrowAmount( - users.buyer.address - ); - const escrowBuyerTkn = await contractCashier.getEscrowTokensAmount( - contractBSNTokenDeposit.address, - users.buyer.address - ); - - assert.isTrue( - BN(sellerDeposits).eq(escrowSellerTkn), - 'Escrow amount is incorrect' - ); - - assert.isTrue( - BN(buyerETHSent).eq(escrowBuyerEth), - 'Escrow amount is incorrect' - ); - - assert.isTrue( - BN(buyerTKNSent).eq(escrowBuyerTkn), - 'Escrow amount is incorrect' - ); - }); - it('[NEGATIVE] Should not create order with incorrect price', async () => { - const nonce = await contractBSNTokenDeposit.nonces( - users.buyer.address - ); - const digestDeposit = await getApprovalDigest( - contractBSNTokenDeposit, - users.buyer.address, - contractCashier.address, - constants.buyer_deposit, - nonce, - deadline - ); - - const {v, r, s} = ecsign( - Buffer.from(digestDeposit.slice(2), 'hex'), - Buffer.from(users.buyer.privateKey.slice(2), 'hex') - ); - - const buyerInstance = contractBosonRouter.connect(users.buyer.signer); - await expect( - buyerInstance.requestVoucherETHTKNWithPermit( + utils.commitToBuy( + users.buyer, + users.seller, TOKEN_SUPPLY_ID, - users.seller.address, - constants.buyer_deposit, - deadline, - v, - r, - s, - { - value: constants.incorrect_product_price, - } + false, + constants.incorrect_product_price, + constants.PROMISE_DEPOSITBU1 ) ).to.be.revertedWith(revertReasons.INCORRECT_PRICE); }); it('[NEGATIVE] Should not create order with incorrect deposit', async () => { - const nonce = await contractBSNTokenDeposit.nonces( - users.buyer.address - ); - const digestDeposit = await getApprovalDigest( - contractBSNTokenDeposit, - users.buyer.address, - contractCashier.address, - constants.buyer_deposit, - nonce, - deadline - ); - - const {v, r, s} = ecsign( - Buffer.from(digestDeposit.slice(2), 'hex'), - Buffer.from(users.buyer.privateKey.slice(2), 'hex') - ); - - const buyerInstance = contractBosonRouter.connect(users.buyer.signer); - await expect( - buyerInstance.requestVoucherETHTKNWithPermit( + utils.commitToBuy( + users.buyer, + users.seller, TOKEN_SUPPLY_ID, - users.seller.address, - constants.buyer_incorrect_deposit, - deadline, - v, - r, - s, - {value: constants.product_price} + false, + constants.PROMISE_PRICE1, + constants.buyer_incorrect_deposit ) ).to.be.revertedWith(revertReasons.INCORRECT_DEPOSIT); }); From 018b6a8721be171b833e5d41874aa2e465685cf8 Mon Sep 17 00:00:00 2001 From: zajck Date: Wed, 6 Oct 2021 10:00:49 +0200 Subject: [PATCH 12/41] TKNTKN commitToBuy unit tests --- test/2_test_fullpath_with_permit.ts | 428 ++++++++++++---------------- 1 file changed, 181 insertions(+), 247 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 9454dbd6..e0eccd2b 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -1814,7 +1814,7 @@ describe('Cashier and VoucherKernel', () => { ).to.be.revertedWith(revertReasons.INCORRECT_PAYMENT_METHOD); }); - it.only('[NEGATIVE] Should not create order with incorrect price', async () => { + it('[NEGATIVE] Should not create order with incorrect price', async () => { await expect( utils.commitToBuy( users.buyer, @@ -1827,7 +1827,7 @@ describe('Cashier and VoucherKernel', () => { ).to.be.revertedWith(revertReasons.INVALID_FUNDS); }); - it.only('[NEGATIVE] Should not create order with incorrect deposit', async () => { + it('[NEGATIVE] Should not create order with incorrect deposit', async () => { await expect( utils.commitToBuy( users.buyer, @@ -2040,8 +2040,8 @@ describe('Cashier and VoucherKernel', () => { }); }); - describe('TKNTKN', () => { - before(async () => { + describe.only('TKNTKN', () => { + beforeEach(async () => { await deployContracts(); utils = await UtilsBuilder.create() @@ -2076,93 +2076,128 @@ describe('Cashier and VoucherKernel', () => { tokensToMintBuyer ); - timestamp = await Utils.getCurrTimestamp(); - constants.PROMISE_VALID_FROM = timestamp; - constants.PROMISE_VALID_TO = timestamp + 2 * constants.SECONDS_IN_DAY; - TOKEN_SUPPLY_ID = await utils.createOrder( users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, + constants.PROMISE_DEPOSITSE1, ORDER_QTY ); }); it('Should create order', async () => { - const nonce1 = await contractBSNTokenDeposit.nonces( - users.buyer.address - ); - const tokensToSend = BN(constants.product_price).add( - BN(constants.buyer_deposit) - ); + await expect( + utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, true) + ) + .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_DELIVERED) + .withArgs( + tokenSupplyKey, + voucherTokenId, + users.seller.address, + users.buyer.address, + promiseId + ) + .to.emit(contractERC1155ERC721, eventNames.TRANSFER_SINGLE) + .withArgs( + contractVoucherKernel.address, + users.seller.address, + constants.ZERO, + tokenSupplyKey, + constants.ONE + ) + .to.emit(contractERC1155ERC721, eventNames.TRANSFER) + .withArgs(constants.ZERO, users.buyer.address, voucherTokenId) + .to.emit(contractBSNTokenDeposit, eventNames.TRANSFER) + .withArgs( + users.buyer.address, + contractCashier.address, + constants.PROMISE_DEPOSITBU1 + ) + .to.emit(contractBSNTokenPrice, eventNames.TRANSFER) + .withArgs( + users.buyer.address, + contractCashier.address, + constants.PROMISE_PRICE1 + ); + }); - const digestDeposit = await getApprovalDigest( - contractBSNTokenDeposit, - users.buyer.address, - contractBosonRouter.address, - constants.buyer_deposit, - nonce1, - deadline - ); + describe('After request', () => { + beforeEach(async () => { + await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID); + }); - const VRS_DEPOSIT = ecsign( - Buffer.from(digestDeposit.slice(2), 'hex'), - Buffer.from(users.buyer.privateKey.slice(2), 'hex') - ); + it('Voucher Kernel state is correct', async () => { + const voucherStatus = await contractVoucherKernel.getVoucherStatus( + voucherTokenId + ); - const vDeposit = VRS_DEPOSIT.v; - const rDeposit = VRS_DEPOSIT.r; - const sDeposit = VRS_DEPOSIT.s; + const expectedStatus = constants.ZERO.or(constants.ONE.shl(7)); // as per contract implementations - const nonce2 = await contractBSNTokenPrice.nonces( - users.buyer.address - ); + assert.equal( + voucherStatus[0], + expectedStatus.toNumber(), + 'Wrong status' + ); + assert.isFalse(voucherStatus[1], 'Payment should not be released'); + assert.isFalse(voucherStatus[2], 'Deposit should not be released'); + assert.isTrue( + voucherStatus[3].eq(constants.ZERO), + 'Complaint period should not started yet' + ); + assert.isTrue( + voucherStatus[4].eq(constants.ZERO), + 'COF period should not started yet' + ); + }); - const digestPrice = await getApprovalDigest( - contractBSNTokenPrice, - users.buyer.address, - contractBosonRouter.address, - constants.product_price, - nonce2, - deadline - ); + it('Cashier Contract has correct amount of funds', async () => { + const sellerDeposit = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(ORDER_QTY) + ); + const expectedDepositBalance = BN(constants.PROMISE_DEPOSITBU1).add( + sellerDeposit + ); - const VRS_PRICE = ecsign( - Buffer.from(digestPrice.slice(2), 'hex'), - Buffer.from(users.buyer.privateKey.slice(2), 'hex') - ); + expect( + await contractBSNTokenPrice.balanceOf(contractCashier.address) + ).to.be.equal( + constants.PROMISE_PRICE1, + 'Escrow amount is incorrect' + ); - const vPrice = VRS_PRICE.v; - const rPrice = VRS_PRICE.r; - const sPrice = VRS_PRICE.s; + expect( + await contractBSNTokenDeposit.balanceOf(contractCashier.address) + ).to.be.equal(expectedDepositBalance, 'Escrow amount is incorrect'); + }); - const buyerInstance = contractBosonRouter.connect(users.buyer.signer); + it('Escrows should be updated', async () => { + const sellerDeposits = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(ORDER_QTY) + ); + const buyerTknPriceSent = BN(constants.PROMISE_PRICE1); + const buyerTknDepositSent = BN(constants.PROMISE_DEPOSITBU1); - const txFillOrder = await buyerInstance.requestVoucherTKNTKNWithPermit( - TOKEN_SUPPLY_ID, - users.seller.address, - tokensToSend, - deadline, - vPrice, - rPrice, - sPrice, - vDeposit, - rDeposit, - sDeposit - ); + expect( + await contractCashier.getEscrowTokensAmount( + contractBSNTokenDeposit.address, + users.seller.address + ) + ).to.be.equal(sellerDeposits, 'Escrow amount is incorrect'); - const txReceipt = await txFillOrder.wait(); + expect( + await contractCashier.getEscrowTokensAmount( + contractBSNTokenPrice.address, + users.buyer.address + ) + ).to.be.equal(buyerTknPriceSent, 'Escrow amount is incorrect'); - eventUtils.assertEventEmitted( - txReceipt, - VoucherKernel_Factory, - eventNames.LOG_VOUCHER_DELIVERED, - (ev) => { - assert.equal(ev._issuer, users.seller.address); - tokenVoucherKey = ev._tokenIdVoucher; - } - ); + expect( + await contractCashier.getEscrowTokensAmount( + contractBSNTokenDeposit.address, + users.buyer.address + ) + ).to.be.equal(buyerTknDepositSent, 'Escrow amount is incorrect'); + }); }); it('[NEGATIVE] Should not create order from a wrong payment type', async () => { @@ -2183,192 +2218,91 @@ describe('Cashier and VoucherKernel', () => { ).to.be.revertedWith(revertReasons.INCORRECT_PAYMENT_METHOD); }); - it('Cashier Contract has correct amount of funds', async () => { - const cashierPriceTokenBalance = await contractBSNTokenPrice.balanceOf( - contractCashier.address - ); - const cashierDepositTokenBalance = await contractBSNTokenDeposit.balanceOf( - contractCashier.address - ); - const sellerDeposit = BN(constants.seller_deposit).mul(BN(ORDER_QTY)); - const expectedDepositBalance = BN(constants.buyer_deposit).add( - sellerDeposit - ); - - assert.isTrue( - BN(cashierPriceTokenBalance).eq(BN(constants.product_price)), - 'Escrow amount is incorrect' - ); - assert.isTrue( - BN(cashierDepositTokenBalance).eq(expectedDepositBalance), - 'Escrow amount is incorrect' - ); - }); - - it('Escrows should be updated', async () => { - const sellerDeposits = BN(constants.seller_deposit).mul( - BN(ORDER_QTY) - ); - const buyerTknPriceSent = BN(constants.product_price); - const buyerTknDepositSent = BN(constants.buyer_deposit); - - const escrowSellerTknDeposit = await contractCashier.getEscrowTokensAmount( - contractBSNTokenDeposit.address, - users.seller.address - ); - const escrowBuyerTknPrice = await contractCashier.getEscrowTokensAmount( - contractBSNTokenPrice.address, - users.buyer.address - ); - const escrowBuyerTknDeposit = await contractCashier.getEscrowTokensAmount( - contractBSNTokenDeposit.address, - users.buyer.address - ); - - assert.isTrue( - BN(sellerDeposits).eq(escrowSellerTknDeposit), - 'Escrow amount is incorrect' - ); - - assert.isTrue( - BN(buyerTknPriceSent).eq(escrowBuyerTknPrice), - 'Escrow amount is incorrect' - ); - - assert.isTrue( - BN(buyerTknDepositSent).eq(escrowBuyerTknDeposit), - 'Escrow amount is incorrect' - ); - }); - it('[NEGATIVE] Should not create order with incorrect price', async () => { - const nonce1 = await contractBSNTokenDeposit.nonces( - users.buyer.address - ); - const tokensToSend = BN(constants.incorrect_product_price).add( - BN(constants.buyer_deposit) - ); - - const digestDeposit = await getApprovalDigest( - contractBSNTokenDeposit, - users.buyer.address, - contractCashier.address, - constants.buyer_deposit, - nonce1, - deadline - ); - - const VRS_DEPOSIT = ecsign( - Buffer.from(digestDeposit.slice(2), 'hex'), - Buffer.from(users.buyer.privateKey.slice(2), 'hex') - ); - - const vDeposit = VRS_DEPOSIT.v; - const rDeposit = VRS_DEPOSIT.r; - const sDeposit = VRS_DEPOSIT.s; - - const nonce2 = await contractBSNTokenPrice.nonces( - users.buyer.address - ); - - const digestPrice = await getApprovalDigest( - contractBSNTokenPrice, - users.buyer.address, - contractCashier.address, - constants.product_price, - nonce2, - deadline - ); - - const VRS_PRICE = ecsign( - Buffer.from(digestPrice.slice(2), 'hex'), - Buffer.from(users.buyer.privateKey.slice(2), 'hex') - ); - - const vPrice = VRS_PRICE.v; - const rPrice = VRS_PRICE.r; - const sPrice = VRS_PRICE.s; - - const buyerInstance = contractBosonRouter.connect(users.buyer.signer); - + // const nonce1 = await contractBSNTokenDeposit.nonces( + // users.buyer.address + // ); + // const tokensToSend = BN(constants.incorrect_product_price).add( + // BN(constants.buyer_deposit) + // ); + + // const digestDeposit = await getApprovalDigest( + // contractBSNTokenDeposit, + // users.buyer.address, + // contractCashier.address, + // constants.buyer_deposit, + // nonce1, + // deadline + // ); + + // const VRS_DEPOSIT = ecsign( + // Buffer.from(digestDeposit.slice(2), 'hex'), + // Buffer.from(users.buyer.privateKey.slice(2), 'hex') + // ); + + // const vDeposit = VRS_DEPOSIT.v; + // const rDeposit = VRS_DEPOSIT.r; + // const sDeposit = VRS_DEPOSIT.s; + + // const nonce2 = await contractBSNTokenPrice.nonces( + // users.buyer.address + // ); + + // const digestPrice = await getApprovalDigest( + // contractBSNTokenPrice, + // users.buyer.address, + // contractCashier.address, + // constants.product_price, + // nonce2, + // deadline + // ); + + // const VRS_PRICE = ecsign( + // Buffer.from(digestPrice.slice(2), 'hex'), + // Buffer.from(users.buyer.privateKey.slice(2), 'hex') + // ); + + // const vPrice = VRS_PRICE.v; + // const rPrice = VRS_PRICE.r; + // const sPrice = VRS_PRICE.s; + + // const buyerInstance = contractBosonRouter.connect(users.buyer.signer); + + // await expect( + // buyerInstance.requestVoucherTKNTKNWithPermit( + // TOKEN_SUPPLY_ID, + // users.seller.address, + // tokensToSend, + // deadline, + // vPrice, + // rPrice, + // sPrice, + // vDeposit, + // rDeposit, + // sDeposit + // ) + // ).to.be.revertedWith(revertReasons.INVALID_FUNDS); await expect( - buyerInstance.requestVoucherTKNTKNWithPermit( + utils.commitToBuy( + users.buyer, + users.seller, TOKEN_SUPPLY_ID, - users.seller.address, - tokensToSend, - deadline, - vPrice, - rPrice, - sPrice, - vDeposit, - rDeposit, - sDeposit + false, + constants.incorrect_product_price, + constants.PROMISE_DEPOSITBU1 ) ).to.be.revertedWith(revertReasons.INVALID_FUNDS); }); it('[NEGATIVE] Should not create order with incorrect deposit', async () => { - const nonce1 = await contractBSNTokenDeposit.nonces( - users.buyer.address - ); - const tokensToSend = BN(constants.product_price).add( - BN(constants.buyer_incorrect_deposit) - ); - - const digestDeposit = await getApprovalDigest( - contractBSNTokenDeposit, - users.buyer.address, - contractCashier.address, - constants.buyer_deposit, - nonce1, - deadline - ); - - const VRS_DEPOSIT = ecsign( - Buffer.from(digestDeposit.slice(2), 'hex'), - Buffer.from(users.buyer.privateKey.slice(2), 'hex') - ); - - const vDeposit = VRS_DEPOSIT.v; - const rDeposit = VRS_DEPOSIT.r; - const sDeposit = VRS_DEPOSIT.s; - - const nonce2 = await contractBSNTokenPrice.nonces( - users.buyer.address - ); - - const digestPrice = await getApprovalDigest( - contractBSNTokenPrice, - users.buyer.address, - contractCashier.address, - constants.product_price, - nonce2, - deadline - ); - - const VRS_PRICE = ecsign( - Buffer.from(digestPrice.slice(2), 'hex'), - Buffer.from(users.buyer.privateKey.slice(2), 'hex') - ); - - const vPrice = VRS_PRICE.v; - const rPrice = VRS_PRICE.r; - const sPrice = VRS_PRICE.s; - - const buyerInstance = contractBosonRouter.connect(users.buyer.signer); - await expect( - buyerInstance.requestVoucherTKNTKNWithPermit( + utils.commitToBuy( + users.buyer, + users.seller, TOKEN_SUPPLY_ID, - users.seller.address, - tokensToSend, - deadline, - vPrice, - rPrice, - sPrice, - vDeposit, - rDeposit, - sDeposit + false, + constants.PROMISE_PRICE1, + constants.buyer_incorrect_deposit ) ).to.be.revertedWith(revertReasons.INVALID_FUNDS); }); From f05db7202374b88c30721b4cd15483c1c4f6bc06 Mon Sep 17 00:00:00 2001 From: zajck Date: Wed, 6 Oct 2021 10:26:21 +0200 Subject: [PATCH 13/41] TKNTKN commitToBuy unit tests --- test/2_test_fullpath_with_permit.ts | 335 +++++++++------------------- 1 file changed, 107 insertions(+), 228 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index e0eccd2b..115691ed 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -2040,7 +2040,7 @@ describe('Cashier and VoucherKernel', () => { }); }); - describe.only('TKNTKN', () => { + describe('TKNTKN', () => { beforeEach(async () => { await deployContracts(); @@ -2219,69 +2219,6 @@ describe('Cashier and VoucherKernel', () => { }); it('[NEGATIVE] Should not create order with incorrect price', async () => { - // const nonce1 = await contractBSNTokenDeposit.nonces( - // users.buyer.address - // ); - // const tokensToSend = BN(constants.incorrect_product_price).add( - // BN(constants.buyer_deposit) - // ); - - // const digestDeposit = await getApprovalDigest( - // contractBSNTokenDeposit, - // users.buyer.address, - // contractCashier.address, - // constants.buyer_deposit, - // nonce1, - // deadline - // ); - - // const VRS_DEPOSIT = ecsign( - // Buffer.from(digestDeposit.slice(2), 'hex'), - // Buffer.from(users.buyer.privateKey.slice(2), 'hex') - // ); - - // const vDeposit = VRS_DEPOSIT.v; - // const rDeposit = VRS_DEPOSIT.r; - // const sDeposit = VRS_DEPOSIT.s; - - // const nonce2 = await contractBSNTokenPrice.nonces( - // users.buyer.address - // ); - - // const digestPrice = await getApprovalDigest( - // contractBSNTokenPrice, - // users.buyer.address, - // contractCashier.address, - // constants.product_price, - // nonce2, - // deadline - // ); - - // const VRS_PRICE = ecsign( - // Buffer.from(digestPrice.slice(2), 'hex'), - // Buffer.from(users.buyer.privateKey.slice(2), 'hex') - // ); - - // const vPrice = VRS_PRICE.v; - // const rPrice = VRS_PRICE.r; - // const sPrice = VRS_PRICE.s; - - // const buyerInstance = contractBosonRouter.connect(users.buyer.signer); - - // await expect( - // buyerInstance.requestVoucherTKNTKNWithPermit( - // TOKEN_SUPPLY_ID, - // users.seller.address, - // tokensToSend, - // deadline, - // vPrice, - // rPrice, - // sPrice, - // vDeposit, - // rDeposit, - // sDeposit - // ) - // ).to.be.revertedWith(revertReasons.INVALID_FUNDS); await expect( utils.commitToBuy( users.buyer, @@ -2308,7 +2245,7 @@ describe('Cashier and VoucherKernel', () => { }); }); - describe('TKNTKN Same', () => { + describe.only('TKNTKN Same', () => { const tokensToMintSeller = BN(constants.seller_deposit).mul( BN(ORDER_QTY) ); @@ -2316,7 +2253,7 @@ describe('Cashier and VoucherKernel', () => { BN(ORDER_QTY) ); - before(async () => { + beforeEach(async () => { await deployContracts(); utils = await UtilsBuilder.create() @@ -2340,70 +2277,112 @@ describe('Cashier and VoucherKernel', () => { tokensToMintBuyer ); - timestamp = await Utils.getCurrTimestamp(); - constants.PROMISE_VALID_FROM = timestamp; - constants.PROMISE_VALID_TO = timestamp + 2 * constants.SECONDS_IN_DAY; - TOKEN_SUPPLY_ID = await utils.createOrder( users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, + constants.PROMISE_DEPOSITSE1, ORDER_QTY ); }); it('Should create voucher', async () => { - const nonce = await utils.contractBSNTokenSame.nonces( - users.buyer.address - ); - const tokensToSend = BN(constants.product_price).add( - BN(constants.buyer_deposit) - ); + await expect( + utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, true) + ) + .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_DELIVERED) + .withArgs( + tokenSupplyKey, + voucherTokenId, + users.seller.address, + users.buyer.address, + promiseId + ) + .to.emit(contractERC1155ERC721, eventNames.TRANSFER_SINGLE) + .withArgs( + contractVoucherKernel.address, + users.seller.address, + constants.ZERO, + tokenSupplyKey, + constants.ONE + ) + .to.emit(contractERC1155ERC721, eventNames.TRANSFER) + .withArgs(constants.ZERO, users.buyer.address, voucherTokenId) + .to.emit(contractBSNTokenPrice, eventNames.TRANSFER) + .withArgs( + users.buyer.address, + contractCashier.address, + BN(constants.PROMISE_PRICE1).add(constants.PROMISE_DEPOSITBU1) + ); + }); - const digestTokens = await getApprovalDigest( - utils.contractBSNTokenSame, - users.buyer.address, - contractBosonRouter.address, - tokensToSend, - nonce, - deadline - ); + describe('After request', () => { + beforeEach(async () => { + await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID); + }); - const VRS_TOKENS = ecsign( - Buffer.from(digestTokens.slice(2), 'hex'), - Buffer.from(users.buyer.privateKey.slice(2), 'hex') - ); + it('Voucher Kernel state is correct', async () => { + const voucherStatus = await contractVoucherKernel.getVoucherStatus( + voucherTokenId + ); - const v = VRS_TOKENS.v; - const r = VRS_TOKENS.r; - const s = VRS_TOKENS.s; + const expectedStatus = constants.ZERO.or(constants.ONE.shl(7)); // as per contract implementations - const buyerInstance = contractBosonRouter.connect(users.buyer.signer); + assert.equal( + voucherStatus[0], + expectedStatus.toNumber(), + 'Wrong status' + ); + assert.isFalse(voucherStatus[1], 'Payment should not be released'); + assert.isFalse(voucherStatus[2], 'Deposit should not be released'); + assert.isTrue( + voucherStatus[3].eq(constants.ZERO), + 'Complaint period should not started yet' + ); + assert.isTrue( + voucherStatus[4].eq(constants.ZERO), + 'COF period should not started yet' + ); + }); - const txFillOrder = await buyerInstance.requestVoucherTKNTKNSameWithPermit( - TOKEN_SUPPLY_ID, - users.seller.address, - tokensToSend, - deadline, - v, - r, - s - ); + it.only('Cashier Contract has correct amount of funds', async () => { + const sellerDeposits = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(ORDER_QTY) + ); + const buyerTokensSent = BN(constants.PROMISE_PRICE1).add( + BN(constants.PROMISE_DEPOSITBU1) + ); + const expectedDepositBalance = buyerTokensSent.add(sellerDeposits); - const txReceipt = await txFillOrder.wait(); + expect( + await utils.contractBSNTokenSame.balanceOf( + contractCashier.address + ) + ).to.equal(expectedDepositBalance, 'Cashier amount is incorrect'); + }); - eventUtils.assertEventEmitted( - txReceipt, - VoucherKernel_Factory, - eventNames.LOG_VOUCHER_DELIVERED, - (ev) => { - assert.equal(ev._issuer, users.seller.address); - tokenVoucherKey1 = ev._tokenIdVoucher; - } - ); + it.only('Escrows should be updated', async () => { + const sellerDeposits = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(ORDER_QTY) + ); + const buyerTknSent = BN(constants.PROMISE_PRICE1).add( + BN(constants.PROMISE_DEPOSITBU1) + ); - assert.isDefined(tokenVoucherKey1.toString()); + expect( + await contractCashier.getEscrowTokensAmount( + utils.contractBSNTokenSame.address, + users.seller.address + ) + ).to.equal(sellerDeposits, 'Escrow amount is incorrect'); + + expect( + await contractCashier.getEscrowTokensAmount( + utils.contractBSNTokenSame.address, + users.buyer.address + ) + ).to.equal(buyerTknSent, 'Escrow amount is incorrect'); + }); }); it('[NEGATIVE] Should not create order from a wrong payment type', async () => { @@ -2424,128 +2403,28 @@ describe('Cashier and VoucherKernel', () => { ).to.be.revertedWith(revertReasons.INCORRECT_PAYMENT_METHOD); }); - it('Cashier Contract has correct amount of funds', async () => { - const cashierTokenBalanceSame = await utils.contractBSNTokenSame.balanceOf( - contractCashier.address - ); - const sellerDeposits = BN(constants.seller_deposit).mul( - BN(ORDER_QTY) - ); - const buyerTokensSent = BN(constants.product_price).add( - BN(constants.buyer_deposit) - ); - const expectedDepositBalance = buyerTokensSent.add(sellerDeposits); - - assert.isTrue( - BN(cashierTokenBalanceSame).eq(expectedDepositBalance), - 'Cashier amount is incorrect' - ); - }); - - it('Escrows should be updated', async () => { - const sellerDeposits = BN(constants.seller_deposit).mul( - BN(ORDER_QTY) - ); - const buyerTknSent = BN(constants.product_price).add( - BN(constants.buyer_deposit) - ); - - const escrowSellerTknDeposit = await contractCashier.getEscrowTokensAmount( - utils.contractBSNTokenSame.address, - users.seller.address - ); - const escrowBuyerTkn = await contractCashier.getEscrowTokensAmount( - utils.contractBSNTokenSame.address, - users.buyer.address - ); - - assert.isTrue( - BN(sellerDeposits).eq(escrowSellerTknDeposit), - 'Escrow amount is incorrect' - ); - - assert.isTrue( - BN(buyerTknSent).eq(escrowBuyerTkn), - 'Escrow amount is incorrect' - ); - }); - it('[NEGATIVE] Should not create order with incorrect price', async () => { - const nonce = await contractBSNTokenDeposit.nonces( - users.buyer.address - ); - const incorrectTokensToSign = BN( - constants.incorrect_product_price - ).add(BN(constants.buyer_deposit)); - const digestTokens = await getApprovalDigest( - utils.contractBSNTokenSame, - users.buyer.address, - contractCashier.address, - incorrectTokensToSign, - nonce, - deadline - ); - - const VRS_TOKENS = ecsign( - Buffer.from(digestTokens.slice(2), 'hex'), - Buffer.from(users.buyer.privateKey.slice(2), 'hex') - ); - - const v = VRS_TOKENS.v; - const r = VRS_TOKENS.r; - const s = VRS_TOKENS.s; - - const buyerInstance = contractBosonRouter.connect(users.buyer.signer); - await expect( - buyerInstance.requestVoucherTKNTKNSameWithPermit( + utils.commitToBuy( + users.buyer, + users.seller, TOKEN_SUPPLY_ID, - users.seller.address, - incorrectTokensToSign, - deadline, - v, - r, - s + false, + constants.incorrect_product_price, + constants.PROMISE_DEPOSITBU1 ) ).to.be.revertedWith(revertReasons.INVALID_FUNDS); }); it('[NEGATIVE] Should not create order with incorrect deposit', async () => { - const nonce = await contractBSNTokenDeposit.nonces( - users.buyer.address - ); - const incorrectTokensToSign = BN(constants.product_price).add( - BN(constants.buyer_incorrect_deposit) - ); - const digestTokens = await getApprovalDigest( - utils.contractBSNTokenSame, - users.buyer.address, - contractCashier.address, - incorrectTokensToSign, - nonce, - deadline - ); - - const VRS_TOKENS = ecsign( - Buffer.from(digestTokens.slice(2), 'hex'), - Buffer.from(users.buyer.privateKey.slice(2), 'hex') - ); - - const v = VRS_TOKENS.v; - const r = VRS_TOKENS.r; - const s = VRS_TOKENS.s; - - const buyerInstance = contractBosonRouter.connect(users.buyer.signer); - await expect( - buyerInstance.requestVoucherTKNTKNSameWithPermit( + utils.commitToBuy( + users.buyer, + users.seller, TOKEN_SUPPLY_ID, - users.seller.address, - incorrectTokensToSign, - deadline, - v, - r, - s + false, + constants.PROMISE_PRICE1, + constants.buyer_incorrect_deposit ) ).to.be.revertedWith(revertReasons.INVALID_FUNDS); }); @@ -2581,15 +2460,15 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, + constants.PROMISE_DEPOSITSE1, ORDER_QTY ); const nonce = await utils.contractBSNTokenSame.nonces( users.buyer.address ); - const tokensToSend = BN(constants.product_price).add( - BN(constants.buyer_deposit) + const tokensToSend = BN(constants.PROMISE_PRICE1).add( + BN(constants.PROMISE_DEPOSITBU1) ); const digestTokens = await getApprovalDigest( From 33cd3e7b58678e1a12864e2c84cfc42486363fd3 Mon Sep 17 00:00:00 2001 From: zajck Date: Wed, 6 Oct 2021 10:40:26 +0200 Subject: [PATCH 14/41] TKNETH committobu unit tests --- test/2_test_fullpath_with_permit.ts | 389 +++++++++++++++++----------- 1 file changed, 232 insertions(+), 157 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 115691ed..f17beb8a 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -2245,7 +2245,7 @@ describe('Cashier and VoucherKernel', () => { }); }); - describe.only('TKNTKN Same', () => { + describe('TKNTKN Same', () => { const tokensToMintSeller = BN(constants.seller_deposit).mul( BN(ORDER_QTY) ); @@ -2345,7 +2345,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it.only('Cashier Contract has correct amount of funds', async () => { + it('Cashier Contract has correct amount of funds', async () => { const sellerDeposits = BN(constants.PROMISE_DEPOSITSE1).mul( BN(ORDER_QTY) ); @@ -2361,7 +2361,7 @@ describe('Cashier and VoucherKernel', () => { ).to.equal(expectedDepositBalance, 'Cashier amount is incorrect'); }); - it.only('Escrows should be updated', async () => { + it('Escrows should be updated', async () => { const sellerDeposits = BN(constants.PROMISE_DEPOSITSE1).mul( BN(ORDER_QTY) ); @@ -2505,7 +2505,7 @@ describe('Cashier and VoucherKernel', () => { }); }); - describe('TKNETH', () => { + describe.only('TKNETH', () => { before(async () => { await deployContracts(); @@ -2521,7 +2521,7 @@ describe('Cashier and VoucherKernel', () => { contractBSNTokenDeposit ); - const tokensToMintBuyer = BN(constants.product_price).mul( + const tokensToMintBuyer = BN(constants.PROMISE_PRICE1).mul( BN(ORDER_QTY) ); @@ -2530,62 +2530,175 @@ describe('Cashier and VoucherKernel', () => { tokensToMintBuyer ); - timestamp = await Utils.getCurrTimestamp(); - constants.PROMISE_VALID_FROM = timestamp; - constants.PROMISE_VALID_TO = timestamp + 2 * constants.SECONDS_IN_DAY; - TOKEN_SUPPLY_ID = await utils.createOrder( users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, + constants.PROMISE_DEPOSITSE1, ORDER_QTY ); }); it('Should create order', async () => { - const nonce = await contractBSNTokenPrice.nonces(users.buyer.address); - - const digestDeposit = await getApprovalDigest( - contractBSNTokenPrice, + await expect( + utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, true) + ) + .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_DELIVERED) + .withArgs( + tokenSupplyKey, + voucherTokenId, + users.seller.address, users.buyer.address, - contractBosonRouter.address, - constants.product_price, - nonce, - deadline - ); - - const {v, r, s} = ecsign( - Buffer.from(digestDeposit.slice(2), 'hex'), - Buffer.from(users.buyer.privateKey.slice(2), 'hex') - ); - - const buyerInstance = contractBosonRouter.connect(users.buyer.signer); - - const txFillOrder = await buyerInstance.requestVoucherTKNETHWithPermit( - TOKEN_SUPPLY_ID, + promiseId + ) + .to.emit(contractERC1155ERC721, eventNames.TRANSFER_SINGLE) + .withArgs( + contractVoucherKernel.address, users.seller.address, - constants.product_price, - deadline, - v, - r, - s, - {value: constants.buyer_deposit} + constants.ZERO, + tokenSupplyKey, + constants.ONE + ) + .to.emit(contractERC1155ERC721, eventNames.TRANSFER) + .withArgs(constants.ZERO, users.buyer.address, voucherTokenId) + .to.emit(contractBSNTokenPrice, eventNames.TRANSFER) + .withArgs( + users.buyer.address, + contractCashier.address, + constants.PROMISE_PRICE1 ); - const txReceipt = await txFillOrder.wait(); + }); + + describe('After request', () => { + beforeEach(async () => { + await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID); + }); + + it('Voucher Kernel state is correct', async () => { + const voucherStatus = await contractVoucherKernel.getVoucherStatus( + voucherTokenId + ); + + const expectedStatus = constants.ZERO.or(constants.ONE.shl(7)); // as per contract implementations + + assert.equal( + voucherStatus[0], + expectedStatus.toNumber(), + 'Wrong status' + ); + assert.isFalse(voucherStatus[1], 'Payment should not be released'); + assert.isFalse(voucherStatus[2], 'Deposit should not be released'); + assert.isTrue( + voucherStatus[3].eq(constants.ZERO), + 'Complaint period should not started yet' + ); + assert.isTrue( + voucherStatus[4].eq(constants.ZERO), + 'COF period should not started yet' + ); + }); + + it('Cashier Contract has correct amount of funds', async () => { + const sellerDeposits = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(ORDER_QTY) + ); + const expectedDepositBalance = BN(constants.PROMISE_DEPOSITBU1).add( + sellerDeposits + ); + + expect(await ethers.provider.getBalance( + contractCashier.address + )).to.equal(expectedDepositBalance, 'Cashier amount is incorrect'); + + expect(await contractBSNTokenPrice.balanceOf( + contractCashier.address + )).to.equal(constants.PROMISE_PRICE1, 'Cashier amount is incorrect'); + + // assert.isTrue( + // BN(cashierDepositETH).eq(expectedDepositBalance), + // 'Cashier amount is incorrect' + // ); + // assert.isTrue( + // BN(cashierPriceTokenBalance).eq(BN(constants.product_price)), + // 'Cashier amount is incorrect' + // ); + }); + + // it.only('Escrow should be updated', async () => { + // const sellerDeposits = BN(constants.PROMISE_DEPOSITSE1).mul( + // BN(ORDER_QTY) + // ); + + // // const buyerTknSent = BN(constants.product_price); + // // const buyerEthSent = BN(constants.buyer_deposit); + + // expect(await contractCashier.getEscrowAmount( + // users.seller.address + // )).to.equal(sellerDeposits, 'Escrow amount is incorrect'); + + // // expect(await contractCashier.getEscrowAmount( + // // users.buyer.address + // // )).to.equal(constants.PROMISE_DEPOSITBU1, 'Escrow amount is incorrect'); + + // expect(await contractCashier.getEscrowTokensAmount( + // contractBSNTokenPrice.address, + // users.buyer.address + // )).to.equal(constants.PROMISE_PRICE1,'Escrow amount is incorrect'); + + // // assert.isTrue( + // // BN(sellerDeposits).eq(escrowSeller), + // // 'Escrow amount is incorrect' + // // ); + + // // assert.isTrue( + // // BN(buyerEthSent).eq(escrowBuyerEth), + // // 'Escrow amount is incorrect' + // // ); + + // // assert.isTrue( + // // BN(buyerTknSent).eq(escrowBuyerTkn), + // // 'Escrow amount is incorrect' + // // ); + // }); + + + it.only('Escrow should be updated', async () => { + const sellerDeposits = BN(constants.PROMISE_PRICE1).mul( + BN(ORDER_QTY) + ); + + const buyerTknSent = BN(constants.PROMISE_PRICE1); + const buyerEthSent = BN(constants.PROMISE_DEPOSITBU1); + + const escrowSeller = await contractCashier.getEscrowAmount( + users.seller.address + ); + const escrowBuyerEth = await contractCashier.getEscrowAmount( + users.buyer.address + ); + const escrowBuyerTkn = await contractCashier.getEscrowTokensAmount( + contractBSNTokenPrice.address, + users.buyer.address + ); + + assert.isTrue( + BN(sellerDeposits).eq(escrowSeller), + 'Escrow amount is incorrect' + ); + + assert.isTrue( + BN(buyerEthSent).eq(escrowBuyerEth), + 'Escrow amount is incorrect' + ); + + assert.isTrue( + BN(buyerTknSent).eq(escrowBuyerTkn), + 'Escrow amount is incorrect' + ); + }); - eventUtils.assertEventEmitted( - txReceipt, - VoucherKernel_Factory, - eventNames.LOG_VOUCHER_DELIVERED, - (ev) => { - assert.equal(ev._issuer, users.seller.address); - tokenVoucherKey = ev._tokenIdVoucher; - } - ); - assert.isDefined(tokenVoucherKey.toString()); }); it('[NEGATIVE] Should not create order from a wrong payment type', async () => { @@ -2606,130 +2719,92 @@ describe('Cashier and VoucherKernel', () => { ).to.be.revertedWith(revertReasons.INCORRECT_PAYMENT_METHOD); }); - it('Cashier Contract has correct amount of funds', async () => { - const cashierDepositETH = await ethers.provider.getBalance( - contractCashier.address - ); - const sellerDeposits = BN(constants.seller_deposit).mul( - BN(ORDER_QTY) - ); - const expectedDepositBalance = BN(constants.buyer_deposit).add( - sellerDeposits - ); - - const cashierPriceTokenBalance = await contractBSNTokenPrice.balanceOf( - contractCashier.address - ); - - assert.isTrue( - BN(cashierDepositETH).eq(expectedDepositBalance), - 'Cashier amount is incorrect' - ); - assert.isTrue( - BN(cashierPriceTokenBalance).eq(BN(constants.product_price)), - 'Cashier amount is incorrect' - ); - }); - - it('Escrow should be updated', async () => { - const sellerDeposits = BN(constants.seller_deposit).mul( - BN(ORDER_QTY) - ); - - const buyerTknSent = BN(constants.product_price); - const buyerEthSent = BN(constants.buyer_deposit); - - const escrowSeller = await contractCashier.getEscrowAmount( - users.seller.address - ); - const escrowBuyerEth = await contractCashier.getEscrowAmount( - users.buyer.address - ); - const escrowBuyerTkn = await contractCashier.getEscrowTokensAmount( - contractBSNTokenPrice.address, - users.buyer.address - ); - assert.isTrue( - BN(sellerDeposits).eq(escrowSeller), - 'Escrow amount is incorrect' - ); - - assert.isTrue( - BN(buyerEthSent).eq(escrowBuyerEth), - 'Escrow amount is incorrect' - ); - - assert.isTrue( - BN(buyerTknSent).eq(escrowBuyerTkn), - 'Escrow amount is incorrect' - ); - }); it('[NEGATIVE] Should not create order with incorrect deposit', async () => { - const nonce = await contractBSNTokenPrice.nonces(users.buyer.address); - - const digestDeposit = await getApprovalDigest( - contractBSNTokenPrice, - users.buyer.address, - contractCashier.address, - constants.product_price, - nonce, - deadline - ); - - const {v, r, s} = ecsign( - Buffer.from(digestDeposit.slice(2), 'hex'), - Buffer.from(users.buyer.privateKey.slice(2), 'hex') - ); - - const buyerInstance = contractBosonRouter.connect(users.buyer.signer); - + // const nonce = await contractBSNTokenPrice.nonces(users.buyer.address); + + // const digestDeposit = await getApprovalDigest( + // contractBSNTokenPrice, + // users.buyer.address, + // contractCashier.address, + // constants.product_price, + // nonce, + // deadline + // ); + + // const {v, r, s} = ecsign( + // Buffer.from(digestDeposit.slice(2), 'hex'), + // Buffer.from(users.buyer.privateKey.slice(2), 'hex') + // ); + + // const buyerInstance = contractBosonRouter.connect(users.buyer.signer); + + // await expect( + // buyerInstance.requestVoucherTKNETHWithPermit( + // TOKEN_SUPPLY_ID, + // users.seller.address, + // constants.product_price, + // deadline, + // v, + // r, + // s, + // { + // value: constants.buyer_incorrect_deposit, + // } + // ) + // ).to.be.revertedWith(revertReasons.INCORRECT_DEPOSIT); await expect( - buyerInstance.requestVoucherTKNETHWithPermit( + utils.commitToBuy( + users.buyer, + users.seller, TOKEN_SUPPLY_ID, - users.seller.address, - constants.product_price, - deadline, - v, - r, - s, - { - value: constants.buyer_incorrect_deposit, - } + false, + constants.PROMISE_PRICE1, + constants.buyer_incorrect_deposit ) ).to.be.revertedWith(revertReasons.INCORRECT_DEPOSIT); }); it('[NEGATIVE] Should not create order with incorrect price', async () => { - const nonce = await contractBSNTokenPrice.nonces(users.buyer.address); - - const digestDeposit = await getApprovalDigest( - contractBSNTokenPrice, - users.buyer.address, - contractCashier.address, - constants.product_price, - nonce, - deadline - ); - - const {v, r, s} = ecsign( - Buffer.from(digestDeposit.slice(2), 'hex'), - Buffer.from(users.buyer.privateKey.slice(2), 'hex') - ); - - const buyerInstance = contractBosonRouter.connect(users.buyer.signer); - + // const nonce = await contractBSNTokenPrice.nonces(users.buyer.address); + + // const digestDeposit = await getApprovalDigest( + // contractBSNTokenPrice, + // users.buyer.address, + // contractCashier.address, + // constants.product_price, + // nonce, + // deadline + // ); + + // const {v, r, s} = ecsign( + // Buffer.from(digestDeposit.slice(2), 'hex'), + // Buffer.from(users.buyer.privateKey.slice(2), 'hex') + // ); + + // const buyerInstance = contractBosonRouter.connect(users.buyer.signer); + + // await expect( + // buyerInstance.requestVoucherTKNETHWithPermit( + // TOKEN_SUPPLY_ID, + // users.seller.address, + // constants.incorrect_product_price, + // deadline, + // v, + // r, + // s, + // {value: constants.buyer_deposit} + // ) + // ).to.be.revertedWith(revertReasons.INCORRECT_PRICE); await expect( - buyerInstance.requestVoucherTKNETHWithPermit( + utils.commitToBuy( + users.buyer, + users.seller, TOKEN_SUPPLY_ID, - users.seller.address, + false, constants.incorrect_product_price, - deadline, - v, - r, - s, - {value: constants.buyer_deposit} + constants.PROMISE_DEPOSITBU1 ) ).to.be.revertedWith(revertReasons.INCORRECT_PRICE); }); From 51dbae1b75a19257f91ccaa4dc9674a66ca62fe7 Mon Sep 17 00:00:00 2001 From: zajck Date: Wed, 6 Oct 2021 13:17:29 +0200 Subject: [PATCH 15/41] fixed TKNETH committobuy tests --- test/2_test_fullpath_with_permit.ts | 170 ++++++++-------------------- 1 file changed, 50 insertions(+), 120 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index f17beb8a..ec0698f1 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -2506,7 +2506,7 @@ describe('Cashier and VoucherKernel', () => { }); describe.only('TKNETH', () => { - before(async () => { + beforeEach(async () => { await deployContracts(); utils = await UtilsBuilder.create() @@ -2543,45 +2543,44 @@ describe('Cashier and VoucherKernel', () => { await expect( utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, true) ) - .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_DELIVERED) - .withArgs( - tokenSupplyKey, - voucherTokenId, - users.seller.address, - users.buyer.address, - promiseId - ) - .to.emit(contractERC1155ERC721, eventNames.TRANSFER_SINGLE) - .withArgs( - contractVoucherKernel.address, - users.seller.address, - constants.ZERO, - tokenSupplyKey, - constants.ONE - ) - .to.emit(contractERC1155ERC721, eventNames.TRANSFER) - .withArgs(constants.ZERO, users.buyer.address, voucherTokenId) - .to.emit(contractBSNTokenPrice, eventNames.TRANSFER) - .withArgs( - users.buyer.address, - contractCashier.address, - constants.PROMISE_PRICE1 - ); - + .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_DELIVERED) + .withArgs( + tokenSupplyKey, + voucherTokenId, + users.seller.address, + users.buyer.address, + promiseId + ) + .to.emit(contractERC1155ERC721, eventNames.TRANSFER_SINGLE) + .withArgs( + contractVoucherKernel.address, + users.seller.address, + constants.ZERO, + tokenSupplyKey, + constants.ONE + ) + .to.emit(contractERC1155ERC721, eventNames.TRANSFER) + .withArgs(constants.ZERO, users.buyer.address, voucherTokenId) + .to.emit(contractBSNTokenPrice, eventNames.TRANSFER) + .withArgs( + users.buyer.address, + contractCashier.address, + constants.PROMISE_PRICE1 + ); }); describe('After request', () => { beforeEach(async () => { await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID); }); - + it('Voucher Kernel state is correct', async () => { const voucherStatus = await contractVoucherKernel.getVoucherStatus( voucherTokenId ); - + const expectedStatus = constants.ZERO.or(constants.ONE.shl(7)); // as per contract implementations - + assert.equal( voucherStatus[0], expectedStatus.toNumber(), @@ -2598,7 +2597,7 @@ describe('Cashier and VoucherKernel', () => { 'COF period should not started yet' ); }); - + it('Cashier Contract has correct amount of funds', async () => { const sellerDeposits = BN(constants.PROMISE_DEPOSITSE1).mul( BN(ORDER_QTY) @@ -2606,99 +2605,32 @@ describe('Cashier and VoucherKernel', () => { const expectedDepositBalance = BN(constants.PROMISE_DEPOSITBU1).add( sellerDeposits ); - - expect(await ethers.provider.getBalance( - contractCashier.address - )).to.equal(expectedDepositBalance, 'Cashier amount is incorrect'); - - expect(await contractBSNTokenPrice.balanceOf( - contractCashier.address - )).to.equal(constants.PROMISE_PRICE1, 'Cashier amount is incorrect'); - - // assert.isTrue( - // BN(cashierDepositETH).eq(expectedDepositBalance), - // 'Cashier amount is incorrect' - // ); - // assert.isTrue( - // BN(cashierPriceTokenBalance).eq(BN(constants.product_price)), - // 'Cashier amount is incorrect' - // ); + + expect( + await ethers.provider.getBalance(contractCashier.address) + ).to.equal(expectedDepositBalance, 'Cashier amount is incorrect'); + + expect( + await contractBSNTokenPrice.balanceOf(contractCashier.address) + ).to.equal(constants.PROMISE_PRICE1, 'Cashier amount is incorrect'); }); - - // it.only('Escrow should be updated', async () => { - // const sellerDeposits = BN(constants.PROMISE_DEPOSITSE1).mul( - // BN(ORDER_QTY) - // ); - - // // const buyerTknSent = BN(constants.product_price); - // // const buyerEthSent = BN(constants.buyer_deposit); - - // expect(await contractCashier.getEscrowAmount( - // users.seller.address - // )).to.equal(sellerDeposits, 'Escrow amount is incorrect'); - - // // expect(await contractCashier.getEscrowAmount( - // // users.buyer.address - // // )).to.equal(constants.PROMISE_DEPOSITBU1, 'Escrow amount is incorrect'); - - // expect(await contractCashier.getEscrowTokensAmount( - // contractBSNTokenPrice.address, - // users.buyer.address - // )).to.equal(constants.PROMISE_PRICE1,'Escrow amount is incorrect'); - - // // assert.isTrue( - // // BN(sellerDeposits).eq(escrowSeller), - // // 'Escrow amount is incorrect' - // // ); - - // // assert.isTrue( - // // BN(buyerEthSent).eq(escrowBuyerEth), - // // 'Escrow amount is incorrect' - // // ); - - // // assert.isTrue( - // // BN(buyerTknSent).eq(escrowBuyerTkn), - // // 'Escrow amount is incorrect' - // // ); - // }); - - - it.only('Escrow should be updated', async () => { - const sellerDeposits = BN(constants.PROMISE_PRICE1).mul( + + it('Escrow should be updated', async () => { + const sellerDeposits = BN(constants.PROMISE_DEPOSITSE1).mul( BN(ORDER_QTY) ); - - const buyerTknSent = BN(constants.PROMISE_PRICE1); - const buyerEthSent = BN(constants.PROMISE_DEPOSITBU1); - - const escrowSeller = await contractCashier.getEscrowAmount( - users.seller.address - ); - const escrowBuyerEth = await contractCashier.getEscrowAmount( - users.buyer.address - ); - const escrowBuyerTkn = await contractCashier.getEscrowTokensAmount( - contractBSNTokenPrice.address, - users.buyer.address - ); - - assert.isTrue( - BN(sellerDeposits).eq(escrowSeller), - 'Escrow amount is incorrect' - ); - - assert.isTrue( - BN(buyerEthSent).eq(escrowBuyerEth), - 'Escrow amount is incorrect' - ); - - assert.isTrue( - BN(buyerTknSent).eq(escrowBuyerTkn), - 'Escrow amount is incorrect' - ); - }); + expect( + await contractCashier.getEscrowAmount(users.seller.address) + ).to.equal(sellerDeposits, 'Escrow amount is incorrect'); + expect( + await contractCashier.getEscrowTokensAmount( + contractBSNTokenPrice.address, + users.buyer.address + ) + ).to.equal(constants.PROMISE_PRICE1, 'Escrow amount is incorrect'); + }); }); it('[NEGATIVE] Should not create order from a wrong payment type', async () => { @@ -2719,8 +2651,6 @@ describe('Cashier and VoucherKernel', () => { ).to.be.revertedWith(revertReasons.INCORRECT_PAYMENT_METHOD); }); - - it('[NEGATIVE] Should not create order with incorrect deposit', async () => { // const nonce = await contractBSNTokenPrice.nonces(users.buyer.address); From 5575e0feb86c62ef340d02686763f33edd4599c8 Mon Sep 17 00:00:00 2001 From: zajck Date: Wed, 6 Oct 2021 15:02:40 +0200 Subject: [PATCH 16/41] additional erc1155erc721 state checs after committobuy --- test/2_test_fullpath_with_permit.ts | 244 ++++++++++++++++++---------- 1 file changed, 160 insertions(+), 84 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index ec0698f1..9bda372b 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -560,15 +560,6 @@ describe('Cashier and VoucherKernel', () => { describe('Voucher Kernel state', () => { it('Promise info is correct', async () => { - await utils.createOrder( - users.seller, - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10, - true - ); - const promiseData = await contractVoucherKernel.getPromiseData( promiseId ); @@ -635,6 +626,7 @@ describe('Cashier and VoucherKernel', () => { const tokenNonce = await contractVoucherKernel.getTokenNonce( users.seller.address ); + assert.isTrue( tokenNonce.eq(constants.ONE), 'Voucher kernel nonce mismatch' @@ -1764,6 +1756,36 @@ describe('Cashier and VoucherKernel', () => { ); }); + it('ERC1155ERC721 state is correct', async () => { + const sellerERC1155ERC721Balance = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.seller.address, + TOKEN_SUPPLY_ID + ) + )[0]; + + assert.isTrue( + sellerERC1155ERC721Balance.eq(constants.QTY_10 - 1), + 'Seller 1155 balance mismatch' + ); + + const buyerERC721Balance = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf721]( + users.buyer.address + ) + )[0]; + + assert.isTrue( + buyerERC721Balance.eq(constants.ONE), + 'Buyer 721 balance mismatch' + ); + + expect(await contractERC1155ERC721.ownerOf(voucherTokenId)).to.equal( + users.buyer.address, + 'Owner address mismatch' + ); + }); + it('Cashier Contract has correct amount of funds', async () => { const sellerDeposits = BN(constants.PROMISE_DEPOSITSE1).mul( BN(constants.QTY_10) @@ -1950,6 +1972,35 @@ describe('Cashier and VoucherKernel', () => { ); }); + it('ERC1155ERC721 state is correct', async () => { + const sellerERC1155ERC721Balance = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.seller.address, + TOKEN_SUPPLY_ID + ) + )[0]; + + assert.isTrue( + sellerERC1155ERC721Balance.eq(ORDER_QTY - 1), + 'Seller 1155 balance mismatch' + ); + + const buyerERC721Balance = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf721]( + users.buyer.address + ) + )[0]; + + assert.isTrue( + buyerERC721Balance.eq(constants.ONE), + 'Buyer 721 balance mismatch' + ); + + expect( + await contractERC1155ERC721.ownerOf(voucherTokenId) + ).to.equal(users.buyer.address, 'Owner address mismatch'); + }); + it('Cashier Contract has correct amount of funds', async () => { const expectedETHBalance = BN(constants.PROMISE_PRICE1); const sellerTokenDeposits = BN(constants.PROMISE_DEPOSITSE1).mul( @@ -2150,6 +2201,35 @@ describe('Cashier and VoucherKernel', () => { ); }); + it('ERC1155ERC721 state is correct', async () => { + const sellerERC1155ERC721Balance = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.seller.address, + TOKEN_SUPPLY_ID + ) + )[0]; + + assert.isTrue( + sellerERC1155ERC721Balance.eq(ORDER_QTY - 1), + 'Seller 1155 balance mismatch' + ); + + const buyerERC721Balance = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf721]( + users.buyer.address + ) + )[0]; + + assert.isTrue( + buyerERC721Balance.eq(constants.ONE), + 'Buyer 721 balance mismatch' + ); + + expect( + await contractERC1155ERC721.ownerOf(voucherTokenId) + ).to.equal(users.buyer.address, 'Owner address mismatch'); + }); + it('Cashier Contract has correct amount of funds', async () => { const sellerDeposit = BN(constants.PROMISE_DEPOSITSE1).mul( BN(ORDER_QTY) @@ -2345,6 +2425,35 @@ describe('Cashier and VoucherKernel', () => { ); }); + it('ERC1155ERC721 state is correct', async () => { + const sellerERC1155ERC721Balance = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.seller.address, + TOKEN_SUPPLY_ID + ) + )[0]; + + assert.isTrue( + sellerERC1155ERC721Balance.eq(ORDER_QTY - 1), + 'Seller 1155 balance mismatch' + ); + + const buyerERC721Balance = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf721]( + users.buyer.address + ) + )[0]; + + assert.isTrue( + buyerERC721Balance.eq(constants.ONE), + 'Buyer 721 balance mismatch' + ); + + expect( + await contractERC1155ERC721.ownerOf(voucherTokenId) + ).to.equal(users.buyer.address, 'Owner address mismatch'); + }); + it('Cashier Contract has correct amount of funds', async () => { const sellerDeposits = BN(constants.PROMISE_DEPOSITSE1).mul( BN(ORDER_QTY) @@ -2505,7 +2614,7 @@ describe('Cashier and VoucherKernel', () => { }); }); - describe.only('TKNETH', () => { + describe('TKNETH', () => { beforeEach(async () => { await deployContracts(); @@ -2598,6 +2707,35 @@ describe('Cashier and VoucherKernel', () => { ); }); + it('ERC1155ERC721 state is correct', async () => { + const sellerERC1155ERC721Balance = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.seller.address, + TOKEN_SUPPLY_ID + ) + )[0]; + + assert.isTrue( + sellerERC1155ERC721Balance.eq(ORDER_QTY - 1), + 'Seller 1155 balance mismatch' + ); + + const buyerERC721Balance = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf721]( + users.buyer.address + ) + )[0]; + + assert.isTrue( + buyerERC721Balance.eq(constants.ONE), + 'Buyer 721 balance mismatch' + ); + + expect( + await contractERC1155ERC721.ownerOf(voucherTokenId) + ).to.equal(users.buyer.address, 'Owner address mismatch'); + }); + it('Cashier Contract has correct amount of funds', async () => { const sellerDeposits = BN(constants.PROMISE_DEPOSITSE1).mul( BN(ORDER_QTY) @@ -2651,92 +2789,30 @@ describe('Cashier and VoucherKernel', () => { ).to.be.revertedWith(revertReasons.INCORRECT_PAYMENT_METHOD); }); - it('[NEGATIVE] Should not create order with incorrect deposit', async () => { - // const nonce = await contractBSNTokenPrice.nonces(users.buyer.address); - - // const digestDeposit = await getApprovalDigest( - // contractBSNTokenPrice, - // users.buyer.address, - // contractCashier.address, - // constants.product_price, - // nonce, - // deadline - // ); - - // const {v, r, s} = ecsign( - // Buffer.from(digestDeposit.slice(2), 'hex'), - // Buffer.from(users.buyer.privateKey.slice(2), 'hex') - // ); - - // const buyerInstance = contractBosonRouter.connect(users.buyer.signer); - - // await expect( - // buyerInstance.requestVoucherTKNETHWithPermit( - // TOKEN_SUPPLY_ID, - // users.seller.address, - // constants.product_price, - // deadline, - // v, - // r, - // s, - // { - // value: constants.buyer_incorrect_deposit, - // } - // ) - // ).to.be.revertedWith(revertReasons.INCORRECT_DEPOSIT); + it('[NEGATIVE] Should not create order with incorrect price', async () => { await expect( utils.commitToBuy( users.buyer, users.seller, TOKEN_SUPPLY_ID, false, - constants.PROMISE_PRICE1, - constants.buyer_incorrect_deposit + constants.incorrect_product_price, + constants.PROMISE_DEPOSITBU1 ) - ).to.be.revertedWith(revertReasons.INCORRECT_DEPOSIT); + ).to.be.revertedWith(revertReasons.INCORRECT_PRICE); }); - it('[NEGATIVE] Should not create order with incorrect price', async () => { - // const nonce = await contractBSNTokenPrice.nonces(users.buyer.address); - - // const digestDeposit = await getApprovalDigest( - // contractBSNTokenPrice, - // users.buyer.address, - // contractCashier.address, - // constants.product_price, - // nonce, - // deadline - // ); - - // const {v, r, s} = ecsign( - // Buffer.from(digestDeposit.slice(2), 'hex'), - // Buffer.from(users.buyer.privateKey.slice(2), 'hex') - // ); - - // const buyerInstance = contractBosonRouter.connect(users.buyer.signer); - - // await expect( - // buyerInstance.requestVoucherTKNETHWithPermit( - // TOKEN_SUPPLY_ID, - // users.seller.address, - // constants.incorrect_product_price, - // deadline, - // v, - // r, - // s, - // {value: constants.buyer_deposit} - // ) - // ).to.be.revertedWith(revertReasons.INCORRECT_PRICE); + it('[NEGATIVE] Should not create order with incorrect deposit', async () => { await expect( utils.commitToBuy( users.buyer, users.seller, TOKEN_SUPPLY_ID, false, - constants.incorrect_product_price, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_PRICE1, + constants.buyer_incorrect_deposit ) - ).to.be.revertedWith(revertReasons.INCORRECT_PRICE); + ).to.be.revertedWith(revertReasons.INCORRECT_DEPOSIT); }); }); }); @@ -2885,8 +2961,8 @@ describe('Cashier and VoucherKernel', () => { TOKEN_SUPPLY_ID ); await utils.redeem(voucherID, users.buyer.signer); - await utils.cancel(voucherID, users.seller.signer), - await advanceTimeSeconds(complainPeriod + constants.ONE_MINUTE); + await utils.cancel(voucherID, users.seller.signer); + await advanceTimeSeconds(complainPeriod + constants.ONE_MINUTE); await expect( utils.complain(voucherID, users.buyer.signer) @@ -2901,8 +2977,8 @@ describe('Cashier and VoucherKernel', () => { ); await utils.redeem(voucherID, users.buyer.signer); - await utils.complain(voucherID, users.buyer.signer), - await advanceTimeSeconds(cancelPeriod + constants.ONE_MINUTE); + await utils.complain(voucherID, users.buyer.signer); + await advanceTimeSeconds(cancelPeriod + constants.ONE_MINUTE); await expect( utils.cancel(voucherID, users.seller.signer) From 96c9230758269e075e39d0477636a87c1fa2d34f Mon Sep 17 00:00:00 2001 From: zajck Date: Thu, 7 Oct 2021 09:56:37 +0200 Subject: [PATCH 17/41] common transfer unit tests --- test/2_test_fullpath_with_permit.ts | 296 +++++++++++++++++++--------- 1 file changed, 205 insertions(+), 91 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 9bda372b..7875ddf1 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -3240,7 +3240,7 @@ describe('Cashier and VoucherKernel', () => { }); }); - describe('TOKEN SUPPLY TRANSFER', () => { + describe.only('TOKEN SUPPLY TRANSFER', () => { let actualOldOwnerBalanceFromEscrow = BN(0); let actualNewOwnerBalanceFromEscrow = BN(0); let expectedBalanceInEscrow = BN(0); @@ -3277,6 +3277,32 @@ describe('Cashier and VoucherKernel', () => { }); it('Should transfer voucher supply', async () => { + // balances before + const user1BalanceBeforeTransfer = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.other1.address, + tokenSupplyKey + ) + )[0]; + + const user2BalanceBeforeTransfer = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.other2.address, + tokenSupplyKey + ) + )[0]; + + assert.equal( + user1BalanceBeforeTransfer, + constants.QTY_10, + 'User1 before balance mismatch' + ); + assert.equal( + user2BalanceBeforeTransfer, + 0, + 'User2 before balance mismatch' + ); + const transferTx = await utils.safeTransfer1155( users.other1.address, users.other2.address, @@ -3299,6 +3325,32 @@ describe('Cashier and VoucherKernel', () => { assert.isTrue(ev._value.eq(constants.QTY_10)); } ); + + // balances after + const user1BalanceAfterTransfer = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.other1.address, + tokenSupplyKey + ) + )[0]; + + const user2BalanceAfterTransfer = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.other2.address, + tokenSupplyKey + ) + )[0]; + + assert.equal( + user1BalanceAfterTransfer, + 0, + 'User1 after balance mismatch' + ); + assert.equal( + user2BalanceAfterTransfer, + constants.QTY_10, + 'User2 after balance mismatch' + ); }); it('Should transfer voucher supply to self and balance should be the same', async () => { @@ -3324,8 +3376,9 @@ describe('Cashier and VoucherKernel', () => { ) )[0]; - assert.isTrue( - balanceBeforeTransfer.eq(balanceAfterTransfer), + assert.equal( + balanceBeforeTransfer.toString(), + balanceAfterTransfer.toString(), 'Balance mismatch!' ); @@ -3368,107 +3421,168 @@ describe('Cashier and VoucherKernel', () => { ).to.be.revertedWith(revertReasons.UNAUTHORIZED_TRANSFER_1155); }); - it('Should transfer batch voucher supply', async () => { - const transferTx = await utils.safeBatchTransfer1155( - users.other1.address, - users.other2.address, - [tokenSupplyKey], - [constants.QTY_10], - users.other1.signer - ); + describe('Batchtransfers', () => { + let tokenSupplyKey2; + let tokenSupplyBatch; + let batchQuantities = [BN(constants.QTY_10), BN(constants.QTY_20)]; - const txReceipt = await transferTx.wait(); + beforeEach(async () => { + const timestamp = await Utils.getCurrTimestamp(); - eventUtils.assertEventEmitted( - txReceipt, - ERC1155ERC721_Factory, - eventNames.TRANSFER_BATCH, - (ev) => { - assert.equal(ev._from, users.other1.address); - assert.equal(ev._to, users.other2.address); - assert.equal( - JSON.stringify(ev._ids), - JSON.stringify([BN(tokenSupplyKey)]) - ); - assert.equal( - JSON.stringify(ev._values), - JSON.stringify([BN(constants.QTY_10)]) - ); - } - ); - }); + tokenSupplyKey2 = await utils.createOrder( + users.other1, + timestamp, + timestamp + constants.SECONDS_IN_DAY, + constants.seller_deposit, + constants.QTY_20 + ); - it('Should transfer batch voucher supply to self and balance should be the same', async () => { - const balanceBeforeTransfer = ( - await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( - users.other1.address, - tokenSupplyKey - ) - )[0]; + tokenSupplyBatch = [BN(tokenSupplyKey), BN(tokenSupplyKey2)]; + }); - const transferTx = await utils.safeBatchTransfer1155( - users.other1.address, - users.other1.address, - [tokenSupplyKey], - [constants.QTY_10], - users.other1.signer - ); + it('Should transfer batch voucher supply', async () => { + // balances before + const user1BalanceBeforeTransfer = await contractERC1155ERC721.balanceOfBatch( + [users.other1.address, users.other1.address], + tokenSupplyBatch + ); - const balanceAfterTransfer = ( - await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + const user2BalanceBeforeTransfer = await contractERC1155ERC721.balanceOfBatch( + [users.other2.address, users.other2.address], + tokenSupplyBatch + ); + + assert.equal( + JSON.stringify(user1BalanceBeforeTransfer), + JSON.stringify(batchQuantities), + 'User1 before balance mismatch' + ); + assert.equal( + JSON.stringify(user2BalanceBeforeTransfer), + JSON.stringify([constants.ZERO, constants.ZERO]), + 'User2 before balance mismatch' + ); + + const transferTx = await utils.safeBatchTransfer1155( users.other1.address, - tokenSupplyKey - ) - )[0]; + users.other2.address, + tokenSupplyBatch, + batchQuantities.map((q) => q.toString()), + users.other1.signer + ); - assert.isTrue( - balanceBeforeTransfer.eq(balanceAfterTransfer), - 'Balance mismatch!' - ); + const txReceipt = await transferTx.wait(); - const txReceipt = await transferTx.wait(); + eventUtils.assertEventEmitted( + txReceipt, + ERC1155ERC721_Factory, + eventNames.TRANSFER_BATCH, + (ev) => { + assert.equal(ev._from, users.other1.address); + assert.equal(ev._to, users.other2.address); + assert.equal( + JSON.stringify(ev._ids), + JSON.stringify(tokenSupplyBatch) + ); + assert.equal( + JSON.stringify(ev._values), + JSON.stringify(batchQuantities) + ); + } + ); - eventUtils.assertEventEmitted( - txReceipt, - ERC1155ERC721_Factory, - eventNames.TRANSFER_BATCH, - (ev) => { - assert.equal(ev._from, users.other1.address); - assert.equal(ev._to, users.other1.address); - assert.equal( - JSON.stringify(ev._ids), - JSON.stringify([BN(tokenSupplyKey)]) - ); - assert.equal( - JSON.stringify(ev._values), - JSON.stringify([BN(constants.QTY_10)]) - ); - } - ); - }); + // balances after + const user1BalanceAfterTransfer = await contractERC1155ERC721.balanceOfBatch( + [users.other1.address, users.other1.address], + tokenSupplyBatch + ); - it('[NEGATIVE] Should revert if owner tries to transfer voucher supply batch partially', async () => { - await expect( - utils.safeBatchTransfer1155( + const user2BalanceAfterTransfer = await contractERC1155ERC721.balanceOfBatch( + [users.other2.address, users.other2.address], + tokenSupplyBatch + ); + + assert.equal( + JSON.stringify(user1BalanceAfterTransfer), + JSON.stringify([constants.ZERO, constants.ZERO]), + 'User1 after balance mismatch' + ); + assert.equal( + JSON.stringify(user2BalanceAfterTransfer), + JSON.stringify(batchQuantities), + 'User2 after balance mismatch' + ); + }); + + it('Should transfer batch voucher supply to self and balance should be the same', async () => { + const balanceBeforeTransfer = await contractERC1155ERC721.balanceOfBatch( + [users.other1.address, users.other1.address], + tokenSupplyBatch + ); + + const transferTx = await utils.safeBatchTransfer1155( users.other1.address, - users.other2.address, - [tokenSupplyKey], - [constants.QTY_1], + users.other1.address, + tokenSupplyBatch, + batchQuantities.map((q) => q.toString()), users.other1.signer - ) - ).to.be.revertedWith(revertReasons.INVALID_QUANTITY); - }); + ); - it('[NEGATIVE] Should revert if Attacker tries to transfer batch voucher supply', async () => { - await expect( - utils.safeBatchTransfer1155( - users.other1.address, - users.other2.address, - [tokenSupplyKey], - [constants.QTY_10], - users.attacker.signer - ) - ).to.be.revertedWith(revertReasons.UNAUTHORIZED_TRANSFER_BATCH_1155); + const balanceAfterTransfer = await contractERC1155ERC721.balanceOfBatch( + [users.other1.address, users.other1.address], + tokenSupplyBatch + ); + + assert.equal( + JSON.stringify(balanceBeforeTransfer), + JSON.stringify(balanceAfterTransfer), + 'Balance mismatch!' + ); + + const txReceipt = await transferTx.wait(); + + eventUtils.assertEventEmitted( + txReceipt, + ERC1155ERC721_Factory, + eventNames.TRANSFER_BATCH, + (ev) => { + assert.equal(ev._from, users.other1.address); + assert.equal(ev._to, users.other1.address); + assert.equal( + JSON.stringify(ev._ids), + JSON.stringify(tokenSupplyBatch) + ); + assert.equal( + JSON.stringify(ev._values), + JSON.stringify(batchQuantities) + ); + } + ); + }); + + it('[NEGATIVE] Should revert if owner tries to transfer voucher supply batch partially', async () => { + await expect( + utils.safeBatchTransfer1155( + users.other1.address, + users.other2.address, + tokenSupplyBatch, + [constants.QTY_10, constants.QTY_10], + users.other1.signer + ) + ).to.be.revertedWith(revertReasons.INVALID_QUANTITY); + }); + + it('[NEGATIVE] Should revert if Attacker tries to transfer batch voucher supply', async () => { + await expect( + utils.safeBatchTransfer1155( + users.other1.address, + users.other2.address, + tokenSupplyBatch, + batchQuantities.map((q) => q.toString()), + users.attacker.signer + ) + ).to.be.revertedWith(revertReasons.UNAUTHORIZED_TRANSFER_BATCH_1155); + }); }); }); From c34959529826d378980e42ee78a58fb35868522f Mon Sep 17 00:00:00 2001 From: zajck Date: Thu, 7 Oct 2021 11:04:01 +0200 Subject: [PATCH 18/41] TOKEN SUPPLY TRANSFER unit tests --- test/2_test_fullpath_with_permit.ts | 374 +++++++++++----------------- 1 file changed, 152 insertions(+), 222 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 7875ddf1..4cca4a4b 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -3240,7 +3240,7 @@ describe('Cashier and VoucherKernel', () => { }); }); - describe.only('TOKEN SUPPLY TRANSFER', () => { + describe('TOKEN SUPPLY TRANSFER', () => { let actualOldOwnerBalanceFromEscrow = BN(0); let actualNewOwnerBalanceFromEscrow = BN(0); let expectedBalanceInEscrow = BN(0); @@ -3265,13 +3265,11 @@ describe('Cashier and VoucherKernel', () => { contractBosonRouter ); - const timestamp = await Utils.getCurrTimestamp(); - tokenSupplyKey = await utils.createOrder( users.other1, - timestamp, - timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, constants.QTY_10 ); }); @@ -3427,13 +3425,11 @@ describe('Cashier and VoucherKernel', () => { let batchQuantities = [BN(constants.QTY_10), BN(constants.QTY_20)]; beforeEach(async () => { - const timestamp = await Utils.getCurrTimestamp(); - tokenSupplyKey2 = await utils.createOrder( users.other1, - timestamp, - timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE2, constants.QTY_20 ); @@ -3604,13 +3600,13 @@ describe('Cashier and VoucherKernel', () => { users.other1, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, + constants.PROMISE_DEPOSITSE1, constants.QTY_1 ); }); it('Should update escrow amounts after transfer', async () => { - expectedBalanceInEscrow = BN(constants.seller_deposit).mul( + expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( BN(constants.QTY_1) ); @@ -3636,10 +3632,11 @@ describe('Cashier and VoucherKernel', () => { tokenSupplyKey, constants.QTY_1, users.other1.signer - ), - (actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( - users.other1.address - )); + ); + + actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + users.other1.address + ); actualNewOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( users.other2.address ); @@ -3655,11 +3652,11 @@ describe('Cashier and VoucherKernel', () => { }); it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { - const expectedBuyerAmount = BN(constants.buyer_deposit); // 0.04 - const expectedSellerAmount = BN(constants.seller_deposit).add( - BN(constants.product_price) - ); // 0.35 - const expectedEscrowAmount = BN(0); // 0 + const expectedBuyerAmount = BN(constants.PROMISE_DEPOSITBU1); + const expectedSellerAmount = BN(constants.PROMISE_DEPOSITSE1).add( + BN(constants.PROMISE_PRICE1) + ); + const expectedEscrowAmount = BN(0); await utils.safeTransfer1155( users.other1.address, @@ -3733,17 +3730,9 @@ describe('Cashier and VoucherKernel', () => { await utils.redeem(voucherID, users.buyer.signer); - const cofTx = await utils.cancel(voucherID, users.other2.signer); - const txReceipt = await cofTx.wait(); - - eventUtils.assertEventEmitted( - txReceipt, - VoucherKernel_Factory, - eventNames.LOG_VOUCHER_FAULT_CANCEL, - (ev) => { - assert.isTrue(ev._tokenIdVoucher.eq(voucherID)); - } - ); + expect(await utils.cancel(voucherID, users.other2.signer)) + .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_FAULT_CANCEL) + .withArgs(voucherID); }); it('[NEGATIVE] Old owner should not be able to COF', async () => { @@ -3771,15 +3760,6 @@ describe('Cashier and VoucherKernel', () => { describe('[WITH PERMIT]', () => { describe('ETHTKN', () => { - let balanceBuyerFromDeposits = BN(0); - - let balanceSellerFromDeposits = BN(0); - - let escrowBalanceFromDeposits = BN(0); - - const cashierPaymentLeft = BN(0); - let cashierDepositLeft = BN(0); - beforeEach(async () => { await deployContracts(); await setPeriods(); @@ -3796,9 +3776,7 @@ describe('Cashier and VoucherKernel', () => { contractBSNTokenDeposit ); - const timestamp = await Utils.getCurrTimestamp(); - - const tokensToMint = BN(constants.seller_deposit).mul( + const tokensToMint = BN(constants.PROMISE_DEPOSITSE1).mul( BN(constants.QTY_1) ); @@ -3810,35 +3788,20 @@ describe('Cashier and VoucherKernel', () => { await utils.mintTokens( 'contractBSNTokenDeposit', users.buyer.address, - constants.buyer_deposit + constants.PROMISE_DEPOSITBU1.toString() ); tokenSupplyKey = await utils.createOrder( users.other1, - timestamp, - timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, constants.QTY_1 ); }); - async function getBalancesDepositToken() { - balanceBuyerFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( - users.buyer.address - ); - balanceSellerFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( - users.other2.address - ); - escrowBalanceFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( - users.deployer.address - ); - cashierDepositLeft = await utils.contractBSNTokenDeposit.balanceOf( - utils.contractCashier.address - ); - } - it('Should update escrow amounts after transfer', async () => { - expectedBalanceInEscrow = BN(constants.seller_deposit).mul( + expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( BN(constants.QTY_1) ); @@ -3866,11 +3829,12 @@ describe('Cashier and VoucherKernel', () => { tokenSupplyKey, constants.QTY_1, users.other1.signer - ), - (actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowTokensAmount( - contractBSNTokenDeposit.address, - users.other1.address - )); + ); + + actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowTokensAmount( + contractBSNTokenDeposit.address, + users.other1.address + ); actualNewOwnerBalanceFromEscrow = await contractCashier.getEscrowTokensAmount( contractBSNTokenDeposit.address, users.other2.address @@ -3887,9 +3851,9 @@ describe('Cashier and VoucherKernel', () => { }); it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { - const expectedBuyerDeposit = BN(constants.buyer_deposit); // 0.04 - const expectedSellerPrice = BN(constants.product_price); //// 0.3 - const expectedSellerDeposit = BN(constants.seller_deposit); // 0.05 + const expectedBuyerDeposit = BN(constants.PROMISE_DEPOSITBU1); + const expectedSellerPrice = BN(constants.PROMISE_PRICE1); + const expectedSellerDeposit = BN(constants.PROMISE_DEPOSITSE1); const expectedEscrowAmountDeposit = BN(0); await utils.safeTransfer1155( @@ -3916,8 +3880,6 @@ describe('Cashier and VoucherKernel', () => { users.deployer.signer ); - await getBalancesDepositToken(); - const txReceipt = await withdrawTx.wait(); eventUtils.assertEventEmitted( txReceipt, @@ -3929,6 +3891,22 @@ describe('Cashier and VoucherKernel', () => { } ); + let balanceBuyerFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( + users.buyer.address + ); + let balanceSellerFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( + users.other2.address + ); + let escrowBalanceFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( + users.deployer.address + ); + let cashierDepositLeft = await utils.contractBSNTokenDeposit.balanceOf( + utils.contractCashier.address + ); + let cashierPaymentLeft = await utils.contractBSNTokenPrice.balanceOf( + utils.contractCashier.address + ); + //Deposits assert.isTrue( balanceBuyerFromDeposits.eq(expectedBuyerDeposit), @@ -3971,7 +3949,9 @@ describe('Cashier and VoucherKernel', () => { await utils.redeem(voucherID, users.buyer.signer); - await utils.cancel(voucherID, users.other2.signer); + expect(await utils.cancel(voucherID, users.other2.signer)) + .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_FAULT_CANCEL) + .withArgs(voucherID); }); it('[NEGATIVE] Old owner should not be able to COF', async () => { @@ -3998,18 +3978,6 @@ describe('Cashier and VoucherKernel', () => { }); describe('TKNTKN', () => { - let balanceBuyerFromPayment = BN(0); - let balanceBuyerFromDeposits = BN(0); - - let balanceSellerFromPayment = BN(0); - let balanceSellerFromDeposits = BN(0); - - let escrowBalanceFromPayment = BN(0); - let escrowBalanceFromDeposits = BN(0); - - let cashierPaymentLeft = BN(0); - let cashierDepositLeft = BN(0); - beforeEach(async () => { await deployContracts(); await setPeriods(); @@ -4027,7 +3995,9 @@ describe('Cashier and VoucherKernel', () => { ); const supplyQty = 1; - const tokensToMint = BN(constants.seller_deposit).mul(BN(supplyQty)); + const tokensToMint = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(supplyQty) + ); await utils.mintTokens( 'contractBSNTokenDeposit', @@ -4037,55 +4007,25 @@ describe('Cashier and VoucherKernel', () => { await utils.mintTokens( 'contractBSNTokenPrice', users.buyer.address, - constants.product_price + BN(constants.PROMISE_PRICE1) ); await utils.mintTokens( 'contractBSNTokenDeposit', users.buyer.address, - constants.buyer_deposit + BN(constants.PROMISE_DEPOSITBU1) ); tokenSupplyKey = await utils.createOrder( users.other1, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, + constants.PROMISE_DEPOSITSE1, supplyQty ); }); - async function getBalancesFromPiceTokenAndDepositToken() { - balanceBuyerFromPayment = await utils.contractBSNTokenPrice.balanceOf( - users.buyer.address - ); - balanceBuyerFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( - users.buyer.address - ); - - balanceSellerFromPayment = await utils.contractBSNTokenPrice.balanceOf( - users.other2.address - ); - balanceSellerFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( - users.other2.address - ); - - escrowBalanceFromPayment = await utils.contractBSNTokenPrice.balanceOf( - users.deployer.address - ); - escrowBalanceFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( - users.deployer.address - ); - - cashierPaymentLeft = await utils.contractBSNTokenPrice.balanceOf( - utils.contractCashier.address - ); - cashierDepositLeft = await utils.contractBSNTokenDeposit.balanceOf( - utils.contractCashier.address - ); - } - it('Should update escrow amounts after transfer', async () => { - expectedBalanceInEscrow = BN(constants.seller_deposit).mul( + expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( BN(constants.QTY_1) ); @@ -4113,11 +4053,12 @@ describe('Cashier and VoucherKernel', () => { tokenSupplyKey, constants.QTY_1, users.other1.signer - ), - (actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowTokensAmount( - contractBSNTokenDeposit.address, - users.other1.address - )); + ); + + actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowTokensAmount( + contractBSNTokenDeposit.address, + users.other1.address + ); actualNewOwnerBalanceFromEscrow = await contractCashier.getEscrowTokensAmount( contractBSNTokenDeposit.address, users.other2.address @@ -4135,9 +4076,9 @@ describe('Cashier and VoucherKernel', () => { it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { const expectedBuyerPrice = BN(0); - const expectedBuyerDeposit = BN(constants.buyer_deposit); // 0.04 - const expectedSellerPrice = BN(constants.product_price); //// 0.3 - const expectedSellerDeposit = BN(constants.seller_deposit); // 0.05 + const expectedBuyerDeposit = BN(constants.PROMISE_DEPOSITBU1); + const expectedSellerPrice = BN(constants.PROMISE_PRICE1); + const expectedSellerDeposit = BN(constants.PROMISE_DEPOSITSE1); const expectedEscrowAmountDeposit = BN(0); const expectedEscrowAmountPrice = BN(0); @@ -4162,45 +4103,64 @@ describe('Cashier and VoucherKernel', () => { await utils.withdraw(voucherID, users.deployer.signer); - await getBalancesFromPiceTokenAndDepositToken(); - //Payments - assert.isTrue( - balanceBuyerFromPayment.eq(expectedBuyerPrice), + expect( + await utils.contractBSNTokenPrice.balanceOf(users.buyer.address) + ).to.equal( + expectedBuyerPrice, 'Buyer did not get expected tokens from PriceTokenContract' ); - assert.isTrue( - balanceSellerFromPayment.eq(expectedSellerPrice), + + expect( + await utils.contractBSNTokenPrice.balanceOf(users.other2.address) + ).to.equal( + expectedSellerPrice, 'Seller did not get expected tokens from PriceTokenContract' ); - assert.isTrue( - escrowBalanceFromPayment.eq(expectedEscrowAmountPrice), + + expect( + await utils.contractBSNTokenPrice.balanceOf(users.deployer.address) + ).to.equal( + expectedEscrowAmountPrice, 'Escrow did not get expected tokens from PriceTokenContract' ); - //Deposits - assert.isTrue( - balanceBuyerFromDeposits.eq(expectedBuyerDeposit), + // //Deposits + expect( + await utils.contractBSNTokenDeposit.balanceOf(users.buyer.address) + ).to.equal( + expectedBuyerDeposit, 'Buyer did not get expected tokens from DepositTokenContract' ); - assert.isTrue( - balanceSellerFromDeposits.eq(expectedSellerDeposit), + + expect( + await utils.contractBSNTokenDeposit.balanceOf(users.other2.address) + ).to.equal( + expectedSellerDeposit, 'Seller did not get expected tokens from DepositTokenContract' ); - assert.isTrue( - escrowBalanceFromDeposits.eq(expectedEscrowAmountDeposit), + + expect( + await utils.contractBSNTokenDeposit.balanceOf( + users.deployer.address + ) + ).to.equal( + expectedEscrowAmountDeposit, 'Escrow did not get expected tokens from DepositTokenContract' ); //Cashier Should be Empty - assert.isTrue( - cashierPaymentLeft.eq(ZERO), - 'Cashier Contract is not empty' - ); - assert.isTrue( - cashierDepositLeft.eq(ZERO), - 'Cashier Contract is not empty' - ); + expect( + await utils.contractBSNTokenPrice.balanceOf( + utils.contractCashier.address + ) + ).to.equal(constants.ZERO, 'Cashier Contract is not empty'); + + expect( + await utils.contractBSNTokenDeposit.balanceOf( + utils.contractCashier.address + ) + ).to.equal(constants.ZERO, 'Cashier Contract is not empty'); }); it('New owner should be able to COF', async () => { @@ -4220,17 +4180,9 @@ describe('Cashier and VoucherKernel', () => { await utils.redeem(voucherID, users.buyer.signer); - const cofTx = await utils.cancel(voucherID, users.other2.signer); - const txReceipt = await cofTx.wait(); - - eventUtils.assertEventEmitted( - txReceipt, - VoucherKernel_Factory, - eventNames.LOG_VOUCHER_FAULT_CANCEL, - (ev) => { - assert.isTrue(ev._tokenIdVoucher.eq(voucherID)); - } - ); + expect(await utils.cancel(voucherID, users.other2.signer)) + .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_FAULT_CANCEL) + .withArgs(voucherID); }); it('[NEGATIVE] Old owner should not be able to COF', async () => { @@ -4257,13 +4209,6 @@ describe('Cashier and VoucherKernel', () => { }); describe('TKNETH', () => { - let balanceBuyerFromPayment = BN(0); - let balanceSellerFromPayment = BN(0); - let escrowBalanceFromPayment = BN(0); - - let cashierPaymentLeft = BN(0); - const cashierDepositLeft = BN(0); - beforeEach(async () => { await deployContracts(); await setPeriods(); @@ -4277,41 +4222,26 @@ describe('Cashier and VoucherKernel', () => { contractCashier, contractBosonRouter, contractBSNTokenPrice, - '' + contractBSNTokenDeposit ); await utils.mintTokens( 'contractBSNTokenPrice', users.buyer.address, - constants.product_price + BN(constants.PROMISE_PRICE1) ); tokenSupplyKey = await utils.createOrder( users.other1, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, + constants.PROMISE_DEPOSITSE1, constants.QTY_1 ); }); - async function getBalancesPriceToken() { - balanceBuyerFromPayment = await utils.contractBSNTokenPrice.balanceOf( - users.buyer.address - ); - balanceSellerFromPayment = await utils.contractBSNTokenPrice.balanceOf( - users.other2.address - ); - escrowBalanceFromPayment = await utils.contractBSNTokenPrice.balanceOf( - users.deployer.address - ); - cashierPaymentLeft = await utils.contractBSNTokenPrice.balanceOf( - utils.contractCashier.address - ); - } - it('Should update escrow amounts after transfer', async () => { - expectedBalanceInEscrow = BN(constants.seller_deposit).mul( + expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( BN(constants.QTY_1) ); @@ -4358,10 +4288,10 @@ describe('Cashier and VoucherKernel', () => { it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { const expectedBuyerPrice = BN(0); - const expectedSellerPrice = BN(constants.product_price); // 0.3 + const expectedSellerPrice = BN(constants.PROMISE_PRICE1); const expectedEscrowPrice = BN(0); - const expectedBuyerDeposit = BN(constants.buyer_deposit); // 0.04 - const expectedSellerDeposit = BN(constants.seller_deposit); // 0.05 + const expectedBuyerDeposit = BN(constants.PROMISE_DEPOSITBU1); + const expectedSellerDeposit = BN(constants.PROMISE_DEPOSITSE1); const expectedEscrowAmountDeposit = BN(0); await utils.safeTransfer1155( @@ -4387,20 +4317,25 @@ describe('Cashier and VoucherKernel', () => { users.deployer.signer ); - await getBalancesPriceToken(); - // Payments in TKN - // Payment should have been sent to seller - assert.isTrue( - balanceBuyerFromPayment.eq(expectedBuyerPrice), + expect( + await utils.contractBSNTokenPrice.balanceOf(users.buyer.address) + ).to.equal( + expectedBuyerPrice, 'Buyer did not get expected tokens from PaymentTokenContract' ); - assert.isTrue( - balanceSellerFromPayment.eq(expectedSellerPrice), + + expect( + await utils.contractBSNTokenPrice.balanceOf(users.other2.address) + ).to.equal( + expectedSellerPrice, 'Seller did not get expected tokens from PaymentTokenContract' ); - assert.isTrue( - escrowBalanceFromPayment.eq(expectedEscrowPrice), + + expect( + await utils.contractBSNTokenPrice.balanceOf(users.deployer.address) + ).to.equal( + expectedEscrowPrice, 'Escrow did not get expected tokens from PaymentTokenContract' ); @@ -4436,14 +4371,17 @@ describe('Cashier and VoucherKernel', () => { ); //Cashier Should be Empty - assert.isTrue( - cashierPaymentLeft.eq(BN(0)), - 'Cashier Contract is not empty' - ); - assert.isTrue( - cashierDepositLeft.eq(BN(0)), - 'Cashier Contract is not empty' - ); + expect( + await utils.contractBSNTokenPrice.balanceOf( + utils.contractCashier.address + ) + ).to.equal(constants.ZERO, 'Cashier Contract is not empty'); + + expect( + await utils.contractBSNTokenDeposit.balanceOf( + utils.contractCashier.address + ) + ).to.equal(constants.ZERO, 'Cashier Contract is not empty'); }); it('New owner should be able to COF', async () => { @@ -4463,17 +4401,9 @@ describe('Cashier and VoucherKernel', () => { await utils.redeem(voucherID, users.buyer.signer); - const cofTx = await utils.cancel(voucherID, users.other2.signer); - const txReceipt = await cofTx.wait(); - - eventUtils.assertEventEmitted( - txReceipt, - VoucherKernel_Factory, - eventNames.LOG_VOUCHER_FAULT_CANCEL, - (ev) => { - assert.isTrue(ev._tokenIdVoucher.eq(voucherID)); - } - ); + expect(await utils.cancel(voucherID, users.other2.signer)) + .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_FAULT_CANCEL) + .withArgs(voucherID); }); it('[NEGATIVE] Old owner should not be able to COF', async () => { From 13e928e48b6e23cc05cf53eef1c963773ea77b4d Mon Sep 17 00:00:00 2001 From: zajck Date: Thu, 7 Oct 2021 11:45:14 +0200 Subject: [PATCH 19/41] vouchers common transfer --- test/2_test_fullpath_with_permit.ts | 157 ++++++++++++++-------------- 1 file changed, 80 insertions(+), 77 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 4cca4a4b..7ee15165 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -3241,10 +3241,6 @@ describe('Cashier and VoucherKernel', () => { }); describe('TOKEN SUPPLY TRANSFER', () => { - let actualOldOwnerBalanceFromEscrow = BN(0); - let actualNewOwnerBalanceFromEscrow = BN(0); - let expectedBalanceInEscrow = BN(0); - afterEach(() => { distributedAmounts = { buyerAmount: BN(0), @@ -3606,14 +3602,14 @@ describe('Cashier and VoucherKernel', () => { }); it('Should update escrow amounts after transfer', async () => { - expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( + let expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( BN(constants.QTY_1) ); - actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + let actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( users.other1.address ); - actualNewOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + let actualNewOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( users.other2.address ); @@ -3801,15 +3797,15 @@ describe('Cashier and VoucherKernel', () => { }); it('Should update escrow amounts after transfer', async () => { - expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( + let expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( BN(constants.QTY_1) ); - actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowTokensAmount( + let actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowTokensAmount( contractBSNTokenDeposit.address, users.other1.address ); - actualNewOwnerBalanceFromEscrow = await contractCashier.getEscrowTokensAmount( + let actualNewOwnerBalanceFromEscrow = await contractCashier.getEscrowTokensAmount( contractBSNTokenDeposit.address, users.other2.address ); @@ -4025,15 +4021,15 @@ describe('Cashier and VoucherKernel', () => { }); it('Should update escrow amounts after transfer', async () => { - expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( + let expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( BN(constants.QTY_1) ); - actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowTokensAmount( + let actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowTokensAmount( contractBSNTokenDeposit.address, users.other1.address ); - actualNewOwnerBalanceFromEscrow = await contractCashier.getEscrowTokensAmount( + let actualNewOwnerBalanceFromEscrow = await contractCashier.getEscrowTokensAmount( contractBSNTokenDeposit.address, users.other2.address ); @@ -4241,14 +4237,14 @@ describe('Cashier and VoucherKernel', () => { }); it('Should update escrow amounts after transfer', async () => { - expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( + let expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( BN(constants.QTY_1) ); - actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + let actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( users.other1.address ); - actualNewOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + let actualNewOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( users.other2.address ); @@ -4432,26 +4428,17 @@ describe('Cashier and VoucherKernel', () => { }); describe('VOUCHER TRANSFER', () => { - let actualOldOwnerBalanceFromEscrowEth = BN(0); - let actualOldOwnerBalanceFromEscrowTkn = BN(0); - let actualNewOwnerBalanceFromEscrowEth = BN(0); - let actualNewOwnerBalanceFromEscrowTkn = BN(0); - afterEach(() => { distributedAmounts = { buyerAmount: BN(0), sellerAmount: BN(0), escrowAmount: BN(0), }; - - actualOldOwnerBalanceFromEscrowEth = BN(0); - actualOldOwnerBalanceFromEscrowTkn = BN(0); - actualNewOwnerBalanceFromEscrowEth = BN(0); - actualNewOwnerBalanceFromEscrowTkn = BN(0); }); describe('Common transfer', () => { - before(async () => { + let voucherID; + beforeEach(async () => { await deployContracts(); await setPeriods(); @@ -4468,37 +4455,62 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, + constants.PROMISE_DEPOSITSE1, constants.QTY_10 ); - }); - it('Should transfer a voucher', async () => { - const voucherID = await utils.commitToBuy( + voucherID = await utils.commitToBuy( users.other1, users.seller, tokenSupplyKey ); + }); - const transferTx = await utils.safeTransfer721( - users.other1.address, - users.other2.address, - voucherID, - users.other1.signer - ); + it('Should transfer a voucher', async () => { + // balances before + expect( + ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf721]( + users.other1.address + ) + )[0] + ).to.equal(1, 'User1 before balance mismatch'); - const txReceipt = await transferTx.wait(); + expect( + ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf721]( + users.other2.address + ) + )[0] + ).to.equal(0, 'User2 before balance mismatch'); - eventUtils.assertEventEmitted( - txReceipt, - ERC1155ERC721_Factory, - eventNames.TRANSFER, - (ev) => { - assert.equal(ev._from, users.other1.address); - assert.equal(ev._to, users.other2.address); - assert.equal(ev._tokenId.toString(), voucherID); - } - ); + expect( + await utils.safeTransfer721( + users.other1.address, + users.other2.address, + voucherID, + users.other1.signer + ) + ) + .to.emit(contractERC1155ERC721, eventNames.TRANSFER) + .withArgs(users.other1.address, users.other2.address, voucherID); + + // balances after + expect( + ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf721]( + users.other1.address + ) + )[0] + ).to.equal(0, 'User1 after balance mismatch'); + + expect( + ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf721]( + users.other2.address + ) + )[0] + ).to.equal(1, 'User2 after balance mismatch'); }); it('Should transfer voucher to self and balance should be the same', async () => { @@ -4515,12 +4527,16 @@ describe('Cashier and VoucherKernel', () => { await balanceOf(users.other1.address) )[0]; - const transferTx = await utils.safeTransfer721( - users.other1.address, - users.other1.address, - voucherID, - users.other1.signer - ); + expect( + await utils.safeTransfer721( + users.other1.address, + users.other1.address, + voucherID, + users.other1.signer + ) + ) + .to.emit(contractERC1155ERC721, eventNames.TRANSFER) + .withArgs(users.other1.address, users.other1.address, voucherID); const balanceAfterTransfer = (await balanceOf(users.other1.address))[0]; @@ -4528,19 +4544,6 @@ describe('Cashier and VoucherKernel', () => { balanceBeforeTransfer.eq(balanceAfterTransfer), 'Balance mismatch!' ); - - const txReceipt = await transferTx.wait(); - - eventUtils.assertEventEmitted( - txReceipt, - ERC1155ERC721_Factory, - eventNames.TRANSFER, - (ev) => { - assert.equal(ev._from, users.other1.address); - assert.equal(ev._to, users.other1.address); - assert.equal(ev._tokenId.toString(), voucherID); - } - ); }); }); @@ -4577,10 +4580,10 @@ describe('Cashier and VoucherKernel', () => { tokenSupplyKey ); - actualOldOwnerBalanceFromEscrowEth = await contractCashier.getEscrowAmount( + let actualOldOwnerBalanceFromEscrowEth = await contractCashier.getEscrowAmount( users.other1.address ); - actualNewOwnerBalanceFromEscrowEth = await contractCashier.getEscrowAmount( + let actualNewOwnerBalanceFromEscrowEth = await contractCashier.getEscrowAmount( users.other2.address ); @@ -4836,20 +4839,20 @@ describe('Cashier and VoucherKernel', () => { tokenSupplyKey ); - actualOldOwnerBalanceFromEscrowEth = await contractCashier.getEscrowAmount( + let actualOldOwnerBalanceFromEscrowEth = await contractCashier.getEscrowAmount( users.other1.address ); - actualOldOwnerBalanceFromEscrowTkn = await contractCashier.getEscrowTokensAmount( + let actualOldOwnerBalanceFromEscrowTkn = await contractCashier.getEscrowTokensAmount( contractBSNTokenDeposit.address, users.other1.address ); - actualNewOwnerBalanceFromEscrowEth = await contractCashier.getEscrowAmount( + let actualNewOwnerBalanceFromEscrowEth = await contractCashier.getEscrowAmount( users.other2.address ); - actualNewOwnerBalanceFromEscrowTkn = await contractCashier.getEscrowTokensAmount( + let actualNewOwnerBalanceFromEscrowTkn = await contractCashier.getEscrowTokensAmount( contractBSNTokenDeposit.address, users.other2.address ); @@ -5449,20 +5452,20 @@ describe('Cashier and VoucherKernel', () => { tokenSupplyKey ); - actualOldOwnerBalanceFromEscrowEth = await contractCashier.getEscrowAmount( + let actualOldOwnerBalanceFromEscrowEth = await contractCashier.getEscrowAmount( users.other1.address ); - actualOldOwnerBalanceFromEscrowTkn = await contractCashier.getEscrowTokensAmount( + let actualOldOwnerBalanceFromEscrowTkn = await contractCashier.getEscrowTokensAmount( contractBSNTokenPrice.address, users.other1.address ); - actualNewOwnerBalanceFromEscrowEth = await contractCashier.getEscrowAmount( + let actualNewOwnerBalanceFromEscrowEth = await contractCashier.getEscrowAmount( users.other2.address ); - actualNewOwnerBalanceFromEscrowTkn = await contractCashier.getEscrowTokensAmount( + let actualNewOwnerBalanceFromEscrowTkn = await contractCashier.getEscrowTokensAmount( contractBSNTokenPrice.address, users.other2.address ); From be83aa5835b4ddcb57857fd4e7da0f2aa10e436d Mon Sep 17 00:00:00 2001 From: zajck Date: Thu, 7 Oct 2021 12:43:18 +0200 Subject: [PATCH 20/41] VOUCHER TRANSFER unit tests --- test/2_test_fullpath_with_permit.ts | 348 ++++++++++++---------------- testHelpers/constants.ts | 2 +- 2 files changed, 152 insertions(+), 198 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 7ee15165..1a253eaa 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -4565,15 +4565,16 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, + constants.PROMISE_DEPOSITSE1, constants.QTY_10 ); }); it('Should update escrow amounts after transfer', async () => { - const expectedBalanceInEscrow = BN(constants.product_price).add( - BN(constants.buyer_deposit) + const expectedBalanceInEscrow = BN(constants.PROMISE_PRICE1).add( + BN(constants.PROMISE_DEPOSITBU1) ); + const voucherID = await utils.commitToBuy( users.other1, users.seller, @@ -4621,11 +4622,15 @@ describe('Cashier and VoucherKernel', () => { }); it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { - const expectedBuyerAmount = BN(constants.buyer_deposit) - .add(BN(constants.product_price)) - .add(BN(constants.seller_deposit).div(BN(2))); // 0.3 + 0.04 + 0.025 - const expectedSellerAmount = BN(constants.seller_deposit).div(BN(4)); // 0.0125 - const expectedEscrowAmount = BN(constants.seller_deposit).div(BN(4)); // 0.0125 + const expectedBuyerAmount = BN(constants.PROMISE_DEPOSITBU1) + .add(BN(constants.PROMISE_PRICE1)) + .add(BN(constants.PROMISE_DEPOSITSE1).div(BN(2))); + const expectedSellerAmount = BN(constants.PROMISE_DEPOSITSE1).div( + BN(4) + ); + const expectedEscrowAmount = BN(constants.PROMISE_DEPOSITSE1).div( + BN(4) + ); const voucherID = await utils.commitToBuy( users.other1, @@ -4748,28 +4753,6 @@ describe('Cashier and VoucherKernel', () => { describe('[WITH PERMIT]', () => { describe('ETHTKN', () => { - let balanceBuyerFromDeposits = BN(0); - let balanceSellerFromDeposits = BN(0); - let escrowBalanceFromDeposits = BN(0); - - let cashierPaymentLeft = BN(0); - let cashierDepositLeft = BN(0); - - async function getBalancesDepositToken() { - balanceBuyerFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( - users.other2.address - ); - balanceSellerFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( - users.seller.address - ); - escrowBalanceFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( - users.deployer.address - ); - cashierDepositLeft = await utils.contractBSNTokenDeposit.balanceOf( - utils.contractCashier.address - ); - } - beforeEach(async () => { await deployContracts(); await setPeriods(); @@ -4787,7 +4770,9 @@ describe('Cashier and VoucherKernel', () => { ); const supplyQty = 1; - const tokensToMint = BN(constants.seller_deposit).mul(BN(supplyQty)); + const tokensToMint = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(supplyQty) + ); await utils.mintTokens( 'contractBSNTokenDeposit', @@ -4797,14 +4782,14 @@ describe('Cashier and VoucherKernel', () => { await utils.mintTokens( 'contractBSNTokenDeposit', users.other1.address, - constants.buyer_deposit + BN(constants.PROMISE_DEPOSITBU1) ); tokenSupplyKey = await utils.createOrder( users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, + constants.PROMISE_DEPOSITSE1, supplyQty ); }); @@ -4815,23 +4800,11 @@ describe('Cashier and VoucherKernel', () => { sellerAmount: BN(0), escrowAmount: BN(0), }; - - balanceBuyerFromDeposits = BN(0); - balanceSellerFromDeposits = BN(0); - escrowBalanceFromDeposits = BN(0); - - cashierPaymentLeft = BN(0); - cashierDepositLeft = BN(0); - - const isPaused = await contractCashier.paused(); - if (isPaused) { - await contractCashier.unpause(); - } }); it('Should update escrow amounts after transfer', async () => { - const expectedBalanceInEscrowEth = BN(constants.product_price); - const expectedBalanceInEscrowTkn = BN(constants.buyer_deposit); + const expectedBalanceInEscrowEth = BN(constants.PROMISE_PRICE1); + const expectedBalanceInEscrowTkn = BN(constants.PROMISE_DEPOSITBU1); const voucherID = await utils.commitToBuy( users.other1, @@ -4924,14 +4897,16 @@ describe('Cashier and VoucherKernel', () => { }); it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { - const expectedBuyerPrice = BN(constants.product_price); // 0.3 - const expectedBuyerDeposit = BN(constants.buyer_deposit).add( - BN(constants.seller_deposit).div(BN(2)) - ); // 0.065 - const expectedSellerDeposit = BN(constants.seller_deposit).div(BN(4)); // 0.0125 - const expectedEscrowAmountDeposit = BN(constants.seller_deposit).div( + const expectedBuyerPrice = BN(constants.PROMISE_PRICE1); + const expectedBuyerDeposit = BN(constants.PROMISE_DEPOSITBU1).add( + BN(constants.PROMISE_DEPOSITSE1).div(BN(2)) + ); + const expectedSellerDeposit = BN(constants.PROMISE_DEPOSITSE1).div( BN(4) - ); // 0.0125 + ); + const expectedEscrowAmountDeposit = BN( + constants.PROMISE_DEPOSITSE1 + ).div(BN(4)); const voucherID = await utils.commitToBuy( users.other1, @@ -4956,8 +4931,6 @@ describe('Cashier and VoucherKernel', () => { users.deployer.signer ); - await getBalancesDepositToken(); - // Payment should have been returned to buyer const txReceipt = await withdrawTx.wait(); eventUtils.assertEventEmitted( @@ -4971,28 +4944,39 @@ describe('Cashier and VoucherKernel', () => { ); //Deposits - assert.isTrue( - balanceBuyerFromDeposits.eq(expectedBuyerDeposit), + expect( + await utils.contractBSNTokenDeposit.balanceOf(users.other2.address) + ).to.equal( + expectedBuyerDeposit, 'NewVoucherOwner did not get expected tokens from DepositTokenContract' ); - assert.isTrue( - balanceSellerFromDeposits.eq(expectedSellerDeposit), + expect( + await utils.contractBSNTokenDeposit.balanceOf(users.seller.address) + ).to.equal( + expectedSellerDeposit, 'Seller did not get expected tokens from DepositTokenContract' ); - assert.isTrue( - escrowBalanceFromDeposits.eq(expectedEscrowAmountDeposit), + expect( + await utils.contractBSNTokenDeposit.balanceOf( + users.deployer.address + ) + ).to.equal( + expectedEscrowAmountDeposit, 'Escrow did not get expected tokens from DepositTokenContract' ); //Cashier Should be Empty - assert.isTrue( - cashierPaymentLeft.eq(BN(0)), - 'Cashier Contract is not empty' - ); - assert.isTrue( - cashierDepositLeft.eq(BN(0)), - 'Cashier Contract is not empty' - ); + expect( + await utils.contractBSNTokenPrice.balanceOf( + utils.contractCashier.address + ) + ).to.equal(constants.ZERO, 'Cashier Contract is not empty'); + + expect( + await utils.contractBSNTokenDeposit.balanceOf( + utils.contractCashier.address + ) + ).to.equal(constants.ZERO, 'Cashier Contract is not empty'); }); it('[NEGATIVE] Should not transfer a voucher if payments / deposits are released', async () => { @@ -5061,48 +5045,6 @@ describe('Cashier and VoucherKernel', () => { }); describe('TKNTKN', () => { - let balanceBuyerFromPayment = BN(0); - let balanceBuyerFromDeposits = BN(0); - - let balanceSellerFromPayment = BN(0); - let balanceSellerFromDeposits = BN(0); - - let escrowBalanceFromPayment = BN(0); - let escrowBalanceFromDeposits = BN(0); - - let cashierPaymentLeft = BN(0); - let cashierDepositLeft = BN(0); - - async function getBalancesFromPiceTokenAndDepositToken() { - balanceBuyerFromPayment = await utils.contractBSNTokenPrice.balanceOf( - users.other2.address - ); - balanceBuyerFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( - users.other2.address - ); - - balanceSellerFromPayment = await utils.contractBSNTokenPrice.balanceOf( - users.seller.address - ); - balanceSellerFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( - users.seller.address - ); - - escrowBalanceFromPayment = await utils.contractBSNTokenPrice.balanceOf( - users.deployer.address - ); - escrowBalanceFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( - users.deployer.address - ); - - cashierPaymentLeft = await utils.contractBSNTokenPrice.balanceOf( - utils.contractCashier.address - ); - cashierDepositLeft = await utils.contractBSNTokenDeposit.balanceOf( - utils.contractCashier.address - ); - } - beforeEach(async () => { await deployContracts(); await setPeriods(); @@ -5120,7 +5062,9 @@ describe('Cashier and VoucherKernel', () => { ); const supplyQty = 1; - const tokensToMint = BN(constants.seller_deposit).mul(BN(supplyQty)); + const tokensToMint = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(supplyQty) + ); await utils.mintTokens( 'contractBSNTokenDeposit', @@ -5142,14 +5086,16 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, + constants.PROMISE_DEPOSITSE1, supplyQty ); }); it('Should update escrow amounts after transfer', async () => { - const expectedBalanceInEscrowTknPrice = BN(constants.product_price); - const expectedBalanceInEscrowTknDeposit = BN(constants.buyer_deposit); + const expectedBalanceInEscrowTknPrice = BN(constants.PROMISE_PRICE1); + const expectedBalanceInEscrowTknDeposit = BN( + constants.PROMISE_DEPOSITBU1 + ); const voucherID = await utils.commitToBuy( users.other1, users.seller, @@ -5252,15 +5198,17 @@ describe('Cashier and VoucherKernel', () => { }); it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { - const expectedBuyerPrice = BN(constants.product_price); // 0.3 - const expectedBuyerDeposit = BN(constants.buyer_deposit).add( - BN(constants.seller_deposit).div(BN(2)) - ); // 0.065 + const expectedBuyerPrice = BN(constants.PROMISE_PRICE1); + const expectedBuyerDeposit = BN(constants.PROMISE_DEPOSITBU1).add( + BN(constants.PROMISE_DEPOSITSE1).div(BN(2)) + ); const expectedSellerPrice = BN(0); - const expectedSellerDeposit = BN(constants.seller_deposit).div(BN(4)); // 0.0125 - const expectedEscrowAmountDeposit = BN(constants.seller_deposit).div( + const expectedSellerDeposit = BN(constants.PROMISE_DEPOSITSE1).div( BN(4) - ); // 0.0125 + ); + const expectedEscrowAmountDeposit = BN( + constants.PROMISE_DEPOSITSE1 + ).div(BN(4)); const expectedEscrowAmountPrice = BN(0); const voucherID = await utils.commitToBuy( @@ -5283,45 +5231,64 @@ describe('Cashier and VoucherKernel', () => { await utils.withdraw(voucherID, users.deployer.signer); - await getBalancesFromPiceTokenAndDepositToken(); - //Payments - assert.isTrue( - balanceBuyerFromPayment.eq(expectedBuyerPrice), + expect( + await utils.contractBSNTokenPrice.balanceOf(users.other2.address) + ).to.equal( + expectedBuyerPrice, 'Buyer did not get expected tokens from PriceTokenContract' ); - assert.isTrue( - balanceSellerFromPayment.eq(expectedSellerPrice), + + expect( + await utils.contractBSNTokenPrice.balanceOf(users.seller.address) + ).to.equal( + expectedSellerPrice, 'Seller did not get expected tokens from PriceTokenContract' ); - assert.isTrue( - escrowBalanceFromPayment.eq(expectedEscrowAmountPrice), + + expect( + await utils.contractBSNTokenPrice.balanceOf(users.deployer.address) + ).to.equal( + expectedEscrowAmountPrice, 'Escrow did not get expected tokens from PriceTokenContract' ); //Deposits - assert.isTrue( - balanceBuyerFromDeposits.eq(expectedBuyerDeposit), + expect( + await utils.contractBSNTokenDeposit.balanceOf(users.other2.address) + ).to.equal( + expectedBuyerDeposit, 'Buyer did not get expected tokens from DepositTokenContract' ); - assert.isTrue( - balanceSellerFromDeposits.eq(expectedSellerDeposit), + + expect( + await utils.contractBSNTokenDeposit.balanceOf(users.seller.address) + ).to.equal( + expectedSellerDeposit, 'Seller did not get expected tokens from DepositTokenContract' ); - assert.isTrue( - escrowBalanceFromDeposits.eq(expectedEscrowAmountDeposit), + + expect( + await utils.contractBSNTokenDeposit.balanceOf( + users.deployer.address + ) + ).to.equal( + expectedEscrowAmountDeposit, 'Buyer did not get expected tokens from DepositTokenContract' ); //Cashier Should be Empty - assert.isTrue( - cashierPaymentLeft.eq(BN(0)), - 'Cashier Contract is not empty' - ); - assert.isTrue( - cashierDepositLeft.eq(BN(0)), - 'Cashier Contract is not empty' - ); + expect( + await utils.contractBSNTokenPrice.balanceOf( + utils.contractCashier.address + ) + ).to.equal(constants.ZERO, 'Cashier Contract is not empty'); + + expect( + await utils.contractBSNTokenDeposit.balanceOf( + utils.contractCashier.address + ) + ).to.equal(constants.ZERO, 'Cashier Contract is not empty'); }); it('[NEGATIVE] Should not transfer a voucher if payments / deposits are released', async () => { @@ -5390,13 +5357,6 @@ describe('Cashier and VoucherKernel', () => { }); describe('TKNETH', () => { - let balanceBuyerFromPayment = BN(0); - let balanceSellerFromPayment = BN(0); - let escrowBalanceFromPayment = BN(0); - - let cashierPaymentLeft = BN(0); - const cashierDepositLeft = BN(0); - beforeEach(async () => { await deployContracts(); await setPeriods(); @@ -5410,42 +5370,27 @@ describe('Cashier and VoucherKernel', () => { contractCashier, contractBosonRouter, contractBSNTokenPrice, - '' + contractBSNTokenDeposit ); await utils.mintTokens( 'contractBSNTokenPrice', users.other1.address, - constants.product_price + BN(constants.PROMISE_PRICE1) ); tokenSupplyKey = await utils.createOrder( users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, + constants.PROMISE_DEPOSITSE1, constants.QTY_1 ); }); - async function getBalancesPriceToken() { - balanceBuyerFromPayment = await utils.contractBSNTokenPrice.balanceOf( - users.other2.address - ); - balanceSellerFromPayment = await utils.contractBSNTokenPrice.balanceOf( - users.seller.address - ); - escrowBalanceFromPayment = await utils.contractBSNTokenPrice.balanceOf( - users.deployer.address - ); - cashierPaymentLeft = await utils.contractBSNTokenPrice.balanceOf( - utils.contractCashier.address - ); - } - it('Should update escrow amounts after transfer', async () => { - const expectedBalanceInEscrowEth = BN(constants.buyer_deposit); - const expectedBalanceInEscrowTkn = BN(constants.product_price); + const expectedBalanceInEscrowEth = BN(constants.PROMISE_DEPOSITBU1); + const expectedBalanceInEscrowTkn = BN(constants.PROMISE_PRICE1); const voucherID = await utils.commitToBuy( users.other1, users.seller, @@ -5536,16 +5481,18 @@ describe('Cashier and VoucherKernel', () => { }); it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { - const expectedBuyerPrice = BN(constants.product_price); // 0.3 + const expectedBuyerPrice = BN(constants.PROMISE_PRICE1); const expectedSellerPrice = BN(0); const expectedEscrowPrice = BN(0); - const expectedBuyerDeposit = BN(constants.buyer_deposit).add( - BN(constants.seller_deposit).div(BN(2)) - ); // 0.065 - const expectedSellerDeposit = BN(constants.seller_deposit).div(BN(4)); // 0.0125 - const expectedEscrowAmountDeposit = BN(constants.seller_deposit).div( + const expectedBuyerDeposit = BN(constants.PROMISE_DEPOSITBU1).add( + BN(constants.PROMISE_DEPOSITSE1).div(BN(2)) + ); + const expectedSellerDeposit = BN(constants.PROMISE_DEPOSITSE1).div( BN(4) - ); // 0.0125 + ); + const expectedEscrowAmountDeposit = BN( + constants.PROMISE_DEPOSITSE1 + ).div(BN(4)); const voucherID = await utils.commitToBuy( users.other1, @@ -5558,8 +5505,8 @@ describe('Cashier and VoucherKernel', () => { users.other2.address, voucherID, users.other1.signer - ), - await utils.refund(voucherID, users.other2.signer); + ); + await utils.refund(voucherID, users.other2.signer); await utils.complain(voucherID, users.other2.signer); await utils.cancel(voucherID, users.seller.signer); await utils.finalize(voucherID, users.deployer.signer); @@ -5569,20 +5516,24 @@ describe('Cashier and VoucherKernel', () => { users.deployer.signer ); - await getBalancesPriceToken(); - // Payments in TKN // Payment should have been returned to buyer - assert.isTrue( - balanceBuyerFromPayment.eq(expectedBuyerPrice), + expect( + await utils.contractBSNTokenPrice.balanceOf(users.other2.address) + ).to.equal( + expectedBuyerPrice, 'Buyer did not get expected tokens from PaymentTokenContract' ); - assert.isTrue( - balanceSellerFromPayment.eq(expectedSellerPrice), + expect( + await utils.contractBSNTokenPrice.balanceOf(users.seller.address) + ).to.equal( + expectedSellerPrice, 'Seller did not get expected tokens from PaymentTokenContract' ); - assert.isTrue( - escrowBalanceFromPayment.eq(expectedEscrowPrice), + expect( + await utils.contractBSNTokenPrice.balanceOf(users.deployer.address) + ).to.equal( + expectedEscrowPrice, 'Escrow did not get expected tokens from PaymentTokenContract' ); @@ -5617,14 +5568,17 @@ describe('Cashier and VoucherKernel', () => { ); //Cashier Should be Empty - assert.isTrue( - cashierPaymentLeft.eq(BN(0)), - 'Cashier Contract is not empty' - ); - assert.isTrue( - cashierDepositLeft.eq(BN(0)), - 'Cashier Contract is not empty' - ); + expect( + await utils.contractBSNTokenPrice.balanceOf( + utils.contractCashier.address + ) + ).to.equal(constants.ZERO, 'Cashier Contract is not empty'); + + expect( + await utils.contractBSNTokenDeposit.balanceOf( + utils.contractCashier.address + ) + ).to.equal(constants.ZERO, 'Cashier Contract is not empty'); }); it('[NEGATIVE] Should not transfer a voucher if payments / deposits are released', async () => { diff --git a/testHelpers/constants.ts b/testHelpers/constants.ts index bbc1e87f..b633c038 100644 --- a/testHelpers/constants.ts +++ b/testHelpers/constants.ts @@ -32,7 +32,7 @@ let PROMISE_VALID_FROM: number; // evaluated based on the current block timestam let PROMISE_VALID_TO: number; // evaluated based on the PROMISE_VALID_FROM + 2 * SECONDS_IN_DAY const PROMISE_PRICE1 = 10; const PROMISE_PRICE2 = 21; -const PROMISE_DEPOSITSE1 = 1; +const PROMISE_DEPOSITSE1 = '1000000'; const PROMISE_DEPOSITSE2 = 5; const PROMISE_DEPOSITBU1 = 1; const PROMISE_DEPOSITBU2 = 2; From 10e91172fa3b46e507579a81b3f9af1b0636f88b Mon Sep 17 00:00:00 2001 From: zajck Date: Thu, 7 Oct 2021 13:16:58 +0200 Subject: [PATCH 21/41] some minor fixes --- test/2_test_fullpath_with_permit.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 1a253eaa..c65e89a9 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -1791,13 +1791,14 @@ describe('Cashier and VoucherKernel', () => { BN(constants.QTY_10) ); const buyerETHSent = BN(constants.PROMISE_PRICE1).add( - BN(constants.PROMISE_DEPOSITSE1) + BN(constants.PROMISE_DEPOSITBU1) ); const expectedBalance = sellerDeposits.add(buyerETHSent); expect( await ethers.provider.getBalance(contractCashier.address) ).to.equal(expectedBalance, 'Escrow amount is incorrect'); + }); it('Escrow should be updated', async () => { @@ -3252,6 +3253,7 @@ describe('Cashier and VoucherKernel', () => { describe('Common transfer', () => { beforeEach(async () => { await deployContracts(); + await setPeriods(); utils = await UtilsBuilder.create() .ETHETH() .buildAsync( From 4653c9717b6c9f0fff31705395778afc1c91cf78 Mon Sep 17 00:00:00 2001 From: zajck Date: Thu, 7 Oct 2021 16:12:41 +0200 Subject: [PATCH 22/41] checking zero buyer deposit is allowed --- test/2_test_fullpath_with_permit.ts | 333 +++++++++++++++++++++++++++- 1 file changed, 330 insertions(+), 3 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index c65e89a9..7ea1a26d 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -419,6 +419,41 @@ describe('Cashier and VoucherKernel', () => { }); }); + it('It should be possible to create Order with 0 buyer deposit', async () => { + await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10, + true, + constants.PROMISE_PRICE1, + constants.ZERO + ); + const promiseOrderData = await contractVoucherKernel.getOrderCosts( + tokenSupplyKey + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.price].eq( + BN(constants.PROMISE_PRICE1) + ), + 'Promise produt price mismatch' + ); + + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositSe].eq( + BN(constants.PROMISE_DEPOSITSE1) + ), + 'Promise seller deposit mismatch' + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositBu].eq( + BN(constants.ZERO) + ), + 'Promise buyer deposit mismatch' + ); + }); + it('[NEGATIVE] Should revert if validTo is set below 5 minutes from now', async () => { await expect( utils.createOrder( @@ -736,6 +771,41 @@ describe('Cashier and VoucherKernel', () => { }); }); + it('It should be possible to create Order with 0 buyer deposit', async () => { + await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10, + true, + constants.PROMISE_PRICE1, + constants.ZERO + ); + const promiseOrderData = await contractVoucherKernel.getOrderCosts( + tokenSupplyKey + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.price].eq( + BN(constants.PROMISE_PRICE1) + ), + 'Promise produt price mismatch' + ); + + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositSe].eq( + BN(constants.PROMISE_DEPOSITSE1) + ), + 'Promise seller deposit mismatch' + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositBu].eq( + BN(constants.ZERO) + ), + 'Promise buyer deposit mismatch' + ); + }); + it('[NEGATIVE] Should revert if validTo is set below 5 minutes from now', async () => { await expect( utils.createOrder( @@ -1079,6 +1149,41 @@ describe('Cashier and VoucherKernel', () => { }); }); + it('It should be possible to create Order with 0 buyer deposit', async () => { + await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10, + true, + constants.PROMISE_PRICE1, + constants.ZERO + ); + const promiseOrderData = await contractVoucherKernel.getOrderCosts( + tokenSupplyKey + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.price].eq( + BN(constants.PROMISE_PRICE1) + ), + 'Promise produt price mismatch' + ); + + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositSe].eq( + BN(constants.PROMISE_DEPOSITSE1) + ), + 'Promise seller deposit mismatch' + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositBu].eq( + BN(constants.ZERO) + ), + 'Promise buyer deposit mismatch' + ); + }); + it('[NEGATIVE] Should fail if token price contract is zero address', async () => { const sellerInstance = contractBosonRouter.connect( users.seller.signer @@ -1405,6 +1510,41 @@ describe('Cashier and VoucherKernel', () => { }); }); + it('It should be possible to create Order with 0 buyer deposit', async () => { + await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + constants.QTY_10, + true, + constants.PROMISE_PRICE1, + constants.ZERO + ); + const promiseOrderData = await contractVoucherKernel.getOrderCosts( + tokenSupplyKey + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.price].eq( + BN(constants.PROMISE_PRICE1) + ), + 'Promise produt price mismatch' + ); + + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositSe].eq( + BN(constants.PROMISE_DEPOSITSE1) + ), + 'Promise seller deposit mismatch' + ); + assert.isTrue( + promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositBu].eq( + BN(constants.ZERO) + ), + 'Promise buyer deposit mismatch' + ); + }); + it('[NEGATIVE] Should revert if validTo is set below 5 minutes from now', async () => { await expect( utils.createOrder( @@ -1798,7 +1938,6 @@ describe('Cashier and VoucherKernel', () => { expect( await ethers.provider.getBalance(contractCashier.address) ).to.equal(expectedBalance, 'Escrow amount is incorrect'); - }); it('Escrow should be updated', async () => { @@ -1819,6 +1958,42 @@ describe('Cashier and VoucherKernel', () => { }); }); + it('It should be possible to request voucher with 0 buyer deposit', async () => { + let TOKEN_SUPPLY_ID = await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + ORDER_QTY, + false, + constants.PROMISE_PRICE1, + constants.ZERO + ); + + await utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.ZERO + ); + + let voucherTokenId = BN(TOKEN_SUPPLY_ID).or(constants.ONE); + + const voucherStatus = await contractVoucherKernel.getVoucherStatus( + voucherTokenId + ); + + const expectedStatus = constants.ZERO.or(constants.ONE.shl(7)); // as per contract implementations + + assert.equal( + voucherStatus[0], + expectedStatus.toNumber(), + 'Wrong status' + ); + }); + it('[NEGATIVE] Should not create order from a wrong payment type', async () => { const utilsTknEth = await UtilsBuilder.create() .ERC20withPermit() @@ -2047,6 +2222,50 @@ describe('Cashier and VoucherKernel', () => { }); }); + it('It should be possible to request voucher with 0 buyer deposit', async () => { + const tokensToMintSeller = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(ORDER_QTY) + ); + await contractBSNTokenDeposit.mint( + users.seller.address, + tokensToMintSeller + ); + + let TOKEN_SUPPLY_ID = await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + ORDER_QTY, + false, + constants.PROMISE_PRICE1, + constants.ZERO + ); + + await utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.ZERO + ); + + let voucherTokenId = BN(TOKEN_SUPPLY_ID).or(constants.ONE); + + const voucherStatus = await contractVoucherKernel.getVoucherStatus( + voucherTokenId + ); + + const expectedStatus = constants.ZERO.or(constants.ONE.shl(7)); // as per contract implementations + + assert.equal( + voucherStatus[0], + expectedStatus.toNumber(), + 'Wrong status' + ); + }); + it('[NEGATIVE] Should not create order from a wrong payment type', async () => { const utilsEthEth = await UtilsBuilder.create() .ERC20withPermit() @@ -2281,6 +2500,42 @@ describe('Cashier and VoucherKernel', () => { }); }); + it('It should be possible to request voucher with 0 buyer deposit', async () => { + let TOKEN_SUPPLY_ID = await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + ORDER_QTY, + false, + constants.PROMISE_PRICE1, + constants.ZERO + ); + + await utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.ZERO + ); + + let voucherTokenId = BN(TOKEN_SUPPLY_ID).or(constants.ONE); + + const voucherStatus = await contractVoucherKernel.getVoucherStatus( + voucherTokenId + ); + + const expectedStatus = constants.ZERO.or(constants.ONE.shl(7)); // as per contract implementations + + assert.equal( + voucherStatus[0], + expectedStatus.toNumber(), + 'Wrong status' + ); + }); + it('[NEGATIVE] Should not create order from a wrong payment type', async () => { const utilsEthTkn = await UtilsBuilder.create() .ERC20withPermit() @@ -2495,6 +2750,42 @@ describe('Cashier and VoucherKernel', () => { }); }); + it('It should be possible to request voucher with 0 buyer deposit', async () => { + let TOKEN_SUPPLY_ID = await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + ORDER_QTY, + false, + constants.PROMISE_PRICE1, + constants.ZERO + ); + + await utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.ZERO + ); + + let voucherTokenId = BN(TOKEN_SUPPLY_ID).or(constants.ONE); + + const voucherStatus = await contractVoucherKernel.getVoucherStatus( + voucherTokenId + ); + + const expectedStatus = constants.ZERO.or(constants.ONE.shl(7)); // as per contract implementations + + assert.equal( + voucherStatus[0], + expectedStatus.toNumber(), + 'Wrong status' + ); + }); + it('[NEGATIVE] Should not create order from a wrong payment type', async () => { const utilsEthEth = await UtilsBuilder.create() .ERC20withPermit() @@ -2772,6 +3063,42 @@ describe('Cashier and VoucherKernel', () => { }); }); + it('It should be possible to request voucher with 0 buyer deposit', async () => { + let TOKEN_SUPPLY_ID = await utils.createOrder( + users.seller, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + constants.PROMISE_DEPOSITSE1, + ORDER_QTY, + false, + constants.PROMISE_PRICE1, + constants.ZERO + ); + + await utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.ZERO + ); + + let voucherTokenId = BN(TOKEN_SUPPLY_ID).or(constants.ONE); + + const voucherStatus = await contractVoucherKernel.getVoucherStatus( + voucherTokenId + ); + + const expectedStatus = constants.ZERO.or(constants.ONE.shl(7)); // as per contract implementations + + assert.equal( + voucherStatus[0], + expectedStatus.toNumber(), + 'Wrong status' + ); + }); + it('[NEGATIVE] Should not create order from a wrong payment type', async () => { const utilsEthEth = await UtilsBuilder.create() .ERC20withPermit() @@ -4629,10 +4956,10 @@ describe('Cashier and VoucherKernel', () => { .add(BN(constants.PROMISE_DEPOSITSE1).div(BN(2))); const expectedSellerAmount = BN(constants.PROMISE_DEPOSITSE1).div( BN(4) - ); + ); const expectedEscrowAmount = BN(constants.PROMISE_DEPOSITSE1).div( BN(4) - ); + ); const voucherID = await utils.commitToBuy( users.other1, From 416b0aa30b852cd80996204a1f27527c196f733e Mon Sep 17 00:00:00 2001 From: zajck Date: Fri, 8 Oct 2021 15:44:59 +0200 Subject: [PATCH 23/41] testing LOG_AMOUNT_DISTRIBUTION --- test/2_test_fullpath_with_permit.ts | 712 +++++++++++++++++++++++++++- 1 file changed, 698 insertions(+), 14 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 7ea1a26d..0337bdc3 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -96,7 +96,6 @@ describe('Cashier and VoucherKernel', () => { }; async function setPeriods() { - // TODO use where applicable; why this async? const timestamp = await Utils.getCurrTimestamp(); constants.PROMISE_VALID_FROM = timestamp; @@ -3569,6 +3568,12 @@ describe('Cashier and VoucherKernel', () => { }); describe('TOKEN SUPPLY TRANSFER', () => { + const paymentType = { + PAYMENT: 0, + DEPOSIT_SELLER: 1, + DEPOSIT_BUYER: 2, + }; + afterEach(() => { distributedAmounts = { buyerAmount: BN(0), @@ -3976,7 +3981,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { + it.only('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { const expectedBuyerAmount = BN(constants.PROMISE_DEPOSITBU1); const expectedSellerAmount = BN(constants.PROMISE_DEPOSITSE1).add( BN(constants.PROMISE_PRICE1) @@ -4014,6 +4019,61 @@ describe('Cashier and VoucherKernel', () => { Cashier_Factory, eventNames.LOG_AMOUNT_DISTRIBUTION, (ev) => { + expect(ev._type).to.be.oneOf(Object.values(paymentType)); + switch (ev._type) { + case paymentType.PAYMENT: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._to, + users.other2.address, + 'Wrong payment recipient' + ); + assert.equal( + ev._payment, + constants.PROMISE_PRICE1, + 'Wrong payment amount' + ); + break; + case paymentType.DEPOSIT_SELLER: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._to, + users.other2.address, + 'Wrong seller deposit recipient' + ); + assert.equal( + ev._payment, + constants.PROMISE_DEPOSITSE1, + 'Wrong seller deposit amount' + ); + break; + case paymentType.DEPOSIT_BUYER: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._to, + users.buyer.address, + 'Wrong buyer deposit recipient' + ); + assert.equal( + ev._payment, + constants.PROMISE_DEPOSITBU1, + 'Wrong buyer deposit amount' + ); + break; + } + utils.calcTotalAmountToRecipients( ev, distributedAmounts, @@ -4175,7 +4235,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { + it.only('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { const expectedBuyerDeposit = BN(constants.PROMISE_DEPOSITBU1); const expectedSellerPrice = BN(constants.PROMISE_PRICE1); const expectedSellerDeposit = BN(constants.PROMISE_DEPOSITSE1); @@ -4206,6 +4266,7 @@ describe('Cashier and VoucherKernel', () => { ); const txReceipt = await withdrawTx.wait(); + eventUtils.assertEventEmitted( txReceipt, Cashier_Factory, @@ -4216,6 +4277,76 @@ describe('Cashier and VoucherKernel', () => { } ); + eventUtils.assertEventEmitted( + txReceipt, + Cashier_Factory, + eventNames.LOG_AMOUNT_DISTRIBUTION, + (ev) => { + expect(ev._type).to.be.oneOf(Object.values(paymentType)); + switch (ev._type) { + case paymentType.PAYMENT: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._to, + users.other2.address, + 'Wrong payment recipient' + ); + assert.equal( + ev._payment, + constants.PROMISE_PRICE1, + 'Wrong payment amount' + ); + break; + case paymentType.DEPOSIT_SELLER: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._to, + users.other2.address, + 'Wrong seller deposit recipient' + ); + assert.equal( + ev._payment, + constants.PROMISE_DEPOSITSE1, + 'Wrong seller deposit amount' + ); + break; + case paymentType.DEPOSIT_BUYER: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._to, + users.buyer.address, + 'Wrong buyer deposit recipient' + ); + assert.equal( + ev._payment, + constants.PROMISE_DEPOSITBU1, + 'Wrong buyer deposit amount' + ); + break; + } + + utils.calcTotalAmountToRecipients( + ev, + distributedAmounts, + '_to', + users.buyer.address, + users.other2.address + ); + } + ); + let balanceBuyerFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( users.buyer.address ); @@ -4399,7 +4530,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { + it.only('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { const expectedBuyerPrice = BN(0); const expectedBuyerDeposit = BN(constants.PROMISE_DEPOSITBU1); const expectedSellerPrice = BN(constants.PROMISE_PRICE1); @@ -4426,7 +4557,82 @@ describe('Cashier and VoucherKernel', () => { await advanceTimeSeconds(60); await utils.finalize(voucherID, users.deployer.signer); - await utils.withdraw(voucherID, users.deployer.signer); + const withdrawTx = await utils.withdraw( + voucherID, + users.deployer.signer + ); + + const txReceipt = await withdrawTx.wait(); + + eventUtils.assertEventEmitted( + txReceipt, + Cashier_Factory, + eventNames.LOG_AMOUNT_DISTRIBUTION, + (ev) => { + expect(ev._type).to.be.oneOf(Object.values(paymentType)); + switch (ev._type) { + case paymentType.PAYMENT: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._to, + users.other2.address, + 'Wrong payment recipient' + ); + assert.equal( + ev._payment, + constants.PROMISE_PRICE1, + 'Wrong payment amount' + ); + break; + case paymentType.DEPOSIT_SELLER: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._to, + users.other2.address, + 'Wrong seller deposit recipient' + ); + assert.equal( + ev._payment, + constants.PROMISE_DEPOSITSE1, + 'Wrong seller deposit amount' + ); + break; + case paymentType.DEPOSIT_BUYER: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._to, + users.buyer.address, + 'Wrong buyer deposit recipient' + ); + assert.equal( + ev._payment, + constants.PROMISE_DEPOSITBU1, + 'Wrong buyer deposit amount' + ); + break; + } + + utils.calcTotalAmountToRecipients( + ev, + distributedAmounts, + '_to', + users.buyer.address, + users.other2.address + ); + } + ); //Payments expect( @@ -4611,7 +4817,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { + it.only('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { const expectedBuyerPrice = BN(0); const expectedSellerPrice = BN(constants.PROMISE_PRICE1); const expectedEscrowPrice = BN(0); @@ -4681,6 +4887,76 @@ describe('Cashier and VoucherKernel', () => { } ); + eventUtils.assertEventEmitted( + txReceipt, + Cashier_Factory, + eventNames.LOG_AMOUNT_DISTRIBUTION, + (ev) => { + expect(ev._type).to.be.oneOf(Object.values(paymentType)); + switch (ev._type) { + case paymentType.PAYMENT: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._to, + users.other2.address, + 'Wrong payment recipient' + ); + assert.equal( + ev._payment, + constants.PROMISE_PRICE1, + 'Wrong payment amount' + ); + break; + case paymentType.DEPOSIT_SELLER: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._to, + users.other2.address, + 'Wrong seller deposit recipient' + ); + assert.equal( + ev._payment, + constants.PROMISE_DEPOSITSE1, + 'Wrong seller deposit amount' + ); + break; + case paymentType.DEPOSIT_BUYER: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._to, + users.buyer.address, + 'Wrong buyer deposit recipient' + ); + assert.equal( + ev._payment, + constants.PROMISE_DEPOSITBU1, + 'Wrong buyer deposit amount' + ); + break; + } + + // utils.calcTotalAmountToRecipients( + // ev, + // distributedAmounts, + // '_to', + // users.buyer.address, + // users.other2.address + // ); + } + ); + //Deposits in ETH assert.isTrue( distributedAmounts.buyerAmount.eq(expectedBuyerDeposit), @@ -4757,6 +5033,12 @@ describe('Cashier and VoucherKernel', () => { }); describe('VOUCHER TRANSFER', () => { + const paymentType = { + PAYMENT: 0, + DEPOSIT_SELLER: 1, + DEPOSIT_BUYER: 2, + }; + afterEach(() => { distributedAmounts = { buyerAmount: BN(0), @@ -4950,7 +5232,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { + it.only('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { const expectedBuyerAmount = BN(constants.PROMISE_DEPOSITBU1) .add(BN(constants.PROMISE_PRICE1)) .add(BN(constants.PROMISE_DEPOSITSE1).div(BN(2))); @@ -5001,6 +5283,111 @@ describe('Cashier and VoucherKernel', () => { } ); + // const withdrawTx = await utils.withdraw( + // voucherID, + // users.deployer.signer + // ); + + // const txReceipt = await withdrawTx.wait(); + + eventUtils.assertEventEmitted( + txReceipt, + Cashier_Factory, + eventNames.LOG_AMOUNT_DISTRIBUTION, + (ev) => { + expect(ev._type).to.be.oneOf( + Object.values(paymentType), + 'Wrong paymeny type' + ); + switch (ev._type) { + case paymentType.PAYMENT: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._to, + users.other2.address, + 'Wrong payment recipient' + ); + assert.equal( + ev._payment, + constants.PROMISE_PRICE1, + 'Wrong payment amount' + ); + break; + case paymentType.DEPOSIT_SELLER: + // expect(ev._type).to.be.oneOf([users.other2.address, users.buyer.address, contractCashier.address], 'Unexpected recepient'); + + switch (ev._to) { + case users.other2.address: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._payment, + BN(constants.PROMISE_DEPOSITSE1).div(2).toString(), + 'Wrong payment amount' + ); + break; + case users.buyer.address: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._payment, + BN(constants.PROMISE_DEPOSITSE1).div(4).toString(), + 'Wrong payment amount' + ); + break; + case contractCashier.address: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._payment, + BN(constants.PROMISE_DEPOSITSE1).div(4).toString(), + 'Wrong payment amount' + ); + break; + } + break; + case paymentType.DEPOSIT_BUYER: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._to, + users.other2.address, + 'Wrong buyer deposit recipient' + ); + assert.equal( + ev._payment, + constants.PROMISE_DEPOSITBU1, + 'Wrong buyer deposit amount' + ); + break; + } + + // utils.calcTotalAmountToRecipients( + // ev, + // distributedAmounts, + // '_to', + // users.other2.address, + // users.seller.address + // ); + } + ); + assert.isTrue( distributedAmounts.buyerAmount.eq(expectedBuyerAmount), 'Buyer Amount is not as expected' @@ -5225,7 +5612,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { + it.only('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { const expectedBuyerPrice = BN(constants.PROMISE_PRICE1); const expectedBuyerDeposit = BN(constants.PROMISE_DEPOSITBU1).add( BN(constants.PROMISE_DEPOSITSE1).div(BN(2)) @@ -5260,8 +5647,109 @@ describe('Cashier and VoucherKernel', () => { users.deployer.signer ); - // Payment should have been returned to buyer const txReceipt = await withdrawTx.wait(); + + eventUtils.assertEventEmitted( + txReceipt, + Cashier_Factory, + eventNames.LOG_AMOUNT_DISTRIBUTION, + + (ev) => { + expect(ev._type).to.be.oneOf( + Object.values(paymentType), + 'Wrong paymeny type' + ); + switch (ev._type) { + case paymentType.PAYMENT: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._to, + users.other2.address, + 'Wrong payment recipient' + ); + assert.equal( + ev._payment, + constants.PROMISE_PRICE1, + 'Wrong payment amount' + ); + break; + case paymentType.DEPOSIT_SELLER: + // expect(ev._to).to.be.oneOf([users.other2.address, users.buyer.address, contractCashier.address], 'Unexpected recepient'); + + switch (ev._to) { + case users.other2.address: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._payment, + BN(constants.PROMISE_DEPOSITSE1).div(2).toString(), + 'Wrong payment amount' + ); + break; + case users.buyer.address: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._payment, + BN(constants.PROMISE_DEPOSITSE1).div(4).toString(), + 'Wrong payment amount' + ); + break; + case contractCashier.address: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._payment, + BN(constants.PROMISE_DEPOSITSE1).div(4).toString(), + 'Wrong payment amount' + ); + break; + } + break; + case paymentType.DEPOSIT_BUYER: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._to, + users.other2.address, + 'Wrong buyer deposit recipient' + ); + assert.equal( + ev._payment, + constants.PROMISE_DEPOSITBU1, + 'Wrong buyer deposit amount' + ); + break; + } + + utils.calcTotalAmountToRecipients( + ev, + distributedAmounts, + '_to', + users.buyer.address, + users.other2.address + ); + } + ); + + // Payment should have been returned to buyer + // const txReceipt = await withdrawTx.wait(); eventUtils.assertEventEmitted( txReceipt, Cashier_Factory, @@ -5526,7 +6014,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { + it.only('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { const expectedBuyerPrice = BN(constants.PROMISE_PRICE1); const expectedBuyerDeposit = BN(constants.PROMISE_DEPOSITBU1).add( BN(constants.PROMISE_DEPOSITSE1).div(BN(2)) @@ -5558,7 +6046,111 @@ describe('Cashier and VoucherKernel', () => { await utils.cancel(voucherID, users.seller.signer); await utils.finalize(voucherID, users.deployer.signer); - await utils.withdraw(voucherID, users.deployer.signer); + // await utils.withdraw(voucherID, users.deployer.signer); + const withdrawTx = await utils.withdraw( + voucherID, + users.deployer.signer + ); + + const txReceipt = await withdrawTx.wait(); + + eventUtils.assertEventEmitted( + txReceipt, + Cashier_Factory, + eventNames.LOG_AMOUNT_DISTRIBUTION, + (ev) => { + expect(ev._type).to.be.oneOf( + Object.values(paymentType), + 'Wrong paymeny type' + ); + switch (ev._type) { + case paymentType.PAYMENT: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._to, + users.other2.address, + 'Wrong payment recipient' + ); + assert.equal( + ev._payment, + constants.PROMISE_PRICE1, + 'Wrong payment amount' + ); + break; + case paymentType.DEPOSIT_SELLER: + // expect(ev._to).to.be.oneOf([users.other2.address, users.buyer.address, contractCashier.address], 'Unexpected recepient'); + + switch (ev._to) { + case users.other2.address: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._payment, + BN(constants.PROMISE_DEPOSITSE1).div(2).toString(), + 'Wrong payment amount' + ); + break; + case users.buyer.address: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._payment, + BN(constants.PROMISE_DEPOSITSE1).div(4).toString(), + 'Wrong payment amount' + ); + break; + case contractCashier.address: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._payment, + BN(constants.PROMISE_DEPOSITSE1).div(4).toString(), + 'Wrong payment amount' + ); + break; + } + break; + case paymentType.DEPOSIT_BUYER: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._to, + users.other2.address, + 'Wrong buyer deposit recipient' + ); + assert.equal( + ev._payment, + constants.PROMISE_DEPOSITBU1, + 'Wrong buyer deposit amount' + ); + break; + } + + utils.calcTotalAmountToRecipients( + ev, + distributedAmounts, + '_to', + users.buyer.address, + users.other2.address + ); + } + ); //Payments expect( @@ -5809,7 +6401,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { + it.only('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { const expectedBuyerPrice = BN(constants.PROMISE_PRICE1); const expectedSellerPrice = BN(0); const expectedEscrowPrice = BN(0); @@ -5845,6 +6437,8 @@ describe('Cashier and VoucherKernel', () => { users.deployer.signer ); + const txReceipt = await withdrawTx.wait(); + // Payments in TKN // Payment should have been returned to buyer expect( @@ -5866,8 +6460,98 @@ describe('Cashier and VoucherKernel', () => { 'Escrow did not get expected tokens from PaymentTokenContract' ); - const txReceipt = await withdrawTx.wait(); - //Deposits in ETH + // const txReceipt = await withdrawTx.wait(); + // //Deposits in ETH + eventUtils.assertEventEmitted( + txReceipt, + Cashier_Factory, + eventNames.LOG_AMOUNT_DISTRIBUTION, + (ev) => { + expect(ev._type).to.be.oneOf( + Object.values(paymentType), + 'Wrong paymeny type' + ); + switch (ev._type) { + case paymentType.PAYMENT: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._to, + users.other2.address, + 'Wrong payment recipient' + ); + assert.equal( + ev._payment, + constants.PROMISE_PRICE1, + 'Wrong payment amount' + ); + break; + case paymentType.DEPOSIT_SELLER: + // expect(ev._to).to.be.oneOf([users.other2.address, users.buyer.address, contractCashier.address], 'Unexpected recepient'); + + switch (ev._to) { + case users.other2.address: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._payment, + BN(constants.PROMISE_DEPOSITSE1).div(2).toString(), + 'Wrong payment amount' + ); + break; + case users.buyer.address: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._payment, + BN(constants.PROMISE_DEPOSITSE1).div(4).toString(), + 'Wrong payment amount' + ); + break; + case contractCashier.address: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._payment, + BN(constants.PROMISE_DEPOSITSE1).div(4).toString(), + 'Wrong payment amount' + ); + break; + } + break; + case paymentType.DEPOSIT_BUYER: + assert.equal( + ev._tokenIdVoucher.toString(), + voucherID.toString(), + 'Wrong token id voucher' + ); + assert.equal( + ev._to, + users.other2.address, + 'Wrong buyer deposit recipient' + ); + assert.equal( + ev._payment, + constants.PROMISE_DEPOSITBU1, + 'Wrong buyer deposit amount' + ); + break; + } + } + ); + eventUtils.assertEventEmitted( txReceipt, Cashier_Factory, From 80b3de7994595a401a8fc005d3e30a79bb4a0957 Mon Sep 17 00:00:00 2001 From: zajck Date: Fri, 8 Oct 2021 17:41:25 +0200 Subject: [PATCH 24/41] log withdrawal unit tests --- test/2_test_fullpath_with_permit.ts | 137 +++++++++++++++++++--------- testHelpers/constants.ts | 2 +- 2 files changed, 95 insertions(+), 44 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 0337bdc3..935ab67c 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -3981,7 +3981,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it.only('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { + it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { const expectedBuyerAmount = BN(constants.PROMISE_DEPOSITBU1); const expectedSellerAmount = BN(constants.PROMISE_DEPOSITSE1).add( BN(constants.PROMISE_PRICE1) @@ -4014,6 +4014,23 @@ describe('Cashier and VoucherKernel', () => { const txReceipt = await withdrawTx.wait(); + eventUtils.assertEventEmitted( + txReceipt, + Cashier_Factory, + eventNames.LOG_WITHDRAWAL, + (ev) => { + expect(ev._payee).to.be.oneOf([users.other2.address,users.buyer.address], 'Incorrect Payee'); + switch (ev._payee) { + case users.other2.address: + expect(ev._payment.toNumber()).to.be.oneOf([constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITSE1]); + break; + case users.buyer.address: + assert.equal(ev._payment, constants.PROMISE_DEPOSITBU1); + break; + } + } + ); + eventUtils.assertEventEmitted( txReceipt, Cashier_Factory, @@ -4235,7 +4252,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it.only('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { + it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { const expectedBuyerDeposit = BN(constants.PROMISE_DEPOSITBU1); const expectedSellerPrice = BN(constants.PROMISE_PRICE1); const expectedSellerDeposit = BN(constants.PROMISE_DEPOSITSE1); @@ -4530,7 +4547,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it.only('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { + it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { const expectedBuyerPrice = BN(0); const expectedBuyerDeposit = BN(constants.PROMISE_DEPOSITBU1); const expectedSellerPrice = BN(constants.PROMISE_PRICE1); @@ -4817,7 +4834,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it.only('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { + it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { const expectedBuyerPrice = BN(0); const expectedSellerPrice = BN(constants.PROMISE_PRICE1); const expectedEscrowPrice = BN(0); @@ -4947,13 +4964,6 @@ describe('Cashier and VoucherKernel', () => { break; } - // utils.calcTotalAmountToRecipients( - // ev, - // distributedAmounts, - // '_to', - // users.buyer.address, - // users.other2.address - // ); } ); @@ -5232,7 +5242,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it.only('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { + it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { const expectedBuyerAmount = BN(constants.PROMISE_DEPOSITBU1) .add(BN(constants.PROMISE_PRICE1)) .add(BN(constants.PROMISE_DEPOSITSE1).div(BN(2))); @@ -5271,25 +5281,23 @@ describe('Cashier and VoucherKernel', () => { eventUtils.assertEventEmitted( txReceipt, Cashier_Factory, - eventNames.LOG_AMOUNT_DISTRIBUTION, + eventNames.LOG_WITHDRAWAL, (ev) => { - utils.calcTotalAmountToRecipients( - ev, - distributedAmounts, - '_to', - users.other2.address, - users.seller.address - ); + expect(ev._payee).to.be.oneOf([users.other2.address, users.seller.address, users.deployer.address], 'Incorrect Payee'); + switch (ev._payee) { + case users.other2.address: + expect(ev._payment.toNumber()).to.be.oneOf([expectedBuyerAmount.sub(constants.PROMISE_PRICE1).toNumber(), constants.PROMISE_PRICE1]); + break; + case users.seller.address: + expect(ev._payment.toNumber()).to.be.oneOf([BN(constants.PROMISE_DEPOSITSE1).div(4).toNumber(), constants.PROMISE_DEPOSITBU1]); + break; + case users.deployer.address: + assert.equal(ev._payment, BN(constants.PROMISE_DEPOSITSE1).div(4).toNumber()); + break; + } } ); - // const withdrawTx = await utils.withdraw( - // voucherID, - // users.deployer.signer - // ); - - // const txReceipt = await withdrawTx.wait(); - eventUtils.assertEventEmitted( txReceipt, Cashier_Factory, @@ -5378,13 +5386,13 @@ describe('Cashier and VoucherKernel', () => { break; } - // utils.calcTotalAmountToRecipients( - // ev, - // distributedAmounts, - // '_to', - // users.other2.address, - // users.seller.address - // ); + utils.calcTotalAmountToRecipients( + ev, + distributedAmounts, + '_to', + users.other2.address, + users.seller.address + ); } ); @@ -5612,7 +5620,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it.only('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { + it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { const expectedBuyerPrice = BN(constants.PROMISE_PRICE1); const expectedBuyerDeposit = BN(constants.PROMISE_DEPOSITBU1).add( BN(constants.PROMISE_DEPOSITSE1).div(BN(2)) @@ -5649,6 +5657,27 @@ describe('Cashier and VoucherKernel', () => { const txReceipt = await withdrawTx.wait(); + eventUtils.assertEventEmitted( + txReceipt, + Cashier_Factory, + eventNames.LOG_WITHDRAWAL, + (ev) => { + expect(ev._payee).to.be.oneOf([users.other2.address,users.seller.address, users.deployer.address], 'Incorrect Payee' ); + switch (ev._payee) { + case users.other2.address: + expect(ev._payment.toNumber()).to.be.oneOf([constants.PROMISE_PRICE1]); + break; + case users.seller.address: + expect(ev._payment.toNumber()).to.be.oneOf([BN(constants.PROMISE_DEPOSITSE1).div(4).toNumber(), constants.PROMISE_DEPOSITBU1]); + break; + case users.deployer.address: + assert.equal(ev._payment, BN(constants.PROMISE_DEPOSITSE1).div(4).toNumber()); + break; + } + + } + ); + eventUtils.assertEventEmitted( txReceipt, Cashier_Factory, @@ -6014,7 +6043,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it.only('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { + it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { const expectedBuyerPrice = BN(constants.PROMISE_PRICE1); const expectedBuyerDeposit = BN(constants.PROMISE_DEPOSITBU1).add( BN(constants.PROMISE_DEPOSITSE1).div(BN(2)) @@ -6460,7 +6489,29 @@ describe('Cashier and VoucherKernel', () => { 'Escrow did not get expected tokens from PaymentTokenContract' ); - // const txReceipt = await withdrawTx.wait(); + eventUtils.assertEventEmitted( + txReceipt, + Cashier_Factory, + eventNames.LOG_WITHDRAWAL, + (ev) => { + + expect(ev._payee).to.be.oneOf([users.other2.address, users.seller.address, users.deployer.address], 'Incorrect Payee'); + switch (ev._payee) { + case users.other2.address: + assert.equal(ev._payment.toString(),expectedBuyerDeposit.toString(),'Wrong payment amount'); + break; + case users.seller.address: + assert.equal(ev._payment.toString(),BN(constants.PROMISE_DEPOSITSE1).div(4).toString(),'Wrong payment amount'); + break; + case users.deployer.address: + assert.equal(ev._payment, BN(constants.PROMISE_DEPOSITSE1).div(4).toString(),'Wrong payment amount'); + break; + } + } + ); + + + // //Deposits in ETH eventUtils.assertEventEmitted( txReceipt, @@ -6490,10 +6541,10 @@ describe('Cashier and VoucherKernel', () => { ); break; case paymentType.DEPOSIT_SELLER: - // expect(ev._to).to.be.oneOf([users.other2.address, users.buyer.address, contractCashier.address], 'Unexpected recepient'); + expect(ev._to).to.be.oneOf([users.seller.address, users.deployer.address, users.other2.address], 'Unexpected recepient'); switch (ev._to) { - case users.other2.address: + case users.seller.address: assert.equal( ev._tokenIdVoucher.toString(), voucherID.toString(), @@ -6501,11 +6552,11 @@ describe('Cashier and VoucherKernel', () => { ); assert.equal( ev._payment, - BN(constants.PROMISE_DEPOSITSE1).div(2).toString(), + BN(constants.PROMISE_DEPOSITSE1).div(4).toString(), 'Wrong payment amount' ); break; - case users.buyer.address: + case users.deployer.address: assert.equal( ev._tokenIdVoucher.toString(), voucherID.toString(), @@ -6517,7 +6568,7 @@ describe('Cashier and VoucherKernel', () => { 'Wrong payment amount' ); break; - case contractCashier.address: + case users.other2.address: assert.equal( ev._tokenIdVoucher.toString(), voucherID.toString(), @@ -6525,7 +6576,7 @@ describe('Cashier and VoucherKernel', () => { ); assert.equal( ev._payment, - BN(constants.PROMISE_DEPOSITSE1).div(4).toString(), + BN(constants.PROMISE_DEPOSITSE1).div(2).toString(), 'Wrong payment amount' ); break; diff --git a/testHelpers/constants.ts b/testHelpers/constants.ts index b633c038..54e04947 100644 --- a/testHelpers/constants.ts +++ b/testHelpers/constants.ts @@ -32,7 +32,7 @@ let PROMISE_VALID_FROM: number; // evaluated based on the current block timestam let PROMISE_VALID_TO: number; // evaluated based on the PROMISE_VALID_FROM + 2 * SECONDS_IN_DAY const PROMISE_PRICE1 = 10; const PROMISE_PRICE2 = 21; -const PROMISE_DEPOSITSE1 = '1000000'; +const PROMISE_DEPOSITSE1 = 1000000; const PROMISE_DEPOSITSE2 = 5; const PROMISE_DEPOSITBU1 = 1; const PROMISE_DEPOSITBU2 = 2; From 3afbf5239f4606be908410f1ca24a7856d911c30 Mon Sep 17 00:00:00 2001 From: zajck Date: Fri, 8 Oct 2021 17:51:40 +0200 Subject: [PATCH 25/41] fixed LOG_AMOUNT_DISTRIBUTION checks --- test/2_test_fullpath_with_permit.ts | 167 ++++++++++++++++++++-------- 1 file changed, 123 insertions(+), 44 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 935ab67c..1dca7f52 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -4019,13 +4019,19 @@ describe('Cashier and VoucherKernel', () => { Cashier_Factory, eventNames.LOG_WITHDRAWAL, (ev) => { - expect(ev._payee).to.be.oneOf([users.other2.address,users.buyer.address], 'Incorrect Payee'); + expect(ev._payee).to.be.oneOf( + [users.other2.address, users.buyer.address], + 'Incorrect Payee' + ); switch (ev._payee) { case users.other2.address: - expect(ev._payment.toNumber()).to.be.oneOf([constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITSE1]); + expect(ev._payment.toNumber()).to.be.oneOf([ + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITSE1, + ]); break; case users.buyer.address: - assert.equal(ev._payment, constants.PROMISE_DEPOSITBU1); + assert.equal(ev._payment, constants.PROMISE_DEPOSITBU1); break; } } @@ -4963,7 +4969,6 @@ describe('Cashier and VoucherKernel', () => { ); break; } - } ); @@ -5283,16 +5288,32 @@ describe('Cashier and VoucherKernel', () => { Cashier_Factory, eventNames.LOG_WITHDRAWAL, (ev) => { - expect(ev._payee).to.be.oneOf([users.other2.address, users.seller.address, users.deployer.address], 'Incorrect Payee'); + expect(ev._payee).to.be.oneOf( + [ + users.other2.address, + users.seller.address, + users.deployer.address, + ], + 'Incorrect Payee' + ); switch (ev._payee) { case users.other2.address: - expect(ev._payment.toNumber()).to.be.oneOf([expectedBuyerAmount.sub(constants.PROMISE_PRICE1).toNumber(), constants.PROMISE_PRICE1]); + expect(ev._payment.toNumber()).to.be.oneOf([ + expectedBuyerAmount.sub(constants.PROMISE_PRICE1).toNumber(), + constants.PROMISE_PRICE1, + ]); break; - case users.seller.address: - expect(ev._payment.toNumber()).to.be.oneOf([BN(constants.PROMISE_DEPOSITSE1).div(4).toNumber(), constants.PROMISE_DEPOSITBU1]); + case users.seller.address: + expect(ev._payment.toNumber()).to.be.oneOf([ + BN(constants.PROMISE_DEPOSITSE1).div(4).toNumber(), + constants.PROMISE_DEPOSITBU1, + ]); break; - case users.deployer.address: - assert.equal(ev._payment, BN(constants.PROMISE_DEPOSITSE1).div(4).toNumber()); + case users.deployer.address: + assert.equal( + ev._payment, + BN(constants.PROMISE_DEPOSITSE1).div(4).toNumber() + ); break; } } @@ -5326,7 +5347,14 @@ describe('Cashier and VoucherKernel', () => { ); break; case paymentType.DEPOSIT_SELLER: - // expect(ev._type).to.be.oneOf([users.other2.address, users.buyer.address, contractCashier.address], 'Unexpected recepient'); + expect(ev._to).to.be.oneOf( + [ + users.seller.address, + users.deployer.address, + users.other2.address, + ], + 'Unexpected recepient' + ); switch (ev._to) { case users.other2.address: @@ -5341,7 +5369,7 @@ describe('Cashier and VoucherKernel', () => { 'Wrong payment amount' ); break; - case users.buyer.address: + case users.seller.address: assert.equal( ev._tokenIdVoucher.toString(), voucherID.toString(), @@ -5353,7 +5381,7 @@ describe('Cashier and VoucherKernel', () => { 'Wrong payment amount' ); break; - case contractCashier.address: + case users.deployer.address: assert.equal( ev._tokenIdVoucher.toString(), voucherID.toString(), @@ -5662,19 +5690,33 @@ describe('Cashier and VoucherKernel', () => { Cashier_Factory, eventNames.LOG_WITHDRAWAL, (ev) => { - expect(ev._payee).to.be.oneOf([users.other2.address,users.seller.address, users.deployer.address], 'Incorrect Payee' ); + expect(ev._payee).to.be.oneOf( + [ + users.other2.address, + users.seller.address, + users.deployer.address, + ], + 'Incorrect Payee' + ); switch (ev._payee) { - case users.other2.address: - expect(ev._payment.toNumber()).to.be.oneOf([constants.PROMISE_PRICE1]); - break; + case users.other2.address: + expect(ev._payment.toNumber()).to.be.oneOf([ + constants.PROMISE_PRICE1, + ]); + break; case users.seller.address: - expect(ev._payment.toNumber()).to.be.oneOf([BN(constants.PROMISE_DEPOSITSE1).div(4).toNumber(), constants.PROMISE_DEPOSITBU1]); - break; + expect(ev._payment.toNumber()).to.be.oneOf([ + BN(constants.PROMISE_DEPOSITSE1).div(4).toNumber(), + constants.PROMISE_DEPOSITBU1, + ]); + break; case users.deployer.address: - assert.equal(ev._payment, BN(constants.PROMISE_DEPOSITSE1).div(4).toNumber()); - break; - } - + assert.equal( + ev._payment, + BN(constants.PROMISE_DEPOSITSE1).div(4).toNumber() + ); + break; + } } ); @@ -5707,7 +5749,14 @@ describe('Cashier and VoucherKernel', () => { ); break; case paymentType.DEPOSIT_SELLER: - // expect(ev._to).to.be.oneOf([users.other2.address, users.buyer.address, contractCashier.address], 'Unexpected recepient'); + expect(ev._to).to.be.oneOf( + [ + users.seller.address, + users.deployer.address, + users.other2.address, + ], + 'Unexpected recepient' + ); switch (ev._to) { case users.other2.address: @@ -5722,7 +5771,7 @@ describe('Cashier and VoucherKernel', () => { 'Wrong payment amount' ); break; - case users.buyer.address: + case users.seller.address: assert.equal( ev._tokenIdVoucher.toString(), voucherID.toString(), @@ -5734,7 +5783,7 @@ describe('Cashier and VoucherKernel', () => { 'Wrong payment amount' ); break; - case contractCashier.address: + case users.deployer.address: assert.equal( ev._tokenIdVoucher.toString(), voucherID.toString(), @@ -6111,7 +6160,14 @@ describe('Cashier and VoucherKernel', () => { ); break; case paymentType.DEPOSIT_SELLER: - // expect(ev._to).to.be.oneOf([users.other2.address, users.buyer.address, contractCashier.address], 'Unexpected recepient'); + expect(ev._to).to.be.oneOf( + [ + users.seller.address, + users.deployer.address, + users.other2.address, + ], + 'Unexpected recepient' + ); switch (ev._to) { case users.other2.address: @@ -6126,7 +6182,7 @@ describe('Cashier and VoucherKernel', () => { 'Wrong payment amount' ); break; - case users.buyer.address: + case users.seller.address: assert.equal( ev._tokenIdVoucher.toString(), voucherID.toString(), @@ -6138,7 +6194,7 @@ describe('Cashier and VoucherKernel', () => { 'Wrong payment amount' ); break; - case contractCashier.address: + case users.deployer: assert.equal( ev._tokenIdVoucher.toString(), voucherID.toString(), @@ -6430,7 +6486,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it.only('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { + it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { const expectedBuyerPrice = BN(constants.PROMISE_PRICE1); const expectedSellerPrice = BN(0); const expectedEscrowPrice = BN(0); @@ -6494,24 +6550,40 @@ describe('Cashier and VoucherKernel', () => { Cashier_Factory, eventNames.LOG_WITHDRAWAL, (ev) => { - - expect(ev._payee).to.be.oneOf([users.other2.address, users.seller.address, users.deployer.address], 'Incorrect Payee'); - switch (ev._payee) { - case users.other2.address: - assert.equal(ev._payment.toString(),expectedBuyerDeposit.toString(),'Wrong payment amount'); - break; + expect(ev._payee).to.be.oneOf( + [ + users.other2.address, + users.seller.address, + users.deployer.address, + ], + 'Incorrect Payee' + ); + switch (ev._payee) { + case users.other2.address: + assert.equal( + ev._payment.toString(), + expectedBuyerDeposit.toString(), + 'Wrong payment amount' + ); + break; case users.seller.address: - assert.equal(ev._payment.toString(),BN(constants.PROMISE_DEPOSITSE1).div(4).toString(),'Wrong payment amount'); - break; + assert.equal( + ev._payment.toString(), + BN(constants.PROMISE_DEPOSITSE1).div(4).toString(), + 'Wrong payment amount' + ); + break; case users.deployer.address: - assert.equal(ev._payment, BN(constants.PROMISE_DEPOSITSE1).div(4).toString(),'Wrong payment amount'); - break; - } + assert.equal( + ev._payment, + BN(constants.PROMISE_DEPOSITSE1).div(4).toString(), + 'Wrong payment amount' + ); + break; + } } ); - - // //Deposits in ETH eventUtils.assertEventEmitted( txReceipt, @@ -6541,7 +6613,14 @@ describe('Cashier and VoucherKernel', () => { ); break; case paymentType.DEPOSIT_SELLER: - expect(ev._to).to.be.oneOf([users.seller.address, users.deployer.address, users.other2.address], 'Unexpected recepient'); + expect(ev._to).to.be.oneOf( + [ + users.seller.address, + users.deployer.address, + users.other2.address, + ], + 'Unexpected recepient' + ); switch (ev._to) { case users.seller.address: From 6a4345cd992feec192161adabfa360c05ff3b35a Mon Sep 17 00:00:00 2001 From: zajck Date: Fri, 8 Oct 2021 17:52:20 +0200 Subject: [PATCH 26/41] removed conditional (tested elswhere) --- test/2_test_fullpath_with_permit.ts | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 1dca7f52..e9b589de 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -1556,28 +1556,6 @@ describe('Cashier and VoucherKernel', () => { ).to.be.revertedWith(revertReasons.INVALID_VALIDITY_TO); }); - it('Create Conditional Commit', async () => { - // ?? todo - expect( - await utils.createOrderConditional( - users.seller, - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - constants.seller_deposit, - constants.QTY_10, - users.seller, - 0, - true - ) - ).to.emit( - contractBosonRouter, - eventNames.LOG_CONDITIONAL_ORDER_CREATED - ); - - // .withArgs(); should calculate token supply id and compare it it - // console.log(tokenSupplyID) - }); - it('[NEGATIVE] Should revert if token price contract address is zero address', async () => { const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); const nonce = await contractBSNTokenDeposit.nonces( From cf2e7c253817f983e01fc431e6e9517fcecc5f97 Mon Sep 17 00:00:00 2001 From: zajck Date: Fri, 8 Oct 2021 18:01:57 +0200 Subject: [PATCH 27/41] minor changes --- test/2_test_fullpath_with_permit.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index e9b589de..3d266e80 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -1696,7 +1696,6 @@ describe('Cashier and VoucherKernel', () => { }); describe('TOKEN SUPPLY CANCELLATION', () => { - // TODO: rewrite to match style before(async () => { await deployContracts(); @@ -1790,7 +1789,7 @@ describe('Cashier and VoucherKernel', () => { describe('VOUCHER CREATION (Commit to buy)', () => { const ORDER_QTY = 5; - let TOKEN_SUPPLY_ID; // todo not really needed probably + let TOKEN_SUPPLY_ID; // calculate expected tokenSupplyID for first voucher const tokenIndex = constants.ONE; @@ -3552,7 +3551,7 @@ describe('Cashier and VoucherKernel', () => { DEPOSIT_BUYER: 2, }; - afterEach(() => { + beforeEach(() => { distributedAmounts = { buyerAmount: BN(0), sellerAmount: BN(0), @@ -5032,7 +5031,7 @@ describe('Cashier and VoucherKernel', () => { DEPOSIT_BUYER: 2, }; - afterEach(() => { + beforeEach(() => { distributedAmounts = { buyerAmount: BN(0), sellerAmount: BN(0), @@ -5524,7 +5523,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - afterEach(async () => { + beforeEach(async () => { distributedAmounts = { buyerAmount: BN(0), sellerAmount: BN(0), From cdc683f1d1b5f5fc97cb832db773ce88c4acdd66 Mon Sep 17 00:00:00 2001 From: zajck Date: Mon, 11 Oct 2021 07:11:17 +0200 Subject: [PATCH 28/41] new promiseId calculation --- test/2_test_fullpath_with_permit.ts | 37 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 3d266e80..7f5ae3e9 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -53,23 +53,6 @@ describe('Cashier and VoucherKernel', () => { await setPeriods(); - // calculate expected tokenSupplyID for first voucher - promiseId = keccak256( - solidityPack( - ['address', 'uint256', 'uint256', 'uint256'], - [ - users.seller.address, - constants.ZERO, - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - ] - ) - ); - - // calculate expected tokenSupplyID for first voucher - const tokenIndex = constants.ONE; - const TYPE_NF_BIT = constants.ONE.shl(255); - tokenSupplyKey = TYPE_NF_BIT.or(tokenIndex.shl(128)).toString(); }); let contractERC1155ERC721: ERC1155ERC721, @@ -183,6 +166,26 @@ describe('Cashier and VoucherKernel', () => { contractBSNTokenDeposit.address, contractBSNTokenDeposit.address ); + + + // calculate expected tokenSupplyID for first voucher + promiseId = keccak256( + solidityPack( + ['address', 'uint256', 'uint256', 'uint256', 'address'], + [ + users.seller.address, + constants.ZERO, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + contractVoucherKernel.address, + ] + ) +); + + // calculate expected tokenSupplyID for first voucher + const tokenIndex = constants.ONE; + const TYPE_NF_BIT = constants.ONE.shl(255); + tokenSupplyKey = TYPE_NF_BIT.or(tokenIndex.shl(128)).toString(); } describe('TOKEN SUPPLY CREATION (Voucher batch creation)', () => { From b22a4ece47c985f371e0136d866e6852b4d44567 Mon Sep 17 00:00:00 2001 From: zajck Date: Mon, 11 Oct 2021 07:25:40 +0200 Subject: [PATCH 29/41] explicit input parameters --- test/2_test_fullpath_with_permit.ts | 575 ++++++++++++++++++++++------ 1 file changed, 462 insertions(+), 113 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 7f5ae3e9..259d60b1 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -52,7 +52,6 @@ describe('Cashier and VoucherKernel', () => { ); await setPeriods(); - }); let contractERC1155ERC721: ERC1155ERC721, @@ -167,20 +166,19 @@ describe('Cashier and VoucherKernel', () => { contractBSNTokenDeposit.address ); - - // calculate expected tokenSupplyID for first voucher - promiseId = keccak256( - solidityPack( - ['address', 'uint256', 'uint256', 'uint256', 'address'], - [ - users.seller.address, - constants.ZERO, - constants.PROMISE_VALID_FROM, - constants.PROMISE_VALID_TO, - contractVoucherKernel.address, - ] - ) -); + // calculate expected tokenSupplyID for first voucher + promiseId = keccak256( + solidityPack( + ['address', 'uint256', 'uint256', 'uint256', 'address'], + [ + users.seller.address, + constants.ZERO, + constants.PROMISE_VALID_FROM, + constants.PROMISE_VALID_TO, + contractVoucherKernel.address, + ] + ) + ); // calculate expected tokenSupplyID for first voucher const tokenIndex = constants.ONE; @@ -220,7 +218,9 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, constants.QTY_10, - true + true, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ) ) .to.emit(contractBosonRouter, eventNames.LOG_ORDER_CREATED) @@ -256,7 +256,10 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, - constants.QTY_10 + constants.QTY_10, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); }); @@ -407,7 +410,14 @@ describe('Cashier and VoucherKernel', () => { ).to.equal(constants.QTY_10, 'Remaining qty is not correct'); for (let i = 0; i < vouchersToBuy; i++) { - await utils.commitToBuy(users.buyer, users.seller, tokenSupplyKey); + await utils.commitToBuy( + users.buyer, + users.seller, + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 + ); expect( await contractVoucherKernel.getRemQtyForSupply( tokenSupplyKey, @@ -463,7 +473,10 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_FROM + constants.ONE_MINUTE, constants.PROMISE_DEPOSITSE1, - constants.QTY_10 + constants.QTY_10, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ) ).to.be.revertedWith(revertReasons.INVALID_VALIDITY_TO); }); @@ -555,7 +568,9 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, constants.QTY_10, - true + true, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ) ) .to.emit(contractBosonRouter, eventNames.LOG_ORDER_CREATED) @@ -591,7 +606,10 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, - constants.QTY_10 + constants.QTY_10, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); }); @@ -758,7 +776,10 @@ describe('Cashier and VoucherKernel', () => { await utils.commitToBuy( users.buyer, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); expect( await contractVoucherKernel.getRemQtyForSupply( @@ -815,7 +836,10 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_FROM + constants.ONE_MINUTE, constants.PROMISE_DEPOSITSE1, - constants.QTY_10 + constants.QTY_10, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ) ).to.be.revertedWith(revertReasons.INVALID_VALIDITY_TO); }); @@ -944,7 +968,9 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, constants.QTY_10, - true + true, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ) ) .to.emit(contractBosonRouter, eventNames.LOG_ORDER_CREATED) @@ -980,7 +1006,10 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, - constants.QTY_10 + constants.QTY_10, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); }); @@ -1136,7 +1165,10 @@ describe('Cashier and VoucherKernel', () => { await utils.commitToBuy( users.buyer, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); expect( await contractVoucherKernel.getRemQtyForSupply( @@ -1294,7 +1326,9 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITBU1, constants.QTY_10, - true + true, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ) ) .to.emit(contractBosonRouter, eventNames.LOG_ORDER_CREATED) @@ -1330,7 +1364,10 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, - constants.QTY_10 + constants.QTY_10, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); }); @@ -1497,7 +1534,10 @@ describe('Cashier and VoucherKernel', () => { await utils.commitToBuy( users.buyer, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); expect( await contractVoucherKernel.getRemQtyForSupply( @@ -1554,7 +1594,10 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_FROM + constants.ONE_MINUTE, constants.PROMISE_DEPOSITSE1, - constants.QTY_10 + constants.QTY_10, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ) ).to.be.revertedWith(revertReasons.INVALID_VALIDITY_TO); }); @@ -1718,7 +1761,10 @@ describe('Cashier and VoucherKernel', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_10 + constants.QTY_10, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); }); @@ -1792,7 +1838,7 @@ describe('Cashier and VoucherKernel', () => { describe('VOUCHER CREATION (Commit to buy)', () => { const ORDER_QTY = 5; - let TOKEN_SUPPLY_ID; + let TOKEN_SUPPLY_ID; // calculate expected tokenSupplyID for first voucher const tokenIndex = constants.ONE; @@ -1818,13 +1864,23 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, - constants.QTY_10 + constants.QTY_10, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); }); it('Should create order', async () => { await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, true) + utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + true, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 + ) ) .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_DELIVERED) .withArgs( @@ -1848,7 +1904,14 @@ describe('Cashier and VoucherKernel', () => { describe('After request', () => { beforeEach(async () => { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID); + await utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 + ); }); it('Voucher Kernel state is correct', async () => { @@ -1987,7 +2050,14 @@ describe('Cashier and VoucherKernel', () => { ); await expect( - utilsTknEth.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID) + utilsTknEth.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 + ) ).to.be.revertedWith(revertReasons.INCORRECT_PAYMENT_METHOD); }); @@ -2056,13 +2126,23 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, - ORDER_QTY + ORDER_QTY, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); }); it('Should create order', async () => { await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, true) + utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + true, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 + ) ) .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_DELIVERED) .withArgs( @@ -2100,7 +2180,14 @@ describe('Cashier and VoucherKernel', () => { describe('After request', () => { beforeEach(async () => { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID); + await utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 + ); }); it('Voucher Kernel state is correct', async () => { @@ -2259,7 +2346,14 @@ describe('Cashier and VoucherKernel', () => { ); await expect( - utilsEthEth.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID) + utilsEthEth.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 + ) ).to.be.revertedWith(revertReasons.INCORRECT_PAYMENT_METHOD); }); @@ -2331,13 +2425,23 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, - ORDER_QTY + ORDER_QTY, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); }); it('Should create order', async () => { await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, true) + utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + true, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 + ) ) .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_DELIVERED) .withArgs( @@ -2373,7 +2477,14 @@ describe('Cashier and VoucherKernel', () => { describe('After request', () => { beforeEach(async () => { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID); + await utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 + ); }); it('Voucher Kernel state is correct', async () => { @@ -2529,7 +2640,14 @@ describe('Cashier and VoucherKernel', () => { ); await expect( - utilsEthTkn.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID) + utilsEthTkn.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 + ) ).to.be.revertedWith(revertReasons.INCORRECT_PAYMENT_METHOD); }); @@ -2597,13 +2715,23 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, - ORDER_QTY + ORDER_QTY, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); }); it('Should create voucher', async () => { await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, true) + utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + true, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 + ) ) .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_DELIVERED) .withArgs( @@ -2633,7 +2761,14 @@ describe('Cashier and VoucherKernel', () => { describe('After request', () => { beforeEach(async () => { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID); + await utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 + ); }); it('Voucher Kernel state is correct', async () => { @@ -2779,7 +2914,14 @@ describe('Cashier and VoucherKernel', () => { ); await expect( - utilsEthEth.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID) + utilsEthEth.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 + ) ).to.be.revertedWith(revertReasons.INCORRECT_PAYMENT_METHOD); }); @@ -2841,7 +2983,10 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, - ORDER_QTY + ORDER_QTY, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); const nonce = await utils.contractBSNTokenSame.nonces( @@ -2915,13 +3060,23 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, - ORDER_QTY + ORDER_QTY, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); }); it('Should create order', async () => { await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, true) + utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + true, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 + ) ) .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_DELIVERED) .withArgs( @@ -2951,7 +3106,10 @@ describe('Cashier and VoucherKernel', () => { describe('After request', () => { beforeEach(async () => { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID); + await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID), + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1; }); it('Voucher Kernel state is correct', async () => { @@ -3092,7 +3250,14 @@ describe('Cashier and VoucherKernel', () => { ); await expect( - utilsEthEth.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID) + utilsEthEth.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 + ) ).to.be.revertedWith(revertReasons.INCORRECT_PAYMENT_METHOD); }); @@ -3150,7 +3315,10 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.seller_deposit, - constants.QTY_10 + constants.QTY_10, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); }); @@ -3160,7 +3328,14 @@ describe('Cashier and VoucherKernel', () => { ); await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID) + utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 + ) ).to.be.revertedWith(revertReasons.OFFER_EXPIRED); }); @@ -3168,7 +3343,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await advanceTimeSeconds( constants.PROMISE_VALID_TO + cancelPeriod + complainPeriod @@ -3183,7 +3361,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.cancel(voucherID, users.seller.signer); @@ -3199,7 +3380,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await advanceTimeSeconds( @@ -3215,7 +3399,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await advanceTimeSeconds( @@ -3231,7 +3418,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.redeem(voucherID, users.buyer.signer); @@ -3248,7 +3438,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.redeem(voucherID, users.buyer.signer); @@ -3265,7 +3458,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.redeem(voucherID, users.buyer.signer); await utils.cancel(voucherID, users.seller.signer); @@ -3280,7 +3476,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.redeem(voucherID, users.buyer.signer); @@ -3296,7 +3495,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.refund(voucherID, users.buyer.signer); @@ -3314,7 +3516,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.refund(voucherID, users.buyer.signer); @@ -3332,7 +3537,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.refund(voucherID, users.buyer.signer); @@ -3349,7 +3557,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.refund(voucherID, users.buyer.signer); @@ -3369,7 +3580,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await advanceTimeSeconds(ONE_WEEK); @@ -3409,7 +3623,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await advanceTimeSeconds(ONE_WEEK); @@ -3449,7 +3666,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await advanceTimeSeconds(ONE_WEEK); @@ -3501,7 +3721,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await advanceTimeSeconds(ONE_WEEK); @@ -3580,7 +3803,10 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, - constants.QTY_10 + constants.QTY_10, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); }); @@ -3740,7 +3966,10 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE2, - constants.QTY_20 + constants.QTY_20, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); tokenSupplyBatch = [BN(tokenSupplyKey), BN(tokenSupplyKey2)]; @@ -3911,7 +4140,10 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, - constants.QTY_1 + constants.QTY_1, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); }); @@ -3979,7 +4211,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.other2, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.redeem(voucherID, users.buyer.signer); @@ -4113,7 +4348,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.other2, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.redeem(voucherID, users.buyer.signer); @@ -4135,7 +4373,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.other2, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.redeem(voucherID, users.buyer.signer); @@ -4184,7 +4425,10 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, - constants.QTY_1 + constants.QTY_1, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); }); @@ -4403,7 +4647,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.other2, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.redeem(voucherID, users.buyer.signer); @@ -4425,7 +4672,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.other2, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.redeem(voucherID, users.buyer.signer); @@ -4479,7 +4729,10 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, - supplyQty + supplyQty, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); }); @@ -4552,7 +4805,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.other2, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.redeem(voucherID, users.buyer.signer); @@ -4709,7 +4965,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.other2, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.redeem(voucherID, users.buyer.signer); @@ -4731,7 +4990,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.other2, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.redeem(voucherID, users.buyer.signer); @@ -4770,7 +5032,10 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, - constants.QTY_1 + constants.QTY_1, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); }); @@ -4839,7 +5104,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.other2, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.redeem(voucherID, users.buyer.signer); @@ -4992,7 +5260,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.other2, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.redeem(voucherID, users.buyer.signer); @@ -5014,7 +5285,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.other2, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.redeem(voucherID, users.buyer.signer); @@ -5062,13 +5336,19 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, - constants.QTY_10 + constants.QTY_10, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); }); @@ -5126,7 +5406,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); const balanceBeforeTransfer = ( @@ -5172,7 +5455,10 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, - constants.QTY_10 + constants.QTY_10, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); }); @@ -5241,7 +5527,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.safeTransfer721( @@ -5446,7 +5735,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.safeTransfer721( @@ -5469,7 +5761,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await expect( @@ -5522,7 +5817,10 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, - supplyQty + supplyQty, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); }); @@ -5541,7 +5839,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); let actualOldOwnerBalanceFromEscrowEth = await contractCashier.getEscrowAmount( @@ -5643,7 +5944,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.safeTransfer721( @@ -5858,7 +6162,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.refund(voucherID, users.other1.signer); @@ -5882,7 +6189,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.safeTransfer721( @@ -5905,7 +6215,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await expect( @@ -5962,7 +6275,10 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, - supplyQty + supplyQty, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); }); @@ -5974,7 +6290,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); let actualOldOwnerBalanceFromEscrowTknPrice = await contractCashier.getEscrowTokensAmount( @@ -6089,7 +6408,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.safeTransfer721( @@ -6281,7 +6603,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.refund(voucherID, users.other1.signer); @@ -6305,7 +6630,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.safeTransfer721( @@ -6328,7 +6656,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await expect( @@ -6370,7 +6701,10 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.PROMISE_DEPOSITSE1, - constants.QTY_1 + constants.QTY_1, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); }); @@ -6380,7 +6714,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); let actualOldOwnerBalanceFromEscrowEth = await contractCashier.getEscrowAmount( @@ -6483,7 +6820,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.safeTransfer721( @@ -6708,7 +7048,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.refund(voucherID, users.other1.signer); @@ -6732,7 +7075,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.safeTransfer721( @@ -6754,7 +7100,10 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + false, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await expect( From dfa5c5a643ec592cfa8407954e9dee422a97df6e Mon Sep 17 00:00:00 2001 From: zajck Date: Mon, 11 Oct 2021 07:37:03 +0200 Subject: [PATCH 30/41] explicit inputs in test 3 --- test/3_withdrawals.ts | 355 ++++++++++++++++++++++++++++++++---------- 1 file changed, 277 insertions(+), 78 deletions(-) diff --git a/test/3_withdrawals.ts b/test/3_withdrawals.ts index cf78aa8e..d4610cfa 100644 --- a/test/3_withdrawals.ts +++ b/test/3_withdrawals.ts @@ -259,7 +259,10 @@ describe('Cashier withdrawals ', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.seller_deposit, - constants.QTY_15 + constants.QTY_15, + false, + constants.product_price, + constants.buyer_deposit, ); }); @@ -273,7 +276,7 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -326,7 +329,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.cancel(voucherID, users.seller.signer); @@ -378,7 +384,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); await utils.complain(voucherID, users.buyer.signer); @@ -432,7 +441,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); await utils.cancel(voucherID, users.seller.signer); @@ -485,7 +497,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -538,7 +553,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.cancel(voucherID, users.seller.signer); @@ -591,7 +609,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); @@ -642,7 +663,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); await utils.complain(voucherID, users.buyer.signer); @@ -698,7 +722,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); await utils.complain(voucherID, users.buyer.signer); @@ -755,7 +782,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); await utils.cancel(voucherID, users.seller.signer); @@ -811,7 +841,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); await utils.cancel(voucherID, users.seller.signer); @@ -936,7 +969,10 @@ describe('Cashier withdrawals ', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.seller_deposit, - supplyQty + supplyQty, + false, + constants.product_price, + constants.buyer_deposit, ); }); @@ -966,7 +1002,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -1046,7 +1085,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.cancel(voucherID, users.seller.signer); @@ -1125,7 +1167,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -1204,7 +1249,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -1284,7 +1332,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -1359,7 +1410,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.cancel(voucherID, users.seller.signer); @@ -1437,7 +1491,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); @@ -1512,7 +1569,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); @@ -1589,7 +1649,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); await utils.complain(voucherID, users.buyer.signer); @@ -1670,7 +1733,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); await utils.cancel(voucherID, users.seller.signer); @@ -1751,7 +1817,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); @@ -1885,7 +1954,10 @@ describe('Cashier withdrawals ', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.seller_deposit, - supplyQty + supplyQty, + false, + constants.product_price, + constants.buyer_deposit, ); }); @@ -1908,7 +1980,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); await utils.complain(voucherID, users.buyer.signer); @@ -1970,7 +2045,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.cancel(voucherID, users.seller.signer); @@ -2032,7 +2110,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -2094,7 +2175,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -2157,7 +2241,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -2215,7 +2302,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.cancel(voucherID, users.seller.signer); @@ -2276,7 +2366,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); @@ -2333,7 +2426,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); @@ -2393,7 +2489,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); await utils.complain(voucherID, users.buyer.signer); @@ -2457,7 +2556,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); await utils.cancel(voucherID, users.seller.signer); @@ -2521,7 +2623,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); @@ -2635,7 +2740,10 @@ describe('Cashier withdrawals ', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.seller_deposit, - supplyQty + supplyQty, + false, + constants.product_price, + constants.buyer_deposit, ); }); @@ -2660,7 +2768,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -2735,7 +2846,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.cancel(voucherID, users.seller.signer); @@ -2809,7 +2923,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -2883,7 +3000,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -2958,7 +3078,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -3028,7 +3151,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.cancel(voucherID, users.seller.signer); @@ -3101,7 +3227,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); @@ -3171,7 +3300,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); @@ -3243,7 +3375,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); await utils.complain(voucherID, users.buyer.signer); @@ -3319,7 +3454,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); await utils.complain(voucherID, users.buyer.signer); @@ -3395,7 +3533,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); @@ -3513,7 +3654,10 @@ describe('Cashier withdrawals ', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.seller_deposit, - constants.QTY_1 + constants.QTY_1, + false, + constants.product_price, + constants.buyer_deposit, ); }); @@ -3521,7 +3665,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -3617,7 +3764,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.cancel(voucherID, users.seller.signer); @@ -3712,7 +3862,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -3807,7 +3960,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -3903,7 +4059,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -3994,7 +4153,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.cancel(voucherID, users.seller.signer); @@ -4088,7 +4250,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); @@ -4179,7 +4344,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); @@ -4272,7 +4440,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); await utils.complain(voucherID, users.buyer.signer); @@ -4369,7 +4540,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); await utils.cancel(voucherID, users.seller.signer); @@ -4466,7 +4640,10 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(voucherID, users.buyer.signer); @@ -4575,7 +4752,7 @@ describe('Cashier withdrawals ', () => { }); }); - describe('Seller cancels uncommitted voucher set', () => { + describe.only('Seller cancels uncommitted voucher set', () => { let remQty = 10; let voucherToBuyBeforeBurn = 5; let tokensToMintSeller, tokensToMintBuyer; @@ -4599,11 +4776,15 @@ describe('Cashier withdrawals ', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.seller_deposit, - constants.QTY_10 + constants.QTY_10, + false, + constants.product_price, + constants.buyer_deposit, ); for (let i = 0; i < voucherToBuyBeforeBurn; i++) { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID); + await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit); + // utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit) remQty--; } }); @@ -4674,7 +4855,7 @@ describe('Cashier withdrawals ', () => { it('[NEGATIVE] Buyer should not be able to commit to buy anything from the burnt supply', async () => { await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID) + utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit) ).to.be.revertedWith(revertReasons.OFFER_EMPTY); }); @@ -4742,11 +4923,14 @@ describe('Cashier withdrawals ', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.seller_deposit, - constants.QTY_10 + constants.QTY_10, + false, + constants.product_price, + constants.buyer_deposit, ); for (let i = 0; i < voucherToBuyBeforeBurn; i++) { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID); + await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit); remQty--; } }); @@ -4835,7 +5019,7 @@ describe('Cashier withdrawals ', () => { it('[NEGATIVE] Buyer should not be able to commit to buy anything from the burnt supply', async () => { await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID) + utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit) ).to.be.revertedWith(revertReasons.OFFER_EMPTY); }); @@ -4901,11 +5085,14 @@ describe('Cashier withdrawals ', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.seller_deposit, - constants.QTY_10 + constants.QTY_10, + false, + constants.product_price, + constants.buyer_deposit, ); for (let i = 0; i < voucherToBuyBeforeBurn; i++) { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID); + await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit); remQty--; } }); @@ -4994,7 +5181,7 @@ describe('Cashier withdrawals ', () => { it('[NEGATIVE] Buyer should not be able to commit to buy anything from the burnt supply', async () => { await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID) + utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit) ).to.be.revertedWith(revertReasons.OFFER_EMPTY); }); @@ -5053,11 +5240,14 @@ describe('Cashier withdrawals ', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.seller_deposit, - constants.QTY_10 + constants.QTY_10, + false, + constants.product_price, + constants.buyer_deposit, ); for (let i = 0; i < voucherToBuyBeforeBurn; i++) { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID); + await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit); remQty--; } }); @@ -5131,7 +5321,7 @@ describe('Cashier withdrawals ', () => { it('[NEGATIVE] Buyer should not be able to commit to buy anything from the burnt supply', async () => { await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID) + utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit) ).to.be.revertedWith(revertReasons.OFFER_EMPTY); }); @@ -5182,7 +5372,10 @@ describe('Cashier withdrawals ', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.seller_deposit, - constants.QTY_10 + constants.QTY_10, + false, + constants.product_price, + constants.buyer_deposit, ); }); @@ -5222,11 +5415,14 @@ describe('Cashier withdrawals ', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.seller_deposit, - constants.QTY_10 + constants.QTY_10, + false, + constants.product_price, + constants.buyer_deposit, ); for (let i = 0; i < vouchersToBuy; i++) { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID); + await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit); } await contractBosonRouter.pause(); @@ -5389,11 +5585,14 @@ describe('Cashier withdrawals ', () => { constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, constants.seller_deposit, - constants.QTY_10 + constants.QTY_10, + false, + constants.product_price, + constants.buyer_deposit, ); for (let i = 0; i < vouchersToBuy; i++) { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID); + await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit); } await contractBosonRouter.pause(); From d2f14a39e5617e161e4983148d48094c72647c5c Mon Sep 17 00:00:00 2001 From: zajck Date: Mon, 11 Oct 2021 07:49:35 +0200 Subject: [PATCH 31/41] explicit inputs 4 --- test/4_pausing_contracts.ts | 179 ++++++++++++++++++++++++++---------- 1 file changed, 129 insertions(+), 50 deletions(-) diff --git a/test/4_pausing_contracts.ts b/test/4_pausing_contracts.ts index abae989c..8c5b0f7e 100644 --- a/test/4_pausing_contracts.ts +++ b/test/4_pausing_contracts.ts @@ -227,7 +227,10 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_1 + constants.QTY_1, + false, + constants.product_price, + constants.buyer_deposit ) ).to.be.revertedWith(revertReasons.PAUSED); }); @@ -238,7 +241,10 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_1 + constants.QTY_1, + false, + constants.product_price, + constants.buyer_deposit ); assert.isNotEmpty(TOKEN_SUPPLY_ID); @@ -250,13 +256,19 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_1 + constants.QTY_1, + false, + constants.product_price, + constants.buyer_deposit ); await contractBosonRouter.pause(); await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID) + utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit) ).to.be.revertedWith(revertReasons.PAUSED); }); }); @@ -303,7 +315,10 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_1 + constants.QTY_1, + false, + constants.product_price, + constants.buyer_deposit ) ).to.be.revertedWith(revertReasons.PAUSED); }); @@ -314,7 +329,10 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_1 + constants.QTY_1, + false, + constants.product_price, + constants.buyer_deposit ); assert.isNotEmpty(TOKEN_SUPPLY_ID); @@ -326,13 +344,19 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_1 + constants.QTY_1, + false, + constants.product_price, + constants.buyer_deposit ); await contractBosonRouter.pause(); await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID) + utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit) ).to.be.revertedWith(revertReasons.PAUSED); }); }); @@ -369,7 +393,10 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_10 + constants.QTY_10, + false, + constants.product_price, + constants.buyer_deposit ); }); @@ -382,7 +409,10 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_1 + constants.QTY_1, + false, + constants.product_price, + constants.buyer_deposit ) ).to.be.revertedWith(revertReasons.PAUSED); }); @@ -393,7 +423,10 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_1 + constants.QTY_1, + false, + constants.product_price, + constants.buyer_deposit ); assert.isNotEmpty(TOKEN_SUPPLY_ID); @@ -405,13 +438,16 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_1 + constants.QTY_1, + false, + constants.product_price, + constants.buyer_deposit ); await contractBosonRouter.pause(); await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID) + utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit) ).to.be.revertedWith(revertReasons.PAUSED); }); }); @@ -464,7 +500,10 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_1 + constants.QTY_1, + false, + constants.product_price, + constants.buyer_deposit ) ).to.be.revertedWith(revertReasons.PAUSED); }); @@ -475,7 +514,10 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_1 + constants.QTY_1, + false, + constants.product_price, + constants.buyer_deposit ); assert.isNotEmpty(TOKEN_SUPPLY_ID); @@ -487,13 +529,16 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_1 + constants.QTY_1, + false, + constants.product_price, + constants.buyer_deposit ); await contractBosonRouter.pause(); await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID) + utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit) ).to.be.revertedWith(revertReasons.PAUSED); }); }); @@ -559,7 +604,10 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_10 + constants.QTY_10, + false, + constants.product_price, + constants.buyer_deposit ); }); @@ -567,7 +615,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -581,7 +629,10 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.refund(VOUCHER_ID, users.buyer.signer); @@ -597,7 +648,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -611,7 +662,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await utils.redeem(VOUCHER_ID, users.buyer.signer); @@ -661,7 +712,10 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_10 + constants.QTY_10, + false, + constants.product_price, + constants.buyer_deposit ); }); @@ -669,7 +723,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -683,7 +737,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await utils.refund(VOUCHER_ID, users.buyer.signer); @@ -699,7 +753,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -713,7 +767,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await utils.redeem(VOUCHER_ID, users.buyer.signer); @@ -757,7 +811,10 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_10 + constants.QTY_10, + false, + constants.product_price, + constants.buyer_deposit ); }); @@ -765,7 +822,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -779,7 +836,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await utils.refund(VOUCHER_ID, users.buyer.signer); @@ -795,7 +852,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -809,7 +866,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await utils.redeem(VOUCHER_ID, users.buyer.signer); @@ -863,7 +920,10 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_10 + constants.QTY_10, + false, + constants.product_price, + constants.buyer_deposit ); }); @@ -871,7 +931,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -885,7 +945,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await utils.refund(VOUCHER_ID, users.buyer.signer); @@ -901,7 +961,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -915,7 +975,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await utils.redeem(VOUCHER_ID, users.buyer.signer); @@ -925,6 +985,7 @@ describe('Cashier && VK', () => { utils.cancel(VOUCHER_ID, users.seller.signer) ).to.be.revertedWith(revertReasons.PAUSED); }); + }); describe('TKNTKN Same', () => { @@ -964,7 +1025,10 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_10 + constants.QTY_10, + false, + constants.product_price, + constants.buyer_deposit ); }); @@ -972,7 +1036,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -986,7 +1050,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await utils.refund(VOUCHER_ID, users.buyer.signer); @@ -1002,7 +1066,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -1016,7 +1080,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await utils.redeem(VOUCHER_ID, users.buyer.signer); @@ -1109,13 +1173,16 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_1 + constants.QTY_1, + false, + constants.product_price, + constants.buyer_deposit ); const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -1169,13 +1236,16 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_1 + constants.QTY_1, + false, + constants.product_price, + constants.buyer_deposit ); const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -1222,13 +1292,16 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_1 + constants.QTY_1, + false, + constants.product_price, + constants.buyer_deposit ); const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -1288,13 +1361,19 @@ describe('Cashier && VK', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_1 + constants.QTY_1, + false, + constants.product_price, + constants.buyer_deposit ); const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); From d9e27ad9030c64f3e3107f40132d53e389144908 Mon Sep 17 00:00:00 2001 From: zajck Date: Mon, 11 Oct 2021 07:56:37 +0200 Subject: [PATCH 32/41] explicit inputs test 6 --- test/6_erc1155721.ts | 73 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 16 deletions(-) diff --git a/test/6_erc1155721.ts b/test/6_erc1155721.ts index ef97f959..a805a76e 100644 --- a/test/6_erc1155721.ts +++ b/test/6_erc1155721.ts @@ -215,11 +215,15 @@ describe('ERC1155ERC721', () => { timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, constants.QTY_10, - true + true, + constants.product_price, + constants.buyer_deposit ); + const txReceipt = await txFillOrder.wait(); + eventUtils.assertEventEmitted( - txFillOrder, + txReceipt, ERC1155ERC721_Factory, eventNames.TRANSFER_SINGLE, (ev) => { @@ -249,11 +253,15 @@ describe('ERC1155ERC721', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - true + true, + constants.product_price, + constants.buyer_deposit ); + const txReceipt = await commitTx.wait(); + eventUtils.assertEventEmitted( - commitTx, + txReceipt, ERC1155ERC721_Factory, eventNames.TRANSFER_SINGLE, (ev) => { @@ -274,7 +282,7 @@ describe('ERC1155ERC721', () => { ); eventUtils.assertEventEmitted( - commitTx, + txReceipt, ERC1155ERC721_Factory, eventNames.TRANSFER, (ev) => { @@ -293,7 +301,10 @@ describe('ERC1155ERC721', () => { const token721 = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); const owner721Instance = contractERC1155ERC721.connect( @@ -333,7 +344,10 @@ describe('ERC1155ERC721', () => { const token721 = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); const attackerInstance = contractERC1155ERC721.connect( @@ -349,7 +363,10 @@ describe('ERC1155ERC721', () => { const token721 = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); const attackerInstance = contractERC1155ERC721.connect( @@ -382,7 +399,10 @@ describe('ERC1155ERC721', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_10 + constants.QTY_10, + false, + constants.product_price, + constants.buyer_deposit ); }); @@ -500,7 +520,10 @@ describe('ERC1155ERC721', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_10 + constants.QTY_10, + false, + constants.product_price, + constants.buyer_deposit ); }); @@ -526,7 +549,10 @@ describe('ERC1155ERC721', () => { const erc721 = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await expect( @@ -543,7 +569,10 @@ describe('ERC1155ERC721', () => { const erc721 = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await expect( @@ -560,7 +589,10 @@ describe('ERC1155ERC721', () => { const erc721 = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await expect( @@ -577,7 +609,10 @@ describe('ERC1155ERC721', () => { const erc721 = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await expect( @@ -618,13 +653,19 @@ describe('ERC1155ERC721', () => { timestamp, timestamp + constants.SECONDS_IN_DAY, constants.seller_deposit, - constants.QTY_10 + constants.QTY_10, + false, + constants.product_price, + constants.buyer_deposit ); erc721 = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID + TOKEN_SUPPLY_ID, + false, + constants.product_price, + constants.buyer_deposit ); await contractERC1155ERC721._setMetadataBase(metadataBase); From 16ef5e66bdaf636358ca781b667656a576c58c44 Mon Sep 17 00:00:00 2001 From: zajck Date: Mon, 11 Oct 2021 08:04:19 +0200 Subject: [PATCH 33/41] explicit parameters 11,12 --- test/11_gate.ts | 7 +++++-- test/12_conditional_commit.ts | 32 +++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/test/11_gate.ts b/test/11_gate.ts index 3c2b18a9..a55157fb 100644 --- a/test/11_gate.ts +++ b/test/11_gate.ts @@ -228,7 +228,10 @@ describe('Gate contract', async () => { constants.seller_deposit, constants.QTY_10, gate, - conditionalOrderNftTokenID + conditionalOrderNftTokenID, + true, + constants.product_price, + constants.buyer_deposit ); const txReceipt = await txOrder.wait(); @@ -481,7 +484,7 @@ describe('Gate contract', async () => { expect(await contractGate.check(users.buyer.address, tokenId)).to.be .true; - await utils.commitToBuy(users.buyer, users.seller, tokenId); + await utils.commitToBuy(users.buyer, users.seller, tokenId, false, constants.product_price, constants.buyer_deposit); expect(await contractGate.check(users.buyer.address, tokenId)).to.be .false; diff --git a/test/12_conditional_commit.ts b/test/12_conditional_commit.ts index 3ea41799..aee41ee1 100644 --- a/test/12_conditional_commit.ts +++ b/test/12_conditional_commit.ts @@ -1894,7 +1894,10 @@ describe('Create Voucher sets and commit to vouchers with token conditional comm constants.PROMISE_DEPOSITSE1, constants.QTY_10, contractGate, - 0 + 0, + true, + constants.product_price, + constants.buyer_deposit ); const txReceipt = await txOrder.wait(); @@ -1993,7 +1996,7 @@ describe('Create Voucher sets and commit to vouchers with token conditional comm }); it('[NEGATIVE] Should not be able to request voucher twice', async () => { - await utils.commitToBuy(users.buyer, users.seller, tokenSupplyKey); + await utils.commitToBuy(users.buyer, users.seller, tokenSupplyKey, false, constants.product_price, constants.buyer_deposit); const {txValue, DEPOSIT, PRICE} = await generateInputs( users.buyer, @@ -2067,7 +2070,10 @@ describe('Create Voucher sets and commit to vouchers with token conditional comm constants.seller_deposit, constants.QTY_10, users.other1, /// gate address that maps to EOA - 0 + 0, + false, + constants.product_price, + constants.buyer_deposit ); const tokenSupplyKey = calculateTokenSupplyKey(constants.TWO); @@ -2112,7 +2118,10 @@ describe('Create Voucher sets and commit to vouchers with token conditional comm constants.seller_deposit, constants.QTY_10, contractGate, - 0 + 0, + false, + constants.product_price, + constants.buyer_deposit ); const tokenSupplyKey = calculateTokenSupplyKey(constants.TWO); @@ -2221,7 +2230,10 @@ describe('Create Voucher sets and commit to vouchers with token conditional comm constants.PROMISE_DEPOSITSE1, constants.QTY_10, contractGate, - 0 + 0, + true, + constants.product_price, + constants.buyer_deposit ); const txReceipt = await txOrder.wait(); @@ -2381,7 +2393,10 @@ describe('Create Voucher sets and commit to vouchers with token conditional comm constants.seller_deposit, constants.QTY_10, users.other1, /// gate address that maps to EOA - 0 + 0, + false, + constants.product_price, + constants.buyer_deposit ); const tokenSupplyKey = calculateTokenSupplyKey(constants.TWO); @@ -2416,7 +2431,10 @@ describe('Create Voucher sets and commit to vouchers with token conditional comm constants.seller_deposit, constants.QTY_10, contractGate, - 0 + 0, + false, + constants.product_price, + constants.buyer_deposit ); const tokenSupplyKey = calculateTokenSupplyKey(constants.TWO); From 3fb58b347ce53f72ea3c6833eb62547e510186c3 Mon Sep 17 00:00:00 2001 From: zajck Date: Mon, 11 Oct 2021 08:32:28 +0200 Subject: [PATCH 34/41] createOrder - parameters order --- test/11_gate.ts | 6 +- test/12_conditional_commit.ts | 40 ++-- test/2_test_fullpath_with_permit.ts | 336 +++++++++++++--------------- test/3_withdrawals.ts | 62 +++-- test/4_pausing_contracts.ts | 154 ++++++------- test/6_erc1155721.ts | 27 +-- testHelpers/utils.ts | 44 ++-- 7 files changed, 299 insertions(+), 370 deletions(-) diff --git a/test/11_gate.ts b/test/11_gate.ts index a55157fb..ce588ce0 100644 --- a/test/11_gate.ts +++ b/test/11_gate.ts @@ -225,13 +225,13 @@ describe('Gate contract', async () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, + constants.product_price, constants.seller_deposit, + constants.buyer_deposit, constants.QTY_10, gate, conditionalOrderNftTokenID, - true, - constants.product_price, - constants.buyer_deposit + true ); const txReceipt = await txOrder.wait(); diff --git a/test/12_conditional_commit.ts b/test/12_conditional_commit.ts index aee41ee1..568458e7 100644 --- a/test/12_conditional_commit.ts +++ b/test/12_conditional_commit.ts @@ -1891,13 +1891,13 @@ describe('Create Voucher sets and commit to vouchers with token conditional comm users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, + constants.product_price, constants.PROMISE_DEPOSITSE1, + constants.buyer_deposit, constants.QTY_10, contractGate, 0, - true, - constants.product_price, - constants.buyer_deposit + true ); const txReceipt = await txOrder.wait(); @@ -2067,13 +2067,12 @@ describe('Create Voucher sets and commit to vouchers with token conditional comm users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, + constants.product_price, constants.seller_deposit, + constants.buyer_deposit, constants.QTY_10, users.other1, /// gate address that maps to EOA - 0, - false, - constants.product_price, - constants.buyer_deposit + 0 ); const tokenSupplyKey = calculateTokenSupplyKey(constants.TWO); @@ -2115,13 +2114,12 @@ describe('Create Voucher sets and commit to vouchers with token conditional comm users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, + constants.product_price, constants.seller_deposit, + constants.buyer_deposit, constants.QTY_10, contractGate, - 0, - false, - constants.product_price, - constants.buyer_deposit + 0 ); const tokenSupplyKey = calculateTokenSupplyKey(constants.TWO); @@ -2227,13 +2225,13 @@ describe('Create Voucher sets and commit to vouchers with token conditional comm users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, + constants.product_price, constants.PROMISE_DEPOSITSE1, + constants.buyer_deposit, constants.QTY_10, contractGate, 0, - true, - constants.product_price, - constants.buyer_deposit + true ); const txReceipt = await txOrder.wait(); @@ -2390,13 +2388,12 @@ describe('Create Voucher sets and commit to vouchers with token conditional comm users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, + constants.product_price, constants.seller_deposit, + constants.buyer_deposit, constants.QTY_10, users.other1, /// gate address that maps to EOA - 0, - false, - constants.product_price, - constants.buyer_deposit + 0 ); const tokenSupplyKey = calculateTokenSupplyKey(constants.TWO); @@ -2428,13 +2425,12 @@ describe('Create Voucher sets and commit to vouchers with token conditional comm users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, + constants.product_price, constants.seller_deposit, + constants.buyer_deposit, constants.QTY_10, contractGate, - 0, - false, - constants.product_price, - constants.buyer_deposit + 0 ); const tokenSupplyKey = calculateTokenSupplyKey(constants.TWO); diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 259d60b1..267ab7b5 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -216,11 +216,11 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, + constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, constants.QTY_10, - true, - constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + true ) ) .to.emit(contractBosonRouter, eventNames.LOG_ORDER_CREATED) @@ -255,11 +255,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + constants.QTY_10 ); }); @@ -436,11 +435,11 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, + constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITSE1, + constants.ZERO, constants.QTY_10, - true, - constants.PROMISE_PRICE1, - constants.ZERO + true ); const promiseOrderData = await contractVoucherKernel.getOrderCosts( tokenSupplyKey @@ -472,11 +471,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_FROM + constants.ONE_MINUTE, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + constants.QTY_10 ) ).to.be.revertedWith(revertReasons.INVALID_VALIDITY_TO); }); @@ -487,11 +485,11 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_FROM + constants.ONE_MINUTE, + constants.ABOVE_ETH_LIMIT, constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, constants.ONE, - true, - constants.ABOVE_ETH_LIMIT, - constants.PROMISE_DEPOSITBU1 + true ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); @@ -502,11 +500,11 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_FROM + constants.ONE_MINUTE, + constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITSE1, + constants.ABOVE_ETH_LIMIT, constants.ONE, - true, - constants.PROMISE_PRICE1, - constants.ABOVE_ETH_LIMIT + true ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); @@ -517,11 +515,11 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_FROM + constants.ONE_MINUTE, + constants.PROMISE_PRICE1, constants.ABOVE_ETH_LIMIT, + constants.PROMISE_DEPOSITBU1, constants.ONE, - true, - constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + true ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); @@ -566,11 +564,11 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, + constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, constants.QTY_10, - true, - constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + true ) ) .to.emit(contractBosonRouter, eventNames.LOG_ORDER_CREATED) @@ -605,11 +603,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + constants.QTY_10 ); }); @@ -799,11 +796,11 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, + constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITSE1, + constants.ZERO, constants.QTY_10, - true, - constants.PROMISE_PRICE1, - constants.ZERO + true ); const promiseOrderData = await contractVoucherKernel.getOrderCosts( tokenSupplyKey @@ -835,11 +832,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_FROM + constants.ONE_MINUTE, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + constants.QTY_10 ) ).to.be.revertedWith(revertReasons.INVALID_VALIDITY_TO); }); @@ -894,11 +890,11 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, + constants.ABOVE_ETH_LIMIT, constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, constants.QTY_10, - true, - constants.ABOVE_ETH_LIMIT, - constants.PROMISE_DEPOSITBU1 + true ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); @@ -909,11 +905,11 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, + constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITSE1, + constants.ABOVE_TOKEN_LIMIT, constants.QTY_10, - true, - constants.PROMISE_PRICE1, - constants.ABOVE_TOKEN_LIMIT + true ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); @@ -924,11 +920,11 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, + constants.PROMISE_PRICE1, constants.ABOVE_TOKEN_LIMIT, + constants.PROMISE_DEPOSITBU1, constants.QTY_10, - true, - constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + true ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); @@ -966,11 +962,11 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, + constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, constants.QTY_10, - true, - constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + true ) ) .to.emit(contractBosonRouter, eventNames.LOG_ORDER_CREATED) @@ -1005,11 +1001,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + constants.QTY_10 ); }); @@ -1188,11 +1183,11 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, + constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITSE1, + constants.ZERO, constants.QTY_10, - true, - constants.PROMISE_PRICE1, - constants.ZERO + true ); const promiseOrderData = await contractVoucherKernel.getOrderCosts( tokenSupplyKey @@ -1241,11 +1236,11 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, + constants.ABOVE_TOKEN_LIMIT, constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, constants.QTY_10, - true, - constants.ABOVE_TOKEN_LIMIT, - constants.PROMISE_DEPOSITBU1 + true ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); @@ -1256,11 +1251,11 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, + constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITSE1, + constants.ABOVE_TOKEN_LIMIT, constants.QTY_10, - true, - constants.PROMISE_PRICE1, - constants.ABOVE_TOKEN_LIMIT + true ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); @@ -1271,11 +1266,11 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, + constants.PROMISE_PRICE1, constants.ABOVE_ETH_LIMIT, + constants.PROMISE_DEPOSITBU1, constants.QTY_10, - true, - constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + true ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); @@ -1324,11 +1319,11 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITSE1, constants.PROMISE_DEPOSITBU1, constants.QTY_10, - true, - constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + true, ) ) .to.emit(contractBosonRouter, eventNames.LOG_ORDER_CREATED) @@ -1363,11 +1358,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + constants.QTY_10 ); }); @@ -1557,11 +1551,11 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, + constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITSE1, + constants.ZERO, constants.QTY_10, - true, - constants.PROMISE_PRICE1, - constants.ZERO + true ); const promiseOrderData = await contractVoucherKernel.getOrderCosts( tokenSupplyKey @@ -1593,11 +1587,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_FROM + constants.ONE_MINUTE, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + constants.QTY_10 ) ).to.be.revertedWith(revertReasons.INVALID_VALIDITY_TO); }); @@ -1699,11 +1692,11 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, + constants.ABOVE_TOKEN_LIMIT, constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, constants.QTY_10, - true, - constants.ABOVE_TOKEN_LIMIT, - constants.PROMISE_DEPOSITBU1 + true ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); @@ -1714,11 +1707,11 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, + constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITSE1, + constants.ABOVE_TOKEN_LIMIT, constants.QTY_10, - true, - constants.PROMISE_PRICE1, - constants.ABOVE_TOKEN_LIMIT + true ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); @@ -1729,11 +1722,11 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, + constants.PROMISE_PRICE1, constants.ABOVE_TOKEN_LIMIT, + constants.PROMISE_DEPOSITBU1, constants.QTY_10, - true, - constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + true ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); @@ -1760,11 +1753,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_10, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.seller_deposit, + constants.PROMISE_DEPOSITBU1, + constants.QTY_10 ); }); @@ -1863,11 +1855,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + constants.QTY_10 ); }); @@ -2005,11 +1996,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - ORDER_QTY, - false, constants.PROMISE_PRICE1, - constants.ZERO + constants.PROMISE_DEPOSITSE1, + constants.ZERO, + ORDER_QTY ); await utils.commitToBuy( @@ -2125,11 +2115,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - ORDER_QTY, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + ORDER_QTY ); }); @@ -2301,11 +2290,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - ORDER_QTY, - false, constants.PROMISE_PRICE1, - constants.ZERO + constants.PROMISE_DEPOSITSE1, + constants.ZERO, + ORDER_QTY ); await utils.commitToBuy( @@ -2424,11 +2412,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - ORDER_QTY, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + ORDER_QTY ); }); @@ -2595,11 +2582,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - ORDER_QTY, - false, constants.PROMISE_PRICE1, - constants.ZERO + constants.PROMISE_DEPOSITSE1, + constants.ZERO, + ORDER_QTY ); await utils.commitToBuy( @@ -2714,11 +2700,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - ORDER_QTY, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + ORDER_QTY ); }); @@ -2869,11 +2854,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - ORDER_QTY, - false, constants.PROMISE_PRICE1, - constants.ZERO + constants.PROMISE_DEPOSITSE1, + constants.ZERO, + ORDER_QTY ); await utils.commitToBuy( @@ -2982,11 +2966,11 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, + constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, ORDER_QTY, - false, - constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + false ); const nonce = await utils.contractBSNTokenSame.nonces( @@ -3059,11 +3043,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - ORDER_QTY, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + ORDER_QTY ); }); @@ -3205,11 +3188,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - ORDER_QTY, - false, constants.PROMISE_PRICE1, - constants.ZERO + constants.PROMISE_DEPOSITSE1, + constants.ZERO, + ORDER_QTY ); await utils.commitToBuy( @@ -3314,11 +3296,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, - constants.QTY_10, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.seller_deposit, + constants.PROMISE_DEPOSITBU1, + constants.QTY_10 ); }); @@ -3802,11 +3783,10 @@ describe('Cashier and VoucherKernel', () => { users.other1, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + constants.QTY_10 ); }); @@ -3965,11 +3945,10 @@ describe('Cashier and VoucherKernel', () => { users.other1, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE2, - constants.QTY_20, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE2, + constants.PROMISE_DEPOSITBU1, + constants.QTY_20 ); tokenSupplyBatch = [BN(tokenSupplyKey), BN(tokenSupplyKey2)]; @@ -4139,11 +4118,10 @@ describe('Cashier and VoucherKernel', () => { users.other1, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_1, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + constants.QTY_1 ); }); @@ -4424,11 +4402,10 @@ describe('Cashier and VoucherKernel', () => { users.other1, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_1, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + constants.QTY_1 ); }); @@ -4728,11 +4705,10 @@ describe('Cashier and VoucherKernel', () => { users.other1, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - supplyQty, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + supplyQty ); }); @@ -5031,11 +5007,10 @@ describe('Cashier and VoucherKernel', () => { users.other1, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_1, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + constants.QTY_1 ); }); @@ -5335,11 +5310,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + constants.QTY_10 ); voucherID = await utils.commitToBuy( @@ -5454,11 +5428,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_10, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + constants.QTY_10 ); }); @@ -5816,11 +5789,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - supplyQty, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + supplyQty ); }); @@ -6274,11 +6246,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - supplyQty, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + supplyQty ); }); @@ -6700,11 +6671,10 @@ describe('Cashier and VoucherKernel', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.PROMISE_DEPOSITSE1, - constants.QTY_1, - false, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITSE1, + constants.PROMISE_DEPOSITBU1, + constants.QTY_1 ); }); diff --git a/test/3_withdrawals.ts b/test/3_withdrawals.ts index d4610cfa..119440ca 100644 --- a/test/3_withdrawals.ts +++ b/test/3_withdrawals.ts @@ -258,11 +258,10 @@ describe('Cashier withdrawals ', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, - constants.QTY_15, - false, constants.product_price, + constants.seller_deposit, constants.buyer_deposit, + constants.QTY_15 ); }); @@ -968,11 +967,10 @@ describe('Cashier withdrawals ', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, - supplyQty, - false, constants.product_price, + constants.seller_deposit, constants.buyer_deposit, + supplyQty ); }); @@ -1953,11 +1951,10 @@ describe('Cashier withdrawals ', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, - supplyQty, - false, constants.product_price, + constants.seller_deposit, constants.buyer_deposit, + supplyQty ); }); @@ -2739,11 +2736,10 @@ describe('Cashier withdrawals ', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, - supplyQty, - false, constants.product_price, + constants.seller_deposit, constants.buyer_deposit, + supplyQty ); }); @@ -3653,11 +3649,10 @@ describe('Cashier withdrawals ', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, - constants.QTY_1, - false, constants.product_price, + constants.seller_deposit, constants.buyer_deposit, + constants.QTY_1 ); }); @@ -4752,7 +4747,7 @@ describe('Cashier withdrawals ', () => { }); }); - describe.only('Seller cancels uncommitted voucher set', () => { + describe('Seller cancels uncommitted voucher set', () => { let remQty = 10; let voucherToBuyBeforeBurn = 5; let tokensToMintSeller, tokensToMintBuyer; @@ -4775,11 +4770,10 @@ describe('Cashier withdrawals ', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, - constants.QTY_10, - false, constants.product_price, + constants.seller_deposit, constants.buyer_deposit, + constants.QTY_10 ); for (let i = 0; i < voucherToBuyBeforeBurn; i++) { @@ -4922,11 +4916,10 @@ describe('Cashier withdrawals ', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, - constants.QTY_10, - false, constants.product_price, + constants.seller_deposit, constants.buyer_deposit, + constants.QTY_10 ); for (let i = 0; i < voucherToBuyBeforeBurn; i++) { @@ -5084,11 +5077,10 @@ describe('Cashier withdrawals ', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, - constants.QTY_10, - false, constants.product_price, + constants.seller_deposit, constants.buyer_deposit, + constants.QTY_10 ); for (let i = 0; i < voucherToBuyBeforeBurn; i++) { @@ -5239,11 +5231,10 @@ describe('Cashier withdrawals ', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, - constants.QTY_10, - false, constants.product_price, + constants.seller_deposit, constants.buyer_deposit, + constants.QTY_10 ); for (let i = 0; i < voucherToBuyBeforeBurn; i++) { @@ -5371,11 +5362,10 @@ describe('Cashier withdrawals ', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, - constants.QTY_10, - false, constants.product_price, + constants.seller_deposit, constants.buyer_deposit, + constants.QTY_10 ); }); @@ -5414,11 +5404,10 @@ describe('Cashier withdrawals ', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, - constants.QTY_10, - false, constants.product_price, + constants.seller_deposit, constants.buyer_deposit, + constants.QTY_10 ); for (let i = 0; i < vouchersToBuy; i++) { @@ -5584,11 +5573,10 @@ describe('Cashier withdrawals ', () => { users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, - constants.seller_deposit, - constants.QTY_10, - false, constants.product_price, + constants.seller_deposit, constants.buyer_deposit, + constants.QTY_10 ); for (let i = 0; i < vouchersToBuy; i++) { diff --git a/test/4_pausing_contracts.ts b/test/4_pausing_contracts.ts index 8c5b0f7e..20f510e9 100644 --- a/test/4_pausing_contracts.ts +++ b/test/4_pausing_contracts.ts @@ -226,11 +226,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_1, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_1 ) ).to.be.revertedWith(revertReasons.PAUSED); }); @@ -240,11 +239,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_1, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_1 ); assert.isNotEmpty(TOKEN_SUPPLY_ID); @@ -255,11 +253,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_1, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_1 ); await contractBosonRouter.pause(); @@ -314,11 +311,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_1, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_1 ) ).to.be.revertedWith(revertReasons.PAUSED); }); @@ -328,11 +324,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_1, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_1 ); assert.isNotEmpty(TOKEN_SUPPLY_ID); @@ -343,11 +338,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_1, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_1 ); await contractBosonRouter.pause(); @@ -392,11 +386,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_10, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_10 ); }); @@ -408,11 +401,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_1, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_1 ) ).to.be.revertedWith(revertReasons.PAUSED); }); @@ -422,11 +414,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_1, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_1 ); assert.isNotEmpty(TOKEN_SUPPLY_ID); @@ -437,11 +428,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_1, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_1 ); await contractBosonRouter.pause(); @@ -499,11 +489,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_1, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_1 ) ).to.be.revertedWith(revertReasons.PAUSED); }); @@ -513,11 +502,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_1, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_1 ); assert.isNotEmpty(TOKEN_SUPPLY_ID); @@ -528,11 +516,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_1, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_1 ); await contractBosonRouter.pause(); @@ -603,11 +590,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_10, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_10 ); }); @@ -711,11 +697,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_10, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_10 ); }); @@ -810,11 +795,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_10, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_10 ); }); @@ -919,11 +903,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_10, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_10 ); }); @@ -1024,11 +1007,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_10, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_10 ); }); @@ -1172,11 +1154,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_1, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_1 ); const voucherID = await utils.commitToBuy( @@ -1235,11 +1216,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_1, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_1 ); const voucherID = await utils.commitToBuy( @@ -1291,11 +1271,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_1, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_1 ); const voucherID = await utils.commitToBuy( @@ -1360,11 +1339,10 @@ describe('Cashier && VK', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_1, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_1 ); const voucherID = await utils.commitToBuy( diff --git a/test/6_erc1155721.ts b/test/6_erc1155721.ts index a805a76e..ef6e5c64 100644 --- a/test/6_erc1155721.ts +++ b/test/6_erc1155721.ts @@ -213,11 +213,11 @@ describe('ERC1155ERC721', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, + constants.product_price, constants.seller_deposit, + constants.buyer_deposit, constants.QTY_10, - true, - constants.product_price, - constants.buyer_deposit + true ); const txReceipt = await txFillOrder.wait(); @@ -398,11 +398,10 @@ describe('ERC1155ERC721', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_10, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_10 ); }); @@ -519,11 +518,10 @@ describe('ERC1155ERC721', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_10, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_10 ); }); @@ -652,11 +650,10 @@ describe('ERC1155ERC721', () => { users.seller, timestamp, timestamp + constants.SECONDS_IN_DAY, - constants.seller_deposit, - constants.QTY_10, - false, constants.product_price, - constants.buyer_deposit + constants.seller_deposit, + constants.buyer_deposit, + constants.QTY_10 ); erc721 = await utils.commitToBuy( diff --git a/testHelpers/utils.ts b/testHelpers/utils.ts index 22c45524..9f91527d 100644 --- a/testHelpers/utils.ts +++ b/testHelpers/utils.ts @@ -32,23 +32,23 @@ class Utils { seller, from, to, + promisePrice, sellerDeposit, + buyerDeposit, qty, - returnTx?, - promisePrice?, - buyerDeposit? + returnTx? ) => any; createOrderConditional: ( seller, from, to, + promisePrice, sellerDeposit, + buyerDeposit, qty, gateContract, nftTokenID, - returnTx?, - promisePrice?, - buyerDeposit? + returnTx? ) => any; commitToBuy: ( buyer, @@ -100,11 +100,11 @@ class Utils { seller: Account, from: number, to: number, + promisePrice: number | string | BigNumber, sellerDeposit: number | string, + buyerDeposit: number | string, qty: number | string, returnTx = false, - promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default - buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default ): Promise { const txValue = BN(sellerDeposit).mul(BN(qty)); @@ -136,15 +136,15 @@ class Utils { } async requestCreateOrderETHTKNSameWithPermit( - // is this really needed? + // todo is this really needed? seller: Account, from: number, to: number, + promisePrice: number | string | BigNumber, sellerDeposit: number | string, + buyerDeposit: number | string, qty: number | string, - returnTx = false, - promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default - buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default + returnTx = false ): Promise { const txValue = BN(sellerDeposit).mul(BN(qty)); @@ -203,11 +203,11 @@ class Utils { seller: Account, from: number, to: number, + promisePrice: number | string | BigNumber, sellerDeposit: number | string, + buyerDeposit: number | string, qty: number | string, returnTx = false, - promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default - buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default ): Promise { const txValue = BN(sellerDeposit).mul(BN(qty)); @@ -265,13 +265,13 @@ class Utils { seller: Account, from: number, to: number, + promisePrice: number | string | BigNumber, sellerDeposit: number | string, + buyerDeposit: number | string, qty: number | string, gateContract: Account, nftTokenId: number | string | null, - returnTx = false, - promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default - buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default + returnTx = false ): Promise { const txValue = BN(sellerDeposit).mul(BN(qty)); @@ -332,11 +332,11 @@ class Utils { seller: Account, from: number, to: number, + promisePrice: number | string | BigNumber, sellerDeposit: number | string, + buyerDeposit: number | string, qty: number | string, - returnTx = false, - promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default - buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default + returnTx = false ): Promise { const txValue = BN(sellerDeposit).mul(BN(qty)); const nonce = await this.contractBSNTokenDeposit.nonces(seller.address); @@ -392,11 +392,11 @@ class Utils { seller: Account, from: number, to: number, + promisePrice: number | string | BigNumber, sellerDeposit: number | string, + buyerDeposit: number | string, qty: number | string, returnTx = false, - promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default - buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default ): Promise { const txValue = BN(sellerDeposit).mul(BN(qty)); From c4da4b7ad909034743bf76df760f6be1b78a8d59 Mon Sep 17 00:00:00 2001 From: zajck Date: Mon, 11 Oct 2021 08:52:24 +0200 Subject: [PATCH 35/41] commitToBuy parameter order --- test/11_gate.ts | 2 +- test/12_conditional_commit.ts | 2 +- test/2_test_fullpath_with_permit.ts | 116 ++++++---------------------- test/3_withdrawals.ts | 79 +++---------------- test/4_pausing_contracts.ts | 57 +++++++------- test/6_erc1155721.ts | 12 +-- testHelpers/utils.ts | 36 ++++----- 7 files changed, 85 insertions(+), 219 deletions(-) diff --git a/test/11_gate.ts b/test/11_gate.ts index ce588ce0..f028ba2e 100644 --- a/test/11_gate.ts +++ b/test/11_gate.ts @@ -484,7 +484,7 @@ describe('Gate contract', async () => { expect(await contractGate.check(users.buyer.address, tokenId)).to.be .true; - await utils.commitToBuy(users.buyer, users.seller, tokenId, false, constants.product_price, constants.buyer_deposit); + await utils.commitToBuy(users.buyer, users.seller, tokenId, constants.product_price, constants.buyer_deposit); expect(await contractGate.check(users.buyer.address, tokenId)).to.be .false; diff --git a/test/12_conditional_commit.ts b/test/12_conditional_commit.ts index 568458e7..695bc400 100644 --- a/test/12_conditional_commit.ts +++ b/test/12_conditional_commit.ts @@ -1996,7 +1996,7 @@ describe('Create Voucher sets and commit to vouchers with token conditional comm }); it('[NEGATIVE] Should not be able to request voucher twice', async () => { - await utils.commitToBuy(users.buyer, users.seller, tokenSupplyKey, false, constants.product_price, constants.buyer_deposit); + await utils.commitToBuy(users.buyer, users.seller, tokenSupplyKey, constants.product_price, constants.buyer_deposit); const {txValue, DEPOSIT, PRICE} = await generateInputs( users.buyer, diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 267ab7b5..a749dd2a 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -413,7 +413,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -774,7 +773,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -1161,7 +1159,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -1529,7 +1526,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -1868,9 +1864,9 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - true, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITBU1, + true ) ) .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_DELIVERED) @@ -1899,7 +1895,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -2006,7 +2001,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.ZERO ); @@ -2044,7 +2038,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ) @@ -2057,7 +2050,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.incorrect_product_price, constants.PROMISE_DEPOSITBU1 ) @@ -2070,7 +2062,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.buyer_incorrect_deposit ) @@ -2127,10 +2118,10 @@ describe('Cashier and VoucherKernel', () => { utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, - true, + TOKEN_SUPPLY_ID, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITBU1, + true ) ) .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_DELIVERED) @@ -2173,7 +2164,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -2300,7 +2290,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.ZERO ); @@ -2338,7 +2327,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ) @@ -2351,7 +2339,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.incorrect_product_price, constants.PROMISE_DEPOSITBU1 ) @@ -2364,7 +2351,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.buyer_incorrect_deposit ) @@ -2425,9 +2411,9 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - true, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITBU1, + true ) ) .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_DELIVERED) @@ -2468,7 +2454,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -2592,7 +2577,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.ZERO ); @@ -2630,7 +2614,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ) @@ -2643,7 +2626,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.incorrect_product_price, constants.PROMISE_DEPOSITBU1 ) @@ -2656,7 +2638,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.buyer_incorrect_deposit ) @@ -2713,9 +2694,9 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - true, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITBU1, + true ) ) .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_DELIVERED) @@ -2750,7 +2731,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -2864,7 +2844,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.ZERO ); @@ -2902,7 +2881,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ) @@ -2915,7 +2893,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.incorrect_product_price, constants.PROMISE_DEPOSITBU1 ) @@ -2928,7 +2905,7 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, + constants.PROMISE_PRICE1, constants.buyer_incorrect_deposit ) @@ -3056,9 +3033,9 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - true, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + constants.PROMISE_DEPOSITBU1, + true ) ) .to.emit(contractVoucherKernel, eventNames.LOG_VOUCHER_DELIVERED) @@ -3089,10 +3066,9 @@ describe('Cashier and VoucherKernel', () => { describe('After request', () => { beforeEach(async () => { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID), - false, + await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1; + constants.PROMISE_DEPOSITBU1) }); it('Voucher Kernel state is correct', async () => { @@ -3198,7 +3174,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.ZERO ); @@ -3236,7 +3211,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ) @@ -3249,7 +3223,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.incorrect_product_price, constants.PROMISE_DEPOSITBU1 ) @@ -3262,7 +3235,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.buyer_incorrect_deposit ) @@ -3313,7 +3285,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ) @@ -3325,7 +3296,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -3343,7 +3313,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -3362,7 +3331,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -3381,7 +3349,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -3400,7 +3367,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -3420,7 +3386,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -3440,7 +3405,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -3458,7 +3422,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -3477,7 +3440,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -3498,7 +3460,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -3519,7 +3480,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -3539,7 +3499,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -3562,7 +3521,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -3605,7 +3563,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -3648,7 +3605,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -3703,7 +3659,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -4190,7 +4145,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.other2, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -4327,7 +4281,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.other2, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -4352,7 +4305,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.other2, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -4476,7 +4428,9 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.buyer, users.other2, - tokenSupplyKey + tokenSupplyKey, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.redeem(voucherID, users.buyer.signer); @@ -4625,7 +4579,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.other2, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -4650,7 +4603,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.other2, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -4782,7 +4734,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.other2, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -4942,7 +4893,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.other2, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -4967,7 +4917,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.other2, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -5080,7 +5029,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.other2, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -5236,7 +5184,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.other2, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -5261,7 +5208,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer, users.other2, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -5320,7 +5266,6 @@ describe('Cashier and VoucherKernel', () => { users.other1, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -5381,7 +5326,6 @@ describe('Cashier and VoucherKernel', () => { users.other1, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -5443,7 +5387,9 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); let actualOldOwnerBalanceFromEscrowEth = await contractCashier.getEscrowAmount( @@ -5501,7 +5447,6 @@ describe('Cashier and VoucherKernel', () => { users.other1, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -5684,7 +5629,9 @@ describe('Cashier and VoucherKernel', () => { const voucherID = await utils.commitToBuy( users.other1, users.seller, - tokenSupplyKey + tokenSupplyKey, + constants.PROMISE_PRICE1, + constants.PROMISE_DEPOSITBU1 ); await utils.refund(voucherID, users.other1.signer); @@ -5709,7 +5656,6 @@ describe('Cashier and VoucherKernel', () => { users.other1, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -5735,7 +5681,6 @@ describe('Cashier and VoucherKernel', () => { users.other1, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -5812,7 +5757,6 @@ describe('Cashier and VoucherKernel', () => { users.other1, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -5917,7 +5861,6 @@ describe('Cashier and VoucherKernel', () => { users.other1, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -6135,7 +6078,6 @@ describe('Cashier and VoucherKernel', () => { users.other1, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -6162,7 +6104,6 @@ describe('Cashier and VoucherKernel', () => { users.other1, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -6188,7 +6129,6 @@ describe('Cashier and VoucherKernel', () => { users.other1, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -6262,7 +6202,6 @@ describe('Cashier and VoucherKernel', () => { users.other1, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -6380,7 +6319,6 @@ describe('Cashier and VoucherKernel', () => { users.other1, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -6575,7 +6513,6 @@ describe('Cashier and VoucherKernel', () => { users.other1, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -6602,7 +6539,6 @@ describe('Cashier and VoucherKernel', () => { users.other1, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -6628,7 +6564,6 @@ describe('Cashier and VoucherKernel', () => { users.other1, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -6685,7 +6620,6 @@ describe('Cashier and VoucherKernel', () => { users.other1, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -6791,7 +6725,6 @@ describe('Cashier and VoucherKernel', () => { users.other1, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -7019,7 +6952,6 @@ describe('Cashier and VoucherKernel', () => { users.other1, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -7046,7 +6978,6 @@ describe('Cashier and VoucherKernel', () => { users.other1, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); @@ -7071,7 +7002,6 @@ describe('Cashier and VoucherKernel', () => { users.other1, users.seller, tokenSupplyKey, - false, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1 ); diff --git a/test/3_withdrawals.ts b/test/3_withdrawals.ts index 119440ca..ca3b2e65 100644 --- a/test/3_withdrawals.ts +++ b/test/3_withdrawals.ts @@ -275,7 +275,7 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -329,7 +329,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -384,7 +383,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -441,7 +439,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -497,7 +494,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -553,7 +549,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -609,7 +604,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -663,7 +657,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -722,7 +715,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -782,7 +774,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -841,7 +832,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -1001,7 +991,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -1084,7 +1073,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -1166,7 +1154,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -1248,7 +1235,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -1331,7 +1317,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -1409,7 +1394,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -1490,7 +1474,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -1568,7 +1551,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -1648,7 +1630,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -1732,7 +1713,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -1816,7 +1796,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -1978,7 +1957,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -2043,7 +2021,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -2108,7 +2085,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -2173,7 +2149,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -2239,7 +2214,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -2300,7 +2274,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -2364,7 +2337,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -2424,7 +2396,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -2487,7 +2458,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -2554,7 +2524,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -2621,7 +2590,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -2765,7 +2733,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -2843,7 +2810,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -2920,7 +2886,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -2997,7 +2962,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -3075,7 +3039,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -3148,7 +3111,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -3224,7 +3186,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -3297,7 +3258,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -3372,7 +3332,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -3451,7 +3410,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -3530,7 +3488,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -3661,7 +3618,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -3760,7 +3716,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -3858,7 +3813,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -3956,7 +3910,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -4055,7 +4008,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -4149,7 +4101,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -4246,7 +4197,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -4340,7 +4290,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -4436,7 +4385,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -4536,7 +4484,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -4636,7 +4583,6 @@ describe('Cashier withdrawals ', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -4777,9 +4723,8 @@ describe('Cashier withdrawals ', () => { ); for (let i = 0; i < voucherToBuyBeforeBurn; i++) { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit); - // utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit) - remQty--; + await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit); + remQty--; } }); @@ -4849,7 +4794,7 @@ describe('Cashier withdrawals ', () => { it('[NEGATIVE] Buyer should not be able to commit to buy anything from the burnt supply', async () => { await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit) + utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit) ).to.be.revertedWith(revertReasons.OFFER_EMPTY); }); @@ -4923,7 +4868,7 @@ describe('Cashier withdrawals ', () => { ); for (let i = 0; i < voucherToBuyBeforeBurn; i++) { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit); + await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit); remQty--; } }); @@ -5012,7 +4957,7 @@ describe('Cashier withdrawals ', () => { it('[NEGATIVE] Buyer should not be able to commit to buy anything from the burnt supply', async () => { await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit) + utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit) ).to.be.revertedWith(revertReasons.OFFER_EMPTY); }); @@ -5084,7 +5029,7 @@ describe('Cashier withdrawals ', () => { ); for (let i = 0; i < voucherToBuyBeforeBurn; i++) { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit); + await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit); remQty--; } }); @@ -5173,7 +5118,7 @@ describe('Cashier withdrawals ', () => { it('[NEGATIVE] Buyer should not be able to commit to buy anything from the burnt supply', async () => { await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit) + utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit) ).to.be.revertedWith(revertReasons.OFFER_EMPTY); }); @@ -5238,7 +5183,7 @@ describe('Cashier withdrawals ', () => { ); for (let i = 0; i < voucherToBuyBeforeBurn; i++) { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit); + await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit); remQty--; } }); @@ -5312,7 +5257,7 @@ describe('Cashier withdrawals ', () => { it('[NEGATIVE] Buyer should not be able to commit to buy anything from the burnt supply', async () => { await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit) + utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit) ).to.be.revertedWith(revertReasons.OFFER_EMPTY); }); @@ -5411,7 +5356,7 @@ describe('Cashier withdrawals ', () => { ); for (let i = 0; i < vouchersToBuy; i++) { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit); + await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit); } await contractBosonRouter.pause(); @@ -5580,7 +5525,7 @@ describe('Cashier withdrawals ', () => { ); for (let i = 0; i < vouchersToBuy; i++) { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit); + await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit); } await contractBosonRouter.pause(); diff --git a/test/4_pausing_contracts.ts b/test/4_pausing_contracts.ts index 20f510e9..00d1189e 100644 --- a/test/4_pausing_contracts.ts +++ b/test/4_pausing_contracts.ts @@ -263,7 +263,6 @@ describe('Cashier && VK', () => { await expect( utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit) ).to.be.revertedWith(revertReasons.PAUSED); @@ -348,7 +347,6 @@ describe('Cashier && VK', () => { await expect( utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit) ).to.be.revertedWith(revertReasons.PAUSED); @@ -437,7 +435,7 @@ describe('Cashier && VK', () => { await contractBosonRouter.pause(); await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit) + utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit) ).to.be.revertedWith(revertReasons.PAUSED); }); }); @@ -525,7 +523,7 @@ describe('Cashier && VK', () => { await contractBosonRouter.pause(); await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit) + utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit) ).to.be.revertedWith(revertReasons.PAUSED); }); }); @@ -601,7 +599,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -615,8 +613,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, - false, + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); @@ -634,7 +631,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -648,7 +645,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); await utils.redeem(VOUCHER_ID, users.buyer.signer); @@ -708,7 +705,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -722,7 +719,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); await utils.refund(VOUCHER_ID, users.buyer.signer); @@ -738,7 +735,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -752,7 +749,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); await utils.redeem(VOUCHER_ID, users.buyer.signer); @@ -806,7 +803,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -820,7 +817,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); await utils.refund(VOUCHER_ID, users.buyer.signer); @@ -836,7 +833,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -850,7 +847,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); await utils.redeem(VOUCHER_ID, users.buyer.signer); @@ -914,7 +911,8 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -928,7 +926,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); await utils.refund(VOUCHER_ID, users.buyer.signer); @@ -944,7 +942,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -958,7 +956,8 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, constants.buyer_deposit ); await utils.redeem(VOUCHER_ID, users.buyer.signer); @@ -1018,7 +1017,8 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -1032,7 +1032,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); await utils.refund(VOUCHER_ID, users.buyer.signer); @@ -1048,7 +1048,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -1062,7 +1062,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); await utils.redeem(VOUCHER_ID, users.buyer.signer); @@ -1163,7 +1163,7 @@ describe('Cashier && VK', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -1225,7 +1225,7 @@ describe('Cashier && VK', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -1280,7 +1280,7 @@ describe('Cashier && VK', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, false, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -1349,7 +1349,6 @@ describe('Cashier && VK', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); diff --git a/test/6_erc1155721.ts b/test/6_erc1155721.ts index ef6e5c64..1a704bdd 100644 --- a/test/6_erc1155721.ts +++ b/test/6_erc1155721.ts @@ -253,9 +253,9 @@ describe('ERC1155ERC721', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - true, constants.product_price, - constants.buyer_deposit + constants.buyer_deposit, + true ); const txReceipt = await commitTx.wait(); @@ -302,7 +302,6 @@ describe('ERC1155ERC721', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -345,7 +344,6 @@ describe('ERC1155ERC721', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -364,7 +362,6 @@ describe('ERC1155ERC721', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -548,7 +545,6 @@ describe('ERC1155ERC721', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -568,7 +564,6 @@ describe('ERC1155ERC721', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -588,7 +583,6 @@ describe('ERC1155ERC721', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -608,7 +602,6 @@ describe('ERC1155ERC721', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); @@ -660,7 +653,6 @@ describe('ERC1155ERC721', () => { users.buyer, users.seller, TOKEN_SUPPLY_ID, - false, constants.product_price, constants.buyer_deposit ); diff --git a/testHelpers/utils.ts b/testHelpers/utils.ts index 9f91527d..5356b2a1 100644 --- a/testHelpers/utils.ts +++ b/testHelpers/utils.ts @@ -54,9 +54,9 @@ class Utils { buyer, seller, tokenSupplyId, - returnTx?, - promisePrice?, - buyerDeposit? + promisePrice, + buyerDeposit, + returnTx? ) => any; factories?: { ERC1155ERC721: ERC1155ERC721__factory | any; @@ -432,9 +432,9 @@ class Utils { buyer: Account, seller: Account, tokenSupplyId: string, - returnTx = false, - promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default - buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default + promisePrice: number | string | BigNumber, + buyerDeposit: number | string, + returnTx = false ): Promise { const txValue = BN(buyerDeposit).add(BN(promisePrice)); const nonce1 = await this.contractBSNTokenDeposit.nonces(buyer.address); @@ -514,9 +514,9 @@ class Utils { buyer: Account, seller: Account, tokenSupplyId: string, - returnTx = false, - promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default - buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default + promisePrice: number | string | BigNumber, + buyerDeposit: number | string, + returnTx = false ): Promise { const txValue = BN(buyerDeposit).add(BN(promisePrice)); const nonce = await this.contractBSNTokenSame.nonces(buyer.address); @@ -573,9 +573,9 @@ class Utils { buyer: Account, seller: Account, tokenSupplyId: string, - returnTx = false, - promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default - buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default + promisePrice: number | string | BigNumber, + buyerDeposit: number | string, + returnTx = false ): Promise { const nonce1 = await this.contractBSNTokenDeposit.nonces(buyer.address); @@ -628,9 +628,9 @@ class Utils { buyer: Account, seller: Account, tokenSupplyId: string, - returnTx = false, - promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default - buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default + promisePrice: number | string | BigNumber, + buyerDeposit: number | string, + returnTx = false ): Promise { const txValue = BN(buyerDeposit).add(BN(promisePrice)); // TODO MAKE PARAMETERS @@ -666,9 +666,9 @@ class Utils { buyer: Account, seller: Account, tokenSupplyId: string, - returnTx = false, - promisePrice = constants.PROMISE_PRICE1, // todo shift on right place, remove default - buyerDeposit = constants.PROMISE_DEPOSITBU1 // todo shift on right place, remove default + promisePrice: number | string | BigNumber, + buyerDeposit: number | string, + returnTx = false ): Promise { const nonce1 = await this.contractBSNTokenPrice.nonces(buyer.address); From db9e674e86286a2bec36c7a559141b3e3e28d690 Mon Sep 17 00:00:00 2001 From: zajck Date: Mon, 11 Oct 2021 09:03:34 +0200 Subject: [PATCH 36/41] code clean up, format, lint --- test/11_gate.ts | 8 +- test/12_conditional_commit.ts | 8 +- test/2_test_fullpath_with_permit.ts | 131 ++++++++++++++-------------- test/3_withdrawals.ts | 86 +++++++++++++++--- test/4_pausing_contracts.ts | 126 +++++++++++++++++++------- testHelpers/utils.ts | 39 +++------ 6 files changed, 258 insertions(+), 140 deletions(-) diff --git a/test/11_gate.ts b/test/11_gate.ts index f028ba2e..f9d0518f 100644 --- a/test/11_gate.ts +++ b/test/11_gate.ts @@ -484,7 +484,13 @@ describe('Gate contract', async () => { expect(await contractGate.check(users.buyer.address, tokenId)).to.be .true; - await utils.commitToBuy(users.buyer, users.seller, tokenId, constants.product_price, constants.buyer_deposit); + await utils.commitToBuy( + users.buyer, + users.seller, + tokenId, + constants.product_price, + constants.buyer_deposit + ); expect(await contractGate.check(users.buyer.address, tokenId)).to.be .false; diff --git a/test/12_conditional_commit.ts b/test/12_conditional_commit.ts index 695bc400..3e385116 100644 --- a/test/12_conditional_commit.ts +++ b/test/12_conditional_commit.ts @@ -1996,7 +1996,13 @@ describe('Create Voucher sets and commit to vouchers with token conditional comm }); it('[NEGATIVE] Should not be able to request voucher twice', async () => { - await utils.commitToBuy(users.buyer, users.seller, tokenSupplyKey, constants.product_price, constants.buyer_deposit); + await utils.commitToBuy( + users.buyer, + users.seller, + tokenSupplyKey, + constants.product_price, + constants.buyer_deposit + ); const {txValue, DEPOSIT, PRICE} = await generateInputs( users.buyer, diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index a749dd2a..80ba266b 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -36,7 +36,7 @@ let utils: Utils; let users; describe('Cashier and VoucherKernel', () => { - let promiseId: string, tokenSupplyKey: string; // todo remove string when finished + let promiseId: string, tokenSupplyKey: string; before(async () => { const signers: Signer[] = await ethers.getSigners(); @@ -62,11 +62,6 @@ describe('Cashier and VoucherKernel', () => { contractBSNTokenDeposit: MockERC20Permit, contractTokenRegistry: TokenRegistry; - let tokenVoucherKey, tokenVoucherKey1; - - const ZERO = BN(0); // TODO: use constants.zero - const ONE_VOUCHER = 1; // TODO: use constants.one - const deadline = toWei(1); let timestamp; @@ -356,7 +351,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it('Deposit and Price address should be zero', async () => { + it('Deposit and Price address should be constants.ZERO', async () => { expect( await contractVoucherKernel.getVoucherPriceToken(tokenSupplyKey) ).to.equal( @@ -503,7 +498,7 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_DEPOSITSE1, constants.ABOVE_ETH_LIMIT, constants.ONE, - true + true ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); @@ -518,7 +513,7 @@ describe('Cashier and VoucherKernel', () => { constants.ABOVE_ETH_LIMIT, constants.PROMISE_DEPOSITBU1, constants.ONE, - true + true ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); @@ -703,7 +698,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it('Deposit contract should be correct and Price address should be zero', async () => { + it('Deposit contract should be correct and Price address should be constants.ZERO', async () => { expect( await contractVoucherKernel.getVoucherPriceToken(tokenSupplyKey) ).to.equal( @@ -838,8 +833,8 @@ describe('Cashier and VoucherKernel', () => { ).to.be.revertedWith(revertReasons.INVALID_VALIDITY_TO); }); - it('[NEGATIVE] Should revert if token deposit contract address is zero address', async () => { - const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); + it('[NEGATIVE] Should revert if token deposit contract address is constants.ZERO address', async () => { + const txValue = BN(constants.seller_deposit).mul(BN(constants.ONE)); const nonce = await contractBSNTokenDeposit.nonces( users.seller.address ); @@ -1100,7 +1095,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it('Price address should be correct and Deposit should be zero', async () => { + it('Price address should be correct and Deposit should be constants.ZERO', async () => { expect( await contractVoucherKernel.getVoucherPriceToken(tokenSupplyKey) ).to.equal( @@ -1210,7 +1205,7 @@ describe('Cashier and VoucherKernel', () => { ); }); - it('[NEGATIVE] Should fail if token price contract is zero address', async () => { + it('[NEGATIVE] Should fail if token price contract is constants.ZERO address', async () => { const sellerInstance = contractBosonRouter.connect( users.seller.signer ); @@ -1252,7 +1247,7 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_DEPOSITSE1, constants.ABOVE_TOKEN_LIMIT, constants.QTY_10, - true + true ) ).to.be.revertedWith(revertReasons.ABOVE_LIMIT); }); @@ -1320,7 +1315,7 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_DEPOSITSE1, constants.PROMISE_DEPOSITBU1, constants.QTY_10, - true, + true ) ) .to.emit(contractBosonRouter, eventNames.LOG_ORDER_CREATED) @@ -1591,8 +1586,8 @@ describe('Cashier and VoucherKernel', () => { ).to.be.revertedWith(revertReasons.INVALID_VALIDITY_TO); }); - it('[NEGATIVE] Should revert if token price contract address is zero address', async () => { - const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); + it('[NEGATIVE] Should revert if token price contract address is constants.ZERO address', async () => { + const txValue = BN(constants.seller_deposit).mul(BN(constants.ONE)); const nonce = await contractBSNTokenDeposit.nonces( users.seller.address ); @@ -1636,8 +1631,8 @@ describe('Cashier and VoucherKernel', () => { ).to.be.revertedWith(revertReasons.ZERO_ADDRESS_NOT_ALLOWED); }); - it('[NEGATIVE] Should revert if token deposit contract address is zero address', async () => { - const txValue = BN(constants.seller_deposit).mul(BN(ONE_VOUCHER)); + it('[NEGATIVE] Should revert if token deposit contract address is constants.ZERO address', async () => { + const txValue = BN(constants.seller_deposit).mul(BN(constants.ONE)); const nonce = await contractBSNTokenDeposit.nonces( users.seller.address ); @@ -1987,7 +1982,7 @@ describe('Cashier and VoucherKernel', () => { }); it('It should be possible to request voucher with 0 buyer deposit', async () => { - let TOKEN_SUPPLY_ID = await utils.createOrder( + const TOKEN_SUPPLY_ID = await utils.createOrder( users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, @@ -2005,7 +2000,7 @@ describe('Cashier and VoucherKernel', () => { constants.ZERO ); - let voucherTokenId = BN(TOKEN_SUPPLY_ID).or(constants.ONE); + const voucherTokenId = BN(TOKEN_SUPPLY_ID).or(constants.ONE); const voucherStatus = await contractVoucherKernel.getVoucherStatus( voucherTokenId @@ -2118,7 +2113,7 @@ describe('Cashier and VoucherKernel', () => { utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, + TOKEN_SUPPLY_ID, constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITBU1, true @@ -2276,7 +2271,7 @@ describe('Cashier and VoucherKernel', () => { tokensToMintSeller ); - let TOKEN_SUPPLY_ID = await utils.createOrder( + const TOKEN_SUPPLY_ID = await utils.createOrder( users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, @@ -2294,7 +2289,7 @@ describe('Cashier and VoucherKernel', () => { constants.ZERO ); - let voucherTokenId = BN(TOKEN_SUPPLY_ID).or(constants.ONE); + const voucherTokenId = BN(TOKEN_SUPPLY_ID).or(constants.ONE); const voucherStatus = await contractVoucherKernel.getVoucherStatus( voucherTokenId @@ -2563,7 +2558,7 @@ describe('Cashier and VoucherKernel', () => { }); it('It should be possible to request voucher with 0 buyer deposit', async () => { - let TOKEN_SUPPLY_ID = await utils.createOrder( + const TOKEN_SUPPLY_ID = await utils.createOrder( users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, @@ -2581,7 +2576,7 @@ describe('Cashier and VoucherKernel', () => { constants.ZERO ); - let voucherTokenId = BN(TOKEN_SUPPLY_ID).or(constants.ONE); + const voucherTokenId = BN(TOKEN_SUPPLY_ID).or(constants.ONE); const voucherStatus = await contractVoucherKernel.getVoucherStatus( voucherTokenId @@ -2830,7 +2825,7 @@ describe('Cashier and VoucherKernel', () => { }); it('It should be possible to request voucher with 0 buyer deposit', async () => { - let TOKEN_SUPPLY_ID = await utils.createOrder( + const TOKEN_SUPPLY_ID = await utils.createOrder( users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, @@ -2848,7 +2843,7 @@ describe('Cashier and VoucherKernel', () => { constants.ZERO ); - let voucherTokenId = BN(TOKEN_SUPPLY_ID).or(constants.ONE); + const voucherTokenId = BN(TOKEN_SUPPLY_ID).or(constants.ONE); const voucherStatus = await contractVoucherKernel.getVoucherStatus( voucherTokenId @@ -3066,9 +3061,13 @@ describe('Cashier and VoucherKernel', () => { describe('After request', () => { beforeEach(async () => { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, + await utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1) + constants.PROMISE_DEPOSITBU1 + ); }); it('Voucher Kernel state is correct', async () => { @@ -3160,7 +3159,7 @@ describe('Cashier and VoucherKernel', () => { }); it('It should be possible to request voucher with 0 buyer deposit', async () => { - let TOKEN_SUPPLY_ID = await utils.createOrder( + const TOKEN_SUPPLY_ID = await utils.createOrder( users.seller, constants.PROMISE_VALID_FROM, constants.PROMISE_VALID_TO, @@ -3178,7 +3177,7 @@ describe('Cashier and VoucherKernel', () => { constants.ZERO ); - let voucherTokenId = BN(TOKEN_SUPPLY_ID).or(constants.ONE); + const voucherTokenId = BN(TOKEN_SUPPLY_ID).or(constants.ONE); const voucherStatus = await contractVoucherKernel.getVoucherStatus( voucherTokenId @@ -3893,7 +3892,7 @@ describe('Cashier and VoucherKernel', () => { describe('Batchtransfers', () => { let tokenSupplyKey2; let tokenSupplyBatch; - let batchQuantities = [BN(constants.QTY_10), BN(constants.QTY_20)]; + const batchQuantities = [BN(constants.QTY_10), BN(constants.QTY_20)]; beforeEach(async () => { tokenSupplyKey2 = await utils.createOrder( @@ -4081,7 +4080,7 @@ describe('Cashier and VoucherKernel', () => { }); it('Should update escrow amounts after transfer', async () => { - let expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( + const expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( BN(constants.QTY_1) ); @@ -4097,7 +4096,7 @@ describe('Cashier and VoucherKernel', () => { 'Old owner balance from escrow does not match' ); assert.isTrue( - actualNewOwnerBalanceFromEscrow.eq(ZERO), + actualNewOwnerBalanceFromEscrow.eq(constants.ZERO), 'New owner balance from escrow does not match' ); @@ -4117,7 +4116,7 @@ describe('Cashier and VoucherKernel', () => { ); assert.isTrue( - actualOldOwnerBalanceFromEscrow.eq(ZERO), + actualOldOwnerBalanceFromEscrow.eq(constants.ZERO), 'Old owner balance from escrow does not match' ); assert.isTrue( @@ -4362,7 +4361,7 @@ describe('Cashier and VoucherKernel', () => { }); it('Should update escrow amounts after transfer', async () => { - let expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( + const expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( BN(constants.QTY_1) ); @@ -4380,7 +4379,7 @@ describe('Cashier and VoucherKernel', () => { 'Old owner balance from escrow does not match' ); assert.isTrue( - actualNewOwnerBalanceFromEscrow.eq(ZERO), + actualNewOwnerBalanceFromEscrow.eq(constants.ZERO), 'New owner balance from escrow does not match' ); @@ -4402,7 +4401,7 @@ describe('Cashier and VoucherKernel', () => { ); assert.isTrue( - actualOldOwnerBalanceFromEscrow.eq(ZERO), + actualOldOwnerBalanceFromEscrow.eq(constants.ZERO), 'Old owner balance from escrow does not match' ); assert.isTrue( @@ -4525,19 +4524,19 @@ describe('Cashier and VoucherKernel', () => { } ); - let balanceBuyerFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( + const balanceBuyerFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( users.buyer.address ); - let balanceSellerFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( + const balanceSellerFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( users.other2.address ); - let escrowBalanceFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( + const escrowBalanceFromDeposits = await utils.contractBSNTokenDeposit.balanceOf( users.deployer.address ); - let cashierDepositLeft = await utils.contractBSNTokenDeposit.balanceOf( + const cashierDepositLeft = await utils.contractBSNTokenDeposit.balanceOf( utils.contractCashier.address ); - let cashierPaymentLeft = await utils.contractBSNTokenPrice.balanceOf( + const cashierPaymentLeft = await utils.contractBSNTokenPrice.balanceOf( utils.contractCashier.address ); @@ -4665,7 +4664,7 @@ describe('Cashier and VoucherKernel', () => { }); it('Should update escrow amounts after transfer', async () => { - let expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( + const expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( BN(constants.QTY_1) ); @@ -4683,7 +4682,7 @@ describe('Cashier and VoucherKernel', () => { 'Old owner balance from escrow does not match' ); assert.isTrue( - actualNewOwnerBalanceFromEscrow.eq(ZERO), + actualNewOwnerBalanceFromEscrow.eq(constants.ZERO), 'New owner balance from escrow does not match' ); @@ -4705,7 +4704,7 @@ describe('Cashier and VoucherKernel', () => { ); assert.isTrue( - actualOldOwnerBalanceFromEscrow.eq(ZERO), + actualOldOwnerBalanceFromEscrow.eq(constants.ZERO), 'Old owner balance from escrow does not match' ); assert.isTrue( @@ -4964,7 +4963,7 @@ describe('Cashier and VoucherKernel', () => { }); it('Should update escrow amounts after transfer', async () => { - let expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( + const expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( BN(constants.QTY_1) ); @@ -4980,7 +4979,7 @@ describe('Cashier and VoucherKernel', () => { 'Old owner balance from escrow does not match' ); assert.isTrue( - actualNewOwnerBalanceFromEscrow.eq(ZERO), + actualNewOwnerBalanceFromEscrow.eq(constants.ZERO), 'New owner balance from escrow does not match' ); @@ -5000,7 +4999,7 @@ describe('Cashier and VoucherKernel', () => { ); assert.isTrue( - actualOldOwnerBalanceFromEscrow.eq(ZERO), + actualOldOwnerBalanceFromEscrow.eq(constants.ZERO), 'Old owner balance from escrow does not match' ); assert.isTrue( @@ -5375,7 +5374,7 @@ describe('Cashier and VoucherKernel', () => { constants.PROMISE_PRICE1, constants.PROMISE_DEPOSITSE1, constants.PROMISE_DEPOSITBU1, - constants.QTY_10 + constants.QTY_10 ); }); @@ -5404,7 +5403,7 @@ describe('Cashier and VoucherKernel', () => { 'Old owner balance from escrow does not match' ); assert.isTrue( - actualNewOwnerBalanceFromEscrowEth.eq(ZERO), + actualNewOwnerBalanceFromEscrowEth.eq(constants.ZERO), 'New owner balance from escrow does not match' ); @@ -5423,7 +5422,7 @@ describe('Cashier and VoucherKernel', () => { ); assert.isTrue( - actualOldOwnerBalanceFromEscrowEth.eq(ZERO), + actualOldOwnerBalanceFromEscrowEth.eq(constants.ZERO), 'Old owner balance from escrow does not match' ); assert.isTrue( @@ -5790,12 +5789,12 @@ describe('Cashier and VoucherKernel', () => { ); assert.isTrue( - actualNewOwnerBalanceFromEscrowEth.eq(ZERO), + actualNewOwnerBalanceFromEscrowEth.eq(constants.ZERO), 'New owner balance from escrow does not match' ); assert.isTrue( - actualNewOwnerBalanceFromEscrowTkn.eq(ZERO), + actualNewOwnerBalanceFromEscrowTkn.eq(constants.ZERO), 'New owner balance from escrow does not match' ); @@ -5825,12 +5824,12 @@ describe('Cashier and VoucherKernel', () => { ); assert.isTrue( - actualOldOwnerBalanceFromEscrowEth.eq(ZERO), + actualOldOwnerBalanceFromEscrowEth.eq(constants.ZERO), 'Old owner balance from escrow does not match' ); assert.isTrue( - actualOldOwnerBalanceFromEscrowTkn.eq(ZERO), + actualOldOwnerBalanceFromEscrowTkn.eq(constants.ZERO), 'Old owner balance from escrow does not match' ); @@ -6241,12 +6240,12 @@ describe('Cashier and VoucherKernel', () => { ); assert.isTrue( - actualNewOwnerBalanceFromEscrowTknPrice.eq(ZERO), + actualNewOwnerBalanceFromEscrowTknPrice.eq(constants.ZERO), 'New owner balance from escrow does not match' ); assert.isTrue( - actualNewOwnerBalanceFromEscrowTknDeposit.eq(ZERO), + actualNewOwnerBalanceFromEscrowTknDeposit.eq(constants.ZERO), 'New owner balance from escrow does not match' ); @@ -6277,12 +6276,12 @@ describe('Cashier and VoucherKernel', () => { ); assert.isTrue( - actualOldOwnerBalanceFromEscrowTknPrice.eq(ZERO), + actualOldOwnerBalanceFromEscrowTknPrice.eq(constants.ZERO), 'Old owner balance from escrow does not match' ); assert.isTrue( - actualOldOwnerBalanceFromEscrowTknDeposit.eq(ZERO), + actualOldOwnerBalanceFromEscrowTknDeposit.eq(constants.ZERO), 'Old owner balance from escrow does not match' ); @@ -6653,12 +6652,12 @@ describe('Cashier and VoucherKernel', () => { ); assert.isTrue( - actualNewOwnerBalanceFromEscrowEth.eq(ZERO), + actualNewOwnerBalanceFromEscrowEth.eq(constants.ZERO), 'New owner balance from escrow does not match' ); assert.isTrue( - actualNewOwnerBalanceFromEscrowTkn.eq(ZERO), + actualNewOwnerBalanceFromEscrowTkn.eq(constants.ZERO), 'New owner balance from escrow does not match' ); @@ -6687,12 +6686,12 @@ describe('Cashier and VoucherKernel', () => { ); assert.isTrue( - actualOldOwnerBalanceFromEscrowEth.eq(ZERO), + actualOldOwnerBalanceFromEscrowEth.eq(constants.ZERO), 'Old owner balance from escrow does not match' ); assert.isTrue( - actualOldOwnerBalanceFromEscrowTkn.eq(ZERO), + actualOldOwnerBalanceFromEscrowTkn.eq(constants.ZERO), 'Old owner balance from escrow does not match' ); diff --git a/test/3_withdrawals.ts b/test/3_withdrawals.ts index ca3b2e65..dc8626fe 100644 --- a/test/3_withdrawals.ts +++ b/test/3_withdrawals.ts @@ -275,7 +275,9 @@ describe('Cashier withdrawals ', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -4723,8 +4725,14 @@ describe('Cashier withdrawals ', () => { ); for (let i = 0; i < voucherToBuyBeforeBurn; i++) { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit); - remQty--; + await utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit + ); + remQty--; } }); @@ -4794,7 +4802,13 @@ describe('Cashier withdrawals ', () => { it('[NEGATIVE] Buyer should not be able to commit to buy anything from the burnt supply', async () => { await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit) + utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit + ) ).to.be.revertedWith(revertReasons.OFFER_EMPTY); }); @@ -4868,7 +4882,13 @@ describe('Cashier withdrawals ', () => { ); for (let i = 0; i < voucherToBuyBeforeBurn; i++) { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit); + await utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit + ); remQty--; } }); @@ -4957,7 +4977,13 @@ describe('Cashier withdrawals ', () => { it('[NEGATIVE] Buyer should not be able to commit to buy anything from the burnt supply', async () => { await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit) + utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit + ) ).to.be.revertedWith(revertReasons.OFFER_EMPTY); }); @@ -5029,7 +5055,13 @@ describe('Cashier withdrawals ', () => { ); for (let i = 0; i < voucherToBuyBeforeBurn; i++) { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit); + await utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit + ); remQty--; } }); @@ -5118,7 +5150,13 @@ describe('Cashier withdrawals ', () => { it('[NEGATIVE] Buyer should not be able to commit to buy anything from the burnt supply', async () => { await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit) + utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit + ) ).to.be.revertedWith(revertReasons.OFFER_EMPTY); }); @@ -5183,7 +5221,13 @@ describe('Cashier withdrawals ', () => { ); for (let i = 0; i < voucherToBuyBeforeBurn; i++) { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit); + await utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit + ); remQty--; } }); @@ -5257,7 +5301,13 @@ describe('Cashier withdrawals ', () => { it('[NEGATIVE] Buyer should not be able to commit to buy anything from the burnt supply', async () => { await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit) + utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit + ) ).to.be.revertedWith(revertReasons.OFFER_EMPTY); }); @@ -5356,7 +5406,13 @@ describe('Cashier withdrawals ', () => { ); for (let i = 0; i < vouchersToBuy; i++) { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit); + await utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit + ); } await contractBosonRouter.pause(); @@ -5525,7 +5581,13 @@ describe('Cashier withdrawals ', () => { ); for (let i = 0; i < vouchersToBuy; i++) { - await utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit); + await utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit + ); } await contractBosonRouter.pause(); diff --git a/test/4_pausing_contracts.ts b/test/4_pausing_contracts.ts index 00d1189e..621c3f45 100644 --- a/test/4_pausing_contracts.ts +++ b/test/4_pausing_contracts.ts @@ -262,9 +262,13 @@ describe('Cashier && VK', () => { await contractBosonRouter.pause(); await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, + utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, constants.product_price, - constants.buyer_deposit) + constants.buyer_deposit + ) ).to.be.revertedWith(revertReasons.PAUSED); }); }); @@ -346,9 +350,13 @@ describe('Cashier && VK', () => { await contractBosonRouter.pause(); await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, + utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, constants.product_price, - constants.buyer_deposit) + constants.buyer_deposit + ) ).to.be.revertedWith(revertReasons.PAUSED); }); }); @@ -435,7 +443,13 @@ describe('Cashier && VK', () => { await contractBosonRouter.pause(); await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit) + utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit + ) ).to.be.revertedWith(revertReasons.PAUSED); }); }); @@ -523,7 +537,13 @@ describe('Cashier && VK', () => { await contractBosonRouter.pause(); await expect( - utils.commitToBuy(users.buyer, users.seller, TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit) + utils.commitToBuy( + users.buyer, + users.seller, + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit + ) ).to.be.revertedWith(revertReasons.PAUSED); }); }); @@ -599,7 +619,9 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -613,7 +635,7 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, + TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit ); @@ -631,7 +653,9 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -645,7 +669,9 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(VOUCHER_ID, users.buyer.signer); @@ -705,7 +731,9 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -719,7 +747,9 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await utils.refund(VOUCHER_ID, users.buyer.signer); @@ -735,7 +765,9 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -749,7 +781,9 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(VOUCHER_ID, users.buyer.signer); @@ -803,7 +837,9 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -817,7 +853,9 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await utils.refund(VOUCHER_ID, users.buyer.signer); @@ -833,7 +871,9 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -847,7 +887,9 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(VOUCHER_ID, users.buyer.signer); @@ -911,8 +953,9 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, - constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -926,7 +969,9 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await utils.refund(VOUCHER_ID, users.buyer.signer); @@ -942,7 +987,9 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -956,8 +1003,9 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, - constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(VOUCHER_ID, users.buyer.signer); @@ -967,7 +1015,6 @@ describe('Cashier && VK', () => { utils.cancel(VOUCHER_ID, users.seller.signer) ).to.be.revertedWith(revertReasons.PAUSED); }); - }); describe('TKNTKN Same', () => { @@ -1017,8 +1064,9 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, - constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -1032,7 +1080,9 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await utils.refund(VOUCHER_ID, users.buyer.signer); @@ -1048,7 +1098,9 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await contractBosonRouter.pause(); @@ -1062,7 +1114,9 @@ describe('Cashier && VK', () => { VOUCHER_ID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await utils.redeem(VOUCHER_ID, users.buyer.signer); @@ -1163,7 +1217,9 @@ describe('Cashier && VK', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -1225,7 +1281,9 @@ describe('Cashier && VK', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); @@ -1280,7 +1338,9 @@ describe('Cashier && VK', () => { const voucherID = await utils.commitToBuy( users.buyer, users.seller, - TOKEN_SUPPLY_ID, constants.product_price, constants.buyer_deposit + TOKEN_SUPPLY_ID, + constants.product_price, + constants.buyer_deposit ); await utils.refund(voucherID, users.buyer.signer); diff --git a/testHelpers/utils.ts b/testHelpers/utils.ts index 5356b2a1..89e4c980 100644 --- a/testHelpers/utils.ts +++ b/testHelpers/utils.ts @@ -3,7 +3,6 @@ import {ecsign} from 'ethereumjs-util'; import {BigNumber, Contract, ContractTransaction, Signer} from 'ethers'; import {Account, DistributionAmounts, DistributionEvent} from './types'; -import constants from './constants'; import * as events from './events'; import fnSignatures from './functionSignatures'; import {toWei, getApprovalDigest} from '../testHelpers/permitUtils'; @@ -104,7 +103,7 @@ class Utils { sellerDeposit: number | string, buyerDeposit: number | string, qty: number | string, - returnTx = false, + returnTx = false ): Promise { const txValue = BN(sellerDeposit).mul(BN(qty)); @@ -121,7 +120,6 @@ class Utils { if (returnTx) return txOrder; // only needed when needed to get _tokenIdSupply. Not really checking anything. - // ?TODO make returnTx = true default? const txReceipt = await txOrder.wait(); let eventArgs; @@ -136,7 +134,6 @@ class Utils { } async requestCreateOrderETHTKNSameWithPermit( - // todo is this really needed? seller: Account, from: number, to: number, @@ -185,7 +182,6 @@ class Utils { if (returnTx) return txOrder; // only needed when needed to get _tokenIdSupply. Not really checking anything. - // ?TODO make returnTx = true default? const txReceipt = await txOrder.wait(); let eventArgs; @@ -207,7 +203,7 @@ class Utils { sellerDeposit: number | string, buyerDeposit: number | string, qty: number | string, - returnTx = false, + returnTx = false ): Promise { const txValue = BN(sellerDeposit).mul(BN(qty)); @@ -247,7 +243,6 @@ class Utils { if (returnTx) return txOrder; // only needed when needed to get _tokenIdSupply. Not really checking anything. - // ?TODO make returnTx = true default? const txReceipt = await txOrder.wait(); let eventArgs; @@ -312,20 +307,17 @@ class Utils { if (returnTx) return txOrder; - // only needed when needed to get _tokenIdSupply. Not really checking anything. - // ?TODO make returnTx = true default? - - // const txReceipt = await txOrder.wait(); - // let eventArgs; + const txReceipt = await txOrder.wait(); + let eventArgs; - // events.assertEventEmitted( - // txReceipt, - // this.factories.BosonRouter, - // events.eventNames.LOG_ORDER_CREATED, - // (e) => (eventArgs = e) - // ); + events.assertEventEmitted( + txReceipt, + this.factories.BosonRouter, + events.eventNames.LOG_ORDER_CREATED, + (e) => (eventArgs = e) + ); - // return eventArgs._tokenIdSupply.toString(); + return eventArgs._tokenIdSupply.toString(); } async requestCreateOrderETHTKNWithPermit( @@ -374,7 +366,6 @@ class Utils { if (returnTx) return txOrder; // only needed when needed to get _tokenIdSupply. Not really checking anything. - // ?TODO make returnTx = true default? const txReceipt = await txOrder.wait(); let eventArgs; @@ -396,7 +387,7 @@ class Utils { sellerDeposit: number | string, buyerDeposit: number | string, qty: number | string, - returnTx = false, + returnTx = false ): Promise { const txValue = BN(sellerDeposit).mul(BN(qty)); @@ -414,7 +405,6 @@ class Utils { if (returnTx) return txOrder; // only needed when needed to get _tokenIdSupply. Not really checking anything. - // ?TODO make returnTx = true default? const txReceipt = await txOrder.wait(); let eventArgs; @@ -496,7 +486,6 @@ class Utils { if (returnTx) return commitTx; // only needed when needed to get _tokenIdSupply. Not really checking anything. - // ?TODO make returnTx = true default? const txReceipt = await commitTx.wait(); let eventArgs; @@ -555,7 +544,6 @@ class Utils { if (returnTx) return commitTx; // only needed when needed to get _tokenIdSupply. Not really checking anything. - // ?TODO make returnTx = true default? const txReceipt = await commitTx.wait(); let eventArgs; @@ -610,7 +598,6 @@ class Utils { if (returnTx) return commitTx; // only needed when needed to get _tokenIdSupply. Not really checking anything. - // ?TODO make returnTx = true default? const txReceipt = await commitTx.wait(); let eventArgs; @@ -648,7 +635,6 @@ class Utils { if (returnTx) return commitTx; // only needed when needed to get _tokenIdSupply. Not really checking anything. - // ?TODO make returnTx = true default? const txReceipt = await commitTx.wait(); let eventArgs; @@ -703,7 +689,6 @@ class Utils { if (returnTx) return commitTx; // only needed when needed to get _tokenIdSupply. Not really checking anything. - // ?TODO make returnTx = true default? const txReceipt = await commitTx.wait(); let eventArgs; From cf7e38eae8ffdb5550ccfc8d254f7b55cb680beb Mon Sep 17 00:00:00 2001 From: zajck Date: Mon, 11 Oct 2021 16:11:39 +0200 Subject: [PATCH 37/41] remove stast/mockBosonRouter --- stash/MockBosonRouter.sol | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 stash/MockBosonRouter.sol diff --git a/stash/MockBosonRouter.sol b/stash/MockBosonRouter.sol deleted file mode 100644 index 74b94cf8..00000000 --- a/stash/MockBosonRouter.sol +++ /dev/null @@ -1,32 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-or-later -pragma solidity 0.7.6; - -import "./../BosonRouter.sol"; - -/** - * @title Mock Contract for testing purposes. - * @notice This mock passes an invalide value to createPaymentMethod from requestCreateOrderETHETH for the purpose of testing calls to VoucherKernel.createPaymentMethod and possibly other functions - */ -contract MockBosonRouter is BosonRouter { - constructor( - address _voucherKernel, - address _tokenRegistry, - address _cashierAddress - ) - BosonRouter(_voucherKernel, _tokenRegistry, _cashierAddress) - // solhint-disable-next-line - { - - } - - function requestCreateOrderETHETH(uint256[] calldata metadata) - external - payable - override - nonReentrant - whenNotPaused - { - checkLimits(metadata, address(0), address(0), 0); - requestCreateOrder(metadata, 5, address(0), address(0), 0); - } -} From 8313d0c2b0d1912598990c472092467104de6804 Mon Sep 17 00:00:00 2001 From: cliffhall Date: Tue, 12 Oct 2021 18:59:45 -0400 Subject: [PATCH 38/41] Updates to 'test full path with permit' test file. * Fixed a bunch of misspellings throughout that the IDE was flagging (produt, PromisId, paymeny,recepient) * Added check of supply holder before and after transfer in a few tests. In one test it didn't work and had a bizarre quality of always expecting the other of two addresses, when I changed the expected address, expected and actual values would inexplicably reverse. Left code commented out in one test with a TODO to call attention to it. * Fixed a weird situation that the IDE was flagging where some statements were separated with a comma instead of semicolon. * Attempted to add check of escrow balances, but it did not turn up the answers I thought I should be expecting. I left code commented out with a TODO and explanation of output I was seeing. --- test/2_test_fullpath_with_permit.ts | 179 ++++++++++++++++++++++------ testHelpers/utils.ts | 2 +- 2 files changed, 145 insertions(+), 36 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 80ba266b..4b16991a 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -307,7 +307,7 @@ describe('Cashier and VoucherKernel', () => { promiseOrderData[constants.PROMISE_ORDER_FIELDS.price].eq( BN(constants.PROMISE_PRICE1) ), - 'Promise produt price mismatch' + 'Promise product price mismatch' ); assert.isTrue( promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositSe].eq( @@ -336,7 +336,7 @@ describe('Cashier and VoucherKernel', () => { await contractVoucherKernel.getPromiseIdFromSupplyId( tokenSupplyKey ), - 'PromisId mismatch' + 'PromiseId mismatch' ); }); @@ -442,7 +442,7 @@ describe('Cashier and VoucherKernel', () => { promiseOrderData[constants.PROMISE_ORDER_FIELDS.price].eq( BN(constants.PROMISE_PRICE1) ), - 'Promise produt price mismatch' + 'Promise product price mismatch' ); assert.isTrue( @@ -654,7 +654,7 @@ describe('Cashier and VoucherKernel', () => { promiseOrderData[constants.PROMISE_ORDER_FIELDS.price].eq( BN(constants.PROMISE_PRICE1) ), - 'Promise produt price mismatch' + 'Promise product price mismatch' ); assert.isTrue( promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositSe].eq( @@ -683,7 +683,7 @@ describe('Cashier and VoucherKernel', () => { await contractVoucherKernel.getPromiseIdFromSupplyId( tokenSupplyKey ), - 'PromisId mismatch' + 'PromiseId mismatch' ); }); @@ -802,7 +802,7 @@ describe('Cashier and VoucherKernel', () => { promiseOrderData[constants.PROMISE_ORDER_FIELDS.price].eq( BN(constants.PROMISE_PRICE1) ), - 'Promise produt price mismatch' + 'Promise product price mismatch' ); assert.isTrue( @@ -936,7 +936,7 @@ describe('Cashier and VoucherKernel', () => { contractCashier, contractBosonRouter, contractBSNTokenPrice, - '' + contractBSNTokenDeposit ); const tokensToMint = BN(constants.product_price).mul( @@ -1051,7 +1051,7 @@ describe('Cashier and VoucherKernel', () => { promiseOrderData[constants.PROMISE_ORDER_FIELDS.price].eq( BN(constants.PROMISE_PRICE1) ), - 'Promise produt price mismatch' + 'Promise product price mismatch' ); assert.isTrue( promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositSe].eq( @@ -1080,7 +1080,7 @@ describe('Cashier and VoucherKernel', () => { await contractVoucherKernel.getPromiseIdFromSupplyId( tokenSupplyKey ), - 'PromisId mismatch' + 'PromiseId mismatch' ); }); @@ -1188,7 +1188,7 @@ describe('Cashier and VoucherKernel', () => { promiseOrderData[constants.PROMISE_ORDER_FIELDS.price].eq( BN(constants.PROMISE_PRICE1) ), - 'Promise produt price mismatch' + 'Promise product price mismatch' ); assert.isTrue( @@ -1407,7 +1407,7 @@ describe('Cashier and VoucherKernel', () => { promiseOrderData[constants.PROMISE_ORDER_FIELDS.price].eq( BN(constants.PROMISE_PRICE1) ), - 'Promise produt price mismatch' + 'Promise product price mismatch' ); assert.isTrue( promiseOrderData[constants.PROMISE_ORDER_FIELDS.depositSe].eq( @@ -1436,7 +1436,7 @@ describe('Cashier and VoucherKernel', () => { await contractVoucherKernel.getPromiseIdFromSupplyId( tokenSupplyKey ), - 'PromisId mismatch' + 'PromiseId mismatch' ); }); @@ -1555,7 +1555,7 @@ describe('Cashier and VoucherKernel', () => { promiseOrderData[constants.PROMISE_ORDER_FIELDS.price].eq( BN(constants.PROMISE_PRICE1) ), - 'Promise produt price mismatch' + 'Promise product price mismatch' ); assert.isTrue( @@ -3745,6 +3745,43 @@ describe('Cashier and VoucherKernel', () => { }); it('Should transfer voucher supply', async () => { + + // Check supply holder before + let supplyHolder = await contractVoucherKernel.getSupplyHolder(tokenSupplyKey); + + assert.equal( + supplyHolder, + users.other1.address, + 'Supply holder mismatch' + ); + +/* + // TODO: why doesn't this work? + let actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + users.other1.address + ); + let actualNewOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + users.other2.address + ); + + assert.isTrue( + actualOldOwnerBalanceFromEscrow.eq(BN(constants.PROMISE_DEPOSITSE1)), + 'Old owner balance from escrow does not match' + ); + assert.isTrue( + actualNewOwnerBalanceFromEscrow.eq(BN(constants.PROMISE_DEPOSITBU1)), + 'New owner balance from escrow does not match' + ); + + console.log (actualOldOwnerBalanceFromEscrow, BN(constants.PROMISE_DEPOSITSE1), actualNewOwnerBalanceFromEscrow, BN(constants.PROMISE_DEPOSITBU1) ) + // actualOldOwnerBalanceFromEscrow: BigNumber { _hex: '0x989680', _isBigNumber: true } + // BN(constants.PROMISE_DEPOSITSE1): BigNumber { _hex: '0x0f4240', _isBigNumber: true } + // actualNewOwnerBalanceFromEscrow: BigNumber { _hex: '0x00', _isBigNumber: true } + // BN(constants.PROMISE_DEPOSITBU1): BigNumber { _hex: '0x01', _isBigNumber: true } + + // From the setup in beforeEach, I expected these asserts to be true. why + +*/ // balances before const user1BalanceBeforeTransfer = ( await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( @@ -3819,6 +3856,15 @@ describe('Cashier and VoucherKernel', () => { constants.QTY_10, 'User2 after balance mismatch' ); + + supplyHolder = await contractVoucherKernel.getSupplyHolder(tokenSupplyKey); + + assert.equal( + supplyHolder, + users.other2.address, + 'Supply holder mismatch' + ); + }); it('Should transfer voucher supply to self and balance should be the same', async () => { @@ -3889,7 +3935,7 @@ describe('Cashier and VoucherKernel', () => { ).to.be.revertedWith(revertReasons.UNAUTHORIZED_TRANSFER_1155); }); - describe('Batchtransfers', () => { + describe('Batch transfers', () => { let tokenSupplyKey2; let tokenSupplyBatch; const batchQuantities = [BN(constants.QTY_10), BN(constants.QTY_20)]; @@ -3909,6 +3955,35 @@ describe('Cashier and VoucherKernel', () => { }); it('Should transfer batch voucher supply', async () => { + +/* + // TODO: why doesn't this work? + + // Check supply holder before + let supplyHolder = await contractVoucherKernel.getSupplyHolder(tokenSupplyKey2); + + assert.equal( + supplyHolder, + users.other1.address, + 'Supply holder mismatch' + ); + + // Supply holder mismatch + // + expected - actual + // + // -0x1487756254E93d00a6DCDfc40bAe757c1e99E8c0 + // +0x7aDCcBe646B707d0E8c0a339dF5277ee006f172B + + // But if I switch the expected supply holder to users.other1.address, + // it fails and the expected/actual values are REVERSED!!!! + + // Supply holder mismatch + // + expected - actual + // + // -0x7aDCcBe646B707d0E8c0a339dF5277ee006f172B + // +0x1487756254E93d00a6DCDfc40bAe757c1e99E8c0 +*/ + // balances before const user1BalanceBeforeTransfer = await contractERC1155ERC721.balanceOfBatch( [users.other1.address, users.other1.address], @@ -3980,9 +4055,20 @@ describe('Cashier and VoucherKernel', () => { JSON.stringify(batchQuantities), 'User2 after balance mismatch' ); + }); it('Should transfer batch voucher supply to self and balance should be the same', async () => { + + // Check supply holder before + let supplyHolder = await contractVoucherKernel.getSupplyHolder(tokenSupplyKey); + + assert.equal( + supplyHolder, + users.other1.address, + 'Supply holder mismatch' + ); + const balanceBeforeTransfer = await contractERC1155ERC721.balanceOfBatch( [users.other1.address, users.other1.address], tokenSupplyBatch @@ -4126,6 +4212,16 @@ describe('Cashier and VoucherKernel', () => { }); it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { + + // Check supply holder before + let supplyHolder = await contractVoucherKernel.getSupplyHolder(tokenSupplyKey); + + assert.equal( + supplyHolder, + users.other1.address, + 'Supply holder mismatch' + ); + const expectedBuyerAmount = BN(constants.PROMISE_DEPOSITBU1); const expectedSellerAmount = BN(constants.PROMISE_DEPOSITSE1).add( BN(constants.PROMISE_PRICE1) @@ -4250,6 +4346,7 @@ describe('Cashier and VoucherKernel', () => { users.buyer.address, users.other2.address ); + } ); @@ -4265,6 +4362,14 @@ describe('Cashier and VoucherKernel', () => { distributedAmounts.escrowAmount.eq(expectedEscrowAmount), 'Escrow Amount is not as expected' ); + + supplyHolder = await contractVoucherKernel.getSupplyHolder(tokenSupplyKey); + + assert.equal( + supplyHolder, + users.other2.address, + 'Supply holder mismatch' + ); }); it('New owner should be able to COF', async () => { @@ -5512,7 +5617,7 @@ describe('Cashier and VoucherKernel', () => { (ev) => { expect(ev._type).to.be.oneOf( Object.values(paymentType), - 'Wrong paymeny type' + 'Wrong payment type' ); switch (ev._type) { case paymentType.PAYMENT: @@ -5539,7 +5644,7 @@ describe('Cashier and VoucherKernel', () => { users.deployer.address, users.other2.address, ], - 'Unexpected recepient' + 'Unexpected recipient' ); switch (ev._to) { @@ -5926,7 +6031,7 @@ describe('Cashier and VoucherKernel', () => { (ev) => { expect(ev._type).to.be.oneOf( Object.values(paymentType), - 'Wrong paymeny type' + 'Wrong payment type' ); switch (ev._type) { case paymentType.PAYMENT: @@ -5953,7 +6058,7 @@ describe('Cashier and VoucherKernel', () => { users.deployer.address, users.other2.address, ], - 'Unexpected recepient' + 'Unexpected recipient' ); switch (ev._to) { @@ -6254,11 +6359,12 @@ describe('Cashier and VoucherKernel', () => { users.other2.address, voucherID, users.other1.signer - ), - (actualOldOwnerBalanceFromEscrowTknPrice = await contractCashier.getEscrowTokensAmount( - contractBSNTokenPrice.address, - users.other1.address - )); + ); + + (actualOldOwnerBalanceFromEscrowTknPrice = await contractCashier.getEscrowTokensAmount( + contractBSNTokenPrice.address, + users.other1.address + )); actualOldOwnerBalanceFromEscrowTknDeposit = await contractCashier.getEscrowTokensAmount( contractBSNTokenDeposit.address, @@ -6349,7 +6455,7 @@ describe('Cashier and VoucherKernel', () => { (ev) => { expect(ev._type).to.be.oneOf( Object.values(paymentType), - 'Wrong paymeny type' + 'Wrong payment type' ); switch (ev._type) { case paymentType.PAYMENT: @@ -6376,7 +6482,7 @@ describe('Cashier and VoucherKernel', () => { users.deployer.address, users.other2.address, ], - 'Unexpected recepient' + 'Unexpected recipient' ); switch (ev._to) { @@ -6666,10 +6772,11 @@ describe('Cashier and VoucherKernel', () => { users.other2.address, voucherID, users.other1.signer - ), - (actualOldOwnerBalanceFromEscrowEth = await contractCashier.getEscrowAmount( - users.other1.address - )); + ); + + (actualOldOwnerBalanceFromEscrowEth = await contractCashier.getEscrowAmount( + users.other1.address + )); actualOldOwnerBalanceFromEscrowTkn = await contractCashier.getEscrowTokensAmount( contractBSNTokenPrice.address, @@ -6814,7 +6921,7 @@ describe('Cashier and VoucherKernel', () => { (ev) => { expect(ev._type).to.be.oneOf( Object.values(paymentType), - 'Wrong paymeny type' + 'Wrong payment type' ); switch (ev._type) { case paymentType.PAYMENT: @@ -6841,7 +6948,7 @@ describe('Cashier and VoucherKernel', () => { users.deployer.address, users.other2.address, ], - 'Unexpected recepient' + 'Unexpected recipient' ); switch (ev._to) { @@ -6986,14 +7093,16 @@ describe('Cashier and VoucherKernel', () => { users.other2.address, voucherID, users.other1.signer - ), - await expect( - utils.redeem(voucherID, users.other1.signer) - ).to.be.revertedWith(revertReasons.UNAUTHORIZED_VOUCHER_OWNER); + ); + + await expect( + utils.redeem(voucherID, users.other1.signer) + ).to.be.revertedWith(revertReasons.UNAUTHORIZED_VOUCHER_OWNER); await expect( utils.refund(voucherID, users.other1.signer) ).to.be.revertedWith(revertReasons.UNAUTHORIZED_VOUCHER_OWNER); + }); it('[NEGATIVE] Transfer should revert if Attacker tries to execute voucher transfer', async () => { diff --git a/testHelpers/utils.ts b/testHelpers/utils.ts index 89e4c980..c4c45e98 100644 --- a/testHelpers/utils.ts +++ b/testHelpers/utils.ts @@ -749,7 +749,7 @@ class Utils { const receipt = await tx.wait(); - console.log('GAS USED: ', receipt.gasUsed.toString()); + //console.log('GAS USED: ', receipt.gasUsed.toString()); return tx; } From 885c74d9f356724716db5f0655ace12a40ecb6c2 Mon Sep 17 00:00:00 2001 From: zajck Date: Wed, 13 Oct 2021 08:25:59 +0200 Subject: [PATCH 39/41] checking supply holders --- test/2_test_fullpath_with_permit.ts | 60 +++++++---------------------- 1 file changed, 14 insertions(+), 46 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 4b16991a..2def661f 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -3745,16 +3745,9 @@ describe('Cashier and VoucherKernel', () => { }); it('Should transfer voucher supply', async () => { - - // Check supply holder before - let supplyHolder = await contractVoucherKernel.getSupplyHolder(tokenSupplyKey); - - assert.equal( - supplyHolder, - users.other1.address, - 'Supply holder mismatch' - ); - + // Check supply holder before + expect(await contractVoucherKernel.getSupplyHolder(tokenSupplyKey)).to.equal(users.other1.address, 'Supply 1 before - holder mismatch'); + /* // TODO: why doesn't this work? let actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( @@ -3857,13 +3850,8 @@ describe('Cashier and VoucherKernel', () => { 'User2 after balance mismatch' ); - supplyHolder = await contractVoucherKernel.getSupplyHolder(tokenSupplyKey); - - assert.equal( - supplyHolder, - users.other2.address, - 'Supply holder mismatch' - ); + // Check supply holder after + expect(await contractVoucherKernel.getSupplyHolder(tokenSupplyKey)).to.equal(users.other2.address, 'Supply 1 after - holder mismatch'); }); @@ -3954,36 +3942,11 @@ describe('Cashier and VoucherKernel', () => { tokenSupplyBatch = [BN(tokenSupplyKey), BN(tokenSupplyKey2)]; }); - it('Should transfer batch voucher supply', async () => { - -/* - // TODO: why doesn't this work? - + it.only('Should transfer batch voucher supply', async () => { // Check supply holder before - let supplyHolder = await contractVoucherKernel.getSupplyHolder(tokenSupplyKey2); - - assert.equal( - supplyHolder, - users.other1.address, - 'Supply holder mismatch' - ); - - // Supply holder mismatch - // + expected - actual - // - // -0x1487756254E93d00a6DCDfc40bAe757c1e99E8c0 - // +0x7aDCcBe646B707d0E8c0a339dF5277ee006f172B - - // But if I switch the expected supply holder to users.other1.address, - // it fails and the expected/actual values are REVERSED!!!! - - // Supply holder mismatch - // + expected - actual - // - // -0x7aDCcBe646B707d0E8c0a339dF5277ee006f172B - // +0x1487756254E93d00a6DCDfc40bAe757c1e99E8c0 -*/ - + expect(await contractVoucherKernel.getSupplyHolder(tokenSupplyKey)).to.equal(users.other1.address, 'Supply 1 before - holder mismatch'); + expect(await contractVoucherKernel.getSupplyHolder(tokenSupplyKey2)).to.equal(users.other1.address, 'Supply 2 before - holder mismatch'); + // balances before const user1BalanceBeforeTransfer = await contractERC1155ERC721.balanceOfBatch( [users.other1.address, users.other1.address], @@ -4056,6 +4019,11 @@ describe('Cashier and VoucherKernel', () => { 'User2 after balance mismatch' ); + + // Check supply holder after + expect(await contractVoucherKernel.getSupplyHolder(tokenSupplyKey)).to.equal(users.other2.address, 'Supply 1 after - holder mismatch'); + expect(await contractVoucherKernel.getSupplyHolder(tokenSupplyKey2)).to.equal(users.other2.address, 'Supply 2 after - holder mismatch'); + }); it('Should transfer batch voucher supply to self and balance should be the same', async () => { From 9511db4566bc291434ba1c4acae820cb6cc41489 Mon Sep 17 00:00:00 2001 From: zajck Date: Wed, 13 Oct 2021 13:28:47 +0200 Subject: [PATCH 40/41] more thorough state checking after voucher(set) transfer --- test/2_test_fullpath_with_permit.ts | 460 +++++++++++++++++++++++++--- 1 file changed, 412 insertions(+), 48 deletions(-) diff --git a/test/2_test_fullpath_with_permit.ts b/test/2_test_fullpath_with_permit.ts index 2def661f..e75bba8e 100644 --- a/test/2_test_fullpath_with_permit.ts +++ b/test/2_test_fullpath_with_permit.ts @@ -3745,11 +3745,15 @@ describe('Cashier and VoucherKernel', () => { }); it('Should transfer voucher supply', async () => { - // Check supply holder before - expect(await contractVoucherKernel.getSupplyHolder(tokenSupplyKey)).to.equal(users.other1.address, 'Supply 1 before - holder mismatch'); - -/* - // TODO: why doesn't this work? + // Check supply holder before + expect( + await contractVoucherKernel.getSupplyHolder(tokenSupplyKey) + ).to.equal(users.other1.address, 'Supply 1 before - holder mismatch'); + + const expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(constants.QTY_10) + ); + let actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( users.other1.address ); @@ -3758,23 +3762,14 @@ describe('Cashier and VoucherKernel', () => { ); assert.isTrue( - actualOldOwnerBalanceFromEscrow.eq(BN(constants.PROMISE_DEPOSITSE1)), + actualOldOwnerBalanceFromEscrow.eq(expectedBalanceInEscrow), 'Old owner balance from escrow does not match' ); assert.isTrue( - actualNewOwnerBalanceFromEscrow.eq(BN(constants.PROMISE_DEPOSITBU1)), + actualNewOwnerBalanceFromEscrow.eq(constants.ZERO), 'New owner balance from escrow does not match' ); - console.log (actualOldOwnerBalanceFromEscrow, BN(constants.PROMISE_DEPOSITSE1), actualNewOwnerBalanceFromEscrow, BN(constants.PROMISE_DEPOSITBU1) ) - // actualOldOwnerBalanceFromEscrow: BigNumber { _hex: '0x989680', _isBigNumber: true } - // BN(constants.PROMISE_DEPOSITSE1): BigNumber { _hex: '0x0f4240', _isBigNumber: true } - // actualNewOwnerBalanceFromEscrow: BigNumber { _hex: '0x00', _isBigNumber: true } - // BN(constants.PROMISE_DEPOSITBU1): BigNumber { _hex: '0x01', _isBigNumber: true } - - // From the setup in beforeEach, I expected these asserts to be true. why - -*/ // balances before const user1BalanceBeforeTransfer = ( await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( @@ -3850,12 +3845,47 @@ describe('Cashier and VoucherKernel', () => { 'User2 after balance mismatch' ); - // Check supply holder after - expect(await contractVoucherKernel.getSupplyHolder(tokenSupplyKey)).to.equal(users.other2.address, 'Supply 1 after - holder mismatch'); + actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + users.other1.address + ); + actualNewOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + users.other2.address + ); + assert.isTrue( + actualOldOwnerBalanceFromEscrow.eq(constants.ZERO), + 'Old owner balance from escrow does not match' + ); + assert.isTrue( + actualNewOwnerBalanceFromEscrow.eq(expectedBalanceInEscrow), + 'New owner balance from escrow does not match' + ); + + // Check supply holder after + expect( + await contractVoucherKernel.getSupplyHolder(tokenSupplyKey) + ).to.equal(users.other2.address, 'Supply 1 after - holder mismatch'); }); it('Should transfer voucher supply to self and balance should be the same', async () => { + // Check supply holder before + expect( + await contractVoucherKernel.getSupplyHolder(tokenSupplyKey) + ).to.equal(users.other1.address, 'Supply 1 before - holder mismatch'); + + const expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( + BN(constants.QTY_10) + ); + + let actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + users.other1.address + ); + + assert.isTrue( + actualOldOwnerBalanceFromEscrow.eq(expectedBalanceInEscrow), + 'Old owner balance from escrow does not match' + ); + const balanceBeforeTransfer = ( await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( users.other1.address, @@ -3897,6 +3927,20 @@ describe('Cashier and VoucherKernel', () => { assert.equal(ev._value.toString(), constants.QTY_10); } ); + + actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + users.other1.address + ); + + assert.isTrue( + actualOldOwnerBalanceFromEscrow.eq(expectedBalanceInEscrow), + 'Old owner balance from escrow does not match' + ); + + // Check supply holder after + expect( + await contractVoucherKernel.getSupplyHolder(tokenSupplyKey) + ).to.equal(users.other1.address, 'Supply 1 after - holder mismatch'); }); it('[NEGATIVE] Should revert if owner tries to transfer voucher supply partially', async () => { @@ -3942,12 +3986,36 @@ describe('Cashier and VoucherKernel', () => { tokenSupplyBatch = [BN(tokenSupplyKey), BN(tokenSupplyKey2)]; }); - it.only('Should transfer batch voucher supply', async () => { + it('Should transfer batch voucher supply', async () => { // Check supply holder before - expect(await contractVoucherKernel.getSupplyHolder(tokenSupplyKey)).to.equal(users.other1.address, 'Supply 1 before - holder mismatch'); - expect(await contractVoucherKernel.getSupplyHolder(tokenSupplyKey2)).to.equal(users.other1.address, 'Supply 2 before - holder mismatch'); - + expect( + await contractVoucherKernel.getSupplyHolder(tokenSupplyKey) + ).to.equal(users.other1.address, 'Supply 1 before - holder mismatch'); + expect( + await contractVoucherKernel.getSupplyHolder(tokenSupplyKey2) + ).to.equal(users.other1.address, 'Supply 2 before - holder mismatch'); + // balances before + let actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + users.other1.address + ); + let actualNewOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + users.other2.address + ); + + const expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1) + .mul(BN(constants.QTY_10)) + .add(BN(constants.PROMISE_DEPOSITSE2).mul(BN(constants.QTY_20))); + + assert.isTrue( + actualOldOwnerBalanceFromEscrow.eq(expectedBalanceInEscrow), + 'Old owner balance from escrow does not match' + ); + assert.isTrue( + actualNewOwnerBalanceFromEscrow.eq(constants.ZERO), + 'New owner balance from escrow does not match' + ); + const user1BalanceBeforeTransfer = await contractERC1155ERC721.balanceOfBatch( [users.other1.address, users.other1.address], tokenSupplyBatch @@ -4019,22 +4087,52 @@ describe('Cashier and VoucherKernel', () => { 'User2 after balance mismatch' ); + actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + users.other1.address + ); + actualNewOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + users.other2.address + ); - // Check supply holder after - expect(await contractVoucherKernel.getSupplyHolder(tokenSupplyKey)).to.equal(users.other2.address, 'Supply 1 after - holder mismatch'); - expect(await contractVoucherKernel.getSupplyHolder(tokenSupplyKey2)).to.equal(users.other2.address, 'Supply 2 after - holder mismatch'); + assert.isTrue( + actualOldOwnerBalanceFromEscrow.eq(constants.ZERO), + 'Old owner balance from escrow does not match' + ); + assert.isTrue( + actualNewOwnerBalanceFromEscrow.eq(expectedBalanceInEscrow), + 'New owner balance from escrow does not match' + ); + // Check supply holder after + expect( + await contractVoucherKernel.getSupplyHolder(tokenSupplyKey) + ).to.equal(users.other2.address, 'Supply 1 after - holder mismatch'); + expect( + await contractVoucherKernel.getSupplyHolder(tokenSupplyKey2) + ).to.equal(users.other2.address, 'Supply 2 after - holder mismatch'); }); it('Should transfer batch voucher supply to self and balance should be the same', async () => { - // Check supply holder before - let supplyHolder = await contractVoucherKernel.getSupplyHolder(tokenSupplyKey); + expect( + await contractVoucherKernel.getSupplyHolder(tokenSupplyKey) + ).to.equal(users.other1.address, 'Supply 1 before - holder mismatch'); + expect( + await contractVoucherKernel.getSupplyHolder(tokenSupplyKey2) + ).to.equal(users.other1.address, 'Supply 2 before - holder mismatch'); - assert.equal( - supplyHolder, - users.other1.address, - 'Supply holder mismatch' + // balances before + let actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + users.other1.address + ); + + const expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1) + .mul(BN(constants.QTY_10)) + .add(BN(constants.PROMISE_DEPOSITSE2).mul(BN(constants.QTY_20))); + + assert.isTrue( + actualOldOwnerBalanceFromEscrow.eq(expectedBalanceInEscrow), + 'Old owner balance from escrow does not match' ); const balanceBeforeTransfer = await contractERC1155ERC721.balanceOfBatch( @@ -4080,6 +4178,23 @@ describe('Cashier and VoucherKernel', () => { ); } ); + + actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + users.other1.address + ); + + assert.isTrue( + actualOldOwnerBalanceFromEscrow.eq(expectedBalanceInEscrow), + 'Old owner balance from escrow does not match' + ); + + // Check supply holder after + expect( + await contractVoucherKernel.getSupplyHolder(tokenSupplyKey) + ).to.equal(users.other1.address, 'Supply 1 after - holder mismatch'); + expect( + await contractVoucherKernel.getSupplyHolder(tokenSupplyKey2) + ).to.equal(users.other1.address, 'Supply 2 after - holder mismatch'); }); it('[NEGATIVE] Should revert if owner tries to transfer voucher supply batch partially', async () => { @@ -4134,6 +4249,11 @@ describe('Cashier and VoucherKernel', () => { }); it('Should update escrow amounts after transfer', async () => { + // Check supply holder before + expect( + await contractVoucherKernel.getSupplyHolder(tokenSupplyKey) + ).to.equal(users.other1.address, 'Supply 1 before - holder mismatch'); + const expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( BN(constants.QTY_1) ); @@ -4177,12 +4297,18 @@ describe('Cashier and VoucherKernel', () => { actualNewOwnerBalanceFromEscrow.eq(expectedBalanceInEscrow), 'New owner balance from escrow does not match' ); + + // Check supply holder after + expect( + await contractVoucherKernel.getSupplyHolder(tokenSupplyKey) + ).to.equal(users.other2.address, 'Supply 1 after - holder mismatch'); }); it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { - // Check supply holder before - let supplyHolder = await contractVoucherKernel.getSupplyHolder(tokenSupplyKey); + let supplyHolder = await contractVoucherKernel.getSupplyHolder( + tokenSupplyKey + ); assert.equal( supplyHolder, @@ -4314,7 +4440,6 @@ describe('Cashier and VoucherKernel', () => { users.buyer.address, users.other2.address ); - } ); @@ -4331,7 +4456,9 @@ describe('Cashier and VoucherKernel', () => { 'Escrow Amount is not as expected' ); - supplyHolder = await contractVoucherKernel.getSupplyHolder(tokenSupplyKey); + supplyHolder = await contractVoucherKernel.getSupplyHolder( + tokenSupplyKey + ); assert.equal( supplyHolder, @@ -4434,6 +4561,12 @@ describe('Cashier and VoucherKernel', () => { }); it('Should update escrow amounts after transfer', async () => { + // Check supply holder before + expect( + await contractVoucherKernel.getSupplyHolder(tokenSupplyKey) + ).to.equal(users.other1.address, 'Supply 1 before - holder mismatch'); + + // balances before const expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( BN(constants.QTY_1) ); @@ -4456,6 +4589,31 @@ describe('Cashier and VoucherKernel', () => { 'New owner balance from escrow does not match' ); + const user1BalanceBeforeTransfer = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.other1.address, + tokenSupplyKey + ) + )[0]; + + const user2BalanceBeforeTransfer = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.other2.address, + tokenSupplyKey + ) + )[0]; + + assert.equal( + user1BalanceBeforeTransfer, + constants.QTY_1, + 'User1 before balance mismatch' + ); + assert.equal( + user2BalanceBeforeTransfer, + 0, + 'User2 before balance mismatch' + ); + await utils.safeTransfer1155( users.other1.address, users.other2.address, @@ -4464,6 +4622,7 @@ describe('Cashier and VoucherKernel', () => { users.other1.signer ); + // balances after actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowTokensAmount( contractBSNTokenDeposit.address, users.other1.address @@ -4473,6 +4632,31 @@ describe('Cashier and VoucherKernel', () => { users.other2.address ); + const user1BalanceAfterTransfer = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.other1.address, + tokenSupplyKey + ) + )[0]; + + const user2BalanceAfterTransfer = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.other2.address, + tokenSupplyKey + ) + )[0]; + + assert.equal( + user1BalanceAfterTransfer, + 0, + 'User1 after balance mismatch' + ); + assert.equal( + user2BalanceAfterTransfer, + constants.QTY_1, + 'User2 after balance mismatch' + ); + assert.isTrue( actualOldOwnerBalanceFromEscrow.eq(constants.ZERO), 'Old owner balance from escrow does not match' @@ -4481,6 +4665,11 @@ describe('Cashier and VoucherKernel', () => { actualNewOwnerBalanceFromEscrow.eq(expectedBalanceInEscrow), 'New owner balance from escrow does not match' ); + + // Check supply holder after + expect( + await contractVoucherKernel.getSupplyHolder(tokenSupplyKey) + ).to.equal(users.other2.address, 'Supply 1 after - holder mismatch'); }); it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { @@ -4737,6 +4926,12 @@ describe('Cashier and VoucherKernel', () => { }); it('Should update escrow amounts after transfer', async () => { + // Check supply holder before + expect( + await contractVoucherKernel.getSupplyHolder(tokenSupplyKey) + ).to.equal(users.other1.address, 'Supply 1 before - holder mismatch'); + + // balances before transfer const expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( BN(constants.QTY_1) ); @@ -4750,6 +4945,31 @@ describe('Cashier and VoucherKernel', () => { users.other2.address ); + const user1BalanceBeforeTransfer = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.other1.address, + tokenSupplyKey + ) + )[0]; + + const user2BalanceBeforeTransfer = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.other2.address, + tokenSupplyKey + ) + )[0]; + + assert.equal( + user1BalanceBeforeTransfer, + constants.QTY_1, + 'User1 before balance mismatch' + ); + assert.equal( + user2BalanceBeforeTransfer, + 0, + 'User2 before balance mismatch' + ); + assert.isTrue( actualOldOwnerBalanceFromEscrow.eq(expectedBalanceInEscrow), 'Old owner balance from escrow does not match' @@ -4767,6 +4987,7 @@ describe('Cashier and VoucherKernel', () => { users.other1.signer ); + // balances after actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowTokensAmount( contractBSNTokenDeposit.address, users.other1.address @@ -4784,6 +5005,36 @@ describe('Cashier and VoucherKernel', () => { actualNewOwnerBalanceFromEscrow.eq(expectedBalanceInEscrow), 'New owner balance from escrow does not match' ); + + const user1BalanceAfterTransfer = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.other1.address, + tokenSupplyKey + ) + )[0]; + + const user2BalanceAfterTransfer = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.other2.address, + tokenSupplyKey + ) + )[0]; + + assert.equal( + user1BalanceAfterTransfer, + 0, + 'User1 after balance mismatch' + ); + assert.equal( + user2BalanceAfterTransfer, + constants.QTY_1, + 'User2 after balance mismatch' + ); + + // Check supply holder after + expect( + await contractVoucherKernel.getSupplyHolder(tokenSupplyKey) + ).to.equal(users.other2.address, 'Supply 1 after - holder mismatch'); }); it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { @@ -5036,6 +5287,12 @@ describe('Cashier and VoucherKernel', () => { }); it('Should update escrow amounts after transfer', async () => { + // Check supply holder before + expect( + await contractVoucherKernel.getSupplyHolder(tokenSupplyKey) + ).to.equal(users.other1.address, 'Supply 1 before - holder mismatch'); + + // balances before const expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITSE1).mul( BN(constants.QTY_1) ); @@ -5056,6 +5313,31 @@ describe('Cashier and VoucherKernel', () => { 'New owner balance from escrow does not match' ); + const user1BalanceBeforeTransfer = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.other1.address, + tokenSupplyKey + ) + )[0]; + + const user2BalanceBeforeTransfer = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.other2.address, + tokenSupplyKey + ) + )[0]; + + assert.equal( + user1BalanceBeforeTransfer, + constants.QTY_1, + 'User1 before balance mismatch' + ); + assert.equal( + user2BalanceBeforeTransfer, + 0, + 'User2 before balance mismatch' + ); + await utils.safeTransfer1155( users.other1.address, users.other2.address, @@ -5064,6 +5346,7 @@ describe('Cashier and VoucherKernel', () => { users.other1.signer ); + // balances after actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( users.other1.address ); @@ -5079,6 +5362,36 @@ describe('Cashier and VoucherKernel', () => { actualNewOwnerBalanceFromEscrow.eq(expectedBalanceInEscrow), 'New owner balance from escrow does not match' ); + + const user1BalanceAfterTransfer = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.other1.address, + tokenSupplyKey + ) + )[0]; + + const user2BalanceAfterTransfer = ( + await contractERC1155ERC721.functions[fnSignatures.balanceOf1155]( + users.other2.address, + tokenSupplyKey + ) + )[0]; + + assert.equal( + user1BalanceAfterTransfer, + 0, + 'User1 after balance mismatch' + ); + assert.equal( + user2BalanceAfterTransfer, + constants.QTY_1, + 'User2 after balance mismatch' + ); + + // Check supply holder after + expect( + await contractVoucherKernel.getSupplyHolder(tokenSupplyKey) + ).to.equal(users.other2.address, 'Supply 1 after - holder mismatch'); }); it('Should finalize 1 voucher to ensure payments are sent to the new owner', async () => { @@ -5345,6 +5658,26 @@ describe('Cashier and VoucherKernel', () => { it('Should transfer a voucher', async () => { // balances before + const expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITBU1).add( + constants.PROMISE_PRICE1 + ); + + let actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + users.other1.address + ); + let actualNewOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + users.other2.address + ); + + assert.isTrue( + actualOldOwnerBalanceFromEscrow.eq(expectedBalanceInEscrow), + 'Old owner balance from escrow does not match' + ); + assert.isTrue( + actualNewOwnerBalanceFromEscrow.eq(constants.ZERO), + 'New owner balance from escrow does not match' + ); + expect( ( await contractERC1155ERC721.functions[fnSignatures.balanceOf721]( @@ -5373,6 +5706,22 @@ describe('Cashier and VoucherKernel', () => { .withArgs(users.other1.address, users.other2.address, voucherID); // balances after + actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + users.other1.address + ); + actualNewOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + users.other2.address + ); + + assert.isTrue( + actualOldOwnerBalanceFromEscrow.eq(constants.ZERO), + 'Old owner balance from escrow does not match' + ); + assert.isTrue( + actualNewOwnerBalanceFromEscrow.eq(expectedBalanceInEscrow), + 'New owner balance from escrow does not match' + ); + expect( ( await contractERC1155ERC721.functions[fnSignatures.balanceOf721]( @@ -5391,17 +5740,23 @@ describe('Cashier and VoucherKernel', () => { }); it('Should transfer voucher to self and balance should be the same', async () => { - const balanceOf = - contractERC1155ERC721.functions[fnSignatures.balanceOf721]; + // balances before + const expectedBalanceInEscrow = BN(constants.PROMISE_DEPOSITBU1).add( + constants.PROMISE_PRICE1 + ); - const voucherID = await utils.commitToBuy( - users.other1, - users.seller, - tokenSupplyKey, - constants.PROMISE_PRICE1, - constants.PROMISE_DEPOSITBU1 + let actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + users.other1.address + ); + + assert.isTrue( + actualOldOwnerBalanceFromEscrow.eq(expectedBalanceInEscrow), + 'Old owner balance from escrow does not match' ); + const balanceOf = + contractERC1155ERC721.functions[fnSignatures.balanceOf721]; + const balanceBeforeTransfer = ( await balanceOf(users.other1.address) )[0]; @@ -5417,6 +5772,16 @@ describe('Cashier and VoucherKernel', () => { .to.emit(contractERC1155ERC721, eventNames.TRANSFER) .withArgs(users.other1.address, users.other1.address, voucherID); + // balances after + actualOldOwnerBalanceFromEscrow = await contractCashier.getEscrowAmount( + users.other1.address + ); + + assert.isTrue( + actualOldOwnerBalanceFromEscrow.eq(expectedBalanceInEscrow), + 'Old owner balance from escrow does not match' + ); + const balanceAfterTransfer = (await balanceOf(users.other1.address))[0]; assert.isTrue( @@ -6329,10 +6694,10 @@ describe('Cashier and VoucherKernel', () => { users.other1.signer ); - (actualOldOwnerBalanceFromEscrowTknPrice = await contractCashier.getEscrowTokensAmount( + actualOldOwnerBalanceFromEscrowTknPrice = await contractCashier.getEscrowTokensAmount( contractBSNTokenPrice.address, users.other1.address - )); + ); actualOldOwnerBalanceFromEscrowTknDeposit = await contractCashier.getEscrowTokensAmount( contractBSNTokenDeposit.address, @@ -6742,9 +7107,9 @@ describe('Cashier and VoucherKernel', () => { users.other1.signer ); - (actualOldOwnerBalanceFromEscrowEth = await contractCashier.getEscrowAmount( + actualOldOwnerBalanceFromEscrowEth = await contractCashier.getEscrowAmount( users.other1.address - )); + ); actualOldOwnerBalanceFromEscrowTkn = await contractCashier.getEscrowTokensAmount( contractBSNTokenPrice.address, @@ -7070,7 +7435,6 @@ describe('Cashier and VoucherKernel', () => { await expect( utils.refund(voucherID, users.other1.signer) ).to.be.revertedWith(revertReasons.UNAUTHORIZED_VOUCHER_OWNER); - }); it('[NEGATIVE] Transfer should revert if Attacker tries to execute voucher transfer', async () => { From 7869e6dae48bc2857645c928900f8de4bc9ef99a Mon Sep 17 00:00:00 2001 From: zajck Date: Wed, 13 Oct 2021 14:46:38 +0200 Subject: [PATCH 41/41] removing gas used output --- testHelpers/utils.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/testHelpers/utils.ts b/testHelpers/utils.ts index c4c45e98..197f997c 100644 --- a/testHelpers/utils.ts +++ b/testHelpers/utils.ts @@ -747,10 +747,6 @@ class Utils { const deployerInstance = this.contractCashier.connect(deployer) as Cashier; const tx = await deployerInstance.withdraw(voucherID); - const receipt = await tx.wait(); - - //console.log('GAS USED: ', receipt.gasUsed.toString()); - return tx; }