import { Action } from "../TasitSdk" ; import helpers from "../testHelpers/helpers" ; import DecentralandUtils from "../helpers/DecentralandUtils" ; const { ERC20 } = Action ; const { Mana } = ERC20 ; const { constants , expectMinimumEtherBalances , expectMinimumTokenBalances , addressesAreEqual , accounts , bigNumberify , ProviderFactory , getContractsAddresses , } = helpers ; import fetch from "node-fetch" ; const { TWO , TEN , BILLION , TOKEN_SUBDIVISIONS } = constants ; const provider = ProviderFactory . getProvider ( ) ; const { MANA_ADDRESS , LAND_PROXY_ADDRESS , ESTATE_ADDRESS , GNOSIS_SAFE_ADDRESS , } = getContractsAddresses ( ) ; describe ( "Decentraland App pre-conditions" , ( ) => { const mana = new Mana ( MANA_ADDRESS ) ; const gnosisSafeOwner = accounts [ 9 ] ; const decentralandUtils = new DecentralandUtils ( ) ; const { getAllAssetsForSale } = decentralandUtils ; let assetsForSale = [ ] ; beforeAll ( async ( ) => { assetsForSale = await getAllAssetsForSale ( ) ; } ) ; describe ( "Gnosis Safe account" , ( ) => { it ( "should have at least ten ethers" , async ( ) => { await expectMinimumEtherBalances ( provider , [ GNOSIS_SAFE_ADDRESS ] , [ TEN ] ) ; } ) ; it ( "should have at least a billion MANA" , async ( ) => { await expectMinimumTokenBalances ( mana , [ GNOSIS_SAFE_ADDRESS ] , [ BILLION ] ) ; } ) ; } ) ; describe ( "Gnosis Safe account owner" , ( ) => { it ( "should have at least two ethers" , async ( ) => { const { address : gnosisSafeOwnerAddress } = gnosisSafeOwner ; await expectMinimumEtherBalances ( provider , [ gnosisSafeOwnerAddress ] , [ TWO ] ) ; } ) ; } ) ; describe ( "Marketplace" , ( ) => { it ( "should have at least 50 assets for sale" , async ( ) => { expect ( assetsForSale . length ) . toBeGreaterThanOrEqual ( 50 ) ; } ) ; it ( "should have at least 1 parcel for sale" , async ( ) => { const parcelsForSale = assetsForSale . filter ( ( asset ) => addressesAreEqual ( asset . nftAddress , LAND_PROXY_ADDRESS ) ) ; expect ( parcelsForSale . length ) . toBeGreaterThanOrEqual ( 1 ) ; } ) ; it ( "should have at least 1 estate for sale" , async ( ) => { const estatessForSale = assetsForSale . filter ( ( asset ) => addressesAreEqual ( asset . nftAddress , ESTATE_ADDRESS ) ) ; expect ( estatessForSale . length ) . toBeGreaterThanOrEqual ( 1 ) ; } ) ; it ( "shouldn't have any duplicated sell orders" , async ( ) => { const assetForSaleIds = [ ] ; assetsForSale . forEach ( ( assetForSale ) => { let { assetId } = assetForSale ; assetId = `${ assetId }` ; if ( ! assetForSaleIds . includes ( assetId ) ) assetForSaleIds . push ( assetId ) ; } ) ; expect ( assetsForSale . length ) . toBe ( assetForSaleIds . length ) ; } ) ; it ( "Assets for sale" , async ( ) => { const minPrice = bigNumberify ( "10000" ) . mul ( TOKEN_SUBDIVISIONS ) ; const maxPrice = bigNumberify ( "100000" ) . mul ( TOKEN_SUBDIVISIONS ) ; const blankImage = await fetch ( "https://api.decentraland.org/v1/estates/5/map.png" ) ; const blankImageData = ( await blankImage . buffer ( ) ) . toString ( "base64" ) ; for ( const asset of assetsForSale ) { const { assetId , nftAddress , priceInWei } = asset ; const price = bigNumberify ( priceInWei ) ; const isParcel = addressesAreEqual ( nftAddress , LAND_PROXY_ADDRESS ) ; const isEstate = addressesAreEqual ( nftAddress , ESTATE_ADDRESS ) ; expect ( price . gte ( minPrice ) ) . toBe ( true ) ; expect ( price . lte ( maxPrice ) ) . toBe ( true ) ; if ( isEstate ) { const image = await fetch ( `https://api.decentraland.org/v1/estates/${ assetId }/map.png` ) ; const imageData = ( await image . buffer ( ) ) . toString ( "base64" ) ; expect ( imageData ) . not . toBe ( blankImageData ) ; } else if ( isParcel ) { } } } ) ; } ) ; } ) ;