示例#1
0
def test_wrapper_transfer_transferFee_4(accounts, erc721mock, wrapper, niftsy20, dai, weth, trmodel):
	#make test data
	erc721mock.transferFrom(accounts[0], accounts[1], ORIGINAL_NFT_IDs[3], {'from':accounts[0]})
	erc721mock.approve(wrapper.address, ORIGINAL_NFT_IDs[3], {'from':accounts[1]})
	logging.info('balanceOf(wrapper.address) = {}'.format(niftsy20.balanceOf(wrapper.address)))
	logging.info('balanceOf(royaltyBeneficiary) = {}'.format(niftsy20.balanceOf(royaltyBeneficiary)))
	#wrap difficult nft

	niftsy20.transfer(accounts[1], protokolFee, {"from": accounts[0]})
	unwrapAfter = chain.time() + 10
	
	before_balance = niftsy20.balanceOf(wrapper.address)
	niftsy20.approve(trmodel, TRANSFER_FEE, {'from':accounts[1]}) 
	makeWrapNFT(wrapper, erc721mock, ['originalTokenId', 'transferFee', 'royaltyPercent' ], [ORIGINAL_NFT_IDs[3], 1, 1], accounts[1], niftsy20)
	assert niftsy20.balanceOf(accounts[1]) == 0
	assert niftsy20.balanceOf(wrapper.address) == before_balance + protokolFee
	assert wrapper.lastWrappedNFTId() == 4

	tokenId = wrapper.lastWrappedNFTId()
	nft = wrapper.getWrappedToken(tokenId)
	logging.info('nft3 = {}'.format(nft))

	checkWrappedNFT(wrapper, 
		tokenId, 
		erc721mock.address, 
		ORIGINAL_NFT_IDs[3], 
		START_NATIVE_COLLATERAL, 
		0,  
		unwrapAfter, 
		1, 
		royaltyBeneficiary, 
		1, 
		UNWRAP_FEE_THRESHOLD)

	wrapper.approve(accounts[3].address, tokenId, {"from": accounts[1]})
	before_balance = niftsy20.balanceOf(wrapper.address) 
	before_balance_royalty = niftsy20.balanceOf(royaltyBeneficiary) 
	niftsy20.transfer(accounts[1].address, 1, {"from": accounts[0]}) #add niftsy tokens to pay transfer fee
	wrapper.transferFrom(accounts[1].address, accounts[2].address, tokenId, {"from": accounts[3]})
	logging.info('balanceOf(wrapper.address) = {}'.format(niftsy20.balanceOf(wrapper.address)))
	logging.info('balanceOf(royaltyBeneficiary) = {}'.format(niftsy20.balanceOf(royaltyBeneficiary)))

	nft = wrapper.getWrappedToken(tokenId)
	logging.info('nft3 = {}'.format(nft))
	assert niftsy20.balanceOf(accounts[1]) == 0
	assert niftsy20.balanceOf(wrapper.address) == before_balance + 1 - round(nft[5]*nft[7]/100)
	assert niftsy20.balanceOf(royaltyBeneficiary) == before_balance_royalty + round(nft[5]*nft[7]/100)
	checkWrappedNFT(wrapper, 
		tokenId, 
		erc721mock.address, 
		ORIGINAL_NFT_IDs[3], 
		START_NATIVE_COLLATERAL, 
		1 - round(nft[5]*nft[7]/100), 
		unwrapAfter, 
		1, 
		royaltyBeneficiary, 
		1, 
		UNWRAP_FEE_THRESHOLD)
示例#2
0
def test_wrapper_transfer_transferFee_2(accounts, erc721mock, wrapper, niftsy20, dai, weth, trmodel):
	#make test data
	erc721mock.transferFrom(accounts[0], accounts[1], ORIGINAL_NFT_IDs[1], {'from':accounts[0]})
	erc721mock.approve(wrapper.address, ORIGINAL_NFT_IDs[1], {'from':accounts[1]})
	#wrap difficult nft

	niftsy20.transfer(accounts[1], protokolFee, {"from": accounts[0]})
	unwrapAfter = chain.time() + 10
	
	makeWrapNFT(wrapper, erc721mock, ['originalTokenId', 'royaltyBeneficiary', 'royaltyPercent'], [ORIGINAL_NFT_IDs[1], zero_address, 0], accounts[1], niftsy20)
	assert niftsy20.balanceOf(accounts[1]) == 0
	assert niftsy20.balanceOf(wrapper.address) == 2 * protokolFee
	assert wrapper.lastWrappedNFTId() == 2

	tokenId = wrapper.lastWrappedNFTId()
	nft = wrapper.getWrappedToken(tokenId)
	logging.info('nft1 = {}'.format(nft))

	checkWrappedNFT(wrapper, 
		tokenId, 
		erc721mock.address, 
		ORIGINAL_NFT_IDs[1], 
		START_NATIVE_COLLATERAL, 
		0,  
		unwrapAfter, 
		TRANSFER_FEE, 
		zero_address, 
		0, 
		UNWRAP_FEE_THRESHOLD)

	#not enough niftsy20 tokens for paying of transferFee
	wrapper.approve(accounts[3].address, tokenId, {"from": accounts[1]})
	with reverts("insufficient NIFTSY balance for fee"):
		wrapper.transferFrom(accounts[1].address, accounts[2].address, tokenId, {"from": accounts[3]})
	#add niftsy tokens to acc1
	before_balance = niftsy20.balanceOf(wrapper.address) 
	niftsy20.transfer(accounts[1].address, TRANSFER_FEE, {"from": accounts[0]}) #add niftsy tokens to pay transfer fee
	niftsy20.approve(trmodel, TRANSFER_FEE, {'from':accounts[1]})
	wrapper.transferFrom(accounts[1].address, accounts[2].address, tokenId, {"from": accounts[3]})

	nft = wrapper.getWrappedToken(tokenId)
	logging.info('nft1 = {}'.format(nft))
	assert niftsy20.balanceOf(accounts[1]) == 0
	assert niftsy20.balanceOf(wrapper.address) == before_balance + TRANSFER_FEE
	checkWrappedNFT(wrapper, 
		tokenId, 
		erc721mock.address, 
		ORIGINAL_NFT_IDs[1], 
		START_NATIVE_COLLATERAL, 
		TRANSFER_FEE,  
		unwrapAfter, 
		TRANSFER_FEE, 
		zero_address, 
		0, 
		UNWRAP_FEE_THRESHOLD)
示例#3
0
def test_wrapper_transfer_1(accounts, erc721mock, wrapper, niftsy20, dai, weth, trmodel):
	#make test data
	makeNFTForTest(accounts, erc721mock, ORIGINAL_NFT_IDs)
	wrapper.setFee(protokolFee, chargeFeeAfter, niftsy20, {"from": accounts[0]})
	#wrap difficult nft

	niftsy20.transfer(accounts[1], protokolFee, {"from": accounts[0]})
	unwrapAfter = chain.time() + 10

	erc721mock.approve(wrapper.address, ORIGINAL_NFT_IDs[0], {'from':accounts[1]})
	niftsy20.approve(wrapper, TRANSFER_FEE, {'from':accounts[1]})
	makeWrapNFT(wrapper, erc721mock, ['originalTokenId', 'transferFee', 'royaltyBeneficiary', 'royaltyPercent', 'unwraptFeeThreshold'], [ORIGINAL_NFT_IDs[0], 0, zero_address, 0, 0], accounts[1], niftsy20)
	tokenId = wrapper.lastWrappedNFTId()

	assert niftsy20.balanceOf(accounts[1]) == 0
	assert niftsy20.balanceOf(wrapper.address) == protokolFee
	assert wrapper.lastWrappedNFTId() == 1
	checkWrappedNFT(wrapper, 
		tokenId, 
		erc721mock.address, 
		ORIGINAL_NFT_IDs[0], 
		START_NATIVE_COLLATERAL, 
		0,  
		unwrapAfter, 
		0, 
		zero_address, 
		0, 
		0)

	#non exists token
	with reverts("ERC721: operator query for nonexistent token"):
		wrapper.transferFrom(accounts[1].address, accounts[2].address, 100, {"from": accounts[3]})

	#not owner tries to transfer token
	with reverts("ERC721: transfer caller is not owner nor approved"):
		wrapper.transferFrom(accounts[1].address, accounts[2].address, tokenId, {"from": accounts[3]})

	wrapper.approve(accounts[3].address, tokenId, {"from": accounts[1]})
	niftsy20.approve(wrapper, TRANSFER_FEE, {'from':accounts[1]})
	wrapper.transferFrom(accounts[1].address, accounts[2].address, tokenId, {"from": accounts[3]})
	assert wrapper.ownerOf(tokenId) == accounts[2].address
	#return tokenId - owner transfer
	wrapper.transferFrom(accounts[2].address, accounts[1].address, tokenId, {"from": accounts[2]})
	assert wrapper.ownerOf(tokenId) == accounts[1].address

	nft = wrapper.getWrappedToken(tokenId)
	assert nft[3] == 0 #check backedTokens
示例#4
0
def test_wrapper_addNativeCollateral(accounts, erc721mock, wrapper, niftsy20,
                                     trmodel):
    #make test data
    makeNFTForTest(accounts, erc721mock, ORIGINAL_NFT_IDs)
    wrapper.setFee(protokolFee, chargeFeeAfter, niftsy20,
                   {"from": accounts[0]})
    #wrap difficult nft

    niftsy20.transfer(accounts[1], protokolFee, {"from": accounts[0]})
    unwrapAfter = chain.time() + 10
    niftsy20.approve(wrapper, TRANSFER_FEE, {'from': accounts[1]})
    erc721mock.approve(wrapper.address, ORIGINAL_NFT_IDs[0],
                       {'from': accounts[1]})
    makeWrapNFT(wrapper, erc721mock, ['originalTokenId'],
                [ORIGINAL_NFT_IDs[0]], accounts[1], niftsy20)
    assert niftsy20.balanceOf(accounts[1]) == 0
    assert niftsy20.balanceOf(wrapper.address) == protokolFee
    assert wrapper.lastWrappedNFTId() == 1
    checkWrappedNFT(wrapper, wrapper.lastWrappedNFTId(), erc721mock.address,
                    ORIGINAL_NFT_IDs[0], START_NATIVE_COLLATERAL, 0,
                    unwrapAfter, TRANSFER_FEE, royaltyBeneficiary,
                    ROAYLTY_PERCENT, UNWRAP_FEE_THRESHOLD)

    nft = wrapper.getWrappedToken(wrapper.lastWrappedNFTId())
    #owner calls addNativeCollateral
    wrapper.addNativeCollateral(wrapper.lastWrappedNFTId(), {
        "from": accounts[1],
        "value": ADD_NATIVE_COLLATERAL
    })
    wrapper.addNativeCollateral(wrapper.lastWrappedNFTId(), {
        "from": accounts[1],
        "value": 0
    })
    assert wrapper.getWrappedToken(
        wrapper.lastWrappedNFTId())[2] == nft[2] + ADD_NATIVE_COLLATERAL
    #nonexist tokenId
    with reverts("ERC721: owner query for nonexistent token"):
        wrapper.addNativeCollateral(100, {
            "from": accounts[2],
            "value": ADD_NATIVE_COLLATERAL
        })
    #not owner calls addNativeCollateral
    wrapper.addNativeCollateral(wrapper.lastWrappedNFTId(), {
        "from": accounts[2],
        "value": ADD_NATIVE_COLLATERAL
    })
def test_wrapper_transfer_1(accounts, erc721mock, wrapper, niftsy20, dai, weth,
                            trmodel):
    #make test data for case
    wrapper.editPartnersItem(niftsy20.address, True, zero_address, False,
                             {'from': accounts[0]})

    #make test data
    makeNFTForTest(accounts, erc721mock, ORIGINAL_NFT_IDs)
    wrapper.setFee(protokolFee, chargeFeeAfter, niftsy20,
                   {"from": accounts[0]})
    #wrap difficult nft

    niftsy20.transfer(accounts[1], protokolFee, {"from": accounts[0]})
    unwrapAfter = chain.time() + 10

    erc721mock.approve(wrapper.address, ORIGINAL_NFT_IDs[0],
                       {'from': accounts[1]})
    niftsy20.approve(wrapper, TRANSFER_FEE, {'from': accounts[1]})
    makeWrapNFT(wrapper, erc721mock, [
        'originalTokenId', 'royaltyBeneficiary', 'royaltyPercent',
        'unwraptFeeThreshold'
    ], [ORIGINAL_NFT_IDs[0], zero_address, 0, 0], accounts[1], niftsy20)
    tokenId = wrapper.lastWrappedNFTId()

    assert niftsy20.balanceOf(accounts[1]) == 0
    assert niftsy20.balanceOf(wrapper.address) == protokolFee
    assert wrapper.lastWrappedNFTId() == 1
    checkWrappedNFT(wrapper, tokenId, erc721mock.address, ORIGINAL_NFT_IDs[0],
                    START_NATIVE_COLLATERAL, 0, unwrapAfter, TRANSFER_FEE,
                    zero_address, 0, 0)

    wrapper.approve(accounts[3].address, tokenId, {"from": accounts[1]})
    niftsy20.approve(wrapper, TRANSFER_FEE, {'from': accounts[1]})
    niftsy20.transfer(accounts[1], TRANSFER_FEE, {'from': accounts[0]})
    wrapper.transferFrom(accounts[1].address, accounts[2].address, tokenId,
                         {"from": accounts[3]})
    assert wrapper.ownerOf(tokenId) == accounts[2].address

    nft = wrapper.getWrappedToken(tokenId)
    assert nft[3] == TRANSFER_FEE  #check backedTokens
def test_wrapper_addERC20Collateral(accounts, erc721mock, wrapper, niftsy20,
                                    dai, weth, trmodel, TokenMock):
    #make test data
    makeNFTForTest(accounts, erc721mock, ORIGINAL_NFT_IDs)
    wrapper.setFee(protokolFee, chargeFeeAfter, niftsy20,
                   {"from": accounts[0]})
    dai.transfer(accounts[1], ERC20_COLLATERAL_AMOUNT, {"from": accounts[0]})
    #wrap difficult nft

    niftsy20.transfer(accounts[1], protokolFee, {"from": accounts[0]})
    unwrapAfter = chain.time() + 10

    erc721mock.approve(wrapper.address, ORIGINAL_NFT_IDs[0],
                       {'from': accounts[1]})
    niftsy20.approve(wrapper, TRANSFER_FEE, {'from': accounts[1]})
    makeWrapNFT(wrapper, erc721mock, ['originalTokenId'],
                [ORIGINAL_NFT_IDs[0]], accounts[1], niftsy20)
    assert niftsy20.balanceOf(accounts[1]) == 0
    assert niftsy20.balanceOf(wrapper.address) == protokolFee
    assert wrapper.lastWrappedNFTId() == 1
    checkWrappedNFT(wrapper, wrapper.lastWrappedNFTId(), erc721mock.address,
                    ORIGINAL_NFT_IDs[0], START_NATIVE_COLLATERAL, 0,
                    unwrapAfter, TRANSFER_FEE, royaltyBeneficiary,
                    ROAYLTY_PERCENT, UNWRAP_FEE_THRESHOLD)

    tokenId = wrapper.lastWrappedNFTId()
    nft = wrapper.getWrappedToken(tokenId)

    #try to add erc20 collaterals
    #there is not allowance
    with reverts("Please approve first"):
        wrapper.addERC20Collateral(tokenId, dai.address,
                                   ERC20_COLLATERAL_AMOUNT,
                                   {"from": accounts[1]})
    dai.approve(wrapper.address, ERC20_COLLATERAL_AMOUNT + 100,
                {"from": accounts[1]})
    with reverts("Low balance for add collateral"):
        wrapper.addERC20Collateral(
            tokenId, dai.address,
            ERC20_COLLATERAL_AMOUNT + ERC20_COLLATERAL_AMOUNT,
            {"from": accounts[1]})
    wrapper.addERC20Collateral(tokenId, dai.address, ERC20_COLLATERAL_AMOUNT,
                               {"from": accounts[1]})
    assert dai.balanceOf(wrapper.address) == ERC20_COLLATERAL_AMOUNT
    assert dai.balanceOf(accounts[1].address) == 0
    logging.info('coll = {}'.format(wrapper.getERC20Collateral(tokenId)))
    assert wrapper.getERC20Collateral(tokenId)[0][0] == dai.address
    assert wrapper.getERC20Collateral(tokenId)[0][1] == ERC20_COLLATERAL_AMOUNT

    #second call
    dai.transfer(accounts[1], ERC20_COLLATERAL_AMOUNT, {"from": accounts[0]})
    dai.approve(wrapper.address, ERC20_COLLATERAL_AMOUNT + 100,
                {"from": accounts[1]})
    wrapper.addERC20Collateral(tokenId, dai.address, ERC20_COLLATERAL_AMOUNT,
                               {"from": accounts[1]})
    assert wrapper.getERC20Collateral(
        tokenId)[0][1] == 2 * ERC20_COLLATERAL_AMOUNT
    assert len(wrapper.getERC20Collateral(tokenId)) == 1
    logging.info('coll = {}'.format(wrapper.getERC20Collateral(tokenId)))

    #nonexist tokenId
    dai.transfer(accounts[1], ERC20_COLLATERAL_AMOUNT, {"from": accounts[0]})
    dai.approve(wrapper.address, ERC20_COLLATERAL_AMOUNT + 100,
                {"from": accounts[1]})
    with reverts("ERC721: owner query for nonexistent token"):
        wrapper.addERC20Collateral(100, dai.address, ERC20_COLLATERAL_AMOUNT,
                                   {"from": accounts[1]})

    #not owner calls addNativeCollateral
    dai.transfer(accounts[2], ERC20_COLLATERAL_AMOUNT, {"from": accounts[0]})
    dai.approve(wrapper.address, ERC20_COLLATERAL_AMOUNT + 100,
                {"from": accounts[2]})
    wrapper.addERC20Collateral(tokenId, dai.address, ERC20_COLLATERAL_AMOUNT,
                               {"from": accounts[2]})
    assert wrapper.getERC20Collateral(
        tokenId)[0][1] == 3 * ERC20_COLLATERAL_AMOUNT
    assert len(wrapper.getERC20Collateral(tokenId)) == 1

    #add second token
    weth.transfer(accounts[1], ERC20_COLLATERAL_AMOUNT, {"from": accounts[0]})
    weth.approve(wrapper.address, ERC20_COLLATERAL_AMOUNT + 100,
                 {"from": accounts[1]})
    wrapper.addERC20Collateral(wrapper.lastWrappedNFTId(), weth.address,
                               ERC20_COLLATERAL_AMOUNT, {"from": accounts[1]})
    logging.info('coll = {}'.format(wrapper.getERC20Collateral(tokenId)))
    assert len(wrapper.getERC20Collateral(tokenId)) == 2
    assert wrapper.getERC20Collateral(tokenId)[1][0] == weth.address
    assert wrapper.getERC20Collateral(tokenId)[1][1] == ERC20_COLLATERAL_AMOUNT

    #add third token#############################
    #add erc20 in allowed address
    with reverts("Ownable: caller is not the owner"):
        wrapper.setCollateralStatus(niftsy20.address, True,
                                    {"from": accounts[1]})
    wrapper.setCollateralStatus(niftsy20.address, True, {"from": accounts[0]})

    #change MAX_ERC20_COUNT
    with reverts("Ownable: caller is not the owner"):
        wrapper.setMaxERC20CollateralCount(2, {"from": accounts[1]})
    wrapper.setMaxERC20CollateralCount(2, {"from": accounts[0]})

    niftsy20.transfer(accounts[1], ERC20_COLLATERAL_AMOUNT,
                      {"from": accounts[0]})
    niftsy20.approve(wrapper.address, ERC20_COLLATERAL_AMOUNT + 100,
                     {"from": accounts[1]})
    logging.info('before niftsy20.balanceOf(accounts[1]) = {}'.format(
        niftsy20.balanceOf(accounts[1])))
    logging.info('before niftsy20.balanceOf(wrapper.address) = {}'.format(
        niftsy20.balanceOf(wrapper.address)))

    with reverts("To much ERC20 tokens in collatteral"):
        wrapper.addERC20Collateral(tokenId, niftsy20.address,
                                   ERC20_COLLATERAL_AMOUNT,
                                   {"from": accounts[1]})
    assert len(wrapper.getERC20Collateral(tokenId)) == 2
    assert niftsy20.balanceOf(accounts[1]) == ERC20_COLLATERAL_AMOUNT
    logging.info('after niftsy20.balanceOf(accounts[1]) = {}'.format(
        niftsy20.balanceOf(accounts[1])))
    logging.info('after niftsy20.balanceOf(wrapper.address) = {}'.format(
        niftsy20.balanceOf(wrapper.address)))

    #try to add erc20 collateral for non allowanced erc20
    with reverts("To much ERC20 tokens in collatteral"):
        dai1 = _addErc20Collateral(accounts[0], accounts[1], wrapper,
                                   ERC20_COLLATERAL_AMOUNT, tokenId, TokenMock)
示例#7
0
def test_simple_wrap(accounts, erc721mock, wrapper, niftsy20, trmodel):
	#make test data
	makeNFTForTest(accounts, erc721mock, ORIGINAL_NFT_IDs)

	#bad _underlineContract
	with reverts(""):
		wrapper.wrap721(
			zero_address, 
			ORIGINAL_NFT_IDs[0], 
			0, 
			1e18,
			zero_address,
			0,
			0, 
            niftsy20,
			{'from':accounts[1]})
	#nonexist nft
	with reverts("ERC721: operator query for nonexistent token"):
		wrapper.wrap721(
			erc721mock.address, 
			1, 
			0, 
			1e18,
			zero_address,
			0,
			0, 
            niftsy20,
			{'from':accounts[1]})
	#there is not allowance for wrapper.address
	with reverts("ERC721: transfer caller is not owner nor approved"):
		wrapper.wrap721(
			erc721mock.address, 
			ORIGINAL_NFT_IDs[0], 
			0, 
			1e18,
			zero_address,
			0,
			0, 
            niftsy20,
			{'from':accounts[1]})
	#check ROYALTY_PERCENT
	erc721mock.approve(wrapper.address, ORIGINAL_NFT_IDs[0], {'from':accounts[1]})
	with reverts("Royalty percent too big"):
		wrapper.wrap721(
			erc721mock.address, 
			ORIGINAL_NFT_IDs[0], 
			0, 
			1e18,
			zero_address,
			wrapper.MAX_ROYALTY_PERCENT() + 1,
			0, 
            niftsy20,
			{'from':accounts[1]})

	#check _unwraptFeeThreshold
	erc721mock.approve(wrapper.address, ORIGINAL_NFT_IDs[0], {'from':accounts[1]})
	with reverts("Cant set Threshold without transferFee"):
		wrapper.wrap721(
			erc721mock.address, 
			ORIGINAL_NFT_IDs[0], 
			0, 
			0,
			zero_address,
			0,
			1,
            niftsy20, 
			{'from':accounts[1]})

	#check ROYALTY_PERCENT again
	with reverts("Royalty source is transferFee"):
		wrapper.wrap721(
			erc721mock.address, 
			ORIGINAL_NFT_IDs[0], 
			0, 
			0,
			zero_address,
			wrapper.MAX_ROYALTY_PERCENT(),
			0, 
            niftsy20,
			{'from':accounts[1]})

	#check ROYALTY_address 
	with reverts("No Royalty without transferFee"):
		wrapper.wrap721(
			erc721mock.address, 
			ORIGINAL_NFT_IDs[0], 
			0, 
			0,
			royaltyBeneficiary,
			0,
			0, 
            niftsy20,
			{'from':accounts[1]})

	#check _unwrapAfter
	with reverts("Too long Wrap"):
		wrapper.wrap721(
			erc721mock.address, 
			ORIGINAL_NFT_IDs[0], 
			chain.time() + wrapper.MAX_TIME_TO_UNWRAP() + 10,
			0,
			zero_address,
			0,
			0, 
            niftsy20,
			{'from':accounts[1]})

	#check _unwraptFeeThreshold
	with reverts("Too much threshold"):
		wrapper.wrap721(
			erc721mock.address, 
			ORIGINAL_NFT_IDs[0], 
			0,
			1,
			zero_address,
			0,
			niftsy20.totalSupply() * wrapper.MAX_FEE_THRESHOLD_PERCENT() / 100 + 1, 
            niftsy20,
			{'from':accounts[1]})

	#check ROYALTY_address again
	with reverts("Royalty to zero address"):
		wrapper.wrap721(
			erc721mock.address, 
			ORIGINAL_NFT_IDs[0], 
			0,
			1,
			zero_address,
			1,
			niftsy20.totalSupply() * wrapper.MAX_FEE_THRESHOLD_PERCENT() / 100 + 1, 
            niftsy20,
			{'from':accounts[1]})


	with reverts("Ownable: caller is not the owner"):
		wrapper.setFee(protokolFee, chargeFeeAfter, niftsy20,{"from": accounts[1]})
	wrapper.setFee(protokolFee, chargeFeeAfter, niftsy20, {"from": accounts[0]})
	#does not have niftsy token for protokol fee
	with reverts("insufficient protocol fee token balance for fee"):
		wrapper.wrap721(
			erc721mock.address, 
			ORIGINAL_NFT_IDs[0], 
			0,
			0,
			zero_address,
			0,
			0, 
            niftsy20,
			{'from':accounts[1]})
	#wrap simple nft
	niftsy20.transfer(accounts[1], protokolFee, {"from": accounts[0]})
	niftsy20.approve(wrapper, TRANSFER_FEE, {'from':accounts[1]})
	wrapper.wrap721(
		erc721mock.address, 
		ORIGINAL_NFT_IDs[0], 
		0,
		0,
		zero_address,
		0,
		0, 
        niftsy20,
		{'from':accounts[1]})
	assert niftsy20.balanceOf(accounts[1]) == 0
	assert niftsy20.balanceOf(wrapper.address) == protokolFee
	assert wrapper.lastWrappedNFTId() == 1
	assert erc721mock.ownerOf(ORIGINAL_NFT_IDs[0]) == wrapper.address
	assert wrapper.ownerOf(wrapper.lastWrappedNFTId()) == accounts[1]
	checkWrappedNFT(wrapper, 
		wrapper.lastWrappedNFTId(), 
		erc721mock.address, 
		ORIGINAL_NFT_IDs[0], 
		0, 
		0, 
		0, 
		0, 
		zero_address, 
		0, 
		0)

	#wrap difficult nft
	erc721mock.transferFrom(accounts[0], accounts[1], ORIGINAL_NFT_IDs[1], {'from':accounts[0]})
	niftsy20.transfer(accounts[1], protokolFee, {"from": accounts[0]})
	unwrapAfter = chain.time() + 10

	erc721mock.approve(wrapper.address, ORIGINAL_NFT_IDs[1], {'from':accounts[1]})
	
	makeWrapNFT(wrapper, erc721mock, ['originalTokenId'], [ORIGINAL_NFT_IDs[1]], accounts[1], niftsy20)
	assert niftsy20.balanceOf(accounts[1]) == 0
	assert niftsy20.balanceOf(wrapper.address) == 2 * protokolFee
	assert wrapper.lastWrappedNFTId() == 2
	checkWrappedNFT(wrapper, 
		wrapper.lastWrappedNFTId(), 
		erc721mock.address, 
		ORIGINAL_NFT_IDs[1], 
		START_NATIVE_COLLATERAL, 
		0,  
		unwrapAfter, 
		TRANSFER_FEE, 
		royaltyBeneficiary, 
		ROAYLTY_PERCENT, 
		UNWRAP_FEE_THRESHOLD)

	logging.info('wrapper.tokenURI(wrapper.lastWrappedNFTId()) = {}'.format(wrapper.tokenURI(wrapper.lastWrappedNFTId())))
	logging.info('wrapper.getWrappedToken(wrapper.lastWrappedNFTId()) = {}'.format(wrapper.getWrappedToken(wrapper.lastWrappedNFTId())))
def test_wrapper_unWrap721_3(accounts, erc721mock, wrapper, niftsy20, dai, weth, trmodel):
	#make test data
	erc721mock.transferFrom(accounts[0], accounts[1], ORIGINAL_NFT_IDs[2], {'from':accounts[0]})
	erc721mock.approve(wrapper.address, ORIGINAL_NFT_IDs[2], {'from':accounts[1]})
	logging.info('balanceOf(wrapper.address) = {}'.format(niftsy20.balanceOf(wrapper.address)))
	logging.info('balanceOf(royaltyBeneficiary) = {}'.format(niftsy20.balanceOf(royaltyBeneficiary)))
	#wrap difficult nft

	niftsy20.transfer(accounts[1], protokolFee, {"from": accounts[0]})
	unwrapAfter = chain.time() + 10
	
	before_balance = niftsy20.balanceOf(wrapper.address) 
	niftsy20.approve(wrapper, TRANSFER_FEE, {'from':accounts[1]})
	makeWrapNFT(wrapper, erc721mock, ['originalTokenId'], [ORIGINAL_NFT_IDs[2]], accounts[1], niftsy20)
	assert niftsy20.balanceOf(accounts[1]) == 0
	assert niftsy20.balanceOf(wrapper.address) == before_balance + protokolFee
	assert wrapper.lastWrappedNFTId() == 3

	tokenId = wrapper.lastWrappedNFTId()
	nft = wrapper.getWrappedToken(tokenId)

	c = round(UNWRAP_FEE_THRESHOLD/TRANSFER_FEE) + 1
	backedTokens = 0
	royalty_tokens = 0
	i = 0
	for i in range(c):
		wrapper.approve(accounts[i+2].address, tokenId, {"from": accounts[i+1]})
		niftsy20.transfer(accounts[i + 1].address, TRANSFER_FEE, {"from": accounts[0]}) #add niftsy tokens to pay transfer fee
		niftsy20.approve(trmodel, TRANSFER_FEE, {'from':accounts[i+1]})
		wrapper.transferFrom(accounts[i+1].address, accounts[i+2].address, tokenId, {"from": accounts[i+2]}) #make transfers
		royalty_tokens += TRANSFER_FEE*nft[7]/100
		backedTokens += TRANSFER_FEE - TRANSFER_FEE*nft[7]/100

	#check backedTokens after transfers
	nft = wrapper.getWrappedToken(tokenId)
	logging.info('nft2 = {}'.format(nft))
	assert nft[3] == backedTokens

	#move date 
	chain.sleep(100)
	chain.mine()
	logging.info('wrapper.totalSupply() = {}'.format(wrapper.totalSupply()))
	logging.info('accounts[i+2].balance() = {}'.format(accounts[i+2].balance()))
	logging.info('wrapper.balanceOf(accounts[i+2]) = {}'.format(wrapper.balanceOf(accounts[i+2])))
	logging.info('niftsy20.balanceOf(accounts[i+2]) = {}'.format(niftsy20.balanceOf(accounts[i+2])))
	logging.info('wrapper.balance() = {}'.format(wrapper.balance()))
	logging.info('niftsy20.balanceOf(wrapper.address) = {}'.format(niftsy20.balanceOf(wrapper.address)))
	balance_eth = accounts[i+2].balance()
	balance_erc20 = niftsy20.balanceOf(wrapper.address)
	balance_erc20_owner = niftsy20.balanceOf(accounts[i+2].address)
	logging.info('********************AFTER UNWRAP*************')
	#unwrap
	wrapper.unWrap721(tokenId, {"from": accounts[i+2]})
	assert wrapper.totalSupply() == 0
	assert wrapper.balanceOf(accounts[i+2].address) == 0
	assert niftsy20.balanceOf(accounts[i+2].address) == balance_erc20_owner + backedTokens
	assert erc721mock.ownerOf(ORIGINAL_NFT_IDs[2]) == accounts[i+2].address
	assert accounts[i+2].balance() == balance_eth + nft[2]
	assert niftsy20.balanceOf(wrapper.address) == balance_erc20 - backedTokens
	assert niftsy20.balanceOf(royaltyBeneficiary) == royalty_tokens

	logging.info('accounts[i+2].balance() = {}'.format(accounts[i+2].balance()))
	logging.info('wrapper.balanceOf(accounts[i+2]) = {}'.format(wrapper.balanceOf(accounts[i+2])))
	logging.info('niftsy20.balanceOf(accounts[i+2]) = {}'.format(niftsy20.balanceOf(accounts[i+2])))
	logging.info('wrapper.balance() = {}'.format(wrapper.balance()))
	logging.info('niftsy20.balanceOf(wrapper.address) = {}'.format(niftsy20.balanceOf(wrapper.address)))
	with reverts("ERC721: owner query for nonexistent token"):
		wrapper.ownerOf(tokenId)

	#wrap this nft again by first nft owner  - after unwrap
	#prepare test data
	niftsy20.transfer(accounts[1], protokolFee, {"from": accounts[0]})
	unwrapAfter = chain.time() + 10
	erc721mock.transferFrom(accounts[i+2], accounts[1], ORIGINAL_NFT_IDs[2], {"from": accounts[i+2]} )
	erc721mock.approve(wrapper.address, ORIGINAL_NFT_IDs[2], {'from':accounts[1]})
	
	#wrap
	before_balance = niftsy20.balanceOf(wrapper.address) 
	niftsy20.approve(wrapper, TRANSFER_FEE, {'from':accounts[1]})
	makeWrapNFT(wrapper, erc721mock, ['originalTokenId'], [ORIGINAL_NFT_IDs[2]], accounts[1], niftsy20)
	assert niftsy20.balanceOf(accounts[1]) == 0
	assert wrapper.balanceOf(accounts[1]) == 1
	assert niftsy20.balanceOf(wrapper.address) == before_balance + protokolFee
	assert wrapper.lastWrappedNFTId() == 4

	tokenId = wrapper.lastWrappedNFTId()

	#check new wrappedNFT
	checkWrappedNFT(wrapper, 
		tokenId, 
		erc721mock.address, 
		ORIGINAL_NFT_IDs[2], 
		START_NATIVE_COLLATERAL, 
		0,  
		unwrapAfter, 
		TRANSFER_FEE, 
		royaltyBeneficiary, 
		ROAYLTY_PERCENT, 
		UNWRAP_FEE_THRESHOLD)
	nft = wrapper.getWrappedToken(tokenId)
	logging.info('new nft = {}'.format(nft))