Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/xchain-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
# v.0.18.0-alpha.1 (2022-06-20)

## Add

- const `DEFAULT_GAS_LIMIT`
- const `DEFAULT_FEE`
- Optional parameter `gasLimit` in `transfer` and `transferOffline`
- Params `clientUrls`, `chainIds` for constructor
- Helper `getDefaultClientUrls`
- Helper `getDefaultChainIds`
- Setter `setNetwork`

## Fix

- `getFees` returns values based on `DEFAULT_FEE`
- Initial one instance of `CosmosSDKClient` only depending on network
- Support IBC assets in `getBalances` (#596)
- Get IBC assets from denom in `getAsset`

## Update

- Result of `getTxsFromHistory` is filtered by given asset
- Move misc. constants into `const.ts`

## Breaking change

- Remove deprecated `AssetMuon`
- Remove deprecated `Client.getMainAsset`

# v.0.17.0 (2022-03-23)

## Update
Expand Down
41 changes: 21 additions & 20 deletions packages/xchain-cosmos/__tests__/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { BaseAmount, baseAmount } from '@xchainjs/xchain-util'
import nock from 'nock'

import { Client } from '../src/client'
import { AssetAtom } from '../src/const'
import { GetTxByHashResponse, TxHistoryResponse } from '../src/cosmos/types'
import { AssetMuon } from '../src/types'

const getClientUrl = (client: Client): string => {
return client.getNetwork() === Network.Testnet
Expand Down Expand Up @@ -78,30 +78,30 @@ describe('Client Test', () => {
const address1_testnet = 'cosmos1924f27fujxqnkt74u4d3ke3sfygugv9qp29hmk'

beforeEach(() => {
cosmosClient = new Client({ phrase, network: 'testnet' as Network })
cosmosClient = new Client({ phrase, network: Network.Testnet })
})

afterEach(() => {
cosmosClient.purgeClient()
})

it('should start with empty wallet', async () => {
const cosmosClientEmptyMain = new Client({ phrase, network: 'mainnet' as Network })
const cosmosClientEmptyMain = new Client({ phrase, network: Network.Mainnet })
expect(cosmosClientEmptyMain.getAddress()).toEqual(address0_mainnet)
expect(cosmosClientEmptyMain.getAddress(1)).toEqual(address1_mainnet)

const cosmosClientEmptyTest = new Client({ phrase, network: 'testnet' as Network })
const cosmosClientEmptyTest = new Client({ phrase, network: Network.Testnet })
expect(cosmosClientEmptyTest.getAddress()).toEqual(address0_testnet)
expect(cosmosClientEmptyTest.getAddress(1)).toEqual(address1_testnet)
})

it('throws an error passing an invalid phrase', async () => {
expect(() => {
new Client({ phrase: 'invalid phrase', network: 'mainnet' as Network })
new Client({ phrase: 'invalid phrase', network: Network.Mainnet })
}).toThrow()

expect(() => {
new Client({ phrase: 'invalid phrase', network: 'testnet' as Network })
new Client({ phrase: 'invalid phrase', network: Network.Testnet })
}).toThrow()
})

Expand All @@ -118,8 +118,8 @@ describe('Client Test', () => {
})

it('should update net', async () => {
const client = new Client({ phrase, network: 'mainnet' as Network })
client.setNetwork('testnet' as Network)
const client = new Client({ phrase, network: Network.Mainnet })
client.setNetwork(Network.Testnet)
expect(client.getNetwork()).toEqual('testnet')

const address = client.getAddress()
Expand All @@ -129,12 +129,12 @@ describe('Client Test', () => {
it('should init, should have right prefix', async () => {
expect(cosmosClient.validateAddress(cosmosClient.getAddress())).toEqual(true)

cosmosClient.setNetwork('mainnet' as Network)
cosmosClient.setNetwork(Network.Mainnet)
expect(cosmosClient.validateAddress(cosmosClient.getAddress())).toEqual(true)
})

it('has no balances', async () => {
cosmosClient.setNetwork('mainnet' as Network)
cosmosClient.setNetwork(Network.Mainnet)

mockAccountsBalance(getClientUrl(cosmosClient), address0_mainnet, {
balances: [],
Expand All @@ -148,19 +148,20 @@ describe('Client Test', () => {
mockAccountsBalance(getClientUrl(cosmosClient), 'cosmos1gehrq0pr5d79q8nxnaenvqh09g56jafm82thjv', {
balances: [
new proto.cosmos.base.v1beta1.Coin({
denom: 'muon',
denom: 'uatom',
amount: '75000000',
}),
],
})
const balances = await cosmosClient.getBalance('cosmos1gehrq0pr5d79q8nxnaenvqh09g56jafm82thjv')

const expected = balances[0].amount.amount().isEqualTo(baseAmount(75000000, 6).amount())
expect(expected).toBeTruthy()
expect(balances[0].asset).toEqual(AssetMuon)
expect(balances[0].asset).toEqual(AssetAtom)
})

it('has an empty tx history', async () => {
cosmosClient.setNetwork('mainnet' as Network)
cosmosClient.setNetwork(Network.Mainnet)

const expected: TxsPage = {
total: 0,
Expand All @@ -186,7 +187,7 @@ describe('Client Test', () => {
to_address: 'cosmos155svs6sgxe55rnvs6ghprtqu0mh69kehrn0dqr',
amount: [
{
denom: 'umuon',
denom: 'uatom',
amount: '4318994970',
},
],
Expand Down Expand Up @@ -222,7 +223,7 @@ describe('Client Test', () => {
let transactions = await cosmosClient.getTransactions({ address: 'cosmos1xvt4e7xd0j9dwv2w83g50tpcltsl90h52003e2' })
expect(transactions.total).toBeGreaterThan(0)

cosmosClient.setNetwork('mainnet' as Network)
cosmosClient.setNetwork(Network.Mainnet)
const msgSend2 = new proto.cosmos.bank.v1beta1.MsgSend({
from_address: 'cosmos1pjkpqxmvz47a5aw40l98fyktlg7k6hd9heq95z',
to_address: 'cosmos155svs6sgxe55rnvs6ghprtqu0mh69kehrn0dqr',
Expand Down Expand Up @@ -291,7 +292,7 @@ describe('Client Test', () => {
assertTxsPost(getClientUrl(cosmosClient), expected_txsPost_result)

const result = await cosmosClient.transfer({
asset: AssetMuon,
asset: AssetAtom,
recipient: to_address,
amount: send_amount,
memo,
Expand All @@ -301,7 +302,7 @@ describe('Client Test', () => {
})

it('get transaction data', async () => {
cosmosClient.setNetwork('mainnet' as Network)
cosmosClient.setNetwork(Network.Mainnet)

const msgSend = new proto.cosmos.bank.v1beta1.MsgSend({
from_address: 'cosmos1pjkpqxmvz47a5aw40l98fyktlg7k6hd9heq95z',
Expand Down Expand Up @@ -346,7 +347,7 @@ describe('Client Test', () => {
// Client created with network === 'testnet'
expect(cosmosClient.getExplorerUrl()).toEqual('https://explorer.theta-testnet.polypore.xyz')

cosmosClient.setNetwork('mainnet' as Network)
cosmosClient.setNetwork(Network.Mainnet)
expect(cosmosClient.getExplorerUrl()).toEqual('https://cosmos.bigdipper.live')
})

Expand All @@ -355,7 +356,7 @@ describe('Client Test', () => {
'https://explorer.theta-testnet.polypore.xyz/account/anotherTestAddressHere',
)

cosmosClient.setNetwork('mainnet' as Network)
cosmosClient.setNetwork(Network.Mainnet)
expect(cosmosClient.getExplorerAddressUrl('testAddressHere')).toEqual(
'https://cosmos.bigdipper.live/account/testAddressHere',
)
Expand All @@ -366,7 +367,7 @@ describe('Client Test', () => {
'https://explorer.theta-testnet.polypore.xyz/transactions/anotherTestTxHere',
)

cosmosClient.setNetwork('mainnet' as Network)
cosmosClient.setNetwork(Network.Mainnet)
expect(cosmosClient.getExplorerTxUrl('testTxHere')).toEqual('https://cosmos.bigdipper.live/transactions/testTxHere')
})
})
24 changes: 11 additions & 13 deletions packages/xchain-cosmos/__tests__/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { cosmosclient, proto } from '@cosmos-client/core'
import { baseAmount } from '@xchainjs/xchain-util'
import { baseAmount, eqAsset } from '@xchainjs/xchain-util'

import { AssetAtom } from '../src/const'
import { APIQueryParam, RawTxResponse, TxResponse } from '../src/cosmos/types'
import { AssetAtom, AssetMuon } from '../src/types'
import { getAsset, getDenom, getQueryString, getTxsFromHistory, isMsgMultiSend, isMsgSend } from '../src/util'

describe('cosmos/util', () => {
Expand Down Expand Up @@ -76,23 +76,21 @@ describe('cosmos/util', () => {
it('get denom for AssetAtom', () => {
expect(getDenom(AssetAtom)).toEqual('uatom')
})

it('get denom for AssetMuon', () => {
expect(getDenom(AssetMuon)).toEqual('umuon')
})
})

describe('getAsset', () => {
it('get asset for umuon', () => {
expect(getAsset('umuon')).toEqual(AssetMuon)
})

it('get asset for uatom', () => {
expect(getAsset('uatom')).toEqual(AssetAtom)
const asset = getAsset('uatom')
const result = asset !== null && eqAsset(asset, AssetAtom)
expect(result).toBeTruthy()
})

it('get asset for unknown', () => {
expect(getAsset('unknown')).toBeNull()
it('get asset for ibc asset (BTSG - Bitsong)', () => {
// see https://github.com/bitsongofficial/docs.bitsong.io/blob/main/relayer.md#official-bitsong-ibc-channels
const denom = 'ibc/E7D5E9D0E9BF8B7354929A817DD28D4D017E745F638954764AA88522A7A409EC'
const asset = getAsset(denom)
const expected = { ...AssetAtom, symbol: denom, ticker: '' }
expect(asset !== null && eqAsset(asset, expected)).toBeTruthy()
})
})
})
Expand Down
14 changes: 7 additions & 7 deletions packages/xchain-cosmos/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xchainjs/xchain-cosmos",
"version": "0.17.0",
"version": "0.18.0-alpha.1",
"description": "Custom Cosmos client and utilities used by XChainJS clients",
"keywords": [
"XChain",
Expand Down Expand Up @@ -32,9 +32,9 @@
"prepublishOnly": "yarn build"
},
"devDependencies": {
"@xchainjs/xchain-client": "^0.11.1",
"@xchainjs/xchain-crypto": "^0.2.4",
"@xchainjs/xchain-util": "^0.5.1",
"@xchainjs/xchain-client": "^0.11.3",
"@xchainjs/xchain-crypto": "^0.2.6",
"@xchainjs/xchain-util": "^0.7.1",
"@cosmos-client/core": "^0.45.1",
"axios": "^0.25.0",
"nock": "^13.0.5"
Expand All @@ -43,9 +43,9 @@
"access": "public"
},
"peerDependencies": {
"@xchainjs/xchain-client": "^0.11.1",
"@xchainjs/xchain-crypto": "^0.2.4",
"@xchainjs/xchain-util": "^0.5.1",
"@xchainjs/xchain-client": "^0.11.3",
"@xchainjs/xchain-crypto": "^0.2.6",
"@xchainjs/xchain-util": "^0.7.1",
"@cosmos-client/core": "^0.45.1",
"axios": "^0.25.0"
}
Expand Down
Loading