Skip to content

Commit

Permalink
v2.0.0: uses new depay-web3-client and adds test for ensureNativeToken
Browse files Browse the repository at this point in the history
  • Loading branch information
10xSebastian committed Sep 2, 2021
1 parent d4cd894 commit ecfc75a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 30 deletions.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "depay-web3-assets",
"moduleName": "Web3Assets",
"version": "1.1.2",
"version": "2.0.0",
"description": "",
"main": "dist/cjs/index.js",
"module": "dist/es/index.js",
Expand Down Expand Up @@ -37,7 +37,7 @@
},
"peerDependencies": {
"depay-web3-blockchains": "^2.4.0",
"depay-web3-client": "^4.0.3",
"depay-web3-client": "^5.0.0",
"depay-web3-constants": "^3.0.1",
"depay-web3-wallets": "^5.1.1"
},
Expand All @@ -55,13 +55,14 @@
"babel-loader": "^8.2.2",
"babel-preset-env": "^1.7.0",
"depay-web3-blockchains": "^2.4.0",
"depay-web3-client": "^4.0.3",
"depay-web3-client": "^5.0.0",
"depay-web3-constants": "^3.0.1",
"depay-web3-mock": "^5.9.0",
"depay-web3-mock": "^7.0.0",
"depay-web3-wallets": "^5.1.1",
"eslint": "^7.15.0",
"eslint-loader": "^4.0.2",
"eslint-plugin-import": "^2.22.1",
"ethers": "^5.4.6",
"fetch-mock": "^9.11.0",
"node-fetch": "^2.6.1",
"regenerator-runtime": "^0.13.7",
Expand Down
56 changes: 56 additions & 0 deletions tests/units/getAssets.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import fetchMock from 'fetch-mock'
import { getAssets } from 'src'
import { mock, resetMocks } from 'depay-web3-mock'
import { provider, resetCache } from 'depay-web3-client'

describe('assets', ()=>{

beforeEach(()=>fetchMock.reset())
beforeEach(resetMocks)
beforeEach(resetCache)
afterEach(resetMocks)

it('raises an error if api key is not set', async ()=>{
Expand Down Expand Up @@ -162,4 +164,58 @@ describe('assets', ()=>{
])
})
})

describe('NATIVE currency missing via API', ()=>{

beforeEach(()=>{
mock({ blockchain: 'ethereum', wallet: 'metamask' })
fetchMock.get({
url: 'https://api.depay.pro/v1/assets?account=0xd8da6bf26964af9d7eed9e03e53415d37aa96045&blockchain=ethereum',
headers: { 'X-Api-Key': 'TEST-123' }
}, [{
"name": "Dai Stablecoin",
"symbol": "DAI",
"address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
"type": "ERC20"
}]
)
fetchMock.get({
url: 'https://api.depay.pro/v1/assets?account=0xd8da6bf26964af9d7eed9e03e53415d37aa96045&blockchain=bsc',
headers: { 'X-Api-Key': 'TEST-123' }
}, [{
"name": "PancakeSwap",
"symbol": "CAKE",
"address": "0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82",
"type": "BEP20"
}]
)
})

it('ensures fetching asset for NATIVE currency', async()=> {
let ethereumBalanceMock = mock({
provider: await provider('ethereum'),
blockchain: 'ethereum',
balance: {
for: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
return: '22222221'
}
})
let bscBalanceMock = mock({
provider: await provider('bsc'),
blockchain: 'bsc',
balance: {
for: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
return: '3333333335'
}
})

let assets = await getAssets({ apiKey: 'TEST-123' })

expect(assets.find((a)=>a.name=='Ether').balance).toEqual('22222221')
expect(assets.find((a)=>a.name=='Binance Coin').balance).toEqual('3333333335')

expect(ethereumBalanceMock).toHaveBeenCalled()
expect(bscBalanceMock).toHaveBeenCalled()
})
})
})
37 changes: 11 additions & 26 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2260,40 +2260,25 @@ del@^5.1.0:
rimraf "^3.0.0"
slash "^3.0.0"

depay-web3-blockchains@^2.1.0, depay-web3-blockchains@^2.4.0:
depay-web3-blockchains@^2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/depay-web3-blockchains/-/depay-web3-blockchains-2.4.0.tgz#4b3bae79a366aa8407148e928a9141fa69877b54"
integrity sha512-6RZ9SKfrlNbu/EK8sCaW54OfZjcik7AZNDm0rYh5AAGspHY2Uuopka15IMCiuGPnP4/O5YYF06HHXhepsDMq5A==

depay-web3-client@^4.0.2, depay-web3-client@^4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/depay-web3-client/-/depay-web3-client-4.0.3.tgz#a27a4a64c389742f0a5c946a028c0247249d11cd"
integrity sha512-4E2fMhaYSjJNjc5BfuHLjVgwaY7iWuDq4fn2m0mbeTP1BEO6VZQLTxWxiP92aXuep+OZdsTcsS4bZfQcGiz4hg==
dependencies:
depay-web3-wallets "^4.2.0"
ethers "^5.4.4"
depay-web3-client@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/depay-web3-client/-/depay-web3-client-5.0.0.tgz#ffc53522b6f26f36a5f82ab1b64386561af9b3a0"
integrity sha512-WL1UQ9YvyJFQTpfn7hHl/Ex5Rd6hMGM6B+oQB8ML4yLnByGw8n0SIq4BXyl2PwEsZ1i+e1CBuMlNQdUTFtX3BQ==

depay-web3-constants@^3.0.0, depay-web3-constants@^3.0.1:
depay-web3-constants@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/depay-web3-constants/-/depay-web3-constants-3.0.1.tgz#c8979b063de9b875eb7692e8d93b0c9da80232b9"
integrity sha512-bRHj8mLnXuPWORZ6eE/2qKry3C9k7W7z4EHPKc5cruTJuBLnhN/zqmZWo/3nbEMaqd6n2tI/ObwW6bzA+E4rlg==

depay-web3-mock@^5.9.0:
version "5.9.0"
resolved "https://registry.yarnpkg.com/depay-web3-mock/-/depay-web3-mock-5.9.0.tgz#9f2b4fab47424a04804cc74b41cc0c6fe2b3e040"
integrity sha512-YbeFaZQjx10QoSBaQv2kqhUWm4MxeMnnA6w/Auctntck3t3DGWFlYMYGBSgnz4aVh/HNrqlWoRRnZmTSYLfyNw==
dependencies:
depay-web3-blockchains "^2.4.0"
ethers "^5.4.4"

depay-web3-wallets@^4.2.0:
version "4.2.4"
resolved "https://registry.yarnpkg.com/depay-web3-wallets/-/depay-web3-wallets-4.2.4.tgz#f65cb51eab54c377f3aa7b5656997a8dbec66dda"
integrity sha512-2SLId1TcU7kM3ToNMxPZiEUHrBZWNeMP0SxAzHM0PCgZIL16Gadu7E6/QmaQjbgX+9URSIQtO2/QS13aGgpCYQ==
dependencies:
depay-web3-blockchains "^2.1.0"
depay-web3-client "^4.0.2"
depay-web3-constants "^3.0.0"
depay-web3-mock@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/depay-web3-mock/-/depay-web3-mock-7.0.0.tgz#d7ceb1261bb4832ea88283f65000612ffe61235d"
integrity sha512-h/O9mFgQT1Z/M31PTx76CgJVuBJlQ+nINx874hf0PefFjriA1cPbwKsQ2K8HTR2RssZvsHWRYFaJWdK1YZNpew==

depay-web3-wallets@^5.1.1:
version "5.1.1"
Expand Down Expand Up @@ -2582,7 +2567,7 @@ esutils@^2.0.2:
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==

ethers@^5.4.4:
ethers@^5.4.6:
version "5.4.6"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.4.6.tgz#fe0a023956b5502c947f58e82fbcf9a73e5e75b6"
integrity sha512-F7LXARyB/Px3AQC6/QKedWZ8eqCkgOLORqL4B/F0Mag/K+qJSFGqsR36EaOZ6fKg3ZonI+pdbhb4A8Knt/43jQ==
Expand Down

0 comments on commit ecfc75a

Please sign in to comment.