Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(): 4.0.5 #2173

Merged
merged 10 commits into from
Dec 5, 2023
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
2 changes: 1 addition & 1 deletion apps/whale-api/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.7"

services:
defi-blockchain:
image: defi/defichain:4.0.0
image: defi/defichain:4.0.5

ports:
- "19554:19554"
Expand Down
17 changes: 15 additions & 2 deletions docs/node/CATEGORIES/08-account.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,12 @@ Create a transfer domain transaction submitted to a connected node.

```ts title="client.account.transferDomain()"
interface account {
transferDomain (payload: Array<Record<string, TransferDomainInfo>>): Promise<string>
transferDomain (payload: Array<Record<TransferDomainKey, TransferDomainInfo> | Record<TransferDomainOptionalKey, TransferDomainOptionalInfo>>): Promise<string>
}

enum TransferDomainKey {
SRC = 'src',
DST = 'dst'
}

interface TransferDomainInfo {
Expand All @@ -176,7 +181,15 @@ enum TransferDomainType {
DVM = 2,
/** type for EVM To DVM Token transfer */
EVM = 3,
};
}

enum TransferDomainOptionalKey {
SINGLE_KEY_CHECK = 'singlekeycheck',
}

interface TransferDomainOptionalInfo {
singleKeyCheck: boolean
}
```

## accountToUtxos
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { ContainerAdapterClient } from '../../container_adapter_client'
import { TransferDomainType } from '../../../src/category/account'
import { TransferDomainType, TransferDomainOptionalInfo } from '../../../src/category/account'
import waitForExpect from 'wait-for-expect'
import BigNumber from 'bignumber.js'

Expand Down Expand Up @@ -137,7 +137,8 @@ describe('Account', () => {
address: evmAddr,
amount: '3@DFI',
domain: TransferDomainType.EVM
}
},
singlekeycheck: false as unknown as TransferDomainOptionalInfo
}
])
await container.generate(1)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { ContainerAdapterClient } from '../../container_adapter_client'
import { TransferDomainOptionalInfo, TransferDomainType } from '../../../src/category/account'
import { RpcApiError } from '@defichain/jellyfish-api-core'
import BigNumber from 'bignumber.js'

describe('TransferDomain', () => {
let legacyAddr: string
let legacyEvmAddr: string
let bech32Addr: string
let bech32EvmAddr: string
const container = new MasterNodeRegTestContainer()
const client = new ContainerAdapterClient(container)

beforeAll(async () => {
await container.start()
await container.waitForWalletCoinbaseMaturity()

await client.masternode.setGov({
ATTRIBUTES: {
'v0/params/feature/evm': 'true',
'v0/params/feature/transferdomain': 'true'
}
})
await container.generate(2)

legacyAddr = await container.getNewAddress('legacy', 'legacy')
legacyEvmAddr = (await container.call('addressmap', [legacyAddr, 1])).format.erc55

bech32Addr = await container.getNewAddress('bech32', 'bech32')
bech32EvmAddr = (await container.call('addressmap', [bech32Addr, 1])).format.erc55

await container.call('utxostoaccount', [{ [legacyAddr]: '100000@0' }])
await container.generate(1)
})

afterAll(async () => {
await container.stop()
})

describe('single key check restricted', () => {
it('should fail as src key and dst key is different', async () => {
const promise = client.account.transferDomain([
{
src: {
address: legacyAddr,
amount: '3@DFI',
domain: TransferDomainType.DVM
},
dst: {
address: bech32EvmAddr,
amount: '3@DFI',
domain: TransferDomainType.EVM
}
}
])
await expect(promise).rejects.toThrow(RpcApiError)
await expect(promise).rejects.toThrow('Dst address does not match source key')
})

it('should transfer domain with same key', async () => {
const legacyAccBefore = await client.account.getAccount(legacyAddr)
const [value] = legacyAccBefore[0].split('@')
const legacyBalanceBefore = new BigNumber(value)
const evmBalanceBefore = await getEVMBalances(client)

await client.account.transferDomain([
{
src: {
address: legacyAddr,
amount: '1@DFI',
domain: TransferDomainType.DVM
},
dst: {
address: legacyEvmAddr,
amount: '1@DFI',
domain: TransferDomainType.EVM
}
}
])
await container.generate(1)

{
const legacyAccAfter = await client.account.getAccount(legacyAddr)
const [value] = legacyAccAfter[0].split('@')
const legacyBalanceAfter = new BigNumber(value)
expect(legacyBalanceAfter).toStrictEqual(legacyBalanceBefore.minus(1))

const evmBalanceAfter = await getEVMBalances(client)
expect(evmBalanceAfter).toStrictEqual(evmBalanceBefore.plus(1))
}
})

it('should transfer domain with different key', async () => {
const legacyAccBefore = await client.account.getAccount(legacyAddr)
const [value] = legacyAccBefore[0].split('@')
const legacyBalanceBefore = new BigNumber(value)
const evmBalanceBefore = await getEVMBalances(client)

await client.account.transferDomain([
{
src: {
address: legacyAddr,
amount: '2@DFI',
domain: TransferDomainType.DVM
},
dst: {
address: bech32EvmAddr,
amount: '2@DFI',
domain: TransferDomainType.EVM
},
singlekeycheck: false as unknown as TransferDomainOptionalInfo
}
])
await container.generate(1)

{
const legacyAccAfter = await client.account.getAccount(legacyAddr)
const [value] = legacyAccAfter[0].split('@')
const legacyBalanceAfter = new BigNumber(value)
expect(legacyBalanceAfter).toStrictEqual(legacyBalanceBefore.minus(2))

const evmBalanceAfter = await getEVMBalances(client)
expect(evmBalanceAfter).toStrictEqual(evmBalanceBefore.plus(2))
}
})
})
})

async function getEVMBalances (client: ContainerAdapterClient): Promise<BigNumber> {
const ethRes = await client.account.getTokenBalances({}, false)
const [eth] = ethRes[0].split('@')
const withEthRes = await client.account.getTokenBalances({}, false, { symbolLookup: false, includeEth: true })
const [withEth] = withEthRes[0].split('@')
return new BigNumber(withEth).minus(eth)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { MasterNodeRegTestContainer, StartFlags } from '@defichain/testcontainers'
import { ContainerAdapterClient } from '../../container_adapter_client'
import { TransferDomainType } from '../../../src/category/account'
import { RpcApiError } from '@defichain/jellyfish-api-core'
Expand All @@ -8,9 +8,11 @@ describe('TransferDomain', () => {
let dvmAddr: string, evmAddr: string, p2shAddr: string
const container = new MasterNodeRegTestContainer()
const client = new ContainerAdapterClient(container)
// add `-tdsinglekeycheck` for backward compatibility
const startFlags: StartFlags[] = [{ name: 'tdsinglekeycheck', value: 0 }]

beforeAll(async () => {
await container.start()
await container.start({ startFlags })
await container.waitForWalletCoinbaseMaturity()

await client.masternode.setGov({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { Testing } from '@defichain/jellyfish-testing'
import { RpcApiError } from '@defichain/jellyfish-api-core/dist/index'
import { ContainerAdapterClient } from '../../container_adapter_client'
import { TransferDomainType } from '../../../src/category/account'
import { TransferDomainType, TransferDomainOptionalInfo } from '../../../src/category/account'
import BigNumber from 'bignumber.js'

describe('EVMTX', () => {
Expand Down Expand Up @@ -69,7 +69,8 @@ describe('EVMTX', () => {
address: ethAddress,
amount: `${amount.HUNDRED}@DFI`,
domain: TransferDomainType.EVM
}
},
singlekeycheck: false as unknown as TransferDomainOptionalInfo
}
]
await container.call('transferdomain', [dvmToEvmTransfer])
Expand Down
16 changes: 13 additions & 3 deletions packages/jellyfish-api-core/src/category/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export enum TransferDomainKey {
DST = 'dst'
}

export enum TransferDomainOptionalKey {
SINGLE_KEY_CHECK = 'singlekeycheck',
}

/**
* Account RPCs for DeFi Blockchain
*/
Expand Down Expand Up @@ -296,16 +300,18 @@ export class Account {
/**
* Create an transfer domain transaction submitted to a connected node.
*
* @param {Array<Record<TransferDomainKey, TransferDomainInfo>>} payload[]
* @param {Record<TransferDomainKey, TransferDomainInfo>} payload
* @param {Array<Record<TransferDomainKey, TransferDomainInfo> | Record<TransferDomainOptionalKey, TransferDomainOptionalInfo>>} payload[]
* @param {Record<TransferDomainKey, TransferDomainInfo> | Record<TransferDomainOptionalKey, TransferDomainOptionalInfo>} payload
* @param {TransferDomainInfo} info
* @param {string} info.address
* @param {string} info.amount
* @param {TransferDomainType} info.domain
* @param {string} [info.data] optional data, note: currently its not used
* @param {TransferDomainOptionalInfo} optionalInfo
* @param {boolean} [optionalInfo.singleKeyCheck=true]
* @return {Promise<string>}
*/
async transferDomain (payload: Array<Record<TransferDomainKey, TransferDomainInfo>>): Promise<string> {
async transferDomain (payload: Array<Record<TransferDomainKey, TransferDomainInfo> | Record<TransferDomainOptionalKey, TransferDomainOptionalInfo>>): Promise<string> {
return await this.client.call('transferdomain', [payload], 'number')
}

Expand Down Expand Up @@ -725,3 +731,7 @@ export interface TransferDomainInfo {
amount: string
domain: TransferDomainType
}

export interface TransferDomainOptionalInfo {
singleKeyCheck: boolean
}
2 changes: 1 addition & 1 deletion packages/testcontainers/src/containers/DeFiDContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export abstract class DeFiDContainer extends DockerContainer {
if (process?.env?.DEFICHAIN_DOCKER_IMAGE !== undefined) {
return process.env.DEFICHAIN_DOCKER_IMAGE
}
return 'defi/defichain:4.0.0' // renovate.json regexManagers
return 'defi/defichain:4.0.5' // renovate.json regexManagers
}

public static readonly DefaultStartOptions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
if (process?.env?.DEFICHAIN_DOCKER_IMAGE !== undefined) {
return process.env.DEFICHAIN_DOCKER_IMAGE
}
return 'defi/defichain:4.0.0' // renovate.json regexManagers
return 'defi/defichain:4.0.5' // renovate.json regexManagers

Check warning on line 32 in packages/testcontainers/src/containers/NativeChainContainer.ts

View check run for this annotation

Codecov / codecov/patch

packages/testcontainers/src/containers/NativeChainContainer.ts#L32

Added line #L32 was not covered by tests
}

public static readonly PREFIX = 'defichain-testcontainers-'
Expand Down