• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

decentraland / marketplace / 10167911878

30 Jul 2024 06:36PM UTC coverage: 66.622% (-0.1%) from 66.726%
10167911878

Pull #2277

github

meelrossi
fix tests
Pull Request #2277: feat: add ui fixes for bids offchain flow

2655 of 5176 branches covered (51.29%)

Branch coverage included in aggregate %.

3 of 7 new or added lines in 4 files covered. (42.86%)

12 existing lines in 5 files now uncovered.

7778 of 10484 relevant lines covered (74.19%)

78.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

18.52
/webapp/src/modules/nft/estate/utils.ts
1
import { ethers } from 'ethers'
33✔
2
import { ChainId } from '@dcl/schemas'
3
import { getNetworkProvider } from 'decentraland-dapps/dist/lib/eth'
33✔
4
import { EstateRegistry__factory } from '../../../contracts'
33✔
5
import { Contract } from '../../vendor/services'
6
import { NFT } from '../types'
7

8
export const getSelection = (estate: NFT['data']['estate']) => {
33✔
9
  return estate!.parcels.map(pair => ({
×
10
    x: +pair.x,
11
    y: +pair.y
12
  }))
13
}
14

15
export const getCenter = (selection: { x: number; y: number }[]) => {
33✔
16
  const xs = [...new Set(selection.map(coords => coords.x).sort())]
×
17
  const ys = [...new Set(selection.map(coords => coords.y).sort())]
×
18
  const x = xs[(xs.length / 2) | 0]
×
19
  const y = ys[(ys.length / 2) | 0]
×
20
  return [x, y]
×
21
}
22

23
export async function generateFingerprint(estateId: string, parcels: { x: number; y: number }[], landContract: Contract) {
×
24
  const provider = await getNetworkProvider(landContract.chainId)
×
25
  const contract = new ethers.Contract(
×
26
    landContract.address,
27
    [
28
      {
29
        constant: true,
30
        inputs: [
31
          { name: 'x', type: 'int256' },
32
          { name: 'y', type: 'int256' }
33
        ],
34
        name: 'encodeTokenId',
35
        outputs: [{ name: '', type: 'uint256' }],
36
        payable: false,
37
        stateMutability: 'pure',
38
        type: 'function'
39
      }
40
    ],
41
    new ethers.providers.Web3Provider(provider)
42
  )
43

44
  const estateTokenIds = []
×
45

46
  for (const parcel of parcels) {
×
47
    estateTokenIds.push(await contract.encodeTokenId(parcel.x, parcel.y))
×
48
  }
49

50
  let fingerprint = BigInt(ethers.utils.solidityKeccak256(['string', 'uint256'], ['estateId', estateId]))
×
51

52
  for (const tokenId of estateTokenIds) {
×
53
    fingerprint ^= BigInt(ethers.utils.solidityKeccak256(['uint256'], [tokenId]))
×
54
  }
55

56
  return ethers.utils.hexlify(fingerprint)
×
57
}
58

NEW
59
export async function getFingerprint(estateId: string, estateContract: Contract, chainId: ChainId) {
×
NEW
60
  const provider = await getNetworkProvider(chainId)
×
61
  if (provider) {
×
NEW
62
    const estateRegistry = EstateRegistry__factory.connect(estateContract.address, new ethers.providers.Web3Provider(provider))
×
63
    return estateRegistry.getFingerprint(estateId)
×
64
  }
65
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc