@cityofzion/bs-ethereum 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/BSEthereum.d.ts +3 -2
  2. package/dist/BSEthereum.js +27 -7
  3. package/dist/BitqueryBDSEthereum.d.ts +1 -2
  4. package/dist/BitqueryBDSEthereum.js +27 -12
  5. package/dist/BitqueryEDSEthereum.d.ts +1 -2
  6. package/dist/BitqueryEDSEthereum.js +20 -5
  7. package/dist/GhostMarketNDSEthereum.d.ts +1 -1
  8. package/dist/GhostMarketNDSEthereum.js +17 -3
  9. package/dist/LedgerServiceEthereum.d.ts +4 -2
  10. package/dist/LedgerServiceEthereum.js +13 -5
  11. package/dist/RpcBDSEthereum.d.ts +1 -1
  12. package/dist/RpcBDSEthereum.js +21 -7
  13. package/package.json +5 -2
  14. package/.eslintignore +0 -13
  15. package/.eslintrc.cjs +0 -22
  16. package/.rush/temp/operation/build/all.log +0 -1
  17. package/.rush/temp/operation/build/state.json +0 -3
  18. package/.rush/temp/package-deps_build.json +0 -30
  19. package/.rush/temp/shrinkwrap-deps.json +0 -531
  20. package/CHANGELOG.json +0 -126
  21. package/CHANGELOG.md +0 -68
  22. package/bs-ethereum.build.log +0 -1
  23. package/jest.config.ts +0 -13
  24. package/jest.setup.ts +0 -1
  25. package/src/BSEthereum.ts +0 -208
  26. package/src/BitqueryBDSEthereum.ts +0 -231
  27. package/src/BitqueryEDSEthereum.ts +0 -67
  28. package/src/GhostMarketNDSEthereum.ts +0 -125
  29. package/src/LedgerServiceEthereum.ts +0 -44
  30. package/src/RpcBDSEthereum.ts +0 -88
  31. package/src/__tests__/BSEthereum.spec.ts +0 -172
  32. package/src/__tests__/BitqueryBDSEthereum.spec.ts +0 -106
  33. package/src/__tests__/BitqueryEDSEthereum.spec.ts +0 -55
  34. package/src/__tests__/GhostMarketNDSEthereum.spec.ts +0 -49
  35. package/src/__tests__/RpcBDSEthereum.spec.ts +0 -62
  36. package/src/assets/tokens/common.json +0 -8
  37. package/src/constants.ts +0 -36
  38. package/src/graphql.ts +0 -288
  39. package/src/index.ts +0 -6
  40. package/tsconfig.build.json +0 -4
  41. package/tsconfig.json +0 -15
@@ -1,67 +0,0 @@
1
- import { Currency, ExchangeDataService, NetworkType, TokenPricesResponse } from '@cityofzion/blockchain-service'
2
- import { Client, fetchExchange } from '@urql/core'
3
- import fetch from 'node-fetch'
4
- import { BITQUERY_URL } from './constants'
5
- import dayjs from 'dayjs'
6
- import utc from 'dayjs/plugin/utc'
7
- import { bitqueryGetPricesQuery } from './graphql'
8
-
9
- dayjs.extend(utc)
10
- export class BitqueryEDSEthereum implements ExchangeDataService {
11
- private readonly client: Client
12
- private readonly networkType: NetworkType
13
-
14
- constructor(networkType: NetworkType, apiKey: string) {
15
- this.networkType = networkType
16
-
17
- this.client = new Client({
18
- url: BITQUERY_URL,
19
- exchanges: [fetchExchange],
20
- fetch,
21
- fetchOptions: {
22
- headers: {
23
- 'X-API-KEY': apiKey,
24
- },
25
- },
26
- })
27
- }
28
-
29
- async getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]> {
30
- if (this.networkType !== 'mainnet') throw new Error('Exchange is only available on mainnet')
31
-
32
- const twoDaysAgo = dayjs.utc().subtract(2, 'day').startOf('date').toISOString()
33
-
34
- const result = await this.client
35
- .query(bitqueryGetPricesQuery, { after: twoDaysAgo, network: 'ethereum' })
36
- .toPromise()
37
- if (result.error) {
38
- throw new Error(result.error.message)
39
- }
40
- if (!result.data) {
41
- throw new Error('There is no price data')
42
- }
43
-
44
- let currencyRatio: number = 1
45
- if (currency !== 'USD') {
46
- currencyRatio = await this.getCurrencyRatio(currency)
47
- }
48
-
49
- const prices = result.data.ethereum.dexTrades.map(
50
- (trade): TokenPricesResponse => ({
51
- symbol: trade.baseCurrency.symbol,
52
- price: trade.quotePrice * currencyRatio,
53
- hash: trade.baseCurrency.address,
54
- })
55
- )
56
-
57
- return prices
58
- }
59
-
60
- private async getCurrencyRatio(currency: Currency): Promise<number> {
61
- const request = await fetch(`https://api.flamingo.finance/fiat/exchange-rate?pair=USD_${currency}`, {
62
- method: 'GET',
63
- })
64
- const data = await request.json()
65
- return data
66
- }
67
- }
@@ -1,125 +0,0 @@
1
- import {
2
- NftResponse,
3
- NftsResponse,
4
- NetworkType,
5
- NftDataService,
6
- GetNftParam,
7
- GetNftsByAddressParams,
8
- } from '@cityofzion/blockchain-service'
9
- import qs from 'query-string'
10
-
11
- import { GHOSTMARKET_CHAIN_BY_NETWORK_TYPE, GHOSTMARKET_URL_BY_NETWORK_TYPE } from './constants'
12
- import fetch from 'node-fetch'
13
-
14
- type GhostMarketNFT = {
15
- tokenId: string
16
- contract: {
17
- chain?: string
18
- hash: string
19
- symbol: string
20
- }
21
- creator: {
22
- address: string
23
- offchainName?: string
24
- }
25
- apiUrl?: string
26
- ownerships: {
27
- owner: {
28
- address?: string
29
- }
30
- }[]
31
- collection: {
32
- name?: string
33
- logoUrl?: string
34
- }
35
- metadata: {
36
- description: string
37
- mediaType: string
38
- mediaUri: string
39
- mintDate: number
40
- mintNumber: number
41
- name: string
42
- }
43
- }
44
-
45
- type GhostMarketAssets = {
46
- assets: GhostMarketNFT[]
47
- next: string
48
- }
49
- export class GhostMarketNDSEthereum implements NftDataService {
50
- private networkType: NetworkType
51
-
52
- constructor(networkType: NetworkType) {
53
- this.networkType = networkType
54
- }
55
-
56
- async getNftsByAddress({ address, size = 18, cursor }: GetNftsByAddressParams): Promise<NftsResponse> {
57
- const url = this.getUrlWithParams({
58
- size,
59
- owners: [address],
60
- cursor: cursor,
61
- })
62
-
63
- const request = await fetch(url, { method: 'GET' })
64
- const data = (await request.json()) as GhostMarketAssets
65
- const nfts = data.assets ?? []
66
-
67
- return { nextCursor: data.next, items: nfts.map(this.parse.bind(this)) }
68
- }
69
-
70
- async getNft({ contractHash, tokenId }: GetNftParam): Promise<NftResponse> {
71
- const url = this.getUrlWithParams({
72
- contract: contractHash,
73
- tokenIds: [tokenId],
74
- })
75
-
76
- const request = await fetch(url, { method: 'GET' })
77
- const data = (await request.json()) as GhostMarketAssets
78
-
79
- return this.parse(data.assets[0])
80
- }
81
-
82
- private treatGhostMarketImage(srcImage?: string) {
83
- if (!srcImage) {
84
- return
85
- }
86
-
87
- if (srcImage.startsWith('ipfs://')) {
88
- const [, imageId] = srcImage.split('://')
89
-
90
- return `https://ghostmarket.mypinata.cloud/ipfs/${imageId}`
91
- }
92
-
93
- return srcImage
94
- }
95
-
96
- private getUrlWithParams(params: any) {
97
- const parameters = qs.stringify(
98
- {
99
- chain: GHOSTMARKET_CHAIN_BY_NETWORK_TYPE[this.networkType],
100
- ...params,
101
- },
102
- { arrayFormat: 'bracket' }
103
- )
104
- return `${GHOSTMARKET_URL_BY_NETWORK_TYPE[this.networkType]}/assets?${parameters}`
105
- }
106
-
107
- private parse(data: GhostMarketNFT) {
108
- const nftResponse: NftResponse = {
109
- collectionImage: this.treatGhostMarketImage(data.collection?.logoUrl),
110
- id: data.tokenId,
111
- contractHash: data.contract.hash,
112
- symbol: data.contract.symbol,
113
- collectionName: data.collection?.name,
114
- image: this.treatGhostMarketImage(data.metadata.mediaUri),
115
- isSVG: String(data.metadata.mediaType).includes('svg+xml'),
116
- name: data.metadata.name,
117
- creator: {
118
- address: data.creator.address,
119
- name: data.creator.offchainName,
120
- },
121
- }
122
-
123
- return nftResponse
124
- }
125
- }
@@ -1,44 +0,0 @@
1
- import { LedgerService } from '@cityofzion/blockchain-service'
2
- import Transport from '@ledgerhq/hw-transport'
3
- import LedgerEthereumApp, { ledgerService as LedgerEthereumAppService } from '@ledgerhq/hw-app-eth'
4
- import { ethers } from 'ethers'
5
-
6
- export class LedgerServiceEthereum implements LedgerService {
7
- private readonly defaultPath = "44'/60'/0'/0/0"
8
-
9
- async getAddress(transport: Transport): Promise<string> {
10
- const ledgerApp = new LedgerEthereumApp(transport)
11
- const { address } = await ledgerApp.getAddress(this.defaultPath)
12
-
13
- return address
14
- }
15
-
16
- async getPublicKey(transport: Transport): Promise<string> {
17
- const ledgerApp = new LedgerEthereumApp(transport)
18
- const { publicKey } = await ledgerApp.getAddress(this.defaultPath)
19
-
20
- return '0x' + publicKey
21
- }
22
-
23
- async getSignTransactionFunction(transport: Transport) {
24
- return async (transaction: ethers.providers.TransactionRequest): Promise<string> => {
25
- const ledgerApp = new LedgerEthereumApp(transport)
26
-
27
- const unsignedTransaction: ethers.utils.UnsignedTransaction = {
28
- ...transaction,
29
- nonce: transaction.nonce ? ethers.BigNumber.from(transaction.nonce).toNumber() : undefined,
30
- }
31
-
32
- const serializedUnsignedTransaction = ethers.utils.serializeTransaction(unsignedTransaction).substring(2)
33
-
34
- const resolution = await LedgerEthereumAppService.resolveTransaction(serializedUnsignedTransaction, {}, {})
35
- const signature = await ledgerApp.signTransaction(this.defaultPath, serializedUnsignedTransaction, resolution)
36
-
37
- return ethers.utils.serializeTransaction(unsignedTransaction, {
38
- v: ethers.BigNumber.from('0x' + signature.v).toNumber(),
39
- r: '0x' + signature.r,
40
- s: '0x' + signature.s,
41
- })
42
- }
43
- }
44
- }
@@ -1,88 +0,0 @@
1
- import {
2
- BalanceResponse,
3
- BlockchainDataService,
4
- ContractResponse,
5
- Network,
6
- Token,
7
- TransactionResponse,
8
- TransactionsByAddressParams,
9
- TransactionsByAddressResponse,
10
- } from '@cityofzion/blockchain-service'
11
- import { ethers } from 'ethers'
12
- import { TOKENS } from './constants'
13
-
14
- export class RpcBDSEthereum implements BlockchainDataService {
15
- private readonly network: Network
16
-
17
- maxTimeToConfirmTransactionInMs: number = 1000 * 60 * 5
18
-
19
- constructor(network: Network) {
20
- this.network = network
21
- }
22
-
23
- async getTransaction(hash: string): Promise<TransactionResponse> {
24
- const provider = new ethers.providers.JsonRpcProvider(this.network.url)
25
-
26
- const transaction = await provider.getTransaction(hash)
27
- if (!transaction || !transaction.blockHash || !transaction.to) throw new Error('Transaction not found')
28
-
29
- const block = await provider.getBlock(transaction.blockHash)
30
- if (!block) throw new Error('Block not found')
31
-
32
- const tokens = TOKENS[this.network.type]
33
- const token = tokens.find(token => token.symbol === 'ETH')!
34
-
35
- return {
36
- block: block.number,
37
- time: block.timestamp,
38
- hash: transaction.hash,
39
- transfers: [
40
- {
41
- type: 'token',
42
- amount: ethers.utils.formatEther(transaction.value),
43
- contractHash: '-',
44
- from: transaction.from,
45
- to: transaction.to,
46
- token,
47
- },
48
- ],
49
- notifications: [],
50
- }
51
- }
52
-
53
- async getTransactionsByAddress(_params: TransactionsByAddressParams): Promise<TransactionsByAddressResponse> {
54
- throw new Error("RPC doesn't support get transactions history of address")
55
- }
56
-
57
- async getContract(): Promise<ContractResponse> {
58
- throw new Error("RPC doesn't support contract info")
59
- }
60
-
61
- async getTokenInfo(hash: string): Promise<Token> {
62
- const tokens = TOKENS[this.network.type]
63
- const token = tokens.find(token => token.hash === hash)
64
- if (!token) throw new Error('Token not found')
65
-
66
- return token
67
- }
68
-
69
- async getBalance(address: string): Promise<BalanceResponse[]> {
70
- const provider = new ethers.providers.JsonRpcProvider(this.network.url)
71
- const balance = await provider.getBalance(address)
72
-
73
- const tokens = TOKENS[this.network.type]
74
- const token = tokens.find(token => token.symbol === 'ETH')!
75
-
76
- return [
77
- {
78
- amount: ethers.utils.formatEther(balance),
79
- token,
80
- },
81
- ]
82
- }
83
-
84
- async getBlockHeight(): Promise<number> {
85
- const provider = new ethers.providers.JsonRpcProvider(this.network.url)
86
- return await provider.getBlockNumber()
87
- }
88
- }
@@ -1,172 +0,0 @@
1
- import { ethers } from 'ethers'
2
- import { BSEthereum } from '../BSEthereum'
3
- import { Account } from '@cityofzion/blockchain-service'
4
- import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'
5
-
6
- let bsEthereum: BSEthereum
7
- let wallet: ethers.Wallet
8
- let account: Account
9
-
10
- describe('BSEthereum', () => {
11
- beforeAll(() => {
12
- bsEthereum = new BSEthereum('neo3', { type: 'testnet' }, process.env.BITQUERY_API_KEY as string)
13
- wallet = ethers.Wallet.createRandom()
14
- account = {
15
- key: wallet.privateKey,
16
- type: 'privateKey',
17
- address: wallet.address,
18
- }
19
- })
20
-
21
- it('Should be able to validate an address', () => {
22
- const validAddress = '0xD81a8F3c3f8b006Ef1ae4a2Fd28699AD7E3e21C5'
23
- const invalidAddress = 'invalid address'
24
-
25
- expect(bsEthereum.validateAddress(validAddress)).toBeTruthy()
26
- expect(bsEthereum.validateAddress(invalidAddress)).toBeFalsy()
27
- })
28
-
29
- it('Should be able to validate an encrypted key', async () => {
30
- const validEncryptedJson = await wallet.encrypt('password')
31
- const invalidEncryptedJson = '{ invalid: json }'
32
-
33
- expect(bsEthereum.validateEncrypted(validEncryptedJson)).toBeTruthy()
34
- expect(bsEthereum.validateEncrypted(invalidEncryptedJson)).toBeFalsy()
35
- })
36
-
37
- it('Should be able to validate a private key', () => {
38
- const validKey = wallet.privateKey
39
- const invalidKey = 'invalid key'
40
-
41
- expect(bsEthereum.validateKey(validKey)).toBeTruthy()
42
- expect(bsEthereum.validateKey(invalidKey)).toBeFalsy()
43
- })
44
-
45
- it('Should be able to validate an domain', () => {
46
- const validDomain = 'alice.eth'
47
- const invalidDomain = 'invalid domain'
48
-
49
- expect(bsEthereum.validateNameServiceDomainFormat(validDomain)).toBeTruthy()
50
- expect(bsEthereum.validateNameServiceDomainFormat(invalidDomain)).toBeFalsy()
51
- })
52
-
53
- it('Should be able to generate a account from mnemonic', () => {
54
- const account = bsEthereum.generateAccountFromMnemonic(wallet.mnemonic.phrase, 0)
55
-
56
- expect(bsEthereum.validateAddress(account.address)).toBeTruthy()
57
- expect(bsEthereum.validateKey(account.key)).toBeTruthy()
58
- })
59
-
60
- it('Should be able to generate a account from wif', () => {
61
- const accountFromWif = bsEthereum.generateAccountFromKey(wallet.privateKey)
62
- expect(accountFromWif).toEqual(account)
63
- })
64
-
65
- it('Should be able to decrypt a encrypted key', async () => {
66
- const password = 'TestPassword'
67
- const validEncryptedJson = await bsEthereum.encrypt(wallet.privateKey, password)
68
- const decryptedAccount = await bsEthereum.decrypt(validEncryptedJson, password)
69
- expect(decryptedAccount).toEqual(account)
70
- })
71
-
72
- it('Should be able to encrypt key', async () => {
73
- const password = 'TestPassword'
74
- const validEncryptedJson = await bsEthereum.encrypt(wallet.privateKey, password)
75
- expect(JSON.parse(validEncryptedJson)).toEqual(
76
- expect.objectContaining({ address: wallet.address.replace('0x', '').toLowerCase() })
77
- )
78
- })
79
-
80
- it.skip('Should be able to calculate transfer fee', async () => {
81
- const account = bsEthereum.generateAccountFromKey(process.env.TESTNET_PRIVATE_KEY as string)
82
-
83
- const fee = await bsEthereum.calculateTransferFee({
84
- senderAccount: account,
85
- intent: {
86
- amount: '0.1',
87
- receiverAddress: '0xFACf5446B71dB33E920aB1769d9427146183aEcd',
88
- tokenDecimals: 18,
89
- tokenHash: '0xBA62BCfcAaFc6622853cca2BE6Ac7d845BC0f2Dc',
90
- },
91
- })
92
-
93
- expect(fee).toEqual(expect.any(String))
94
- }, 50000)
95
-
96
- it.skip('Should be able to transfer a native token', async () => {
97
- const account = bsEthereum.generateAccountFromKey(process.env.TESTNET_PRIVATE_KEY as string)
98
-
99
- const transactionHash = await bsEthereum.transfer({
100
- senderAccount: account,
101
- intent: {
102
- amount: '0.00000001',
103
- receiverAddress: '0xFACf5446B71dB33E920aB1769d9427146183aEcd',
104
- tokenDecimals: 18,
105
- tokenHash: '-',
106
- },
107
- })
108
-
109
- expect(transactionHash).toEqual(expect.any(String))
110
- }, 50000)
111
-
112
- it.skip('Should be able to transfer a ERC20 token', async () => {
113
- const account = bsEthereum.generateAccountFromKey(process.env.TESTNET_PRIVATE_KEY as string)
114
-
115
- const transactionHash = await bsEthereum.transfer({
116
- senderAccount: account,
117
- intent: {
118
- amount: '0.00000001',
119
- receiverAddress: '0xFACf5446B71dB33E920aB1769d9427146183aEcd',
120
- tokenDecimals: 18,
121
- tokenHash: '0xba62bcfcaafc6622853cca2be6ac7d845bc0f2dc',
122
- },
123
- })
124
-
125
- expect(transactionHash).toEqual(expect.any(String))
126
- }, 50000)
127
-
128
- it.skip('Should be able to transfer a native token with ledger', async () => {
129
- const transport = await TransportNodeHid.create()
130
- const publicKey = await bsEthereum.ledgerService.getPublicKey(transport)
131
- const account = bsEthereum.generateAccountFromPublicKey(publicKey)
132
-
133
- const transactionHash = await bsEthereum.transfer({
134
- senderAccount: account,
135
- intent: {
136
- amount: '0.00000001',
137
- receiverAddress: '0x82B5Cd984880C8A821429cFFf89f36D35BaeBE89',
138
- tokenDecimals: 18,
139
- tokenHash: '-',
140
- },
141
- isLedger: true,
142
- ledgerTransport: transport,
143
- })
144
-
145
- expect(transactionHash).toEqual(expect.any(String))
146
- }, 50000)
147
-
148
- it.skip('Should be able to transfer a ERC20 token with ledger', async () => {
149
- const transport = await TransportNodeHid.create()
150
- const publicKey = await bsEthereum.ledgerService.getPublicKey(transport)
151
- const account = bsEthereum.generateAccountFromPublicKey(publicKey)
152
-
153
- const transactionHash = await bsEthereum.transfer({
154
- senderAccount: account,
155
- intent: {
156
- amount: '0.00000001',
157
- receiverAddress: '0x82B5Cd984880C8A821429cFFf89f36D35BaeBE89',
158
- tokenDecimals: 18,
159
- tokenHash: '0xcf185f2F3Fe19D82bFdcee59E3330FD7ba5f27ce',
160
- },
161
- isLedger: true,
162
- ledgerTransport: transport,
163
- })
164
-
165
- expect(transactionHash).toEqual(expect.any(String))
166
- }, 50000)
167
-
168
- it('Should be able to resolve a name service domain', async () => {
169
- const address = await bsEthereum.resolveNameServiceDomain('alice.eth')
170
- expect(address).toEqual('0xa974890156A3649A23a6C0f2ebd77D6F7A7333d4')
171
- }, 10000)
172
- })
@@ -1,106 +0,0 @@
1
- import { BitqueryBDSEthereum } from '../BitqueryBDSEthereum'
2
- import { DEFAULT_URL_BY_NETWORK_TYPE } from '../constants'
3
-
4
- const bitqueryBDSEthereum = new BitqueryBDSEthereum(
5
- { type: 'testnet', url: DEFAULT_URL_BY_NETWORK_TYPE.testnet },
6
- process.env.BITQUERY_API_KEY as string
7
- )
8
-
9
- describe('BitqueryBDSEthereum', () => {
10
- it('Should be able to get transaction - %s', async () => {
11
- const hash = '0x43fa3015d077a13888409cfbd6228df8900abcd5314ff11ea6ce0c49e8b7c94d'
12
- const transaction = await bitqueryBDSEthereum.getTransaction(hash)
13
-
14
- expect(transaction).toEqual(
15
- expect.objectContaining({
16
- block: expect.any(Number),
17
- hash,
18
- notifications: [],
19
- time: expect.any(Number),
20
- })
21
- )
22
- transaction.transfers.forEach(transfer => {
23
- expect(transfer).toEqual(
24
- expect.objectContaining({
25
- from: expect.any(String),
26
- to: expect.any(String),
27
- contractHash: expect.any(String),
28
- amount: expect.any(String),
29
- type: expect.any(String),
30
- })
31
- )
32
- })
33
- }, 10000)
34
-
35
- it('Should be able to get transactions of address - %s', async () => {
36
- const address = '0x82B5Cd984880C8A821429cFFf89f36D35BaeBE89'
37
- const response = await bitqueryBDSEthereum.getTransactionsByAddress({ address: address, page: 1 })
38
- expect(response.totalCount).toBeGreaterThan(0)
39
- response.transactions.forEach(transaction => {
40
- expect(transaction).toEqual(
41
- expect.objectContaining({
42
- block: expect.any(Number),
43
- hash: expect.any(String),
44
- notifications: [],
45
- time: expect.any(Number),
46
- fee: expect.any(String),
47
- })
48
- )
49
-
50
- transaction.transfers.forEach(transfer => {
51
- expect(transfer).toEqual(
52
- expect.objectContaining({
53
- from: expect.any(String),
54
- to: expect.any(String),
55
- contractHash: expect.any(String),
56
- amount: expect.any(String),
57
- type: expect.any(String),
58
- })
59
- )
60
- })
61
- })
62
- }, 10000)
63
-
64
- it('Should be able to get eth info - %s', async () => {
65
- const hash = '-'
66
- const token = await bitqueryBDSEthereum.getTokenInfo(hash)
67
-
68
- expect(token).toEqual({
69
- symbol: 'ETH',
70
- name: 'Ethereum',
71
- hash: '-',
72
- decimals: 18,
73
- })
74
- })
75
-
76
- it('Should be able to get token info - %s', async () => {
77
- const hash = '0xBA62BCfcAaFc6622853cca2BE6Ac7d845BC0f2Dc'
78
- const token = await bitqueryBDSEthereum.getTokenInfo(hash)
79
-
80
- expect(token).toEqual({
81
- hash: '0xba62bcfcaafc6622853cca2be6ac7d845bc0f2dc',
82
- name: 'FaucetToken',
83
- symbol: 'FAU',
84
- decimals: 18,
85
- })
86
- })
87
-
88
- it('Should be able to get balance - %s', async () => {
89
- const address = '0x82B5Cd984880C8A821429cFFf89f36D35BaeBE89'
90
- const balance = await bitqueryBDSEthereum.getBalance(address)
91
-
92
- balance.forEach(balance => {
93
- expect(balance).toEqual(
94
- expect.objectContaining({
95
- amount: expect.any(String),
96
- token: {
97
- hash: expect.any(String),
98
- name: expect.any(String),
99
- symbol: expect.any(String),
100
- decimals: expect.any(Number),
101
- },
102
- })
103
- )
104
- })
105
- })
106
- })
@@ -1,55 +0,0 @@
1
- import { BitqueryEDSEthereum } from '../BitqueryEDSEthereum'
2
-
3
- let bitqueryEDSEthereum: BitqueryEDSEthereum
4
-
5
- describe('FlamingoEDSNeo3', () => {
6
- beforeAll(() => {
7
- bitqueryEDSEthereum = new BitqueryEDSEthereum('mainnet', process.env.BITQUERY_API_KEY as string)
8
- })
9
-
10
- it('Should return a list with prices of tokens using USD', async () => {
11
- const tokenPriceList = await bitqueryEDSEthereum.getTokenPrices('USD')
12
-
13
- tokenPriceList.forEach(tokenPrice => {
14
- expect(tokenPrice).toEqual({
15
- price: expect.any(Number),
16
- symbol: expect.any(String),
17
- hash: expect.any(String),
18
- })
19
- })
20
- })
21
-
22
- it('Should return a list with prices of tokens using BRL', async () => {
23
- const tokenPriceListInUSD = await bitqueryEDSEthereum.getTokenPrices('USD')
24
- const tokenPriceList = await bitqueryEDSEthereum.getTokenPrices('BRL')
25
-
26
- tokenPriceList.forEach((tokenPrice, index) => {
27
- expect(tokenPrice.price).toBeGreaterThan(tokenPriceListInUSD[index].price)
28
- expect(tokenPrice).toEqual({
29
- price: expect.any(Number),
30
- symbol: expect.any(String),
31
- hash: expect.any(String),
32
- })
33
- })
34
- })
35
-
36
- it('Should return a list with prices of tokens using EUR', async () => {
37
- const tokenPriceListInUSD = await bitqueryEDSEthereum.getTokenPrices('USD')
38
- const tokenPriceList = await bitqueryEDSEthereum.getTokenPrices('EUR')
39
-
40
- tokenPriceList.forEach((tokenPrice, index) => {
41
- expect(tokenPrice.price).toBeLessThan(tokenPriceListInUSD[index].price)
42
- expect(tokenPrice).toEqual({
43
- price: expect.any(Number),
44
- symbol: expect.any(String),
45
- hash: expect.any(String),
46
- })
47
- })
48
- })
49
-
50
- it('Should return the ETH price in USD', async () => {
51
- const tokenPriceList = await bitqueryEDSEthereum.getTokenPrices('USD')
52
-
53
- expect(tokenPriceList).toEqual(expect.arrayContaining([{ symbol: 'ETH', hash: '-', price: expect.any(Number) }]))
54
- })
55
- })