Skip to content

Commit

Permalink
Merge e813710 into e04d129
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosantangelo committed Apr 22, 2022
2 parents e04d129 + e813710 commit daa01fa
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"printWidth": 80
},
"dependencies": {
"@dcl/schemas": "^2.2.1",
"@dcl/schemas": "^4.6.0",
"@types/sqlite3": "^3.1.7",
"@well-known-components/env-config-provider": "^1.1.1",
"@well-known-components/http-server": "^1.0.0",
Expand Down
20 changes: 9 additions & 11 deletions src/logic/ethereum.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { utils } from 'ethers'
import { ChainName, ChainId } from '@dcl/schemas'
import { ChainName, ChainId, getChainId } from '@dcl/schemas'
import { ContractData } from 'decentraland-transactions'
import { getNetworkMapping } from '@dcl/schemas/dist/dapps/chain-id'

export function getMaticChainIdFromNetwork(network: ChainName): ChainId {
switch (network) {
case ChainName.ETHEREUM_MAINNET:
return ChainId.MATIC_MAINNET
case ChainName.ETHEREUM_ROPSTEN:
return ChainId.MATIC_MUMBAI
default:
throw new Error(
`The chain name ${network} doesn't have a matic chain id to map to`
)
export function getMaticChainIdFromChainName(chainName: ChainName): ChainId {
const chainId = getChainId(chainName)
if (!chainId) {
throw new Error(
`The chain name ${chainName} doesn't have a matic chain id to map to`
)
}
return getNetworkMapping(chainId).MATIC
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/ports/transaction/validation/checkSalePrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ContractName, getContract } from 'decentraland-transactions'
import { BigNumber } from 'ethers'
import {
decodeFunctionData,
getMaticChainIdFromNetwork,
getMaticChainIdFromChainName,
} from '../../../logic/ethereum'
import { InvalidSalePriceError } from '../errors'
import { TransactionData } from '../types'
Expand All @@ -18,7 +18,10 @@ export const checkSalePrice: ITransactionValidator = async (

const minPriceInWei = await config.requireString('MIN_SALE_VALUE_IN_WEI')
const chainName = (await config.requireString('CHAIN_NAME')) as ChainName
const salePrice = getSalePrice(params, getMaticChainIdFromNetwork(chainName))
const salePrice = getSalePrice(
params,
getMaticChainIdFromChainName(chainName)
)

if (salePrice !== null && BigNumber.from(salePrice).lte(minPriceInWei)) {
throw new InvalidSalePriceError(minPriceInWei, salePrice)
Expand Down
8 changes: 4 additions & 4 deletions test/tests/logic/ethereum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import { ContractName, getContract } from 'decentraland-transactions'
import { BigNumber } from 'ethers'
import {
decodeFunctionData,
getMaticChainIdFromNetwork,
getMaticChainIdFromChainName,
} from '../../../src/logic/ethereum'

describe('getMaticChainIdFromNetwork', () => {
describe('when using a valid chain name', () => {
it('should return the mapped MAINNET Matic Chain Id for ETHEREUM MAINNET', () => {
expect(getMaticChainIdFromNetwork(ChainName.ETHEREUM_MAINNET)).toBe(
expect(getMaticChainIdFromChainName(ChainName.ETHEREUM_MAINNET)).toBe(
ChainId.MATIC_MAINNET
)
})

it('should return the mapped MUMBAI Matic Chain Id for ETHEREUM ROPSTEN', () => {
expect(getMaticChainIdFromNetwork(ChainName.ETHEREUM_ROPSTEN)).toBe(
expect(getMaticChainIdFromChainName(ChainName.ETHEREUM_ROPSTEN)).toBe(
ChainId.MATIC_MUMBAI
)
})
Expand All @@ -24,7 +24,7 @@ describe('getMaticChainIdFromNetwork', () => {
describe('when using an unsupported chain name', () => {
it('should throw with an error explaining the lack of a mapping', () => {
expect(() =>
getMaticChainIdFromNetwork('Something' as ChainName)
getMaticChainIdFromChainName('Something' as ChainName)
).toThrow(
"The chain name Something doesn't have a matic chain id to map to"
)
Expand Down

0 comments on commit daa01fa

Please sign in to comment.