import DecentralandUtils from "../helpers/DecentralandUtils" ; import coreHelpers from "@tasit/test-helpers" ; const { addressesAreEqual , expectMinimumTokenBalances , ProviderFactory , } = coreHelpers ; const getNetworkName = ( ) => { const provider = ProviderFactory . getProvider ( ) ; const { _network : network } = provider ; const networkName = ! network ? "local" : network . name ; return networkName ; } ; export const getContractsAddresses = ( ) => { const networkName = getNetworkName ( ) ; const { MANAToken , LANDProxy , EstateRegistry , Marketplace , GnosisSafe : GnosisSafeInfo , } = TasitContracts [ networkName ] ; const { address : MANA_ADDRESS } = MANAToken ; const { address : LAND_ADDRESS } = LANDProxy ; const { address : ESTATE_ADDRESS } = EstateRegistry ; const { address : MARKETPLACE_ADDRESS } = Marketplace ; const { address : GNOSIS_SAFE_ADDRESS } = GnosisSafeInfo ; const addresses = { ESTATE_ADDRESS , LAND_ADDRESS , MARKETPLACE_ADDRESS , MANA_ADDRESS , GNOSIS_SAFE_ADDRESS , } ; return addresses ; } ; export const pickAssetsForSale = async ( ) => { const { LAND_ADDRESS , ESTATE_ADDRESS } = getContractsAddresses ( ) ; let landForSale ; let estateForSale ; const decentralandUtils = new DecentralandUtils ( ) ; const { getAllAssetsForSale } = decentralandUtils ; const openSellOrders = await getAllAssetsForSale ( ) ; expect ( Object . keys ( openSellOrders ) ) . not . toHaveLength ( 0 ) ; for ( const order of openSellOrders ) { const { nftAddress , expiresAt } = order ; const isLand = addressesAreEqual ( nftAddress , LAND_ADDRESS ) ; const isEstate = addressesAreEqual ( nftAddress , ESTATE_ADDRESS ) ; const nowInSeconds = Date . now ( ) / 1000 ; const expired = Number ( expiresAt ) < nowInSeconds ; if ( isLand && ! expired ) landForSale = order ; if ( isEstate && ! expired ) estateForSale = order ; if ( landForSale && estateForSale ) break ; if ( ! isLand && ! isEstate ) expect ( false ) . toBe ( true ) ; } return { landForSale , estateForSale } ; } ; export const checkAsset = async ( nftContract , erc20Contract , assetForSale , ownerOfFunds ) => { const { MARKETPLACE_ADDRESS } = getContractsAddresses ( ) ; const { assetId , nftAddress , seller , priceInWei , expiresAt } = assetForSale ; const nftContractAddress = nftContract . getAddress ( ) ; expect ( addressesAreEqual ( nftAddress , nftContractAddress ) ) . toBe ( true ) ; const expiresTime = Number ( expiresAt ) ; const nowInSeconds = Date . now ( ) / 1000 ; expect ( nowInSeconds ) . toBeLessThan ( expiresTime ) ; await expectMinimumTokenBalances ( erc20Contract , [ ownerOfFunds ] , [ priceInWei ] ) ; const approvedForAsset = await nftContract . getApproved ( assetId ) ; const approvedForAll = await nftContract . isApprovedForAll ( seller , MARKETPLACE_ADDRESS ) ; const approved = addressesAreEqual ( approvedForAsset , MARKETPLACE_ADDRESS ) || approvedForAll ; expect ( approved ) . toBe ( true ) ; } ; export const helpers = { ... coreHelpers , pickAssetsForSale , checkAsset , getContractsAddresses , } ; export default helpers ;